:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --bg-grad: radial-gradient(1200px 600px at 50% -200px, #eef1ff 0%, transparent 60%);
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e8ee;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-fill: #e0e7ff;
  --accent-fill-2: #c7d2fe;
  --accent-ink: #4338ca;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --ok-line: #a7f3d0;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --bad-line: #fecaca;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-line: #fde68a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --ring: 0 0 0 3px rgba(99, 102, 241, 0.28);
}

/* Grayscale (灰度 100%) toggle, applied on <html>. */
html.grayscale { filter: grayscale(100%); }
/* In grayscale mode, keep the card's word/gloss readable but lighter. */
html.grayscale .prompt,
html.grayscale .reveal,
html.grayscale .dict-word,
html.grayscale .wm-word,
html.grayscale .wm-sense__gloss,
html.grayscale .fb-ans b {
  font-weight: 400;
  color: var(--muted);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-repeat: no-repeat;
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent-fill), var(--accent-fill-2));
  color: var(--accent-ink); font-size: 15px; font-weight: 800;
  box-shadow: var(--shadow-sm);
}
.brand h1 { font-size: 17px; margin: 0; }

.shell { max-width: 720px; margin: 0 auto; padding: 28px 20px 72px; }
.shell--center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 16px; }

h2 { font-size: 15px; margin: 0 0 14px; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: 10px; }

/* buttons */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn--primary { background: var(--accent-fill); border-color: var(--accent-fill-2); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-fill-2); border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

/* toggle switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  background: var(--line);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent-fill-2); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch-text { font-size: 14px; color: var(--ink); }

/* inputs */
.input, .select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: block; }

/* stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  text-align: center;
}
.stat b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat small { display: block; margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.stat--accent b { color: var(--accent); }
.stat--link { cursor: pointer; font: inherit; color: inherit; -webkit-appearance: none; appearance: none; }
.stat--link:hover { border-color: var(--accent); }

/* next-7-days due list */
.due-list { list-style: none; margin: 0; padding: 0; }
.due-list li { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.due-list li:last-child { border-bottom: 0; }
.due-list span { color: var(--muted); font-size: 13px; }
.due-list b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}
.chip--accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* prompt */
.prompt {
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 6px 0 22px;
  word-break: break-word;
}
.prompt--zh { font-size: clamp(24px, 5vw, 34px); }
.pos-tag { color: var(--muted); font-size: 0.6em; font-weight: 700; vertical-align: 0.15em; }

/* dictionary link */
.dict-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: -14px 0 20px; }
.phon { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dict-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  transition: border-color 0.15s, background 0.15s;
}
.dict-link:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); background: var(--accent-soft); }
.dict-link:focus-visible { outline: none; box-shadow: var(--ring); }
.dict-link__arrow { font-size: 11px; opacity: 0.75; }
.feedback .fb-ans .dict-link { margin-left: 8px; vertical-align: middle; }

/* recently studied (gloss hidden until clicked) */
.recall { display: grid; }
.recall-item {
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.recall-item:first-child { border-top: 0; }
.recall-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.recall-main { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.recall-word {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  border-bottom: 2px dotted color-mix(in srgb, var(--accent) 40%, var(--line));
  transition: color 0.15s, border-color 0.15s;
}
.recall-word:hover { color: var(--accent); border-bottom-color: var(--accent); }
.recall-word:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }
.recall-item.is-open .recall-word { color: var(--accent); border-bottom-color: transparent; }
.recall-phon { font-size: 13px; color: var(--muted); }
.phon-pos { font-weight: 600; opacity: 0.85; font-style: normal; }
.recall-meta { display: flex; align-items: center; gap: 8px; flex: none; }
.recent-time { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.recall-gloss {
  position: relative;
  margin-top: 8px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.55;
  overflow: hidden;
}
.recall-item:not(.is-open) .recall-gloss { cursor: pointer; user-select: none; }
.recall-item:not(.is-open) .recall-gloss-text { visibility: hidden; }
.recall-item:not(.is-open) .recall-gloss::after {
  content: "点击显示释义";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

/* word list / search */
.wordlist { display: grid; }
.word-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.word-row:first-child { border-top: 0; }
.word-row__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.word-row__word {
  font-weight: 700;
  font-size: 15.5px;
  color: var(--ink);
  text-decoration: none;
}
.word-row__word:hover { color: var(--accent); }
.word-row__word .dict-link__arrow { font-size: 11px; opacity: 0.55; margin-left: 2px; }
.word-row__gloss { position: relative; font-size: 13.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.word-slot { position: relative; display: inline-flex; align-items: center; }

/* masked fields in the word list: covered until the row is clicked */
.cover {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  white-space: nowrap;
  cursor: pointer;
}
.cover:hover { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.word-row.mask-en:not(.is-revealed) .word-slot { min-width: 78px; }
.word-row.mask-en:not(.is-revealed) .word-row__word { visibility: hidden; }
.word-row.mask-en:not(.is-revealed) .recall-phon { visibility: hidden; }
.word-row.mask-en:not(.is-revealed) .cover--word { display: flex; }
.word-row.mask-zh:not(.is-revealed) .word-row__gloss-text { visibility: hidden; }
.word-row.mask-zh:not(.is-revealed) .cover--gloss { display: flex; }
.word-row__action { margin-left: auto; }
.btn--sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.list-toggle.is-in {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--accent-soft);
}

/* dictation */
.dict-count { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.dict-word {
  font-size: clamp(34px, 8vw, 56px);
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 10px 0 6px;
  min-height: 1.2em;
  word-break: break-word;
}
/* study card: fixed height, scrollable content, pinned actions */
.card.study {
  display: flex;
  flex-direction: column;
  height: clamp(360px, 72vh, 620px);
}
.study-main { flex: 1 1 auto; overflow-y: auto; }
.study-actions { flex: none; margin-top: 16px; }
/* Match the grade buttons' height to the block buttons so switching between
   states does not nudge the buttons. */
.study-actions .grade { padding-top: 11px; padding-bottom: 11px; }
.study-foot { margin-top: 14px; }
/* The key hint gets its own line with a reserved height, so a hint that wraps
   on a narrow screen cannot resize the action area and shift the buttons. */
.study-hint { margin: 10px 0 0; min-height: 1.5em; }
@media (max-width: 560px) {
  .study-hint { min-height: 3.2em; }
}

.dict-icon { font-size: 0.5em; opacity: 0.45; }
.dict-gloss { font-size: 15px; color: var(--muted); min-height: 1.4em; }

/* options */
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.option + .option { margin-top: 10px; }
.option:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); background: var(--surface-2); }
.option:active { transform: translateY(1px); }
.option:focus-visible { outline: none; box-shadow: var(--ring); }
.option .key {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.option.is-correct { border-color: var(--ok-line); background: var(--ok-soft); }
.option.is-wrong { border-color: var(--bad-line); background: var(--bad-soft); }
.option:disabled { cursor: default; opacity: 1; }
.option:disabled:hover { background: var(--surface); border-color: var(--line); }
.option.is-correct:disabled:hover { background: var(--ok-soft); }
.option.is-wrong:disabled:hover { background: var(--bad-soft); }

/* self-assessment reveal */
.reveal {
  font-size: clamp(20px, 4.5vw, 26px);
  font-weight: 650;
  line-height: 1.5;
  letter-spacing: -0.01em;
  padding: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
/* bilingual example sentence under the revealed answer */
.example {
  margin: -4px 0 16px;
  padding: 0 4px;
  border-left: 3px solid var(--line);
}
.example-en { font-size: 16px; line-height: 1.55; color: var(--ink); }
.example-zh { font-size: 15px; line-height: 1.55; color: var(--muted); margin-top: 2px; }
.example--hint {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}
.example--hint .example-zh { margin-top: 0; font-size: 15px; }

.grade-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grade { width: 100%; padding: 14px 8px; }
.grade--ok { border-color: var(--ok-line); color: var(--ok); }
.grade--ok:hover { background: var(--ok-soft); border-color: var(--ok); }
.grade--mid { color: var(--ink); }
.grade--mid:hover { background: var(--surface-2); }
.grade--bad { border-color: var(--bad-line); color: var(--bad); }
.grade--bad:hover { background: var(--bad-soft); border-color: var(--bad); }

/* feedback */
.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.feedback.ok { border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.feedback.bad { border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }
.feedback.close { border-color: var(--warn-line); background: var(--warn-soft); color: var(--warn); }
.feedback .fb-head { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.feedback .fb-ans { color: var(--ink); margin-top: 6px; }
.feedback .fb-ans b { font-weight: 750; }
.feedback .fb-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.feedback .row { margin-top: 12px; }
.override { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin-top: 10px; }
.override input { width: 16px; height: 16px; accent-color: var(--accent); }

/* views */
.view { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.view:first-child { border-top: 0; padding-top: 0; }
.view .view-label { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.view h1, .view h2, .view h3 { font-size: 16px; margin: 10px 0 8px; }
.view table { border-collapse: collapse; width: 100%; font-size: 13.5px; display: block; overflow-x: auto; }
.view th, .view td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; white-space: nowrap; }
.view th { background: var(--surface-2); font-weight: 700; }
.view p { margin: 8px 0; }
.view code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; font-size: 0.9em; }

/* misc */
.hint { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.error { color: var(--bad); font-size: 14px; margin-top: 10px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.center { text-align: center; }
kbd {
  font: inherit; font-size: 12px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; color: var(--muted);
}

/* semantic fields */
.field-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.field-chip { padding: 8px 12px; }
.field-chip .muted { font-weight: 500; }
.field-cluster { border-top: 1px solid var(--line); padding: 8px 0; }
.field-cluster:first-of-type { border-top: 0; }
.field-cluster > summary { cursor: pointer; font-weight: 650; color: var(--accent); }
.field-cluster[open] > summary { margin-bottom: 8px; }

/* collapsible field categories */
.field-cat { border-top: 1px solid var(--line); padding: 10px 0; }
.field-cat:first-child { border-top: 0; }
.field-cat > summary {
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  gap: 10px; font-weight: 650; font-size: 16px; list-style: none;
}
.field-cat > summary::-webkit-details-marker { display: none; }
.field-cat > summary::before { content: "▸"; color: var(--accent); margin-right: 6px; }
.field-cat[open] > summary::before { content: "▾"; }
.field-cat__name { flex: 1; }
.field-cat[open] > summary { margin-bottom: 8px; }
.field-cat .wordlist { margin-top: 4px; }

/* word-detail modal */
body.modal-open { overflow: hidden; }
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.modal__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: auto;
  width: min(680px, 92vw);
  max-height: 86vh;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}
.modal__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.modal__close:hover { color: var(--ink); border-color: var(--accent); }
.modal__body { overflow: auto; padding: 22px 22px 4px; }

button.word-row__word {
  font: inherit;
  font-weight: 700;
  font-size: 15.5px;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button.word-row__word:hover { color: var(--accent); }
.dict-link.dict-mini { padding: 2px 7px; font-size: 12px; }

.wm-head { margin-bottom: 14px; }
.wm-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-right: 40px; }
.wm-word { margin: 0; font-size: 24px; }
.wm-phon { font-size: 14px; color: var(--muted); }
.wm-def { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.wm-senses { display: flex; flex-direction: column; gap: 10px; }
.wm-sense {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.wm-sense__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.wm-sense__gloss { font-size: 14.5px; color: var(--ink); font-weight: 550; }
.wm-ex { margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line); }
.wm-ex__en { font-size: 13.5px; color: var(--ink); }
.wm-ex__zh { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.wm-views { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.wm-views .view:last-child { margin-bottom: 12px; }
