/* 색상 토큰 · 공통 요소 */
:root {
  --bg: #e3e9ee;
  --surface: #f8fafb;
  --surface-2: #edf1f4;
  --line: #d0d9e0;
  --text: #1c2731;
  --muted: #5a6875;
  --faint: #8592a0;
  --accent: #d4612a;
  --accent-ink: #ffffff;
  --accent-soft: #f8e2d5;
  --accent-text: #b04d1a;
  --track: #d5dde4;
  --bad-bg: #fbe2df;  --bad: #b02a20;
  --mid-bg: #f9eecd;  --mid: #855800;
  --good-bg: #dbf0e1; --good: #1c703e;
  --shadow: 0 1px 2px rgba(28, 42, 56, .05), 0 6px 20px rgba(28, 42, 56, .06);
  --ko: "IBM Plex Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs: 1;   /* 글자 크기 배율 — 상단 가−/가+ 버튼이 바꾼다 */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a20;
    --surface: #1c252d;
    --surface-2: #232e37;
    --line: #313e4a;
    --text: #e4eaef;
    --muted: #9cabb8;
    --faint: #6e7d8a;
    --accent: #ec7b40;
    --accent-ink: #1b0f07;
    --accent-soft: #3a2519;
    --accent-text: #f59c68;
    --track: #2c3843;
    --bad-bg: #3a1d1b;  --bad: #ff9c90;
    --mid-bg: #352a12;  --mid: #f0c75e;
    --good-bg: #16301f; --good: #80d69c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ko);
  font-size: calc(16px * var(--fs));
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: 0; border-radius: 14px; padding: 15px 16px;
  font-size: calc(17px * var(--fs)); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:active { filter: brightness(.94); }
.btn.primary:disabled { background: var(--track); color: var(--faint); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn .num { font-family: var(--mono); }

.sect { margin: 26px 0 10px; font-size: calc(13px * var(--fs)); font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.note { margin-top: 10px; font-size: calc(12.5px * var(--fs)); color: var(--faint); }

/* 학습·가이드 화면 상단 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.back { border: 0; background: none; padding: 6px 2px; font-size: calc(15px * var(--fs)); font-weight: 600; color: var(--muted); }

.kbd {
  display: none; font-family: var(--mono); font-size: calc(11px * var(--fs)); font-weight: 500;
  padding: 0 5px; border-radius: 4px; border: 1px solid currentColor; opacity: .6;
}
@media (hover: hover) and (pointer: fine) { .kbd { display: inline-block; } }

.loading, .error { padding: 40px 0; text-align: center; color: var(--muted); }
.error .btn { margin-top: 16px; }

.btn.secondary { background: var(--surface); color: var(--accent-text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.btn.secondary:active { background: var(--surface-2); }
.btn.secondary:disabled { color: var(--faint); box-shadow: none; }

/* 글자 크기 조절 (모든 화면 상단) */
.fontctl { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.fontctl button {
  border: 0; background: transparent; color: var(--muted); font-weight: 700; line-height: 1;
  width: 40px; height: 34px; display: grid; place-items: center;
}
.fontctl button + button { border-left: 1px solid var(--line); }
.fontctl .s { font-size: 13px; }
.fontctl .l { font-size: 18px; }
.fontctl button:disabled { opacity: .35; }
.fontctl button:active:not(:disabled) { background: var(--line); }
.topbar .right { display: flex; align-items: center; gap: 10px; }

/* 새 버전 알림 */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(528px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  font-size: calc(14.5px * var(--fs)); z-index: 10;
}
.toast button {
  flex: none; border: 0; border-radius: 10px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: calc(14px * var(--fs));
}
.toast .x { background: transparent; color: inherit; opacity: .7; padding: 8px; }
