:root {
  --paper: #eee8dd;
  --paper-light: #f7f3eb;
  --surface: #f7f3eb;
  --paper-deep: #ddd3c3;
  --ink: #17241f;
  --muted: #667169;
  --line: #cfc3b2;
  --accent: #a84438;
  --accent-dark: #7d2f29;
  --night: #172b25;
  --green: #254139;
  --serif: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
::selection { color: var(--surface); background: var(--accent-dark); }
[hidden] { display: none !important; }

.skip-link {
  position: absolute;
  top: 8px;
  left: 12px;
  z-index: 10;
  padding: 8px 12px;
  color: var(--surface);
  background: var(--night);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  width: 100%;
  min-height: 64px;
  padding: 13px clamp(18px, 5vw, 76px);
  border-bottom: 1px solid rgba(207, 195, 178, .9);
  background: rgba(238, 232, 221, .94);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; width: max-content; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--accent); color: var(--accent); font-family: var(--serif); font-size: 17px; transform: rotate(-6deg); }
.brand-name { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.main-nav { display: flex; align-items: center; gap: 22px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.main-nav a { padding: 8px 0; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.main-nav a:hover, .main-nav a.is-current { color: var(--ink); border-color: var(--accent); }
.back-link { justify-self: end; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-decoration: none; text-transform: uppercase; }
.back-link:hover, .back-link:focus-visible { color: var(--accent-dark); }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.page-intro { max-width: 760px; padding: clamp(64px, 9vw, 112px) 0 70px; }
.eyebrow, .section-kicker { margin: 0 0 17px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; }
h1 { margin-bottom: 24px; font-size: clamp(46px, 7.3vw, 76px); letter-spacing: 0; line-height: .98; text-wrap: balance; }
h1 em { color: var(--accent); font-style: normal; }
.lede { max-width: 650px; margin-bottom: 0; color: var(--muted); font-size: 17px; line-height: 1.55; }

.screen { border-top: 1px solid var(--ink); }
.start-screen { padding: 45px 0 0; }
.screen-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .74fr); gap: clamp(48px, 9vw, 120px); align-items: start; }
.screen-copy h2, .results-head h2 { margin-bottom: 14px; font-size: clamp(31px, 4vw, 51px); letter-spacing: 0; line-height: 1; }
.screen-copy > p:not(.section-kicker):not(.today-count) { max-width: 360px; margin-bottom: 28px; color: var(--muted); font-size: 18px; line-height: 1.6; }
.today-count { display: flex; align-items: baseline; gap: 8px; margin: 0; color: var(--muted); font-size: 14px; }
.today-count strong { color: var(--accent-dark); font-family: var(--serif); font-size: 30px; font-weight: 500; }
.setup-form { display: grid; gap: 10px; padding: 0 0 44px 34px; border-left: 1px solid var(--line); }
.field-label, .quantity-group legend { color: var(--ink); font-size: 13px; font-weight: 800; }
.setup-form select { width: 100%; min-height: 49px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 0; color: var(--ink); background: var(--surface); cursor: pointer; }
.setup-form select:focus { border-color: var(--accent); outline: 2px solid rgba(201,95,73,.25); outline-offset: 2px; }
.field-meta { min-height: 21px; margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.quantity-group { margin: 0 0 13px; padding: 0; border: 0; }
.quantity-group legend { margin-bottom: 8px; }
.quantity-options { display: grid; grid-template-columns: repeat(3, 1fr); }
.quantity-option { min-height: 48px; border: 1px solid var(--line); border-right: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 15px; font-weight: 800; }
.quantity-option:last-child { border-right: 1px solid var(--line); }
.quantity-option:hover, .quantity-option:focus-visible { color: var(--accent-dark); background: var(--surface); }
.quantity-option.is-selected { color: var(--surface); border-color: var(--accent-dark); background: var(--accent-dark); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px; padding: 11px 17px; border: 1px solid transparent; border-radius: 0; cursor: pointer; font-size: 13px; font-weight: 800; letter-spacing: .06em; text-decoration: none; text-transform: uppercase; }
.button:disabled { cursor: not-allowed; opacity: .46; }
.button-primary { color: var(--surface); background: var(--accent-dark); }
.button-primary:hover:not(:disabled) { background: var(--night); }
.button-dark { color: var(--surface); background: var(--night); }
.button-dark:hover { background: var(--accent-dark); }
.form-status { min-height: 22px; margin: 1px 0 0; color: var(--accent-dark); font-size: 13px; font-weight: 700; }

.recent-details { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.recent-details summary { display: flex; justify-content: space-between; gap: 20px; padding: 17px 0; cursor: pointer; list-style: none; font-size: 16px; font-weight: 700; }
.recent-details summary::-webkit-details-marker { display: none; }
.summary-action { color: var(--accent-dark); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.recent-details[open] .summary-action span { display: inline-block; transform: rotate(45deg); }
.recent-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 25px; padding: 0 0 21px; }
.recent-row { display: grid; grid-template-columns: 1fr auto; gap: 13px; padding: 12px 0; border-top: 1px solid var(--line); }
.recent-row strong { display: block; font-family: var(--serif); font-size: 19px; font-weight: 500; }
.recent-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.recent-row .recent-words { max-width: 260px; overflow-wrap: anywhere; }
.recent-score { color: var(--accent-dark); font: 18px var(--serif); white-space: nowrap; }
.recent-empty { grid-column: 1 / -1; margin: 0; padding: 13px 0 2px; color: var(--muted); font-size: 13px; }
.sync-status { min-height: 20px; margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.sync-status[data-state="success"] { color: var(--green); }
.sync-status[data-state="warning"] { color: var(--accent-dark); }

.quiz-screen { padding: 28px 0 72px; }
.quiz-header { display: grid; grid-template-columns: auto 1fr; gap: 11px 28px; align-items: center; margin-bottom: 31px; }
.quiet-button { min-height: 44px; padding: 7px 0; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; font-weight: 800; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.quiet-button:hover, .quiet-button:focus-visible { color: var(--accent-dark); }
.progress-copy { display: flex; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 13px; font-weight: 700; }
.progress-copy span:last-child { color: var(--ink); }
.progress-track { grid-column: 1 / -1; height: 5px; overflow: hidden; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent-dark); transition: width 180ms ease; }
.question-card { max-width: 760px; padding: clamp(27px, 5vw, 48px); border: 1px solid var(--line); background: var(--surface); }
.question-meta { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 23px; color: var(--accent-dark); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.question-meta span:last-child { color: var(--muted); font-family: var(--serif); font-size: 21px; font-weight: 500; letter-spacing: 0; }
.question-card h2 { max-width: 590px; margin-bottom: 16px; font-size: clamp(28px, 3.2vw, 37px); line-height: 1.1; }
.definition { max-width: 600px; margin-bottom: 12px; color: var(--ink); font: 22px/1.35 var(--serif); }
.word-meta { min-height: 20px; margin-bottom: 27px; color: var(--muted); font-size: 13px; }
.answer-area { display: grid; gap: 10px; }
.choice { display: flex; align-items: center; width: 100%; min-height: 53px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 0; color: var(--ink); background: transparent; cursor: pointer; text-align: left; }
.choice:hover, .choice:focus-visible { border-color: var(--accent); background: #fff9f3; }
.choice.is-selected { color: var(--surface); border-color: var(--accent-dark); background: var(--accent-dark); }
.answer-label { display: block; color: var(--ink); font-size: 13px; font-weight: 800; }
.answer-input { width: 100%; min-height: 53px; margin-top: 8px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 0; color: var(--ink); background: var(--paper); font-size: 18px; }
.answer-input:focus { border-color: var(--accent); outline: 2px solid rgba(201,95,73,.25); outline-offset: 2px; }
.quiz-status { min-height: 23px; margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.quiz-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 17px; max-width: 760px; margin-top: 20px; }
.quiz-note { color: var(--muted); font-size: 12px; }

.results-screen { padding: 45px 0 72px; }
.results-head { max-width: 680px; }
.results-head h2 { margin-bottom: 11px; font-size: clamp(48px, 7vw, 72px); }
.results-message { margin: 0; color: var(--muted); font-size: 18px; line-height: 1.55; }
.skill-split { display: grid; grid-template-columns: repeat(2, minmax(0, 230px)); gap: 10px; margin: 37px 0 48px; }
.skill-stat { padding: 16px 17px 18px; border-top: 2px solid var(--accent-dark); background: var(--surface); }
.skill-stat span, .skill-stat small { display: block; }
.skill-stat span { margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.skill-stat strong { display: block; margin-bottom: 5px; color: var(--ink); font: 28px/1.1 var(--serif); font-weight: 500; }
.skill-stat small { color: var(--muted); font-size: 12px; }
.missed-section { max-width: 800px; }
.section-line { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--ink); }
.section-line h3 { margin: 0; font-size: 27px; }
.section-line span { color: var(--muted); font-size: 12px; }
.missed-list { display: grid; }
.missed-item { display: grid; grid-template-columns: minmax(150px, .55fr) minmax(0, 1fr) auto; gap: 21px; align-items: start; padding: 17px 0; border-bottom: 1px solid var(--line); }
.missed-term strong { display: block; font: 22px/1.15 var(--serif); font-weight: 500; overflow-wrap: anywhere; }
.missed-term small, .missed-definition small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.missed-definition p { margin: 0; color: var(--ink); font-size: 14px; line-height: 1.45; }
.missed-definition .chinese { color: var(--muted); }
.listen-button { min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 0; color: var(--accent-dark); background: transparent; cursor: pointer; font-size: 12px; font-weight: 800; }
.listen-button:hover, .listen-button:focus-visible { border-color: var(--accent); background: var(--paper); }
.results-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; margin-top: 31px; }
.load-error { margin: 38px 0; padding: 15px; border-left: 2px solid var(--accent); color: var(--accent-dark); background: var(--surface); font-size: 14px; }
.load-error button { margin-left: 8px; padding: 0; border: 0; color: inherit; background: transparent; cursor: pointer; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.footer { display: flex; justify-content: space-between; gap: 20px; width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 45px; color: var(--muted); font-size: 11px; }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; min-height: 62px; gap: 14px; padding-inline: 15px; }
  .main-nav { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; gap: 18px; width: 100%; border-top: 1px solid var(--line); }
  .main-nav a { padding: 11px 0 10px; font-size: 11px; }
  .back-link { font-size: 10px; }
  .page-shell, .footer { width: min(100% - 30px, 1180px); }
  .page-intro { padding: 59px 0 52px; }
  .lede { font-size: 16px; }
  .start-screen, .results-screen { padding-top: 33px; }
  .screen-grid { grid-template-columns: 1fr; gap: 31px; }
  .screen-copy > p:not(.section-kicker):not(.today-count) { font-size: 16px; }
  .setup-form { padding: 0 0 34px; border-left: 0; }
  .recent-list { grid-template-columns: 1fr; }
  .quiz-screen { padding: 21px 0 59px; }
  .quiz-header { grid-template-columns: 1fr; gap: 9px; }
  .quiz-header .quiet-button { justify-self: start; }
  .progress-copy { font-size: 12px; }
  .progress-track { grid-column: 1; }
  .question-card { padding: 24px 18px; }
  .definition { font-size: 20px; }
  .skill-split { grid-template-columns: 1fr 1fr; gap: 8px; margin: 30px 0 40px; }
  .skill-stat { padding: 13px 12px 15px; }
  .skill-stat strong { font-size: 24px; }
  .missed-item { grid-template-columns: 1fr auto; gap: 9px 14px; }
  .missed-definition { grid-column: 1 / -1; grid-row: 2; }
  .missed-item .listen-button { grid-column: 2; grid-row: 1; }
  .results-actions { align-items: flex-start; flex-direction: column; gap: 13px; }
  .footer { flex-direction: column; padding-bottom: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .progress-track span { transition: none; }
}
