:root {
  --bg: #f3efe7;
  --paper: #fffcf8;
  --ink: #1c1916;
  --muted: #6f675e;
  --faint: #8a8176;
  --line: #e4dcd0;
  --cinnabar: #9f2d2d;
  --cinnabar-dark: #7e2222;
  --cinnabar-soft: #f8ece7;
  --play: #0f6e62;
  --play-soft: #e5f4f1;
  --side: #221e1b;
  --side-2: #2b2622;
  --side-text: #f6f1ea;
  --side-muted: #b7aea3;
  --side-line: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(48, 32, 18, 0.05);
  --sidebar-w: 292px;
  --topbar-h: 56px;
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans-zh: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  --sans: "Be Vietnam Pro", "Segoe UI", sans-serif;
  --py: "Noto Sans", "Segoe UI", "Be Vietnam Pro", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 480px at 80% -10%, rgba(159, 45, 45, 0.06), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

body.nav-open { overflow: hidden; }

button, textarea { font: inherit; color: inherit; }

::selection { background: #f3d2cc; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: min(var(--sidebar-w), 88vw);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(62px + env(safe-area-inset-bottom));
  background: var(--side);
  color: var(--side-text);
  transform: translateX(-105%);
  transition: transform 0.24s ease;
  box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
}

.sidebar.is-open { transform: translateX(0); }

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--side-line);
}

.seal {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--cinnabar);
  color: white;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.side-brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.side-brand-text strong { font-size: 16px; letter-spacing: 0.04em; }
.side-brand-text span { color: var(--side-muted); font-size: 12.5px; }

.sidebar-close { color: var(--side-text); }

.lesson-list {
  flex: 1;
  overflow: auto;
  padding: 8px;
  overscroll-behavior: contain;
}

.lesson-list::-webkit-scrollbar { width: 8px; }
.lesson-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}

.lesson-link {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 8px;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 8px 8px;
  margin: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.lesson-link:hover { background: rgba(255, 255, 255, 0.05); }

.lesson-link[aria-current="page"] {
  background: var(--side-2);
  box-shadow: inset 3px 0 0 var(--cinnabar);
}

.lesson-no {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--side-muted);
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.lesson-link[aria-current="page"] .lesson-no {
  background: var(--cinnabar);
  color: white;
}

.lesson-copy { min-width: 0; display: flex; flex-direction: column; }
.lesson-copy .lz {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.35;
}
.lesson-copy .lv {
  color: var(--side-muted);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.seen {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d7a15e;
}

.side-foot {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--side-line);
  color: var(--side-muted);
  font-size: 12px;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(22, 16, 12, 0.48);
  border: 0;
}

.backdrop[hidden] { display: none !important; }

.main { min-width: 0; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(243, 239, 231, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-title { min-width: 0; display: flex; flex-direction: column; }
.topbar-title span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
.topbar-title strong {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
}

.sidebar .icon-btn {
  background: transparent;
  border-color: var(--side-line);
  color: var(--side-text);
}

.lesson {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 22px 16px calc(36px + env(safe-area-inset-bottom));
}

.loading { color: var(--muted); }

.hero { margin: 4px 0 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }

.kicker {
  margin: 0 0 6px;
  color: var(--cinnabar);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-zh {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.05rem, 6vw, 3.35rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
}

.hero-py {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--py);
  font-size: 1.05rem;
}

.hero-vi {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.hint {
  margin: 10px 0 0;
  color: var(--faint);
  font-size: 13px;
}

.section { margin-top: 16px; }

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
}

.sec-head h2 {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.idx {
  width: 1.35rem;
  height: 1.35rem;
  display: inline-grid;
  place-items: center;
  border-radius: 7px;
  background: var(--cinnabar);
  color: white;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.count {
  color: var(--faint);
  font-style: normal;
  font-weight: 550;
  font-size: 12px;
}

.sheet-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin: 0 0 8px;
}

.sheet-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--cinnabar-dark);
  font-weight: 650;
  font-size: 13.5px;
  cursor: pointer;
}

.sheet-btn:hover { background: var(--cinnabar-soft); }
.sheet-btn:disabled { opacity: 0.65; cursor: progress; }
.sheet-note { color: var(--faint); font-size: 13px; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--cinnabar-dark);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  padding: 4px 2px;
}

.text-btn.is-on { color: var(--play); }

.empty {
  margin: 0;
  padding: 16px 18px;
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stack { list-style: none; margin: 0; padding: 0; }
.stack li + li { border-top: 1px solid var(--line); }

.word, .sent {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  grid-template-areas:
    "zh play"
    "py play"
    "vi play";
  column-gap: 10px;
  row-gap: 0;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.word { grid-template-columns: 1.5rem minmax(0, 1fr) 32px; }
.word-no { grid-area: no; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; align-self: start; padding-top: 4px; }
.word { grid-template-areas: "no zh play" "no py play" "no vi play"; }

.star {
  color: var(--cinnabar);
  font-family: var(--sans);
  font-size: 0.72em;
  font-weight: 700;
  margin-right: 1px;
  vertical-align: super;
}

.zh {
  grid-area: zh;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.28rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.py { grid-area: py; color: var(--muted); font-family: var(--py); font-size: 0.95rem; line-height: 1.35; }
.vi { grid-area: vi; font-size: 0.92rem; line-height: 1.4; color: var(--ink); }
.speaker { grid-area: play; }

.word:hover, .sent:hover, .line:hover { background: #faf6f1; }
.word.is-on, .sent.is-on, .line.is-on { background: var(--play-soft); }
.word.is-on .zh, .sent.is-on .zh, .line.is-on .zh { color: var(--play); }

.rolebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.rolebar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  font-size: 14px;
  font-weight: 650;
}

.rolebar input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--cinnabar);
}

.settings {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
}

.settings[hidden] { display: none !important; }

.settings-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(22, 16, 12, 0.48);
  cursor: pointer;
}

.settings-panel {
  position: relative;
  width: min(440px, 100%);
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 24px 60px rgba(28, 25, 22, 0.22);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.set-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.set-field label {
  font-size: 14.5px;
  font-weight: 700;
}

.set-field p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.set-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.set-row input {
  width: 5.2rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
}

.set-row span { color: var(--muted); font-size: 14px; }

.settings-later {
  margin: 16px 0 2px;
  color: var(--faint);
  font-size: 13px;
}

.role-hint {
  margin: 0 0 8px;
  color: var(--faint);
  font-size: 13px;
}

.dlg + .dlg { border-top: 1px solid var(--line); }

.dlg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 2px;
}

.dlg-no {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.dlg-file {
  margin-right: auto;
  color: var(--faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.line {
  width: 100%;
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 32px;
  grid-template-areas:
    "who zh play"
    "who py play"
    "who vi play"
    "who turn play";
  column-gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.who {
  grid-area: who;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.who-a { background: var(--cinnabar-soft); color: var(--cinnabar-dark); }
.who-b { background: #e5f3f6; color: #0f5f73; }

.turn-label {
  grid-area: turn;
  display: none;
  color: #9a5b12;
  font-size: 12px;
  font-weight: 700;
}

.line.is-turn { background: #fff4e5; }
.line.is-turn .turn-label { display: inline; }
.line.is-role { opacity: 0.62; }
.line.is-role.is-turn,
.line.is-role.is-on { opacity: 1; }

.speaker {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cinnabar-soft);
  color: var(--cinnabar);
}

.speaker .w2 { opacity: 0.35; }
.is-on .speaker { background: var(--play); color: white; }
.is-on .speaker .w1,
.is-on .speaker .w2 { opacity: 1; animation: wave 1s ease-in-out infinite; }
.is-on .speaker .w2 { animation-delay: 0.15s; }

@keyframes wave {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.notes { margin: 0; padding: 4px 16px 12px 34px; }
.notes li { margin: 8px 0; padding-left: 2px; }
.notes li::marker { color: var(--cinnabar); }

.my-note {
  margin-top: 10px;
  padding: 12px;
  background: var(--paper);
  border: 1px dashed #d9cfc2;
  border-radius: 16px;
}

.my-note label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 6px;
}

.my-note textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  line-height: 1.5;
}

.my-note textarea:focus {
  outline: 2px solid rgba(159, 45, 45, 0.35);
  border-color: transparent;
}

.my-note p { margin: 6px 0 0; color: var(--faint); font-size: 12px; }

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.pager button {
  min-height: 58px;
  text-align: left;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.pager button:last-child { text-align: right; align-items: flex-end; }
.pager button small { color: var(--faint); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.pager button strong {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 400;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pager button:hover { border-color: #d7c8b6; }
.pager button:disabled { opacity: 0.38; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.toast[hidden] { display: none !important; }

.playbar {
  position: fixed;
  z-index: 55;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 6px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.playbar[hidden] { display: none !important; }

.playbar button {
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--cinnabar-dark);
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
  cursor: pointer;
}

.playbar button:hover { background: var(--cinnabar-soft); }

body.is-playing .lesson { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.read-part + .read-part { border-top: 1px solid var(--line); }

.read-vi {
  margin: 0;
  padding: 0 14px 2px;
  color: var(--faint);
  font-size: 13px;
}

.read-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: 8px;
  padding: 8px 12px 14px;
}

.read-grid:not(.pics):not(.phrases):not(:has(.stack)) {
  grid-template-columns: repeat(var(--cols, 4), 4.35rem);
  justify-content: start;
}

.read-rows .read-grid:not(.pics):not(.phrases) {
  grid-template-columns: repeat(var(--cols), max-content);
  justify-content: start;
  padding: 0 12px 8px;
}

.read-rows .read-grid:first-child { padding-top: 8px; }
.read-rows .read-grid:last-child { padding-bottom: 14px; }

.read-grid.pics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.read-grid.phrases {
  display: block;
  padding: 0;
}

.read-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
  padding: 8px 6px;
}

.read-item .py { font-size: 1.15rem; color: var(--ink); }
.read-item .zh { font-size: 1.15rem; }
.read-item .vi { font-size: 0.78rem; color: var(--muted); }

.read-item.chip { min-height: 42px; padding: 7px 12px; }
.read-rows .read-item.chip { min-width: 4.35rem; }
.read-rows .read-item.chip .py { white-space: nowrap; }
.read-item.chip.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 96px;
  padding: 14px 10px;
}
.read-grid:has(.chip.stack) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.read-item.pic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
}
.read-item.pic img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  background: #f7f4ef;
}
.read-item.phrase {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "zh" "py" "vi";
  text-align: left;
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  padding: 10px 14px;
}
.read-item.is-on,
.read-item.phrase.is-on {
  background: var(--play-soft);
  border-color: var(--play);
}
.read-item.is-on .zh,
.read-item.is-on .py { color: var(--play); }

.lesson-link:focus-visible,
.word:focus-visible,
.sent:focus-visible,
.line:focus-visible,
.read-item:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible,
.sheet-btn:focus-visible,
.playbar button:focus-visible,
.pager button:focus-visible {
  outline: 2px solid var(--cinnabar);
  outline-offset: 2px;
}

.colhead {
  display: none;
}

@media (min-width: 720px) {
  .word, .sent, .colhead {
    column-gap: 14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .word, .colhead.for-words {
    grid-template-columns: 2.25rem 5.5rem 9.5rem minmax(0, 1fr) 2rem;
  }
  .word {
    grid-template-areas: "no zh py vi play";
    align-items: center;
    padding-top: 9px;
    padding-bottom: 9px;
  }
  .word-no { align-self: center; padding-top: 0; }
  .zh { font-size: 1.2rem; }
  .sent, .colhead.for-sents {
    grid-template-columns: 13.5rem 10rem minmax(0, 1fr) 2rem;
  }
  .sent {
    grid-template-areas: "zh py vi play";
    align-items: center;
    padding-top: 11px;
    padding-bottom: 11px;
  }
  .dlg .stack {
    display: grid;
    grid-template-columns: 2rem max-content max-content minmax(0, 1fr) auto 2rem;
    column-gap: 14px;
  }
  .dlg .stack > li {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
  }
  .line {
    grid-template-columns: subgrid;
    grid-template-areas: none;
    grid-column: 1 / -1;
    column-gap: 0;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .line .who,
  .line .zh,
  .line .py,
  .line .vi,
  .line .turn-label,
  .line .speaker { grid-area: auto; }
  .line .who { grid-column: 1; }
  .line .zh { grid-column: 2; }
  .line .py { grid-column: 3; white-space: nowrap; }
  .line .vi { grid-column: 4; }
  .line .turn-label { grid-column: 5; }
  .line .speaker { grid-column: 6; }
  .read-grid.pics,
  .read-grid:has(.chip.stack) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .read-item.phrase {
    grid-template-columns: 8.5rem 11rem minmax(0, 1fr);
    grid-template-areas: "zh py vi";
    align-items: center;
  }
  .colhead {
    display: grid;
    align-items: center;
    padding-top: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
    color: var(--faint);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
}

@media (min-width: 960px) {
  body { padding-left: var(--sidebar-w); }
  body.nav-open { overflow: auto; }
  .sidebar { transform: none; box-shadow: none; }
  .sidebar-close, .topbar, .backdrop { display: none !important; }
  .lesson { padding: 36px 28px 64px; }
  .playbar { left: calc(var(--sidebar-w) + (100% - var(--sidebar-w)) / 2); }
}

body.settings-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sidebar { transition: none; }
  .is-on .speaker .w1,
  .is-on .speaker .w2 { animation: none; }
}

.quiz-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  margin-top: 18px;
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.quiz-entry h2 { margin: 0; font-size: 1.15rem; }
.quiz-entry p { margin: 4px 0 0; color: var(--muted); }
.quiz-last { color: var(--cinnabar-dark) !important; font-weight: 650; }

.quiz-go {
  border: 0;
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 16px;
  background: var(--cinnabar);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.quiz-go:hover { background: var(--cinnabar-dark); }

.quiz-zh {
  margin: -4px 0 10px;
  color: var(--muted);
  font-family: var(--serif);
  font-weight: 400;
}

.quiz-read p {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0;
  padding: 10px 14px;
  font-family: var(--py);
}

.quiz-read p + p { border-top: 1px solid var(--line); }

.quiz-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.quiz-card {
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.quiz-card img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: contain;
  background: white;
  border-radius: 10px;
}

.quiz-picks, .quiz-tones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.quiz-picks button, .quiz-tones button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 4px 10px;
  cursor: pointer;
  font-family: var(--py);
}

.quiz-picks button[aria-pressed="true"], .quiz-tones button[aria-pressed="true"] {
  border-color: var(--cinnabar);
  background: var(--cinnabar-soft);
  color: var(--cinnabar-dark);
}

.quiz-sec .sec-head { align-items: center; }

.quiz-hear {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.quiz-lines { list-style: none; margin: 0; padding: 0; }

.quiz-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
}

.quiz-no { width: 1.6rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.quiz-prompt { font-family: var(--py); }
.quiz-prompt input {
  width: 4.5rem;
  border: 0;
  border-bottom: 1px solid #b7aea3;
  background: transparent;
  font: inherit;
  text-align: center;
}

.quiz-prompt input:focus { outline: none; border-bottom-color: var(--cinnabar); }

.quiz-card.is-ok, .quiz-line.is-ok { box-shadow: inset 3px 0 0 #1f7a4d; }
.quiz-card.is-wrong, .quiz-line.is-wrong { box-shadow: inset 3px 0 0 var(--cinnabar); }
.quiz-key {
  display: block;
  margin-top: 8px;
  color: var(--cinnabar-dark);
  font-family: var(--py);
  font-size: 0.95rem;
  line-height: 1.4;
}

.quiz-hand h3 { margin: 14px 0 6px; font-size: 1rem; }
.quiz-hand h3:first-child { margin-top: 0; }
.quiz-hand-list { margin: 0; padding-left: 1.2rem; }
.quiz-hand-list li { margin: 6px 0; }
.quiz-hand .zh { font-family: var(--serif); font-weight: 400; font-size: 1.25rem; }
.quiz-hand .py { font-family: var(--py); color: var(--muted); margin-right: 6px; }

.quiz-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  position: sticky;
  bottom: 12px;
}

.quiz-score { margin: 0; font-weight: 700; }

body.needs-auth .app { display: none; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 420px at 80% -10%, rgba(159, 45, 45, 0.08), transparent 55%),
    var(--bg);
}

.gate[hidden] { display: none !important; }

.gate-card {
  width: min(420px, 100%);
  padding: 28px 22px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.gate-card h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.8rem;
  font-weight: 400;
}

.gate-card p { margin: 8px 0 0; color: var(--muted); }

.gate-card label,
.class-add label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.gate-card input,
.class-add input,
.class-reset input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.gate-error { min-height: 1.3em; color: var(--cinnabar); }

.gate-card .quiz-go { width: 100%; margin-top: 8px; }
.gate-card select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font: inherit; }
.gate-links { display: flex; justify-content: space-between; gap: 8px; }
.gate-links .text-btn { padding-left: 0; }
#gate-code { letter-spacing: 0.4em; font-size: 1.3rem; text-align: center; }
.class-mail { display: block; color: var(--faint); font-size: 12px; font-weight: 400; }

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#who-name {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.class-add h2 { margin: 0 0 4px; font-size: 1.05rem; }
.class-add .quiz-go { margin-top: 14px; }
.class-msg { min-height: 1.3em; margin: 8px 0 0; color: var(--cinnabar-dark); }
.class-miss { color: var(--faint); }
.class-wrap { overflow-x: auto; padding: 6px 8px 10px; }
.class-table { width: 100%; border-collapse: collapse; }
.class-table th,
.class-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.class-table th { font-size: 13px; }
.class-table th span { display: block; font-weight: 400; color: var(--faint); }
.class-score { font-variant-numeric: tabular-nums; white-space: nowrap; }
.class-name {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-weight: 650;
}
.class-name span { display: block; font-weight: 400; color: var(--faint); font-size: 12px; }
.class-detail td { background: #faf7f2; }
.class-detail h3 { margin: 14px 0 4px; font-size: 1rem; }
.class-detail h3:first-child { margin-top: 0; }
.class-review { max-height: 240px; overflow: auto; margin: 8px 0 0; padding-left: 1.1rem; }
.class-reset { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.class-reset input { flex: 1; }
.class-delete { margin-top: 4px; }

@media print {
  .gate { display: none !important; }
}

@media print {
  body { padding: 0; background: white; }
  .sidebar, .topbar, .backdrop, .settings, .pager, .toast, .playbar, .text-btn, .sheet-row, .my-note, .speaker, .hint, .app-tabs, .story-pop { display: none !important; }
  .card { box-shadow: none; }
}

.app-tabs {
  position: fixed;
  z-index: 70;
  left: 0;
  bottom: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #1a1614;
  border-top: 1px solid var(--side-line);
}

.app-tab {
  border: 0;
  border-radius: 12px;
  padding: 10px 8px;
  background: transparent;
  color: var(--side-muted);
  font-weight: 650;
  cursor: pointer;
}

.app-tab.is-on {
  background: var(--cinnabar);
  color: white;
}

.story-group {
  margin: 14px 8px 6px;
  color: var(--side-muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.story-title {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.story-label {
  margin: 0 0 12px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.story-block { margin-top: 8px; }
.story-block-py {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.story-zh-title,
.story-zh,
.story-word.is-han {
  font-family: var(--sans-zh);
}

.story-zh-title {
  margin: 0 0 16px;
  font-size: 28px;
  line-height: 1.5;
  font-weight: 700;
}

.story-zh {
  margin: 0 0 16px;
  font-size: 24px;
  line-height: 1.9;
  font-weight: 500;
}

.story-py-title,
.story-py { font-family: var(--py); }

.story-py-title {
  margin: 0 0 14px;
  font-size: 22px;
  line-height: 1.8;
}

.story-py {
  margin: 0 0 16px;
  font-size: 20px;
  line-height: 2;
  color: #3d342c;
}

.story-word {
  display: inline;
  border: 0;
  padding: 0 1px;
  margin: 0;
  background: transparent;
  border-radius: 6px;
  font: inherit;
  line-height: inherit;
  color: inherit;
  cursor: pointer;
}

.story-word:hover,
.story-word.is-on { background: #f8e7df; }

.story-keep { white-space: nowrap; }

.story-syl { border-bottom: 2px solid #9a9086; padding-bottom: 1px; }
.story-syl.t1 { border-bottom-color: #d4534a; }
.story-syl.t2 { border-bottom-color: #d0892a; }
.story-syl.t3 { border-bottom-color: #2f9d6a; }
.story-syl.t4 { border-bottom-color: #3a6fd8; }

.story-pop {
  position: fixed;
  z-index: 80;
  width: min(340px, calc(100vw - 24px));
  padding: 16px 16px 14px;
  border-radius: 18px;
  background: #1d2830;
  color: white;
  box-shadow: 0 18px 40px rgba(16, 22, 28, 0.35);
}

.story-pop[hidden] { display: none !important; }

.story-pop::before {
  content: "";
  position: absolute;
  left: var(--arrow, 28px);
  top: -7px;
  width: 14px;
  height: 14px;
  background: #1d2830;
  transform: rotate(45deg);
}

.story-pop.above::before { top: auto; bottom: -7px; }
.story-pop-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.story-pop-actions { display: flex; gap: 2px; flex: none; }
.story-pop-word { margin: 0; font-family: var(--py); font-size: 32px; font-weight: 650; }
.story-pop-han { margin: 2px 0 0; font-family: var(--sans-zh); font-size: 22px; color: #f2d7cf; font-weight: 700; }

.story-icon {
  border: 0;
  background: transparent;
  color: #d5e0e8;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
}

.story-icon:hover,
.story-icon.is-playing { background: rgba(255, 255, 255, 0.08); }
.story-icon.is-playing { color: #7df0b8; }

.story-badges { display: flex; gap: 8px; margin: 12px 0; }

.story-badge {
  border: 1px solid #3ecf8e;
  color: #7df0b8;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 700;
}

.story-gloss { margin: 0; font-size: 16px; line-height: 1.5; }
.story-more { margin: 8px 0 0; padding-left: 18px; color: #d5e0e8; }
.story-more li { margin: 4px 0; }

.story-more-link {
  display: inline-block;
  margin-top: 12px;
  border: 0;
  background: transparent;
  color: #3ddc8a;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

@media (max-width: 959px) {
  .sidebar { width: 100%; }
  .lesson { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .story-zh-title { font-size: 24px; }
  .story-zh { font-size: 22px; }
  .story-py { font-size: 18px; }
}

@media (min-width: 960px) {
  .app-tabs { width: var(--sidebar-w); }
}
