:root {
  --bg: #0b0d10;
  --bg-elev: #15181d;
  --fg: #e8ecef;
  --muted: #8a93a0;
  --accent: #4aa3ff;
  --danger: #ff6b6b;
  --ok: #49d17a;
  --border: rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.14);
  --radius: 14px;
  --notes-size: 28px;                 /* 10인치 태블릿 기준 기본 크게 */
  --topbar-h: 80px;                   /* 기본 상단바 (iframe 모드) */
  --topbar-h-compact: 96px;           /* compact 모드 상단바 (시계/카운트다운 포함) */
  --timer-h: 260px;                   /* iframe 모드 타이머 높이 */
  --timer-scale: 1;                   /* iframe 배율 */
  --remote-h: 96px;                   /* 고정 하단 리모컨 높이 예약 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* ── 홈 페이지 ──────────────────────────────────── */
body.home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}
.home-wrap {
  width: min(92vw, 420px);
  padding: 28px 24px 32px;
  background: var(--bg-elev);
  border-radius: 18px;
  text-align: center;
}
.home-title {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: 0.5px;
}
.home-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
}
.home-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.home-form input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  font-size: 22px;
  text-align: center;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
.home-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.home-form button {
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.home-form button:active { transform: scale(0.98); filter: brightness(0.92); }
.home-err {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* ── 상단 채널 배지 (뷰어) ─────────────────────── */
.ch-badge {
  margin-left: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(74,163,255,.15);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR",
               "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── 상단 바 (화면 상단에 고정) ───────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid rgba(255,255,255,.06);
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
}
.progress {
  display: flex; align-items: baseline;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}
.progress .big {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1;
}
.progress .sep {
  font-size: 32px; color: var(--muted);
}
.progress .label {
  margin-left: 14px;
  font-size: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tools {
  display: flex; gap: 8px;
  flex-shrink: 0;
}
.tool {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 18px;
  cursor: pointer;
  min-width: 46px;
  min-height: 46px;
}
.tool:active { transform: scale(0.96); }

/* ── 타이머 iframe (기본 = 큰 모드, 상단바 아래 고정) ──── */
.timer-frame {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  height: var(--timer-h);
  z-index: 10;
  background: var(--bg-elev);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.timer-frame.hidden { display: none; }
.timer-scaler {
  position: absolute; inset: 0;
  overflow: hidden;
}
.timer-scaler iframe {
  border: 0;
  display: block;
  transform: scale(var(--timer-scale));
  transform-origin: top left;
  width:  calc(100% / var(--timer-scale));
  height: calc(100% / var(--timer-scale));
}

/* ── Compact 모드: iframe 을 상단바의 flex 항목으로 삽입 ──
   JS 가 <header class="topbar"> 안 tools 앞에 .timer-frame 을 insertBefore 함.
   여기서는 fixed 포지셔닝을 끊고 flex child 로 동작하게 override. */
body.timer-compact {
  --topbar-h: var(--topbar-h-compact);
}
body.timer-compact .timer-frame {
  /* position: relative 로 해야 자식 .timer-scaler(position:absolute;inset:0)
     가 이 요소 기준으로 크기를 잡음. static 이면 scaler 크기가 0 이 됨. */
  position: relative;
  top: auto; left: auto; right: auto; bottom: auto;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 560px;
  height: calc(var(--topbar-h) - 16px);
  margin: 0 12px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
}
body.timer-compact .notes {
  /* iframe 이 상단바 안으로 들어갔으니 노트는 상단바 바로 아래 */
  top: var(--topbar-h);
}

/* ── 노트 본문 (상단바 아래부터 리모컨 위까지) ───── */
.notes {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: var(--remote-h);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px 24px 36px;
  font-size: var(--notes-size);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
body.no-remote .notes {
  /* 리모컨 숨겨졌을 때 바닥까지 확장 */
  bottom: 0;
  padding-bottom: calc(24px + var(--safe-bot));
}
.notes .placeholder {
  color: var(--muted);
  font-size: 22px;
  text-align: center;
  padding-top: 18vh;
}

/* ── 리모컨 (화면 하단에 고정) ─────────────────────── */
.remote {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  gap: 14px;
  padding: 14px 16px calc(14px + var(--safe-bot));
  background: var(--bg-elev);
  border-top: 1px solid rgba(255,255,255,.06);
}
.remote.hidden { display: none; }
.rbtn {
  flex: 1;
  min-height: 68px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
}
.rbtn:active { transform: scale(0.98); filter: brightness(0.9); }

/* ── 설정 다이얼로그 ────────────────────────────────── */
.settings {
  border: none;
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 20px 22px;
  width: min(92vw, 420px);
}
.settings::backdrop { background: rgba(0,0,0,.55); }
.settings h2 { margin: 0 0 12px; font-size: 18px; }
.settings .row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-top: 1px solid rgba(255,255,255,.06);
}
.settings .row:first-of-type { border-top: none; }
.settings .row.col {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.settings .row.section {
  border-top: none;
  padding: 16px 0 6px;
}
.settings .section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.settings input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font-size: 16px;
}
.settings input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.settings .hint {
  color: var(--muted);
  font-size: 12px;
}
.settings .stepper {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.settings .stepper-value {
  min-width: 54px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.settings .dot {
  margin-left: auto;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.settings .dot.ok     { background: var(--ok); }
.settings .dot.err    { background: var(--danger); }

/* ── 반응형 ───────────────────────────────────────── */
/* 태블릿(>=768px): 여유있게 */
@media (min-width: 768px) {
  :root { --notes-size: 30px; --topbar-h: 92px; --remote-h: 104px; }
  .progress .big { font-size: 52px; }
  .progress .sep { font-size: 36px; }
  .rbtn { font-size: 28px; min-height: 76px; }
}

/* 대형 태블릿(>=1000px) */
@media (min-width: 1000px) {
  :root { --notes-size: 32px; }
}

/* 좁은 세로 화면 (폰 등) */
@media (max-width: 520px) {
  .progress .big { font-size: 34px; }
  .progress .sep { font-size: 24px; }
  .ch-badge { display: none; }
  body.timer-compact .timer-frame {
    margin: 0 8px;
  }
}
