/* Chinese Flow: calm, paper-and-ink, lightly Chinese. */
@import url("/static/fonts/wenkai.css");
@import url("/static/fonts/nunito.css");
@import url("/static/fonts/noto-sans-sc.css");


:root {
  /* Light, colorful, roomy, big targets. */
  --paper: #fffaf0;
  --paper-2: #fff0d9;
  --ink: #2b2140;
  --ink-2: #4a3f63;
  --stone: #6e6484;
  --line: #f1dcc2;
  --cinnabar: #e0503a;
  --cinnabar-2: #c23c27;
  --jade: #23875a;
  --jade-2: #dff5e9;
  --danger-bg: #ffe9e3;
  --violet: #6a3fd1;    /* selection: a chosen card or row */
  --violet-bg: #f4efff;
  --gold: #ffd27a;      /* the border of cards to play with */
  --card: #fff;
  --radius: 18px;
  /* Chinese is written in Kai (楷体) everywhere: LXGW WenKai comes first,
     and its unicode-range covers Chinese only, so Latin text keeps the
     next font. */
  --serif: "LXGW WenKai", "Nunito", system-ui, sans-serif;
  --hanzi: "LXGW WenKai", "Noto Sans SC", "Kaiti SC", "KaiTi", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sans: "LXGW WenKai", "Nunito", system-ui, sans-serif;
  --ease: cubic-bezier(.2,.7,.2,1);
  --dur: 240ms;
}


*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 10% 0%, #fff3c4 0, transparent 40%), radial-gradient(circle at 100% 20%, #ffe0ec 0, transparent 35%), var(--paper);
  color: var(--ink);
  color-scheme: light;
  font-family: var(--sans);
  font-size: 1.15rem;
  line-height: 1.65;
}
h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 800;
  line-height: 1.2;
  margin: 0 0 .6em;
}
h1 { font-size: clamp(2rem, 4vw, 2.75rem); color: #6a3fd1; }
h2 { font-size: 1.4rem; margin-top: 2rem; }
p { margin: 0 0 1rem; }
a { color: var(--cinnabar); text-decoration: none; background-image: linear-gradient(currentColor, currentColor); background-size: 0% 1px; background-repeat: no-repeat; background-position: 0 100%; transition: background-size var(--dur) var(--ease); }
a:hover, a:focus-visible { background-size: 100% 1px; }
code { font-size: .9em; }
.hanzi { font-family: var(--hanzi); font-size: 1.75rem; line-height: 1.4; }

/* Header */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); background: none; }
.brand-name { font-family: var(--serif); font-size: 1.15rem; letter-spacing: .04em; }
.seal {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem;
  font-family: var(--serif); font-size: 1.1rem; font-weight: 600;
  color: var(--paper); background: var(--cinnabar);
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  transition: transform var(--dur) var(--ease);
}
.brand:hover .seal { transform: rotate(-4deg); }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .35rem 1.25rem; font-size: .95rem; }
@media (max-width: 40rem) {
  .site-header { flex-wrap: wrap; }
  .site-nav { gap: .35rem 1rem; justify-content: flex-start; }
}
.site-nav a { color: var(--ink-2); }

/* Global playback speed, a two-way switch in the header. */
.speed-switch { display: inline-flex; align-items: center; gap: .1rem; padding: .15rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; line-height: 1; }
.speed-label { padding: 0 .35rem 0 .5rem; color: var(--stone); }
.speed-switch label { position: relative; cursor: pointer; }
.speed-switch input { position: absolute; opacity: 0; pointer-events: none; }
.speed-switch label span { display: inline-block; min-width: 2.6rem; padding: .35rem .55rem; border-radius: 999px; text-align: center; color: var(--ink-2); transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.speed-switch label:hover span { color: var(--ink); }
.speed-switch input:checked + span { background: var(--cinnabar); color: var(--paper); }
.speed-switch input:focus-visible + span { outline: 2px solid var(--cinnabar); outline-offset: 2px; }
.site-nav a:hover { color: var(--ink); }
.inline { display: inline; margin: 0; }
button.link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer;
}
button.link:hover { color: var(--cinnabar); }

/* Layout */
.page {
  flex: 1;
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) clamp(1rem, 4vw, 3rem);
  animation: rise var(--dur) var(--ease) both;
}
.narrow { max-width: 28rem; }
.wide { max-width: 60rem; }
.site-footer { text-align: center; padding: 2.5rem 1rem 2rem; color: var(--stone); font-size: .95rem; }
.credits { max-width: 40rem; }
.credit-list { padding-left: 1.2rem; }
.credit-list li { margin-bottom: .5rem; }

/* Hero */
.hero { max-width: 40rem; padding-top: clamp(1rem, 6vw, 4rem); }
.hero-small { padding-top: 0; }
.eyebrow {
  font-family: var(--serif); color: var(--cinnabar); letter-spacing: .12em;
  text-transform: uppercase; font-size: .8rem; margin-bottom: .75rem;
}
.eyebrow .hanzi { font-size: 1.2em; line-height: 1; letter-spacing: 0; }
.lede { color: var(--ink-2); font-size: 1.15rem; max-width: 34rem; margin-bottom: 1.75rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem 1.2rem; border-radius: var(--radius); min-height: 44px;
  font: inherit; font-size: .95rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; background: none;
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cinnabar); color: #fff; }
.btn-primary:hover { background: var(--cinnabar-2); color: #fff; }
.btn-ghost { border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--stone); color: var(--ink); }
.btn-danger { color: var(--cinnabar); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: .4rem .8rem; font-size: .85rem; min-height: 36px; }
.btn-block { width: 100%; }
a.btn { background-image: none; }

/* Forms */
.form-page h1 { margin-bottom: 1.25rem; }
.form-page .form { margin-top: .5rem; }
.form { display: grid; gap: 1.1rem; }
.form-row { grid-template-columns: 1fr 1fr auto; align-items: end; margin-bottom: 2rem; }
@media (max-width: 40rem) { .form-row { grid-template-columns: 1fr; } }
.field { display: grid; gap: .35rem; }
.field label { font-size: .9rem; color: var(--ink-2); }
.field input {
  font: inherit; padding: .6rem .75rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field input:focus { outline: none; border-color: var(--cinnabar); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cinnabar) 18%, transparent); }
.hint, .small { font-size: .85rem; color: var(--stone); margin: 0; }
.muted { color: var(--stone); }
.field-error { font-size: .85rem; color: var(--cinnabar); margin: 0; }
.form-error, .form-success {
  padding: .7rem .9rem; border-radius: var(--radius); font-size: .95rem; margin-bottom: 1.2rem;
  animation: rise var(--dur) var(--ease) both;
}
.form-error { background: var(--danger-bg); color: var(--cinnabar-2); }
.form-success { background: var(--jade-2); color: var(--jade); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1.2rem; margin: 0 0 1rem; }
.meta dt { color: var(--stone); font-size: .9rem; }
.meta dd { margin: 0; }

/* Table */
.table-wrap { overflow-x: auto; }
.students, .lessons { width: 100%; border-collapse: collapse; font-size: .95rem; }
.students th, .students td, .lessons th, .lessons td { text-align: left; padding: .75rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.students th, .lessons th { font-weight: 500; color: var(--stone); font-size: .85rem; letter-spacing: .04em; }
.students tbody tr, .lessons tbody tr { animation: rise var(--dur) var(--ease) both; }
.actions { white-space: nowrap; text-align: right; }
.tag {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .8rem; background: var(--paper-2); color: var(--ink-2); border: 1px solid var(--line);
}
.tag-ok { background: var(--jade-2); color: var(--jade); border-color: transparent; }
.tag-warn { background: var(--danger-bg); color: var(--cinnabar-2); border-color: transparent; }
.invite-link { display: inline-block; margin-top: .3rem; word-break: break-all; color: var(--ink-2); font-size: .8rem; }

/* ---- Lesson editor ----
   The editor follows the student's path: four numbered steps, each a seal
   that fills in when opened. Chinese text is the only large type; every
   control around it stays small and quiet. */
:root {
  --block-blue: #dfe7f1;
  --block-blue-ink: #2d4b70;
  --block-orange: #f5e3d0;
  --block-orange-ink: #87501c;
  --block-purple: #e9e1f1;
  --block-purple-ink: #5b3b7d;
  --block-teal: #d9ecec;
  --block-teal-ink: #1f5f61;
  --tint: color-mix(in srgb, var(--cinnabar) 6%, var(--paper));
}

.lessons .hanzi { font-size: 1.1rem; margin-left: .35rem; }
.theme-group { margin-bottom: 2.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.theme-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; }
.theme-head h2 { margin: 0; }
.theme-head .hanzi { color: var(--ink-2); }
.theme-group .titles { margin: .3rem 0 .8rem; }
.theme-new { margin: 0 0 2.5rem; }
.theme-new > summary { list-style: none; }
.theme-new > summary::-webkit-details-marker { display: none; }
.theme-new[open] > summary { margin-bottom: 1rem; }
.theme-new form { max-width: 44rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 12px; }
.theme-new .form-row { display: grid; gap: 1.1rem; grid-template-columns: 1fr 1fr; margin-bottom: 0; }
.theme-new .btn, .lessons-add .btn { justify-self: start; }
.lessons select { font: inherit; font-size: .85rem; padding: .3rem .5rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); max-width: 14rem; }
@media (max-width: 40rem) { .theme-new .form-row { grid-template-columns: 1fr; } }
.lessons-add { margin-top: 1rem; }
.lessons-add > summary { display: inline-block; color: var(--cinnabar); font-weight: 600; cursor: pointer; }
.lessons-add form { max-width: 36rem; margin-top: .75rem; }

.field select, .field textarea,
.editor input[type="text"], .editor select, .editor textarea {
  font: inherit; padding: .55rem .7rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  min-width: 0;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field select:focus, .field textarea:focus,
.editor input[type="text"]:focus, .editor select:focus, .editor textarea:focus {
  outline: none; border-color: var(--cinnabar);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cinnabar) 18%, transparent);
}
.editor textarea { width: 100%; resize: vertical; line-height: 1.6; }
.editor input[readonly] { color: var(--stone); background: transparent; }
.editor fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.editor legend, .field-label { display: block; padding: 0; margin-bottom: .4rem; font-size: .9rem; color: var(--ink-2); }
.editor .item-main p, .editor .step-body p { margin: 0; }
.editor .hint + *, .editor .sub-title + .hint { margin-top: .35rem; }
.hanzi-input { font-family: var(--hanzi); font-size: 1.15rem; }
.hanzi-inline { font-family: var(--hanzi); font-size: 1.05em; }
.btn.btn-link { border: 0; padding-left: 0; padding-right: 0; color: var(--cinnabar); }
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:focus-visible, .editor summary:focus-visible, .chip input:focus-visible + span {
  outline: 2px solid var(--cinnabar); outline-offset: 2px;
}

.editor { max-width: 56rem; }
.editor-back { font-size: .95rem; margin-bottom: 1.5rem; }
.lesson-head { margin-bottom: 2.25rem; }
.lesson-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .75rem 1.5rem; }
.lesson-title h1 { font-size: clamp(1.75rem, 3.5vw, 2.3rem); margin: 0; }
.lesson-title h1 .hanzi { font-size: .85em; color: var(--ink-2); }
.lesson-state { display: flex; align-items: center; gap: .6rem; }
.lesson-head .form-error, .lesson-head .form-success { margin: 1rem 0 0; }
.lesson-head .form-error ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.audio-status { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem 1rem; margin-top: .5rem; font-size: .9rem; color: var(--stone); }
.audio-status p { margin: 0; }

.editor details > summary { list-style: none; cursor: pointer; }
.editor details > summary::-webkit-details-marker { display: none; }
.titles { margin-top: .5rem; }
.titles > summary, .upload > summary, .preview > summary { display: inline-block; color: var(--cinnabar); font-size: .9rem; }
.titles > summary:hover, .upload > summary:hover, .preview > summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.titles[open] > summary { margin-bottom: 1rem; }

/* Steps */
.step { border-top: 1px solid var(--line); }
.step-note { border-top: 1px solid var(--line); }
.step > summary {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: .9rem;
  padding: 1.15rem .25rem;
}
.step > summary::after {
  content: ""; width: .5rem; height: .5rem; margin: 0 .4rem .2rem;
  border-right: 1.5px solid var(--stone); border-bottom: 1.5px solid var(--stone);
  transform: rotate(45deg); transition: transform var(--dur) var(--ease);
}
.step[open] > summary::after { transform: rotate(-135deg); margin-bottom: -.2rem; }
.step > summary:hover .step-title { color: var(--cinnabar); }
.step-n {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; flex: none;
  font-family: var(--serif); font-size: 1rem; font-weight: 600;
  color: var(--cinnabar); border: 1.5px solid var(--cinnabar); border-radius: 3px;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.step[open] .step-n { background: var(--cinnabar); color: var(--paper); }
.step-title { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; transition: color var(--dur) var(--ease); }
.sub-step { margin: 1.5rem 0; border: 1px solid var(--line); border-radius: 6px; padding: 0 1rem; }
.sub-step > summary { cursor: pointer; padding: .8rem 0; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; display: flex; gap: .8rem; align-items: baseline; }
.sub-step > summary .step-sum { margin-left: auto; font-family: var(--sans); font-weight: 400; }
.sub-step[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: .6rem; }
.input-with-action { display: flex; gap: .5rem; align-items: center; }
.input-with-action input { flex: 1; min-width: 0; }
.step-sum { justify-self: end; text-align: right; color: var(--stone); font-size: .9rem; }
.step-body { padding: 0 .25rem 2.25rem 3.15rem; }
.step-note { display: flex; align-items: center; gap: .9rem; margin: 0; padding: 1.15rem .25rem; color: var(--stone); font-size: .95rem; }
.step-note .step-n { color: var(--stone); border-color: var(--line); }
.sub-title { font-size: 1.1rem; margin: 2.5rem 0 0; }

/* Item lists */
.item-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .5rem 1.25rem;
  padding: .9rem 0; border-bottom: 1px solid var(--line);
}
.item:first-child { border-top: 1px solid var(--line); }
.item .hanzi { font-size: 1.45rem; line-height: 1.35; }
.item-main { min-width: 0; }
.item-title { font-weight: 500; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }
.item-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .2rem; }
.item-actions .btn { min-height: 34px; padding: .25rem .6rem; }
.pinyin { color: var(--ink-2); }
.item.editing {
  display: block; margin: .6rem 0; padding: 1.25rem;
  background: var(--tint); border: 1px solid var(--line); border-radius: var(--radius);
}
.form-title { font-size: 1.05rem; margin: 0; }
.vocab-item { grid-template-columns: minmax(4.5rem, auto) 1fr auto; }
.vocab-item > .hanzi { font-size: 1.8rem; }
.line-item { grid-template-columns: auto 1fr auto; align-items: start; }
.line-item .pinyin, .line-item .fr { font-size: .95rem; }
.line-item .fr { color: var(--ink-2); }
.speaker {
  display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; flex: none;
  border: 1.5px solid currentColor; border-radius: 50%;
  font-size: .8rem; font-weight: 600; line-height: 1;
}
.line-side { display: flex; flex-direction: column; align-items: center; gap: .3rem; margin-top: .3rem; min-width: 1.8rem; }
.line-n { font-size: .8rem; color: var(--stone); font-variant-numeric: tabular-nums; }
.needs-review { font-family: var(--sans); font-size: .75rem; vertical-align: middle; }
.speaker-A { color: var(--cinnabar); }
.speaker-B { color: var(--jade); }

.upload { text-align: right; font-size: .85rem; }
.upload-form { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .4rem; margin-top: .4rem; }
.upload-form input[type="file"] { max-width: 15rem; font-size: .8rem; color: var(--ink-2); }
.upload-inline { justify-content: flex-start; margin: 0; }
.upload-inline .field-label { width: 100%; margin: 0; }

/* Add forms */
.add { margin-top: 1rem; }
.add > summary {
  display: inline-flex; align-items: center; gap: .5rem; min-height: 40px;
  padding: .45rem .9rem; border: 1px dashed var(--stone); border-radius: var(--radius);
  color: var(--ink-2); font-size: .95rem;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.add > summary::before { content: "+"; color: var(--cinnabar); font-size: 1.15rem; line-height: 1; }
.add > summary:hover { border-color: var(--cinnabar); color: var(--ink); }
.add[open] > summary {
  padding: 0; min-height: 0; margin-bottom: .9rem; border: 0;
  font-family: var(--serif); font-size: 1.05rem; font-weight: 600; color: var(--ink);
}
.add[open] > summary::before { content: "−"; }

.item-form { gap: 1.1rem; }
.fields { display: grid; gap: 1rem; }
.fields-3 { grid-template-columns: 1.2fr 1fr 1.3fr; }
.input-with-action { display: flex; gap: .4rem; }
.input-with-action input { flex: 1; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.speaker-choice { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.5rem; }
.speaker-choice legend { width: 100%; }
.speaker-choice label, .check { display: inline-flex; align-items: center; gap: .45rem; min-height: 36px; cursor: pointer; }
.check-list { display: grid; }

/* Sentence editor */
.sentence-editor { display: grid; gap: .5rem; }
.sentence-editor .field-label { margin-bottom: 0; }
.sentence-editor p { margin: 0; }
.sentence-input { display: flex; gap: .4rem; }
.sentence-input input { flex: 1; }
.token-rows { display: grid; gap: .3rem; }
.token-head, .token-row { display: grid; grid-template-columns: 6.5rem 9.5rem 1fr 14.5rem; gap: .4rem; align-items: start; }
.token-head { padding: 0 .4rem; font-size: .8rem; color: var(--stone); }
.token-row { padding: .3rem .3rem .3rem .4rem; border-left: 3px solid transparent; border-radius: var(--radius); }
.token-row.unknown { background: var(--tint); border-left-color: var(--cinnabar); }
.token-row input { width: 100%; }
.token-fr { display: grid; gap: .3rem; }
.editor .readings { padding: .2rem .4rem; font-size: .8rem; color: var(--ink-2); }
.token-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .15rem; }
/* A word's punctuation shows beside it, read-only: it is never a row. */
.token-word { display: flex; align-items: center; gap: .15rem; min-width: 0; }
.token-word input[type="text"] { flex: 1; min-width: 0; }
.mark { font-family: var(--hanzi); font-size: 1.1rem; color: var(--stone); }
.token-actions .btn { min-height: 34px; padding: .2rem .5rem; font-size: .8rem; }

/* Step files */
.lesson-files { margin: -1.5rem 0 2.25rem; }
.lesson-files > summary { color: var(--cinnabar); font-size: .95rem; cursor: pointer; }
.lesson-files[open] > summary { margin-bottom: .6rem; }
.file-list { list-style: none; margin: .4rem 0; padding: 0; display: grid; gap: .3rem; }
.file-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem; }
.file-list a { overflow-wrap: anywhere; }

/* Questions */
.chip-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { position: relative; display: inline-flex; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; gap: .3rem; min-height: 44px;
  padding: .15rem .6rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); font-family: var(--hanzi); font-size: 1.2rem;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip small { font-family: var(--sans); font-size: .75rem; }
.chip:hover span { border-color: var(--stone); }
.chip input:checked + span { background: var(--cinnabar); border-color: var(--cinnabar); color: var(--paper); }
.chip input:focus-visible + span { outline: 2px solid var(--cinnabar); outline-offset: 2px; }
.check-list { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.check { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; }
.line-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.line-checks .check { align-items: baseline; flex-wrap: wrap; }
.line-checks .line-n { color: var(--stone); font-size: .85rem; }
.wrong-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: .4rem; }
.wrong-inputs input, .option-row input[type=text] {
  font: inherit; padding: .5rem .7rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); min-width: 0;
}
.test-editor { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.test-editor .switch { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; font-weight: 500; }
.test-editor .switch input { width: 1.2rem; height: 1.2rem; accent-color: var(--jade); }
.test-tools { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.test-group { font-size: 1rem; margin: 1rem 0 .3rem; }
.badge-unchecked { font-family: var(--sans); font-size: .75rem; }
.match-preview { border-collapse: collapse; margin: .3rem 0; font-size: .95rem; }
.match-preview th { font-weight: 500; font-size: .8rem; color: var(--stone); text-align: left; padding: 0 1rem .2rem 0; }
.match-preview td { padding: .1rem 1rem .1rem 0; border-top: 1px solid var(--line); }
.lines-preview { margin: .2rem 0; padding-left: 1.2rem; }
.hanzi-inline { font-family: var(--hanzi); }
.question-form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .4rem; }
.question-form legend { font-size: .9rem; color: var(--ink-2); margin-bottom: .3rem; }
.listening-edit audio, .item audio { max-width: 100%; }
.options { list-style: none; margin: .2rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .2rem 1rem; font-size: .95rem; color: var(--ink-2); }
.options .right { color: var(--jade); font-weight: 500; }
.option-rows { display: grid; gap: .4rem; }
.option-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .6rem; }

/* Grammar */
.breakdown { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.block { display: inline-flex; align-items: baseline; gap: .4rem; padding: .1rem .55rem; border-radius: var(--radius); font-size: .8rem; }
.item .block .hanzi { font-size: 1.05rem; }
.block-blue { background: var(--block-blue); color: var(--block-blue-ink); }
.block-orange { background: var(--block-orange); color: var(--block-orange-ink); }
.block-green { background: var(--jade-2); color: var(--jade); }
.block-purple { background: var(--block-purple); color: var(--block-purple-ink); }
.block-teal { background: var(--block-teal); color: var(--block-teal-ink); }
.block-grey { background: var(--paper-2); color: var(--ink-2); }
.chunk-editor { display: grid; gap: .3rem; }
.chunk-editor .field-label { margin: 0; }
.chunk-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.chunk-row { display: grid; grid-template-columns: minmax(6rem, auto) 10rem 1fr; gap: .4rem; align-items: center; }
.chunk-row .block .hanzi { font-size: 1.1rem; }
.chunk-actions { display: flex; flex-wrap: wrap; gap: .15rem; }
.chunk-actions .btn, .block-actions .btn { min-height: 34px; padding: .2rem .5rem; font-size: .8rem; }
.block-actions { display: flex; justify-content: flex-end; gap: .15rem; }
.drill-add { display: flex; flex-wrap: wrap; gap: .4rem; }
.char-input { max-width: 6rem; font-size: 1.6rem; text-align: center; }
.stroke.stroke-preview { width: 9rem; height: 9rem; border: 1px solid var(--line); border-radius: var(--radius); }
.example { display: grid; gap: .6rem; margin-bottom: .6rem; padding: .9rem; border: 1px solid var(--line); border-radius: var(--radius); }
.example legend { padding: 0 .3rem; margin: 0; }

/* Culture */
.culture-image { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin: 1.25rem 0; }
.culture-preview { display: block; max-width: 16rem; border-radius: var(--radius); }
.preview { margin-top: .5rem; }
.prose { max-width: 38rem; padding-top: .75rem; line-height: 1.75; }
.editor .prose p { margin: 0 0 .9rem; }

@media (max-width: 40rem) {
  .step > summary { grid-template-columns: auto 1fr auto; row-gap: .1rem; }
  .step-sum { grid-column: 2; grid-row: 2; justify-self: start; text-align: left; }
  .step-body { padding-left: .25rem; }
  .fields-3 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr; }
  .vocab-item, .line-item { grid-template-columns: auto 1fr; }
  .item-side { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .upload { text-align: left; }
  .token-head { display: none; }
  .token-row { grid-template-columns: 1fr 1fr; background: var(--paper-2); }
  .token-fr, .token-actions { grid-column: 1 / -1; }
  .token-actions { justify-content: flex-start; }
  .chunk-row { grid-template-columns: auto 1fr; }
  .chunk-actions { grid-column: 1 / -1; }
}

/* ---- Learner pages ---- */
.learn { max-width: 44rem; }
.learn h1 .hanzi { margin-left: .5rem; }
.steps { list-style: none; padding: 0; margin: 1.5rem 0; display: grid; gap: .6rem; }
.steps li a, .steps li span.step-link { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; min-height: 56px; padding: .6rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); font-size: 1.15rem; text-decoration: none; color: var(--ink); }
.steps .dot { width: .8rem; height: .8rem; border-radius: 50%; border: 1px solid var(--stone); flex: none; }
.steps .done .dot { background: var(--jade); border-color: var(--jade); }
.lesson-list { list-style: none; padding: 0; display: grid; gap: .8rem; }
.lesson-list a { display: block; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.lesson-list .progress { color: var(--stone); font-size: .9rem; }
.home-theme { margin-top: 2rem; }
.home-theme h2 { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .3rem 1rem; }
.home-theme h2 .progress { font-family: var(--sans); font-size: .9rem; font-weight: 400; color: var(--stone); }
.next-lesson { margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }

.word { font: inherit; font-family: var(--hanzi); background: none; border: 0; border-bottom: 1px dotted var(--stone); padding: 0 .05em; margin: 0; color: inherit; cursor: pointer; min-height: 44px; }
.word:hover, .word:focus-visible { border-bottom-color: var(--cinnabar); color: var(--cinnabar); outline: none; }
/* A word and its punctuation never break apart, so a mark never starts a line. */
.w { white-space: nowrap; }
.popover { position: absolute; z-index: 10; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: .8rem 1rem; min-width: 9rem; text-align: center; }
.popover .hanzi { font-size: 1.75rem; }
.popover .play { margin-top: .4rem; }

.play, .loop, .play-all { font: inherit; background: none; border: 1px solid var(--line); border-radius: var(--radius); min-width: 44px; min-height: 44px; cursor: pointer; color: var(--ink-2); }
.play:hover, .loop:hover, .play-all:hover { border-color: var(--stone); color: var(--ink); }
.loop.active { border-color: var(--cinnabar); color: var(--cinnabar); }
/* Whatever is playing gets the same tint and red edge: rows, lines, words,
   popovers. An outline, not a border, so table rows show it too and nothing
   shifts. The popover already has a border, so it recolors that instead. */
.playing { background: var(--playing-bg); outline: 1px solid var(--cinnabar); outline-offset: -1px; border-radius: var(--radius); }
.popover.playing { outline: none; border-color: var(--cinnabar); }
.word.playing { border-radius: 3px; }

.vocab-table { width: 100%; border-collapse: collapse; margin-top: .25rem; }
.vocab-table th { text-align: left; font-weight: 500; font-size: .85rem; color: var(--stone); padding: 0 1rem .5rem 0; border-bottom: 1px solid var(--line); }
.vocab-table td { padding: .5rem 1rem .5rem 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.vocab-table td.hanzi { font-size: 2rem; line-height: 1.3; white-space: nowrap; }
.vocab-table td.pinyin { color: var(--ink-2); white-space: nowrap; }
.vocab-table .listen { width: 1%; padding-right: 0; text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.dialogue-lines { list-style: none; padding: 0; margin: 0; }
.line { display: grid; grid-template-columns: 2rem 1fr auto auto; gap: .4rem .6rem; align-items: start; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.line .speaker { color: var(--stone); font-weight: 600; }
.line .text { font-family: var(--hanzi); font-size: 1.5rem; line-height: 1.6; }
.line .pinyin, .line .fr { grid-column: 2; }

.grammar-point { margin: 2rem 0; }
.example-label { margin: 1.2rem 0 0; font-weight: 600; color: var(--stone); text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; }
/* Grammar sentences reuse .line but have no speaker column. */
.line.grammar-sentence { grid-template-columns: 1fr auto; }
.line.grammar-sentence .pinyin, .line.grammar-sentence .fr { grid-column: 1; }
/* A text with no speaker at all drops the speaker column. */
.no-speakers .line { grid-template-columns: 1fr auto auto; }
.no-speakers .line .pinyin, .no-speakers .line .fr { grid-column: 1; }
.learn .breakdown { gap: .4rem; margin: .6rem 0; }
.learn .block { flex-direction: column; align-items: center; gap: 0; padding: .2rem .6rem; font-size: 1.25rem; }
.learn .block .word { min-height: 0; }
.learn .block-h { font-family: var(--hanzi); }
.learn .block .pinyin, .learn .block .fr, .learn .block small { font-family: var(--sans); font-size: .75rem; }
.learn .block small { margin-top: .15rem; text-transform: uppercase; letter-spacing: .04em; opacity: .8; }
.explanation { padding-top: 0; }
.explanation .word { min-height: 0; }
.explain-pinyin { color: var(--stone); font-size: .9em; }
.pattern { margin-bottom: 1rem; }
.lexicon-title { font-size: .85rem; color: var(--stone); }
.word-blocks { display: flex; flex-wrap: wrap; gap: .4rem; }
.wblock { display: inline-flex; flex-direction: column; align-items: center; padding: .2rem .4rem; border: 1px solid var(--line); border-radius: var(--radius); }
.wblock-pinyin, .wblock-fr { font-size: .8rem; color: var(--ink-2); }
.wblock-h { border: 0; font-family: var(--hanzi); font-size: 1.4rem; color: var(--ink); }
.answer-pinyin { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; color: var(--ink-2); }

/* Mini-tests and quiz */
.test { margin: 2.5rem 0 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); }
.test-title { margin: 0 0 .5rem; font-size: 1.2rem; }
.test-body { display: grid; gap: .6rem; }
.test-body > p { margin: 0; }
.test-progress { font-size: .85rem; color: var(--stone); }
.item-card { display: grid; gap: .7rem; }
.item-card p { margin: 0; }
.item-task { font-weight: 700; }
.item-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.prompt-text { font-size: 1.15rem; }
.prompt-hanzi { font-family: var(--hanzi); font-size: 2.6rem; line-height: 1.2; }
.prompt-audio .play-big { min-width: 5rem; min-height: 5rem; font-size: 2rem; border-radius: 50%; background: var(--paper); }
.prompt-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; }
.prompt-words { font-family: var(--hanzi); font-size: 1.5rem; }
.prompt-sentence .pinyin { flex-basis: 100%; color: var(--ink-2); }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: .5rem; }
.choices-mcq { grid-template-columns: 1fr; }
.choice {
  font: inherit; min-height: 44px; padding: .6rem .8rem; cursor: pointer; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--ink);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.choices-mcq .choice { text-align: left; }
.choice:hover:not(:disabled) { border-color: var(--cinnabar); }
.choice:disabled { cursor: default; }
.choice-hanzi { font-family: var(--hanzi); font-size: 1.8rem; }
.choice-pinyin { font-size: 1.15rem; }
.choices-radical .choice { display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.choice-fr { font-size: .9rem; }
.choices-listen { grid-template-columns: 1fr; }
.choices-listen .choice { text-align: left; }
.prompt-char { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem .8rem; }
.prompt-char .prompt-hanzi { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; }
.choice.choice-wrong { border-color: var(--cinnabar); background: var(--danger-bg); color: var(--cinnabar-2); text-decoration: line-through; }
.choice.choice-right { border-color: var(--jade); background: var(--jade-2); color: var(--jade); }
.feedback { padding: .6rem .8rem; border-radius: var(--radius); margin: 0; animation: rise var(--dur) var(--ease) both; }
.feedback p { margin: 0; }
.feedback-ok { background: var(--jade-2); color: var(--jade); }
.feedback-correct { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; }
.feedback-correct p { margin: 0; }
.correction-title { margin-top: 1.5rem; }
.feedback-hint { background: var(--block-orange); color: var(--block-orange-ink); }
.feedback-reveal { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; background: var(--danger-bg); color: var(--cinnabar-2); }
.feedback-reveal .small { flex-basis: 100%; color: inherit; opacity: .85; }
.order-label { font-size: .85rem; color: var(--stone); }
.blocks { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 3.4rem; padding: .3rem; border-radius: var(--radius); }
.answer-line { border: 1px dashed var(--stone); background: var(--paper); }
.oblock-btn {
  font: inherit; display: inline-flex; flex-direction: column; align-items: center; min-width: 44px; min-height: 44px;
  padding: .2rem .6rem; cursor: pointer; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--ink);
}
.oblock-btn:hover:not(:disabled) { border-color: var(--cinnabar); }
.oblock-h { font-family: var(--hanzi); font-size: 1.4rem; line-height: 1.3; }
.oblock-btn .pinyin { font-size: .75rem; color: var(--ink-2); }
.oblock-bad .oblock-btn { border-color: var(--cinnabar); background: var(--danger-bg); }
.reveal-answer { display: grid; gap: .4rem; }
.reveal-fr { font-size: 1.15rem; }
.self-rate { display: flex; flex-wrap: wrap; gap: .4rem; }
.self-rate .btn { min-height: 56px; }
.rated { color: var(--ink-2); }
.match-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.match-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.match-col { display: grid; gap: .4rem; align-content: start; }
.match-head { font-size: .8rem; color: var(--stone); text-align: center; }
.cell-wrap { display: flex; gap: .2rem; align-items: stretch; }
.cell-wrap .play { flex: none; }
.cell {
  font: inherit; flex: 1; min-width: 0; min-height: 44px; padding: .35rem .4rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; position: relative;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--ink);
  overflow-wrap: anywhere; text-align: center;
}
.cell:hover { border-color: var(--stone); }
.cell[aria-pressed="true"] { border-color: var(--cinnabar); box-shadow: 0 0 0 2px var(--cinnabar) inset; }
.cell-hanzi { font-family: var(--hanzi); font-size: 1.35rem; line-height: 1.3; }
.cell-pinyin { font-size: .85rem; color: var(--ink-2); }
.cell-fr { font-size: .95rem; }
.cell-locked { cursor: default; border-color: var(--jade); background: var(--jade-2); color: var(--jade); }
.match-quiz .cell-locked { border-color: var(--stone); background: var(--paper-2); color: var(--ink-2); }
.cell-link { position: absolute; top: .1rem; left: .3rem; font-size: .7rem; font-weight: 600; }
.cell-hint { border-color: var(--cinnabar); animation: shake 300ms var(--ease); }
.item-lines .cell-hanzi { font-size: 1.15rem; }
.score { font-size: 1.15rem; }
.score-big { font-family: var(--serif); font-size: 1.6rem; }
.step-score { margin-left: auto; font-size: .85rem; color: var(--jade); font-weight: 500; }
.steps .current a { border-color: var(--cinnabar); }
.step-nav { margin: 2rem 0 1rem; }
.listening { display: grid; gap: .3rem; padding: .6rem .8rem; border-radius: var(--radius); background: var(--paper); border: 1px solid var(--line); }
.listening-title { font-weight: 500; }
.listening-player { display: flex; flex-wrap: wrap; gap: .4rem; }
.quiz-results h2 { font-size: 1.2rem; }
.correction { padding-left: 1.2rem; display: grid; gap: .8rem; }
.correction li { padding-left: .2rem; }
.correction p { margin: .1rem 0; }
.correction .mark { font-weight: 700; }
.correction .right > .correction-head .mark, .links .right { color: var(--jade); }
.correction .wrong > .correction-head .mark, .links .wrong { color: var(--cinnabar); }
.correction-answer { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; }
.answer-py { color: var(--ink-2); }
.links { margin: .1rem 0; padding-left: 1.1rem; }
.links li { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.transcript summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.transcript-text { font-family: var(--hanzi); font-size: 1.3rem; }
@keyframes shake {
  0%, 100% { transform: none; }
  30% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
}
/* Three narrow columns on a phone: smaller characters, tighter cells. */
@media (max-width: 400px) {
  .match-grid.cols-3 { gap: .25rem; }
  .cols-3 .cell { padding: .3rem .15rem; }
  .cols-3 .cell-hanzi { font-size: 1.1rem; }
  .cols-3 .cell-pinyin, .cols-3 .cell-fr { font-size: .75rem; }
  .cols-3 .cell-wrap .play { min-width: 28px; }
  .test { padding: .8rem .6rem; }
}
/* Lines stack: the dialogue lines, then their translations. */
@media (max-width: 480px) {
  .item-lines .match-grid { grid-template-columns: 1fr; }
}

.char-grid { display: grid; gap: 1rem; margin: 1rem 0; }
.char-card { display: grid; grid-template-columns: 10rem 1fr; gap: 1.2rem; align-items: start; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.char-strokes { display: grid; justify-items: center; gap: .4rem; }
.char-strokes .stroke { width: 10rem; }
.char-strokes .stroke-actions { gap: .3rem; }
.char-strokes .stroke-actions .btn { min-height: 36px; padding: .2rem .5rem; }
.char-big { margin: 0; font-family: var(--hanzi); font-size: 4.5rem; line-height: 1.2; color: var(--ink); }
.char-info { display: grid; gap: .35rem; min-width: 0; }
.char-info p { margin: 0; }
.char-head { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.char-small { font-family: var(--hanzi); font-size: 1.6rem; line-height: 1; }
.char-pinyin { font-size: 1.25rem; font-weight: 600; }
.char-play { margin-left: auto; flex: none; }
.char-fr { font-size: 1.05rem; }
.char-radical { color: var(--ink-2); font-size: .95rem; }
.char-label { display: inline-block; margin-right: .2rem; padding: 0 .4rem; border-radius: 999px; background: var(--paper-2); color: var(--stone); font-size: .72rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; vertical-align: .1em; }
.char-origin { display: flex; gap: .7rem; align-items: flex-start; margin-top: .3rem; padding-top: .6rem; border-top: 1px solid var(--line); }
.char-ancient { flex: none; margin: 0; display: grid; justify-items: center; gap: .15rem; }
.char-ancient img { width: 56px; height: 56px; object-fit: contain; padding: 4px; border-radius: var(--radius); background: #fbf8f2; }
.char-ancient figcaption { font-size: .68rem; color: var(--stone); text-align: center; max-width: 5rem; }
.char-etym { font-size: .92rem; line-height: 1.45; color: var(--ink-2); }
@media (max-width: 480px) {
  .char-card { grid-template-columns: 1fr; }
  .char-strokes .stroke { width: min(11rem, 100%); }
}
.stroke { width: min(18rem, 100%); aspect-ratio: 1; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); touch-action: none; }
.stroke-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.stroke-actions .btn { min-height: 56px; }

.learn .culture-image { display: block; max-width: 100%; border-radius: var(--radius); margin: 1rem 0; }
.culture-figure, .video { margin: 1.25rem 0; }
.culture-figure figcaption, .video figcaption { margin-top: .4rem; font-size: .9rem; color: var(--stone); }
.culture-figure .culture-image { margin: 0; }
.video { max-width: 40rem; }
.video-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--paper-2); border: 1px solid var(--line); }
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.video-play {
  font: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
  width: 100%; height: 100%; min-height: 44px; padding: 1rem; border: 0; background: none; color: var(--ink); cursor: pointer; text-align: center;
}
.video-play:hover .video-icon, .video-play:focus-visible .video-icon { background: var(--cinnabar-2); }
.video-icon {
  display: grid; place-items: center; width: 3.5rem; height: 3.5rem; border-radius: 50%;
  background: var(--cinnabar); color: #fff; font-size: 1.3rem; padding-left: .2rem;
}
.culture-add { margin-top: .75rem; }
.culture-block .item-main .prose { padding-top: 0; }
.prose p { line-height: 1.7; }

.fiche-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-start; }
.fiche-pdf { flex-basis: 100%; }
.fiche-pdf a { display: inline-flex; align-items: center; min-height: 44px; overflow-wrap: anywhere; }
.fiche-image img { display: block; width: 9rem; height: 9rem; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); }

@media (max-width: 480px) {
    .vocab-table td.hanzi { font-size: 1.6rem; }
    .vocab-table td.pinyin { white-space: normal; }
    /* The line takes the full width; its buttons sit side by side below it. */
    .dialogue-lines .line { grid-template-columns: 2rem auto auto 1fr; }
    .dialogue-lines .line .text, .dialogue-lines .line .pinyin, .dialogue-lines .line .fr { grid-column: 2 / -1; }
    .dialogue-lines .line .play { grid-column: 2; grid-row: 2; }
    .dialogue-lines .line .loop { grid-column: 3; grid-row: 2; }
    .dialogue-lines.no-speakers .line { grid-template-columns: auto auto 1fr; }
    .dialogue-lines.no-speakers .line .text, .dialogue-lines.no-speakers .line .pinyin, .dialogue-lines.no-speakers .line .fr { grid-column: 1 / -1; }
    .dialogue-lines.no-speakers .line .play { grid-column: 1; }
    .dialogue-lines.no-speakers .line .loop { grid-column: 2; }
}

/* Tone colors: one hue per tone, the same everywhere tones are shown. */
:root {
  --playing-bg: color-mix(in srgb, var(--cinnabar) 13%, var(--paper));
  --tone-1: #c23b30;
  --tone-2: #b86e00;
  --tone-3: #2f7d3e;
  --tone-4: #2d62a8;
  --tone-5: #857f76;
}
.tone {
  --tone-c: var(--tone-5);
  display: inline-block; margin: .1rem .3rem .1rem 0; padding: .1rem .55rem;
  border-radius: 999px; font-size: .8rem; font-weight: 500; white-space: nowrap;
  color: var(--tone-c);
  background: color-mix(in srgb, var(--tone-c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone-c) 40%, transparent);
}
.tone-1 { --tone-c: var(--tone-1); }
.tone-2 { --tone-c: var(--tone-2); }
.tone-3 { --tone-c: var(--tone-3); }
.tone-4 { --tone-c: var(--tone-4); }
.tone-5 { --tone-c: var(--tone-5); }
.vocab-table td.tones { white-space: nowrap; }

/* htmx states */
.htmx-request .btn-primary, .btn-primary.htmx-request { opacity: .7; cursor: progress; }
.htmx-swapping { opacity: 0; transition: opacity 120ms ease-out; }
.htmx-settling { animation: rise var(--dur) var(--ease) both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

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

/* Phones: the tone chips wrap instead of pushing the French and play
   columns off screen. */
@media (max-width: 480px) {
    .vocab-table td.tones { white-space: normal; }
    .vocab-table td.tones > * { margin-bottom: .2rem; }
    .vocab-table th, .vocab-table td { padding-right: .6rem; }
}

/* Characters: the revision grid after the mini-test. */
.memorize { margin: 2rem 0; }
/* Tracing area: one large square, one character at a time. */
.practice { margin: 1rem 0; padding: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.practice-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-bottom: 1.2rem; }
.practice-tab { font: inherit; font-family: var(--hanzi); font-size: 1.6rem; min-width: 3rem; min-height: 3rem; border: 1px solid var(--line); border-radius: var(--radius); background: none; color: var(--ink); cursor: pointer; }
.practice-tab[aria-selected="true"] { border-color: var(--cinnabar); color: var(--cinnabar); background: var(--danger-bg); }
.practice-panel { display: grid; justify-items: center; gap: 1rem; }
.practice-panel[hidden] { display: none; }
.practice-head { display: flex; align-items: baseline; flex-wrap: wrap; justify-content: center; gap: .6rem; margin: 0; }
.practice-head .char-small { font-size: 2rem; }
.practice-stroke { width: min(22rem, 100%); }
.practice-nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: min(22rem, 100%); }
.memo-info { margin: 0; text-align: center; }
.memo-info .char-fr { color: var(--stone); }

/* Order questions: the teacher cuts a line between its words. */
.cut-row { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem; margin: .3rem 0 .6rem 1.6rem; }
.cut-word { font-size: 1.2rem; padding: 0 .1rem; }
.cut { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; border-radius: var(--radius); cursor: pointer; color: var(--line); }
.cut input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cut:has(input:checked) { color: var(--cinnabar); background: var(--danger-bg); }
.cut:has(input:focus-visible) { outline: 2px solid var(--cinnabar); }

/* Je retiens: the characters to learn to write are underlined. */
u.learn { text-decoration: underline 2px var(--cinnabar); text-underline-offset: .2em; }
.memo { margin: 2rem 0; }
.learn-note { margin-top: 1.2rem; padding: .8rem 1rem; border-left: 3px solid var(--cinnabar); background: var(--paper); }
.learn-note p { margin: 0 0 .8rem; }

/* Ancient forms: black ink drawings, kept legible on the dark theme. */
.ancient-line img, .ancient-option img { background: #fbf8f2; border-radius: 4px; object-fit: contain; vertical-align: middle; }
.ancient-options { display: flex; flex-wrap: wrap; gap: .6rem; }
.ancient-option { display: grid; justify-items: center; gap: .2rem; padding: .4rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; font-size: .8rem; }
.ancient-option:has(input:checked) { border-color: var(--cinnabar); }
.ancient-option input { margin: 0; }
.ancient-none { display: grid; place-items: center; width: 56px; height: 56px; font-size: 1.6rem; color: var(--stone); }
.culture-heading { margin: 1.8rem 0 .6rem; font-family: var(--serif); font-size: 1.25rem; }
.choices-ancient .choice { display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.prompt-picture img { width: 120px; height: 120px; object-fit: contain; background: #fbf8f2; border-radius: var(--radius); padding: 6px; }
.ancient-thumb { background: #fbf8f2; border-radius: 4px; object-fit: contain; vertical-align: middle; }

/* Words: an emoji or a picture helps younger students. */
.vocab-table td.pic, .vocab-table th.pic { width: 3.2rem; text-align: center; padding-right: 0; }
.vocab-table td.pic img { width: 44px; height: 44px; object-fit: cover; border-radius: var(--radius); display: block; }
.word-emoji { font-size: 1.9rem; line-height: 1; }
.fr .word-emoji { font-size: 1.2rem; }
.word-pic { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; vertical-align: middle; }
.emoji-field input { max-width: 8rem; font-size: 1.4rem; }
.form-warning { padding: .5rem .8rem; border-radius: var(--radius); background: var(--block-orange); color: var(--block-orange-ink); }

.did-you-know { margin: 1.2rem 0; padding: .8rem 1rem; border-left: 4px solid var(--jade); border-radius: var(--radius); background: var(--jade-2); color: var(--ink); }
.did-you-know .dyk-title { margin: 0 0 .3rem; font-weight: 700; color: var(--jade); }
.did-you-know .prose p { margin: .2rem 0; }

/* ---- Big targets ---- */
.btn { min-height: 56px; padding: .8rem 1.5rem; font-size: 1.1rem; font-weight: 700; border-radius: 999px; }
.btn-sm { min-height: 48px; padding: .5rem 1.1rem; font-size: 1rem; }
.btn-primary { background: #ff7a45; box-shadow: 0 4px 0 #d95a28; }
.btn-primary:hover { background: #ff8c5c; }
.btn-primary:active { box-shadow: 0 1px 0 #d95a28; transform: translateY(3px); }
.btn-ghost { background: #fff; border: 2px solid var(--line); }
.choice { min-height: 64px; font-size: 1.3rem; border-width: 2px; border-radius: var(--radius); background: #fff; }
.choices { gap: 1rem; }
.item-card { gap: 1.2rem; }
.test { border: 3px solid #ffd27a; border-radius: 24px; background: #fff; }
.play { min-width: 56px; min-height: 56px; font-size: 1.4rem; border-radius: 50%; }
.feedback { font-size: 1.15rem; border-radius: var(--radius); }
.feedback-correct p::first-line { font-weight: 800; }
.cell { min-height: 64px; font-size: 1.2rem; border-radius: var(--radius); }

/* Flashcards: one word per screen. */
.flashcards { margin: 1rem 0; }
.flashcard { display: grid; justify-items: center; gap: .6rem; padding: 2rem 1rem; text-align: center; border-radius: 28px; background: #fff; border: 3px solid #ffd27a; box-shadow: 0 8px 24px rgba(106, 63, 209, .08); }
.flashcard[hidden] { display: none; }
.fc-pic { font-size: 5.5rem; line-height: 1; min-height: 6rem; }
.fc-pic img { width: 9rem; height: 9rem; object-fit: cover; border-radius: 22px; }
.fc-hanzi { margin: 0; font-family: var(--hanzi); font-size: 4.5rem; line-height: 1.15; color: var(--ink); }
.fc-pinyin { margin: 0; font-size: 1.5rem; font-weight: 700; color: #6a3fd1; }
.fc-fr { margin: 0; font-size: 1.25rem; }
.fc-listen { min-height: 56px; padding: 0 1.4rem; font-size: 1.15rem; font-weight: 700; border-radius: 999px !important; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.fc-nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; max-width: 26rem; margin-top: .6rem; }
.fc-count { font-weight: 700; color: var(--stone); }

/* Progress in tests. */
.test-progress-bar { height: 12px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.test-progress-bar span { display: block; height: 100%; background: linear-gradient(90deg, #ffb13b, #ff7a45); border-radius: 3px; transition: width var(--dur) var(--ease); }
.test-start { display: flex; justify-content: center; padding: 1rem 0; }
.test-start .btn { font-size: 1.15rem; }
.test-intro { display: grid; justify-items: center; gap: .8rem; text-align: center; }
.test-done .test-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

/* Feedback: a small pop. */
@keyframes pop { 0% { transform: scale(.8); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
.feedback-correct { animation: pop 380ms var(--ease) both; }
@media (prefers-reduced-motion: reduce) { .feedback-correct { animation: none; } }
.center { text-align: center; }
.lesson-stars { font-size: 1.3rem; letter-spacing: .1em; color: #f0a500; white-space: nowrap; }
.badge { display: inline-block; padding: .2rem .8rem; border-radius: 999px; background: #fff0c2; color: #8a5a00; font-size: .95rem; font-weight: 800; }
.progress-thin { display: block; flex-basis: 100%; height: 3px; margin-top: .3rem; border-radius: 2px; background: var(--paper-2); overflow: hidden; }
.progress-thin span { display: block; height: 100%; background: var(--jade); }
.cell-emoji { font-size: 2rem; line-height: 1; }
.cell-image { width: 3.2rem; height: 3.2rem; object-fit: cover; border-radius: var(--radius); }
.trace-box { display: grid; justify-items: center; gap: .5rem; }
.picture-preview { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.picture-preview img { object-fit: cover; border-radius: 6px; vertical-align: middle; }

/* Placement test */
#placement .switch { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; font-weight: 500; }
#placement .switch input { width: 1.2rem; height: 1.2rem; accent-color: var(--jade); }
#placement h2 { margin-top: 2rem; }
#placement .test-actions { margin-top: 1.5rem; }
.placement .row-start td { background: var(--paper-2); font-weight: 600; }
.field-short { max-width: 10rem; }
.placement-skip { margin-top: .75rem; text-align: center; }
.placement-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin: 0 0 2rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-2); }
.placement-card p { margin: 0; }
.further-card { display: flex; flex-direction: column; gap: .2rem; margin: 1.5rem 0 0; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-2); color: var(--ink); text-decoration: none; }
.further-card:hover { border-color: var(--jade); }
.further-card span { color: var(--ink-2); }
.sheets-card { gap: .6rem; }
.sheets-card h2 { margin: 0; font-size: 1.15rem; }
.sheet-link { display: flex; flex-direction: column; gap: .2rem; color: var(--ink); text-decoration: none; }
.sheet-link strong { color: var(--jade); }
.sheet-link:hover strong { text-decoration: underline; text-underline-offset: 3px; }
/* Source numbers, the same as on the printed sheet. */
.src-tag, .further-card .src-tag { font-family: var(--sans); font-size: .72rem; font-weight: 600; color: var(--stone); letter-spacing: .03em; white-space: nowrap; }
p.src-tag { margin: 0; }
.vocab-table .pic .src-tag { display: block; margin-bottom: .2rem; }
.fc-src { text-align: center; }
.further-admin { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.tag-start { background: var(--cinnabar); color: #fff; }
#placement .form .btn { justify-self: start; }
#placement .form-row { grid-template-columns: minmax(0, 24rem) auto; margin: 1.5rem 0 0; }
@media (max-width: 40rem) { #placement .form-row { grid-template-columns: 1fr; } }

/* Praise, streak and stickers */
.praise { margin: 0 0 .3rem; font-size: 1.35rem; }
.praise-zh { display: inline-block; font-family: var(--font-zh, inherit); font-size: 1.8rem; font-weight: 600; animation: grow 600ms var(--ease) both; }
.praise-py, .praise-fr { color: var(--ink-2); }
.praise-star { display: inline-block; animation: jump 700ms var(--ease) both; }
@keyframes grow { 0% { transform: scale(.6); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-.5em) rotate(15deg); } }
.streak { display: inline-block; margin: 0 0 .4rem; padding: .15rem .7rem; border-radius: 999px; background: #fff0c2; color: #8a5a00; font-size: 1.1rem; font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .praise-zh, .praise-star { animation: none !important; } }
.child-progress { margin: .5rem 0 1.5rem; padding: .9rem 1rem; border-radius: 16px; background: var(--paper-2); }
.child-progress-head { margin: 0 0 .5rem; font-weight: 700; }
.stickers { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0 0; padding: 0; list-style: none; }
.stickers li { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 2px dashed var(--line); color: var(--ink-2); font-size: 1.5rem; }
.stickers li.won { border: 2px solid #ffb13b; background: #fff7e0; }
.stickers li.current { box-shadow: 0 0 0 3px rgba(255, 122, 69, .35); }
.step-sticker { margin-left: .4rem; }
.steps .progress-thin { margin-top: .4rem; }
.sticker-won { font-size: 1.3rem; font-weight: 800; animation: pop 500ms var(--ease) both; }
@media (prefers-reduced-motion: reduce) { .sticker-won { animation: none; } }
.feedback .praise { flex-basis: 100%; }
.feedback .streak { flex-basis: auto; }

/* A celebration, in the middle of the screen: a finished test, a right answer */
.celebrate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(255, 248, 235, .55); backdrop-filter: blur(2px); animation: fade-in 180ms ease-out both; cursor: pointer; }
.celebrate.out { animation: fade-out 280ms ease-in both; }
.celebrate-card { position: relative; max-width: calc(100vw - 2rem); overflow-wrap: anywhere; padding: 1.6rem 2.4rem; border-radius: 28px; background: #fff; box-shadow: 0 18px 60px rgba(255, 122, 69, .35); text-align: center; animation: burst 520ms cubic-bezier(.2, 1.4, .4, 1) both; }
.celebrate-big { margin: 0; font-size: clamp(3.5rem, 16vw, 6.5rem); line-height: 1.1; font-weight: 700; color: #ff7a45; }
.celebrate-line { margin: .4rem 0 0; font-size: 1.5rem; font-weight: 800; color: #3b2a55; }
.celebrate-sub { display: inline-block; margin: .6rem 0 0; padding: .2rem .9rem; border-radius: 999px; background: #fff0c2; color: #8a5a00; font-size: 1.2rem; font-weight: 800; }
.confetti { position: absolute; left: 50%; top: 50%; font-size: 2rem; transform: translate(-50%, -50%); animation: fly 900ms ease-out both; }
@keyframes fly { 0% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--a)) translateY(0) scale(.4); } 100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--a)) translateY(calc(-1 * var(--d) - 8rem)) scale(1.2); } }
@keyframes burst { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .celebrate, .celebrate-card, .celebrate.out { animation: none; } .confetti { display: none; } }
/* The big card says the praise; the feedback keeps it for screen readers. */
.feedback .praise { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { vertical-align: -0.15em; }

/* Admin messages */
.messages tr.unread td { font-weight: 600; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Block instruction and oral tasks */
.block-intro { margin: .4rem 0 1.2rem; padding: .7rem 1rem; border-radius: var(--radius); background: var(--paper-2); border: 1px solid var(--line); color: var(--ink-2); }
.block-intro p { margin: .2rem 0; }
.oral-task { margin: 1.5rem 0; padding: 1rem 1.25rem; border: 2px dashed color-mix(in srgb, var(--cinnabar) 45%, var(--line)); border-radius: var(--radius); background: color-mix(in srgb, var(--paper-2) 60%, #fff); }
.oral-title { margin: 0 0 .4rem; font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: var(--cinnabar); }
.oral-task .prose p { margin: .2rem 0; }
.recorder { margin-top: .8rem; }
.recorder-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .4rem 0; }
.recorder audio, .recording-list audio, .recordings audio { display: block; width: 100%; max-width: 22rem; margin: .4rem 0; }
.rec-time { font-variant-numeric: tabular-nums; margin-left: .3rem; }
.my-recordings:empty { display: none; }
.my-recordings { margin-top: .8rem; }
.recording-list { list-style: none; margin: .3rem 0 0; padding: 0; display: grid; gap: .5rem; }
.recording-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; }
.recording-list li audio { flex: 1 1 14rem; margin: 0; }
.recording-item.unheard { border-color: var(--cinnabar); }
.nav-count { display: inline-block; min-width: 1.3rem; margin-left: .25rem; padding: 0 .35rem; border-radius: 999px; background: var(--cinnabar); color: #fff; font-size: .75rem; line-height: 1.3rem; text-align: center; }
.nav-count[hidden], .recorder[hidden], .recorder .btn[hidden], .recorder-review[hidden] { display: none; }
.block-settings { margin-bottom: .6rem; }

/* Listening sequence: 4 numbered clips, 5 meanings to number. */
.seq-clips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; justify-items: center; }
.seq-play { position: relative; width: 72px; height: 72px; cursor: pointer; border: 3px solid #ffd27a; background: #fff; }
.seq-play .seq-n { position: absolute; top: -.4rem; left: -.4rem; min-width: 1.7rem; height: 1.7rem; line-height: 1.7rem; border-radius: 999px; background: #6a3fd1; color: #fff; font-size: 1rem; font-weight: 800; }
.seq-options { display: grid; gap: .6rem; }
.seq-card {
  font: inherit; display: flex; align-items: center; gap: .8rem; min-height: 64px; padding: .5rem .9rem; cursor: pointer; text-align: left;
  border: 2px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink); font-size: 1.2rem;
}
.seq-card:disabled { cursor: default; }
.seq-badge { flex: none; display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 999px; border: 2px dashed var(--line); font-weight: 800; }
.seq-card[aria-pressed="true"] { border-color: #6a3fd1; }
.seq-card[aria-pressed="true"] .seq-badge { border: none; background: #6a3fd1; color: #fff; }
.seq-card.seq-right { border-color: var(--jade); }
.seq-card.seq-right .seq-badge { background: var(--jade); }
.seq-card.seq-wrong { border-color: var(--cinnabar); background: var(--danger-bg); }
.seq-answer { display: grid; gap: .3rem; margin: .4rem 0; padding-left: 1.6rem; }
.seq-answer li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.seq-answer .hanzi-inline { font-size: 1.4rem; }
@media (max-width: 400px) { .seq-play { width: 60px; height: 60px; } }

/* Word match: meanings with a slot each, then the pool of words. Side by
   side on a wide screen, the pool under the meanings on a phone. Once done,
   a row answered wrong shows its right word "corrigé", in jade with a mark. */
.wm { display: grid; gap: 1rem; }
@media (min-width: 720px) { .wm { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } }
.wm-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.wm-row { display: flex; align-items: center; gap: .5rem; padding: .3rem; border: 2px solid transparent; border-radius: var(--radius); }
.wm-row.wm-selected { border-color: var(--violet); background: var(--violet-bg); }
.wm-row.wm-wrong { border-color: var(--cinnabar); background: var(--danger-bg); }
.wm-row.wm-right { border-color: var(--jade); }
.wm-row.wm-fixed { border-color: var(--jade); border-style: dashed; background: var(--jade-2); }
.wm-meaning { font: inherit; font-size: 1.2rem; min-height: 56px; padding: .4rem .7rem; cursor: pointer; text-align: left; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); overflow-wrap: anywhere; }
.wm-meaning[aria-pressed="true"] { border-color: var(--violet); }
.wm-meaning:disabled, .wm-card:disabled, .wm-empty:disabled { cursor: default; }
.wm-dots { flex: 1 1 1rem; min-width: .8rem; border-bottom: 3px dotted var(--line); }
.wm-slot { position: relative; flex: none; display: flex; }
.wm-empty { font: inherit; width: 88px; min-height: 72px; cursor: pointer; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); color: var(--stone); font-size: 1.4rem; }
.wm-empty[hidden] { display: none; }
.wm-pool { display: flex; flex-wrap: wrap; gap: .6rem; align-content: start; }
.wm-card {
  font: inherit; display: grid; justify-items: center; gap: .1rem; min-width: 88px; min-height: 72px; padding: .4rem .6rem; cursor: pointer;
  border: 3px solid var(--gold); border-radius: var(--radius); background: var(--card); color: var(--ink);
}
.wm-slot .wm-card { border-color: var(--violet); }
.wm-right .wm-slot .wm-card, .wm-fixed .wm-slot .wm-card { border-color: var(--jade); }
.wm-wrong .wm-slot .wm-card { border-color: var(--cinnabar); }
.wm-fixed-mark { position: absolute; top: -.75rem; right: -.4rem; padding: 0 .45rem; border-radius: 999px; background: var(--jade); color: var(--card); font-size: .8rem; font-weight: 800; line-height: 1.5; white-space: nowrap; }
.wm-hanzi { font-family: var(--hanzi); font-size: 1.8rem; line-height: 1.1; }
.wm-pinyin { font-size: .9rem; color: var(--ink-2); }
@media (max-width: 400px) {
  .wm-meaning { min-height: 48px; font-size: 1.1rem; }
  .wm-empty, .wm-card { min-width: 72px; min-height: 60px; }
  .wm-empty { width: 72px; }
  .wm-hanzi { font-size: 1.5rem; }
}

/* Memory: 12 cards, 3 columns on a phone, 4 on a wide screen. */
.memory { margin: 1.5rem 0; }
.memory-game { display: grid; gap: .8rem; }
.memory-game[hidden] { display: none; }
.memory-status { margin: 0; min-height: 1.5em; text-align: center; font-weight: 700; }
.memory-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
@media (min-width: 600px) { .memory-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mem-card {
  font: inherit; display: grid; place-items: center; aspect-ratio: 1; min-height: 80px; padding: .3rem; cursor: pointer; overflow: hidden;
  border: 3px solid #ffd27a; border-radius: var(--radius); color: var(--ink);
  background: repeating-linear-gradient(45deg, #fff0d9, #fff0d9 10px, #ffe6bf 10px, #ffe6bf 20px);
}
.mem-card.up { background: #fff; border-color: #6a3fd1; }
.mem-card.found { border-color: var(--jade); background: var(--jade-2); cursor: default; }
.mem-card .mem-face { display: grid; justify-items: center; gap: .1rem; }
.mem-card .mem-face[hidden] { display: none; }
.mem-hanzi { font-family: var(--hanzi); font-size: 2rem; line-height: 1.1; }
.mem-pinyin { font-size: .85rem; color: var(--ink-2); }
.mem-emoji { font-size: 2.6rem; line-height: 1; }
.mem-fr { font-size: 1rem; overflow-wrap: anywhere; }
.mem-card img { width: 100%; max-width: 6rem; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }
.memory-end { text-align: center; }
.memory-end .test-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; }
@media (prefers-reduced-motion: no-preference) { .mem-card { transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); } }

/* Dictation: one character per screen. */
.dictation-card { display: grid; justify-items: start; gap: .4rem; margin: 1.5rem 0; padding: 1rem 1.2rem; border: 3px solid #ffd27a; border-radius: 24px; background: #fff; }
.dictation-card h2, .dictation-card p { margin: 0; }
.dictation-intro, .dictation-screen, .dictation-end { display: grid; justify-items: center; gap: .8rem; padding: 1.5rem 1rem; text-align: center; border-radius: 28px; background: #fff; border: 3px solid #ffd27a; }
.dictation-screen[hidden], .dictation-intro[hidden], .dictation-end[hidden], .dictation-answer[hidden] { display: none; }
.dictation-screen:focus, .dictation-end:focus { outline: none; }
.dictation-count { margin: 0; font-weight: 700; color: var(--stone); }
.dictation-fr { margin: 0; font-size: 2.2rem; font-weight: 800; line-height: 1.2; }
.dictation-pinyin { margin: 0; font-size: 1.3rem; color: #6a3fd1; }
.dictation-answer { display: grid; justify-items: center; gap: .5rem; }
.dictation-stroke { width: min(16rem, 70vw); }
.dictation-actions, .dictation-end .test-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; }
.progress-reset { margin-top: 2.5rem; text-align: center; }
/* Instructions stand out: the block's, the oral task's. */
.block-intro, .oral-task .prose { font-weight: 700; }
.memo-lines .pinyin, .memo-lines .fr { white-space: pre-line; }
.grammar-review { margin-top: .5rem; }
.grammar-review summary { cursor: pointer; color: var(--cinnabar); font-weight: 600; }
.review-label { margin: .8rem 0 .2rem !important; font-weight: 700; }
.review-examples { margin: 0; padding-left: 1.4rem; display: grid; gap: .5rem; }
.review-examples .breakdown { margin-top: 0; }
/* Student text: as wide as the cards around it, justified where lines are
   long enough (a phone line would open wide gaps); Chinese characters are
   never spread apart. */
.learn .prose { max-width: none; hyphens: auto; -webkit-hyphens: auto; }
@media (min-width: 600px) {
  .learn .prose p { text-align: justify; text-justify: inter-word; }
}
