/* 탁상시계 PWA 전체 스타일 — 색·크기를 CSS 변수로 두어 야간 디밍/무드등에서 재사용한다 */

:root {
  --bg: #000000;
  --fg: #e9ecf3;
  --dim: #6b7280;
  --accent: #ffb05c;
  --panel: #14161c;
  --panel-2: #1c1f27;
  --line: #2a2f3a;
  --card: #1a1c22;

  /* 번인 방지용 미세 이동값. 2단계에서 주기적으로 갱신한다 */
  --shift-x: 0px;
  --shift-y: 0px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* ── 시계 무대 ───────────────────────────────────────── */

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#shift {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(var(--shift-x), var(--shift-y));
  transition: transform 1.2s ease-in-out;
}

.clock {
  position: relative;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  line-height: 1;
  white-space: nowrap;
}

.date {
  color: #98a1b3;
  letter-spacing: 0.02em;
  font-size: clamp(16px, 3.6vh, 34px);
  margin-top: 0.9em;
}

.date[hidden] { display: none; }

/* 디지털 — 기본. 거치해두고 멀리서 보는 용도라 크고 진하게 잡는다 */
.clock.face-digital {
  font-size: min(34vw, 54vh);
  font-weight: 500;
  letter-spacing: -0.02em;
}
.clock.face-digital.with-seconds { font-size: min(23vw, 38vh); }

/* 미니멀 — 상대적으로 얇고 넓게 */
.clock.face-minimal {
  font-size: min(33vw, 52vh);
  font-weight: 200;
  letter-spacing: 0.06em;
  color: #eef1f7;
}
.clock.face-minimal.with-seconds { font-size: min(22vw, 37vh); }

/* 오전/오후 — 시계 위쪽에 띄운다. 숫자 폭에 영향을 주지 않아 시계가 늘 정중앙에 온다 */
.meridiem {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 0.5em;
  font-size: 0.2em;
  font-weight: 400;
  color: var(--dim);
  letter-spacing: 0.08em;
}

/* 콜론 — 초 표시가 꺼져 있으면 1초마다 은은히 깜빡인다 */
.colon { color: #9aa3b2; }
.colon.blink { animation: colon-blink 2s steps(1, end) infinite; }
@keyframes colon-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0.25; }
}

/* ── 플립 시계 ───────────────────────────────────────── */

.clock.face-flip {
  display: flex;
  align-items: center;
  font-size: min(22vw, 36vh);
  font-weight: 600;
}
.clock.face-flip.with-seconds { font-size: min(15vw, 28vh); }

.flip-group { display: flex; gap: 0.08em; }

.flip-sep {
  color: var(--dim);
  font-size: 0.46em;
  padding: 0 0.14em;
}

/* 카드를 글자보다 조금 크게 잡아 위아래 여백을 만든다 */
.flip-digit {
  position: relative;
  width: 0.75em;
  height: 1.1em;
  perspective: 900px;
}

.flip-digit .half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: var(--card);
  backface-visibility: hidden;
}

.flip-digit .half.top {
  top: 0;
  border-radius: 0.08em 0.08em 0 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.55);
}
.flip-digit .half.bottom {
  bottom: 0;
  border-radius: 0 0 0.08em 0.08em;
}

.flip-digit .half > span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 1.1em;      /* 카드 높이와 같게. 글자가 카드 안에서 세로 중앙에 온다 */
  line-height: 1.1em;
  text-align: center;
}
.flip-digit .half.top > span { top: 0; }
/* -100%는 반쪽(카드 높이의 절반)의 100%다. -50%로 두면 숫자 아래쪽이 반만 밀려 어긋난다 */
.flip-digit .half.bottom > span { top: -100%; }

/* 넘어가는 두 장 */
.flip-digit .half.fold {
  z-index: 2;
  transform-origin: bottom;
  animation: fold-down 0.26s cubic-bezier(0.36, 0, 0.66, 0.3) forwards;
}
.flip-digit .half.unfold {
  z-index: 2;
  transform-origin: top;
  transform: rotateX(90deg);
  animation: unfold-down 0.26s cubic-bezier(0.34, 0.7, 0.64, 1) 0.26s forwards;
}

@keyframes fold-down {
  from { transform: rotateX(0deg); }
  to   { transform: rotateX(-90deg); }
}
@keyframes unfold-down {
  from { transform: rotateX(90deg); }
  to   { transform: rotateX(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .flip-digit .half.fold,
  .flip-digit .half.unfold { animation-duration: 0.01s; animation-delay: 0s; }
  .colon.blink { animation: none; }
  #shift { transition: none; }
}

/* ── 하단 컨트롤 바 ──────────────────────────────────── */

.hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px calc(18px + env(safe-area-inset-right))
           calc(14px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}
.hud.visible { opacity: 1; transform: none; pointer-events: auto; }

.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(28, 31, 39, 0.9);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.hud-btn:active { background: var(--panel-2); }
.hud-btn[hidden] { display: none; }
.hud-btn svg { width: 20px; height: 20px; fill: currentColor; }

.hud-left { display: flex; align-items: center; gap: 10px; }

.hud-status { display: flex; align-items: center; }

.wake-status {
  font-size: 13px;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.wake-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}
.wake-status.on::before { background: #4ade80; }
.wake-status.off::before { background: #6b7280; }
.wake-status.fail::before { background: #f87171; }

/* ── 설정 패널 ───────────────────────────────────────── */

.panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: panel-in 0.22s ease;
}
.panel[hidden] { display: none; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.panel-head h1 { margin: 0; font-size: 19px; font-weight: 600; }

.panel-close {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.panel-close:active { background: var(--panel-2); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 22px 28px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

.field {
  display: block;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.field.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.field-label { font-size: 16px; }

.field-help {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--dim);
}
.field-help:empty { display: none; }

/* 세그먼트 선택 */
.seg {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.seg button {
  flex: 1 1 auto;
  min-width: 96px;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--panel-2);
  border-color: var(--accent);
  color: var(--fg);
}

/* 토글 스위치 */
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 54px;
  height: 32px;
  margin: 0;
  border-radius: 999px;
  background: #343a46;
  position: relative;
  cursor: pointer;
  transition: background 0.18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(22px); }

/* ── 알림 문구 ───────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 10px);
  z-index: 30;
  max-width: min(88vw, 460px);
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(32, 36, 45, 0.96);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
