:root {
  --paper: #f7f6f0;
  --white: #fffefa;
  --ink: #233b32;
  --muted: #5f6b62;
  --line: #dedfd3;
  --orange: #c54724;
  --orange-light: #fff0dc;
  --green: #227453;
  --sans: "Helvetica Neue", Arial, "PingFang HK", "Noto Sans CJK TC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }
a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--green); outline-offset: 4px; }
[hidden] { display: none !important; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 32px; line-height: 1.3; margin-bottom: 0; }
h2 { font-size: 22px; line-height: 1.4; }
kbd { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; background: #fafaf5; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 16px; top: 8px; z-index: 5; background: var(--white); padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; }

.site-shell { max-width: 1000px; padding: 0 32px 48px; margin: auto; }
.site-header { min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.back-link { display: inline-flex; align-items: center; gap: 6px; padding: 10px 0; color: var(--muted); font-size: 16px; text-decoration: none; }
.back-link:hover { color: var(--green); }
.game-badge { display: flex; align-items: center; gap: 8px; font-size: 14px; border: 1px solid var(--line); border-radius: 24px; padding: 4px 12px; white-space: nowrap; }
.game-badge > span { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.hero { padding: 32px 0 24px; }
.hero-note { margin: 8px 0 0; color: var(--muted); }
/* 官方三輪流程：頁頂橫額同完場嘅下一輪掣（?flow=1 專用，平時收埋）。 */
.flow-banner { margin: 24px 0 0; padding: 12px 16px; border: 1px solid #cfddc8; border-left: 4px solid var(--green); border-radius: 8px; background: #eaf1e5; font-size: 15px; }
.result-actions .flow-next { justify-content: center; text-decoration: none; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.panel h2 { margin-bottom: 12px; }
.rules { margin: 0; padding-left: 20px; }
.rules li + li { margin-top: 8px; }
.rules strong { color: var(--orange); }

.setup-panel form { display: flex; flex-direction: column; gap: 8px; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 8px; background: #e5e8dc; }
.segmented button { flex: 1; padding: 10px 20px; border: 0; border-radius: 5px; background: transparent; font-size: 16px; white-space: nowrap; }
.segmented button:hover { background: #dde1d0; }
.segmented button.selected { background: var(--white); }
.field-label { font-size: 14px; color: var(--muted); }
.field-note { margin: 0; font-size: 14px; color: var(--muted); }
.seed-input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); font-family: var(--mono); }
.seed-input::placeholder { font-family: var(--sans); color: #9aa39b; }
.start-button { margin-top: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 20px; border: 0; border-radius: 10px; background: var(--orange); color: var(--white); font-size: 18px; font-weight: 600; }
.start-button:hover { background: #a93a1d; }
#best-note { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.card { background: var(--white); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.card-topline { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.progress-label { font-weight: 600; }
.subtle { color: var(--muted); font-size: 14px; font-family: var(--mono); }
.time-track { height: 3px; background: #edeee5; }
.time-track > div { height: 100%; width: 0; background: var(--green); transition: width .15s linear; }
.play-body { padding: 24px; }

.typing-surface { position: relative; padding: 8px 0 4px; border-radius: 10px; }
.typing-surface:focus-visible { outline: 2px solid var(--green); outline-offset: 8px; }
body.playing .typing-surface { cursor: text; }
.word-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 0; padding: 0; list-style: none; }
.word-cell { display: flex; flex-direction: column; align-items: center; min-width: 104px; padding: 8px 4px 4px; border-bottom: 3px solid transparent; }
.word-cell.current { border-bottom-color: var(--orange); }
.cell-input { display: flex; align-items: center; justify-content: center; min-height: 34px; font-family: var(--mono); font-size: 22px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.cell-hanzi { font-size: 44px; font-weight: 600; line-height: 1.3; color: #89938b; }
.cell-typed { color: #202722; }
.cell-correct { padding: 0 2px; border-radius: 3px; background: #d7ebdc; color: #20643f; }
.cell-wrong { padding: 0 2px; border-radius: 3px; background: #f4dada; color: #a12e2e; text-decoration: line-through; text-decoration-thickness: 2px; }
.cell-pending { color: #b6bdb6; }
.word-cell.current .cell-hanzi { color: var(--orange); }
.word-cell.correct .cell-hanzi { color: var(--green); }
.word-cell.incorrect .cell-hanzi { color: #ad3323; text-decoration: underline wavy; text-decoration-thickness: 1px; text-underline-offset: 8px; }
.caret { display: inline-block; width: 2px; height: 24px; margin-left: 2px; background: var(--orange); animation: blink 1s steps(1, end) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.typing-capture { position: absolute; top: 0; left: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; font-size: 16px; pointer-events: none; }
.draft-line { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 12px 0 0; font-family: var(--mono); font-size: 20px; }
.draft-label { color: var(--muted); font-family: var(--sans); font-size: 14px; }
#draft { min-height: 28px; color: #202722; letter-spacing: 1px; }
.combo-line { display: flex; justify-content: center; gap: 12px; margin: 16px 0 0; font-size: 16px; }
#combo { font-weight: 600; }
.multiplier { padding: 2px 10px; border: 1px solid var(--line); border-radius: 24px; color: var(--muted); font-variant-numeric: tabular-nums; }
.multiplier.capped { border-color: #e5c99f; background: var(--orange-light); color: #805116; font-weight: 600; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.metric { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric-label { color: var(--muted); font-size: 14px; }
.metric strong { font-size: 30px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.feedback { margin: 20px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }

.result-panel { max-width: 720px; margin-inline: auto; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 24px; margin: 16px 0 0; }
.result-grid dt { color: var(--muted); font-size: 14px; }
.result-grid dd { margin: 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
#result-detail { font-size: 18px; }
.result-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 16px 24px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.result-actions .start-button { margin-top: 0; font-size: 16px; padding: 12px 18px; }

@media (max-width: 760px) {
  .site-shell { padding: 0 18px 32px; }
  .site-header { min-height: 72px; }
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
  .word-cell { min-width: 88px; }
  .cell-hanzi { font-size: 38px; }
  .metrics { grid-template-columns: repeat(2, 1fr); gap: 16px 0; }
  .metric:nth-child(3) { border-left: 0; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
}
