:root {
  --paper: #f4f1e8;
  --ink: #17181d;
  --night: #111218;
  --muted: #6f716f;
  --line: #d2cfc5;
  --yellow: #ffd83d;
  --coral: #ff7048;
  --lime: #baff29;
  --display: "Arial Black", "Pretendard Variable", Pretendard, sans-serif;
  --body: "Pretendard Variable", Pretendard, "Noto Sans KR", Arial, sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { min-width: 320px; min-height: 100svh; display: flex; flex-direction: column; margin: 0; color: var(--ink); background: var(--paper); font-family: var(--body); }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }

.top { display: flex; align-items: baseline; gap: 16px; padding: 18px 24px; border-bottom: 2px solid var(--ink); }
.home { color: var(--muted); font: 800 11px var(--display); text-decoration: none; letter-spacing: .06em; }
.home:hover { color: var(--ink); }
.wordmark { font: 900 19px var(--display); letter-spacing: .02em; }
.wordmark b { color: transparent; -webkit-text-stroke: 1.4px var(--ink); }
.top-note { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 700; }

main { flex: 1; width: min(760px, 100% - 40px); margin: 0 auto; }

/* 화면 전환: body[data-screen]이 스위치다. */
.screen { display: none; padding: 40px 0 60px; }
body[data-screen="ready"] .screen-ready,
body[data-screen="run"] .screen-run,
body[data-screen="done"] .screen-done { display: block; }

.eyebrow { margin: 0; color: var(--coral); font-size: 11px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 12px 0 0; font: 900 clamp(40px, 8vw, 64px)/1.04 var(--display); }
.lead { margin: 20px 0 0; color: #4c4e53; font-size: 15px; line-height: 1.75; }

.duration-row { display: flex; gap: 8px; margin-top: 30px; }
.duration { min-height: 42px; padding: 0 20px; border: 2px solid var(--ink); border-radius: 999px; background: transparent; font-size: 14px; font-weight: 800; transition: background .15s ease, transform .15s ease; }
.duration:hover { transform: translateY(-1px); }
.duration.is-active { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }

.mode-row { display: flex; gap: 8px; margin-top: 12px; }
.mode { min-height: 40px; padding: 0 16px; border: 2px dashed var(--line); border-radius: 999px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 800; transition: border-color .15s ease, color .15s ease; }
.mode.is-active { border-style: solid; border-color: var(--ink); color: var(--ink); background: #fffdf6; }

/* 받아쓰기 진행 패널: 문장 대신 이 패널이 보인다. */
.dictation-panel { display: none; align-items: center; gap: 14px; min-height: 74px; margin-top: 34px; padding: 16px 20px; border: 2px dashed var(--ink); background: #fffdf6; }
body[data-run-mode="dictation"] .dictation-panel { display: flex; }
body[data-run-mode="dictation"] .sentence, body[data-run-mode="dictation"] .sentence-next { display: none; }
.dict-icon { font-size: 26px; }
.dictation-panel p { margin: 0; flex: 1; font-size: 15px; font-weight: 700; }
.dict-replay { margin: 0; min-height: 40px; }

.start-btn { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; margin-top: 22px; padding: 0 26px; border: 2px solid var(--ink); background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 850; transition: transform .15s ease, box-shadow .15s ease; }
.start-btn:hover { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--yellow); }
.ghost-btn { min-height: 52px; margin-top: 22px; padding: 0 20px; border: 2px solid var(--ink); background: transparent; color: var(--ink); font-size: 14px; font-weight: 800; }
.ghost-btn:hover { background: #fffdf6; }
.ready-best { margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.ready-best b { color: var(--ink); font-family: var(--mono); }

/* 리더보드 */
.board { margin-top: 56px; }
.board header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 2px solid var(--ink); }
.board h2 { margin: 0; font: 900 18px var(--display); }
.board h2 span { color: var(--coral); }
.board-note { color: var(--muted); font-size: 11px; font-weight: 700; }
.board-note b { font-family: var(--mono); }
.board-list { margin: 0; padding: 0; list-style: none; }
.board-list li { display: grid; grid-template-columns: 34px 1fr auto auto; align-items: baseline; gap: 14px; padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.board-list li.is-you { background: #fff7d6; outline: 2px solid var(--yellow); outline-offset: -2px; }
.board-list i { font: 800 12px var(--mono); font-style: normal; color: var(--muted); }
.board-list li:nth-child(1) i, .board-list li:nth-child(2) i, .board-list li:nth-child(3) i { color: var(--coral); }
.board-list .b-name { overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.board-list .b-cpm { font: 700 15px var(--mono); }
.board-list .b-cpm small { color: var(--muted); font-size: 10px; }
.board-list .b-acc { color: var(--muted); font: 700 11px var(--mono); }
.board-empty { color: var(--muted); font-size: 13px; }

/* 진행 화면 */
.run-top { display: flex; gap: 34px; margin-top: 6px; }
.run-stat span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.run-stat b { font: 700 30px/1.2 var(--mono); }
.run-stat:first-child b { color: var(--coral); }
.time-bar { height: 6px; margin-top: 14px; background: #e6e2d6; }
.time-bar i { display: block; height: 100%; background: var(--yellow); transform-origin: left; }

.sentence { min-height: 74px; margin-top: 34px; font-size: clamp(20px, 3.4vw, 27px); font-weight: 650; line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere; }
.sentence .ok { color: var(--ink); }
.sentence .bad { color: var(--coral); background: #ffe3d9; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.sentence .now { background: var(--yellow); }
.sentence .todo { color: #b4b1a6; }
.sentence-next { margin-top: 10px; color: #b4b1a6; font-size: 15px; word-break: keep-all; }

#typing { width: 100%; margin-top: 26px; padding: 14px 16px; border: 2px solid var(--ink); border-radius: 0; background: #fffdf6; color: var(--ink); font-family: var(--body); font-size: 19px; }
#typing:focus { outline: 3px solid var(--yellow); outline-offset: 2px; }
.run-hint { margin: 12px 0 0; color: var(--muted); font-size: 11px; }
.run-hint kbd { padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; background: #fffdf6; font-family: var(--mono); font-size: 10px; }

/* 결과 화면 */
.done-cpm { margin: 10px 0 0; font: 700 clamp(64px, 13vw, 108px)/1 var(--mono); letter-spacing: -.02em; }
.done-cpm small { margin-left: 8px; color: var(--muted); font-size: 18px; font-family: var(--body); font-weight: 800; }
.done-badge { display: inline-block; margin: 14px 0 0; padding: 6px 12px; background: var(--yellow); font-size: 13px; font-weight: 850; box-shadow: 3px 3px 0 var(--ink); }
.done-stats { display: flex; gap: 34px; margin: 30px 0 0; }
.done-stats dt { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.done-stats dd { margin: 2px 0 0; }
.done-stats b { font: 700 24px var(--mono); }
.done-stats small { margin-left: 2px; color: var(--muted); font-size: 11px; }

.spark { display: flex; align-items: flex-end; gap: 5px; height: 56px; margin-top: 28px; }
.spark i { flex: 0 0 14px; min-height: 4px; background: #e0dccd; }
.spark i.is-last { background: var(--yellow); outline: 2px solid var(--ink); outline-offset: -2px; }

.register { margin-top: 34px; }
.register label { display: block; font-size: 12px; font-weight: 850; text-transform: uppercase; }
.register-row { display: flex; gap: 8px; margin-top: 8px; }
#callsign { flex: 1; max-width: 260px; padding: 11px 13px; border: 2px solid var(--ink); background: #fffdf6; font-family: var(--body); font-size: 15px; }
#callsign:focus { outline: 3px solid var(--yellow); outline-offset: 2px; }
#register-btn { padding: 0 20px; border: 2px solid var(--ink); background: var(--yellow); font-size: 14px; font-weight: 850; }
#register-btn:disabled { opacity: .5; cursor: default; }
.register-result { margin: 10px 0 0; font-size: 14px; font-weight: 750; }
.register-result b { color: var(--coral); font-family: var(--mono); }

.done-actions { display: flex; gap: 10px; }

.foot { display: flex; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 700; }

@media (max-width: 560px) {
  .top { padding: 14px 16px; gap: 10px; }
  .top-note { display: none; }
  main { width: calc(100% - 32px); }
  .screen { padding: 28px 0 48px; }
  .run-top { gap: 22px; }
  .run-stat b { font-size: 24px; }
  .done-stats { gap: 22px; }
  .board-list li { grid-template-columns: 26px 1fr auto; }
  .board-list .b-acc { display: none; }
  .done-actions { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
