/* Warm paper, red seal accent. Tone colours follow the common convention:
   1 red, 2 green, 3 blue, 4 purple, neutral grey. */

:root {
  --bg: #fbf7f0;
  --paper: #fffdf9;
  --ink: #231f1c;
  --muted: #6f675f;
  --rule: #e4dcd0;
  --accent: #c0392b;
  --accent-ink: #fff;
  --ok: #2f7d4f; --ok-bg: #e2f1e7;
  --no: #b83227; --no-bg: #f8e1dd;
  --t1: #d0342c; --t2: #2e8b3e; --t3: #2b62c4; --t4: #8a3fb8; --t5: #8a837b;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --han: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1b1a; --paper: #262322; --ink: #eee8df; --muted: #a59d93; --rule: #3a3532;
    --accent: #ff7a66; --accent-ink: #1d1b1a;
    --ok: #8fd6a3; --ok-bg: #22372a; --no: #f4a29a; --no-bg: #3e2522;
    --t1: #ff7a70; --t2: #7fd68f; --t3: #7fa8ff; --t4: #cf96f5; --t5: #9c958d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--sans); }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

header {
  position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem;
  padding: .5rem max(1rem, calc(50vw - 480px)); background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
nav { display: flex; flex-wrap: wrap; gap: .2rem .9rem; font-size: .95rem; }
nav a { color: var(--muted); text-decoration: none; }
nav a.active { color: var(--ink); box-shadow: inset 0 -2px var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
footer { text-align: center; padding: 2rem 1rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.2; margin: .4rem 0 .6rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .3rem; }
.lead { font-size: 1.15rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.note { background: var(--paper); border: 1px solid var(--rule); border-left: 4px solid var(--accent); padding: .6rem .8rem; border-radius: 6px; font-size: .92rem; }

.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }

.hz { font-family: var(--han); font-size: 1.6rem; line-height: 1.25; }
.hz.big { font-size: 2.2rem; }
.hz.huge { font-size: clamp(3rem, 14vw, 4.6rem); }
.en.big { font-size: 1.3rem; }
.en.huge { font-size: clamp(1.6rem, 6vw, 2.2rem); font-weight: 600; }
.py { font-size: 1.05rem; }
.spoken { display: block; }

button { cursor: pointer; border: 1px solid var(--rule); background: var(--paper); border-radius: 8px; padding: .5rem .9rem; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--no); border-color: var(--no); }
.play { padding: .15rem .55rem; font-size: .8rem; line-height: 1.4; border-radius: 999px; vertical-align: middle; }
.huge-play { font-size: 2.4rem; width: 6rem; height: 6rem; border-radius: 50%; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; margin: 1.2rem 0; }
.tile { display: flex; flex-direction: column; gap: .25rem; padding: 1rem; background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; color: var(--ink); text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.tile strong { font-size: 1.1rem; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.chip { padding: .3rem .75rem; border-radius: 999px; font-size: .9rem; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tabs { display: flex; gap: 1.2rem; border-bottom: 1px solid var(--rule); margin-bottom: .6rem; }
.tabs a { padding: .4rem 0; text-decoration: none; color: var(--muted); }
.tabs a.on { color: var(--ink); box-shadow: inset 0 -2px var(--accent); }
.search { width: 100%; padding: .6rem .8rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); margin: .4rem 0; }

.list { display: flex; flex-direction: column; gap: .4rem; }
.row { display: grid; grid-template-columns: minmax(5.5rem, auto) 1fr auto auto; align-items: center; gap: .8rem; padding: .55rem .8rem; background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; cursor: pointer; }
.row:hover { border-color: var(--muted); }
.row-text { display: flex; flex-direction: column; min-width: 0; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--rule); }
.dot.seen { background: var(--t3); }
.dot.mature { background: var(--ok); }

.tone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .8rem; margin: 1rem 0; }
.tone-card { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: .8rem; display: flex; flex-direction: column; gap: .3rem; }
.tone-head { display: flex; flex-direction: column; }
.tone-ex { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
.contour { width: 100%; height: auto; }
.contour .grid { stroke: var(--rule); stroke-width: 1; }
.contour .curve { fill: none; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.c1 { stroke: var(--t1); } .c2 { stroke: var(--t2); } .c3 { stroke: var(--t3); } .c4 { stroke: var(--t4); }
.rule p { margin: .2rem 0 .4rem; }
.examples { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.examples .hz { font-size: 1.3rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 1rem 0; }
.stats div { display: flex; flex-direction: column; align-items: center; background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; padding: .6rem; }
.stats strong { font-size: 1.5rem; }
.stats span { font-size: .8rem; color: var(--muted); }
.card { background: var(--paper); border: 1px solid var(--rule); border-radius: 16px; padding: 2rem 1rem; text-align: center; min-height: 14rem; display: flex; flex-direction: column; justify-content: center; gap: .6rem; margin-bottom: 1rem; box-shadow: 0 2px 10px rgb(0 0 0 / .05); }
.card-back { display: flex; flex-direction: column; gap: .4rem; align-items: center; border-top: 1px dashed var(--rule); padding-top: .8rem; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.grade { display: flex; flex-direction: column; align-items: center; }
.g0 strong { color: var(--no); } .g3 strong { color: var(--ok); }

.prompt { text-align: center; padding: 1.4rem 1rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .5rem; }
.options.four { grid-template-columns: repeat(4, 1fr); }
.option { display: flex; align-items: center; gap: .7rem; text-align: left; padding: .7rem .9rem; min-height: 3.4rem; }
.options.four .option { flex-direction: column; gap: .1rem; text-align: center; }
.option .key { font-size: .75rem; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 0 .35rem; }
.right { background: var(--ok-bg) !important; border-color: var(--ok) !important; }
.wrong { background: var(--no-bg) !important; border-color: var(--no) !important; }
.typing { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.typing p { flex-basis: 100%; text-align: center; margin: .2rem 0; }
.answer { flex: 1 1 14rem; max-width: 22rem; padding: .6rem .8rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); font-size: 1.1rem; }
.feedback { margin-top: 1rem; padding: .9rem 1rem; border-radius: 12px; border: 1px solid; display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }
.feedback.ok { background: var(--ok-bg); border-color: var(--ok); }
.feedback.no { background: var(--no-bg); border-color: var(--no); }
.entry { display: flex; flex-direction: column; gap: .15rem; }
.progress { text-align: right; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.match > div { display: flex; flex-direction: column; gap: .5rem; }
.tile-btn { min-height: 3.6rem; padding: .5rem; }
.tile-btn .hz { font-size: 1.5rem; }
.tile-btn.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tile-btn.done { opacity: .35; }

.settings { display: flex; flex-direction: column; gap: .8rem; }
.setting select { margin-left: .3rem; padding: .25rem; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper); }

@media (max-width: 520px) {
  .row { grid-template-columns: auto 1fr auto; }
  .row .dot { display: none; }
  .stats strong { font-size: 1.2rem; }
  .options.four { grid-template-columns: repeat(2, 1fr); }
}
