:root {
  --paper: #f3eddf;
  --paper-deep: #e7ddca;
  --ink: #173b36;
  --ink-soft: #4b625d;
  --red: #df553f;
  --red-dark: #be3e2d;
  --jade: #b8d1bd;
  --white: #fffdf7;
  --line: rgba(23, 59, 54, 0.14);
  --shadow: 0 26px 60px rgba(37, 45, 34, 0.16), 0 5px 14px rgba(37, 45, 34, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  height: 100dvh;
  background: #cfc9bd;
  color: var(--ink);
  font-family: "Manrope", system-ui, sans-serif;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
button, img { -webkit-user-drag: none; }
button { user-select: none; }

.app-shell {
  position: relative;
  width: min(100%, 460px);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 86% 4%, rgba(223, 85, 63, .11), transparent 30%),
    linear-gradient(155deg, #f8f3e9 0%, var(--paper) 65%, #eee5d5 100%);
}

[hidden] { display: none !important; }
.menu-screen {
  height: 100dvh;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.menu-header, .menu-player, .random-panel__top, .all-cards-panel__top, .section-heading, .all-cards-button, .all-cards-count {
  display: flex;
  align-items: center;
}
.menu-header { justify-content: space-between; }
.brand-mark {
  display: grid;
  width: 45px;
  height: 45px;
  place-items: center;
  border-radius: 50% 50% 50% 18%;
  background: var(--red);
  color: white;
  font-family: "Noto Serif SC", serif;
  font-size: 24px;
  font-weight: 700;
  transform: rotate(-4deg);
}
.menu-player { gap: 7px; font-size: 12px; font-weight: 800; }
.menu-player .avatar { border-color: rgba(255,255,255,.65); }
.menu-intro { margin: clamp(28px, 6dvh, 54px) 2px 24px; }
.menu-intro h1 { max-width: 340px; font-size: clamp(36px, 10vw, 48px); line-height: 1.02; }
.menu-intro > p:last-child { max-width: 330px; margin: 13px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }
.random-panel {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border-radius: 26px 26px 52px 26px;
  background: var(--ink);
  color: white;
  box-shadow: 0 18px 44px rgba(23,59,54,.16);
}
.random-panel::after {
  content: "";
  position: absolute;
  right: -42px;
  bottom: -65px;
  width: 150px;
  height: 150px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 50%;
  box-shadow: 0 0 0 28px rgba(255,255,255,.025), 0 0 0 56px rgba(255,255,255,.018);
}
.random-panel__top { position: relative; z-index: 1; justify-content: space-between; }
.menu-kicker { color: #e7a89b; font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.random-panel h2 { margin-top: 3px; color: white; font-size: 24px; }
.random-glyph { font-family: "Noto Serif SC", serif; font-size: 50px; line-height: 1; opacity: .2; }
.deck-size { position: relative; z-index: 1; display: flex; gap: 8px; margin: 20px 0 12px; }
.deck-size button {
  min-width: 58px;
  min-height: 44px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 13px;
  background: rgba(255,255,255,.07);
  color: white;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.deck-size button.is-selected { border-color: #f2b0a2; background: var(--red); }
.menu-primary {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 0 17px;
  border: 0;
  border-radius: 15px;
  background: var(--white);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.menu-primary span { font-size: 20px; }
#startReview { justify-content: center; text-align: center; }
.topics-section { margin-top: 28px; }
.section-heading { justify-content: space-between; margin: 0 2px 13px; }
.section-heading h2 { font-size: 21px; }
.section-heading span { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.topic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.topic-button {
  min-width: 0;
  min-height: 118px;
  padding: 12px 9px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,253,247,.67);
  text-align: left;
  cursor: pointer;
}
.topic-glyph {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
  place-items: center;
  border-radius: 50% 50% 16px 50%;
  font-family: "Noto Serif SC", serif;
  font-size: 22px;
  font-weight: 700;
}
.topic-glyph--coral { background: #f2c7bb; color: #9f3e2f; }
.topic-glyph--gold { background: #efdbac; color: #805b17; }
.topic-glyph--green { background: #c9ddca; color: #2f6659; }
.topic-glyph--blue { background: #c5dbe1; color: #326576; }
.topic-glyph--violet { background: #dad0e2; color: #634f75; }
.topic-glyph--ink { background: #cbd3cc; color: #294c46; }
.topic-glyph--rose { background: #e6c6cf; color: #8f4a5e; }
.topic-glyph--clay { background: #ddc9ac; color: #7a5230; }
.topic-button strong, .topic-button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-button strong { font-size: 12px; }
.topic-button small { margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
.all-cards-panel {
  position: relative;
  overflow: hidden;
  margin-top: 14px;
  padding: 20px;
  border-radius: 26px 26px 52px 26px;
  background: #1b4650;
  color: white;
  box-shadow: 0 18px 44px rgba(23,59,54,.16);
}
.all-cards-panel::after {
  content: "";
  position: absolute;
  right: -42px;
  bottom: -65px;
  width: 150px;
  height: 150px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 50%;
  box-shadow: 0 0 0 28px rgba(255,255,255,.025), 0 0 0 56px rgba(255,255,255,.018);
}
.all-cards-panel__top { position: relative; z-index: 1; justify-content: space-between; }
.all-cards-panel .menu-kicker { color: #9cc9bb; }
.all-cards-panel h2 { margin-top: 3px; color: white; font-size: 24px; }
.panel-glyph { font-family: "Noto Serif SC", serif; font-size: 50px; line-height: 1; opacity: .2; }
.all-cards-button {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 70px;
  justify-content: space-between;
  margin-top: 16px;
  padding: 0 17px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px;
  background: rgba(255,255,255,.07);
  color: white;
  text-align: left;
  cursor: pointer;
}
.all-cards-copy strong, .all-cards-copy small { display: block; }
.all-cards-copy strong { font-size: 15px; }
.all-cards-copy small { margin-top: 3px; color: rgba(255,255,255,.68); font-size: 11px; }
.all-cards-total { opacity: .72; }
.all-cards-count { gap: 12px; }
.all-cards-count > span { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: var(--jade); color: var(--ink); font-size: 18px; }
.all-cards-panel .toggle-row { position: relative; z-index: 1; border-bottom: 0; }
.all-cards-panel .switch { background: rgba(255,255,255,.24); }
.all-cards-panel .toggle-row[aria-checked="true"] .switch { background: var(--jade); }

.toggle-row {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.toggle-row:last-of-type { border-bottom: 0; }
.switch { position: relative; flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: rgba(23,59,54,.22); transition: background .2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s ease; }
.toggle-row[aria-checked="true"] .switch { background: var(--red); }
.toggle-row[aria-checked="true"] .switch::after { transform: translateX(18px); }
.toggle-arrow { color: var(--red-dark); font-size: 18px; font-weight: 800; }

.game-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 20px max(14px, env(safe-area-inset-bottom));
}

.topbar, .progress-row, .answer-buttons, .score-strip, .sheet-header {
  display: flex;
  align-items: center;
}
.topbar { justify-content: space-between; min-height: 44px; }
.topbar__left { display: flex; align-items: center; gap: 5px; }
.back-button { font-size: 25px; }
.avatar {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid var(--paper);
  border-radius: 50%;
  color: white;
  font-size: 10px;
  font-weight: 800;
}
.avatar--red { background: var(--red); }
.avatar--blue { background: #467d8b; }
.avatar--gold { background: #c5953d; }
.icon-button, .close-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.icon-button svg { width: 23px; height: 23px; }

.eyebrow { margin: 0 0 4px; color: var(--red-dark); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
h1, h2 { margin: 0; letter-spacing: -.04em; }
h1 { font-size: clamp(26px, 7vw, 32px); line-height: 1.1; }
h2 { font-size: 25px; }
.timer { position: relative; display: grid; width: 52px; height: 52px; place-items: center; }
.timer svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3; }
.timer__track { stroke: rgba(23,59,54,.12); }
.timer__progress { stroke: var(--red); stroke-linecap: round; stroke-dasharray: 113.1; stroke-dashoffset: 0; transition: stroke-dashoffset .3s linear; }
.timer span { font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.is-hidden { display: none; }

.progress-row { gap: 10px; margin: 14px 2px 14px; }
.progress-bar { flex: 1; height: 4px; overflow: hidden; border-radius: 99px; background: rgba(23,59,54,.11); }
.progress-bar span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--red); transition: transform .35s ease-out; transform-origin: left; }
.progress-row > span { min-width: 40px; color: var(--ink-soft); font-size: 11px; font-weight: 800; }
.progress-row .timer { flex: 0 0 auto; width: 38px; height: 38px; }
.progress-row .timer span { font-size: 9px; }

.card-stage { position: relative; flex: 1; min-height: 0; perspective: 1300px; }
.card-swipe-surface {
  position: absolute;
  z-index: 1;
  inset: 0;
  perspective: 1300px;
  transition: transform .35s cubic-bezier(.2,.75,.25,1), opacity .35s ease;
  will-change: transform;
}
.card-swipe-surface.is-dragging { transition: none; }
.card-swipe-surface.is-reset { transition: none !important; }
.card-bookmark {
  position: absolute;
  z-index: 5;
  top: -7px;
  right: 24px;
  width: 38px;
  height: 58px;
  padding: 0;
  border: 2px solid #326576;
  border-top: 0;
  background: #d9e8ec;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
  cursor: pointer;
  filter: drop-shadow(0 5px 5px rgba(37,45,34,.12));
}
.card-bookmark.is-active { background: #326576; }
.card-speak, .quiz-speak { display: inline-grid; place-items: center; width: 46px; height: 46px; border: 0; border-radius: 50%; background: linear-gradient(135deg, #fa8466, #cf4934); color: white; box-shadow: 0 4px 12px rgba(223,85,63,.3); cursor: pointer; }
.card-speak:active, .quiz-speak:active { transform: scale(.94); }
.card-speak { position: absolute; z-index: 5; top: 14px; left: 16px; }
.card-stack { position: absolute; z-index: 0; inset: 0; pointer-events: none; }
.stack-card {
  position: absolute;
  inset: 0;
  display: block;
  border: 1px solid rgba(255,255,255,.78);
  border-radius: 30px 30px 68px 30px;
  background: rgba(255,253,247,.72);
  box-shadow: 0 14px 36px rgba(37,45,34,.08);
  transform-origin: 50% 85%;
  transition: opacity .28s ease, transform .4s cubic-bezier(.2,.75,.25,1);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.stack-card--3 { opacity: .38; transform: translate(4px, -17px) rotate(2.6deg) scale(.962); }
.stack-card--2 { opacity: .56; transform: translate(-5px, -11px) rotate(-1.8deg) scale(.976); }
.stack-card--1 { opacity: .82; transform: translate(3px, -5px) rotate(.8deg) scale(.99); }
.stack-card.is-hidden { opacity: 0; transform: translateY(0) scale(.94); }
.flashcard { position: absolute; z-index: 1; inset: 0; width: 100%; height: auto; min-height: 0; padding: 0; border: 0; background: none; cursor: pointer; touch-action: none; }
.flashcard.is-reset,
.flashcard.is-reset .flashcard__inner,
.flashcard.is-reset .flashcard__face,
.flashcard.no-flip .flashcard__inner,
.flashcard.no-flip .flashcard__face { transition: none !important; }
.swipe-cue {
  position: absolute;
  z-index: 3;
  top: 72px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s linear;
}
.swipe-cue span { font-size: 18px; }
.swipe-cue--miss { left: 18px; background: rgba(229,222,209,.94); color: #6f5d56; border: 2px solid #c8bda9; transform: rotate(-6deg); }
.swipe-cue--hit { right: 18px; background: rgba(23,59,54,.94); color: white; border: 2px solid #2f7061; transform: rotate(6deg); }
.swipe-hint { position: absolute; z-index: 4; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; opacity: 0; transition: opacity .25s ease; pointer-events: none; }
.swipe-hint.is-visible { opacity: 1; }
.swipe-hint__side { display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 96px; color: var(--ink); }
.swipe-hint__side--miss { color: #7a655c; }
.swipe-hint__side--hit { color: var(--ink); }
.swipe-hint__arrow { font-size: 46px; font-weight: 800; line-height: 1; }
.swipe-hint__label { font-size: 12px; font-weight: 800; text-align: center; }
.flashcard__inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; -webkit-transform-style: preserve-3d; transition: transform .62s cubic-bezier(.2,.75,.25,1); }
.flashcard.is-flipped .flashcard__inner { transform: rotateY(180deg); }
.flashcard__face {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
  border-radius: 30px 30px 68px 30px;
  background: var(--white);
  box-shadow: var(--shadow);
  /* The visible face is decided purely by its orientation: no delayed
     visibility swap that can desync from the rotation and flash the other side. */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flashcard__front { flex-direction: column; align-items: center; justify-content: center; padding: 28px; transform: rotateY(0deg) translateZ(1px); }
.flashcard__front::before {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border: 1px solid rgba(223,85,63,.13);
  border-radius: 50%;
  box-shadow: 0 0 0 38px rgba(223,85,63,.04), 0 0 0 76px rgba(223,85,63,.025);
}
.card-label { z-index: 1; color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.hanzi { z-index: 1; display: flex; align-items: center; justify-content: center; margin: -4px 0 6px; font-family: "Noto Serif SC", serif; font-size: clamp(64px, min(34vw, 24dvh), 160px); font-weight: 600; line-height: 1; }
.hanzi[data-length="2"] { font-size: clamp(52px, min(26vw, 18dvh), 120px); }
.hanzi[data-length="3"] { font-size: clamp(40px, min(20vw, 14dvh), 92px); }
.hanzi-char { color: var(--radical-color, var(--ink)); }
.pinyin { z-index: 1; font-size: 26px; font-weight: 600; }
.flip-hint {
  position: absolute;
  bottom: 24px;
  z-index: 2;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font-size: 12px;
  font-weight: 800;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .24s ease, transform .24s ease;
}
.flip-hint.is-tutorial-visible { opacity: 1; transform: none; }
.flashcard__back { flex-direction: column; transform: rotateY(180deg) translateZ(1px); }
.association { display: block; width: 100%; height: 54%; flex: 0 0 54%; min-height: 0; object-fit: contain; object-position: center; background: #eee5d5; transition: opacity .12s ease; }
.association.is-loading,
.quiz-image.is-loading { opacity: 0; }
.back-copy { display: flex; flex: 1 1 auto; min-height: 0; flex-direction: column; align-items: center; justify-content: center; padding: 14px 18px; overflow: hidden; }
.translation { margin: 4px 0 2px; max-width: 100%; font-size: clamp(20px, 5.6vw, 32px); font-weight: 800; letter-spacing: -.03em; line-height: 1.12; text-align: center; overflow-wrap: anywhere; }
.back-pinyin { color: var(--ink-soft); font-size: 15px; font-weight: 600; text-align: center; }
.back-hanzi { font-family: "Noto Serif SC", serif; font-weight: 700; }

.answer-area { height: 93px; padding-top: 13px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.answer-area.is-visible { opacity: 1; pointer-events: auto; transform: none; }
.answer-area p { margin: 0 0 8px; color: var(--ink-soft); text-align: center; font-size: 11px; font-weight: 700; }
.answer-buttons { gap: 10px; }
.answer-button { flex: 1; min-height: 48px; border: 0; border-radius: 16px; font-size: 14px; font-weight: 800; cursor: pointer; }
.answer-button span { margin-right: 4px; font-size: 20px; vertical-align: -1px; }
.answer-button--miss { background: #e5ded1; color: #6f5d56; }
.answer-button--hit { background: var(--ink); color: white; }

.score-strip { justify-content: center; gap: 16px; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.score-player { display: grid; grid-template-columns: 28px auto auto; column-gap: 8px; align-items: center; }
.score-player .avatar { grid-row: 1; }
.score-player span:not(.avatar) { font-size: 12px; font-weight: 700; }
.score-player strong { font-size: 18px; line-height: 1; }

.result-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(22px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}
.result-heading h1 { font-size: clamp(30px, 8vw, 38px); }
.result-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0 16px; }
.result-stat { padding: 15px 17px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,253,247,.72); }
.result-stat b { display: block; font-size: 34px; line-height: 1; letter-spacing: -.04em; }
.result-stat span { display: block; margin-top: 5px; color: var(--ink-soft); font-size: 10px; font-weight: 800; letter-spacing: .1em; }
.result-stat--hit b { color: #2f6659; }
.result-stat--miss b { color: var(--red-dark); }
.result-list { flex: 1; min-height: 0; margin: 0; padding: 0; list-style: none; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); }
.result-item { border-bottom: 1px solid var(--line); font-size: 14px; }
.result-item__open { display: flex; width: 100%; gap: 10px; padding: 12px 4px; border: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.result-item__open:hover { background: rgba(23,59,54,.04); }
.result-mark { flex: 0 0 auto; width: 18px; font-weight: 800; text-align: center; }
.result-item.is-hit .result-mark { color: #2f6659; }
.result-item.is-miss .result-mark { color: var(--red); }
.result-word { min-width: 0; overflow-wrap: anywhere; }
.result-hanzi { color: var(--ink); font-family: "Noto Serif SC", serif; font-weight: 700; }
.result-item__open:hover .result-hanzi, .result-item__open:focus-visible .result-hanzi { color: var(--red-dark); }
.result-pinyin { margin-left: 4px; color: var(--ink-soft); }
.result-translation { color: var(--ink-soft); }
.result-home { display: flex; width: 100%; min-height: 56px; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; border: 0; border-radius: 18px; background: var(--ink); color: white; font-size: 15px; font-weight: 800; cursor: pointer; }
.result-home span { font-size: 20px; }

.sheet-backdrop { position: absolute; z-index: 5; inset: 0; background: rgba(20,33,30,.33); backdrop-filter: blur(3px); }
.settings-sheet {
  position: absolute;
  z-index: 6;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 20px max(18px, env(safe-area-inset-bottom));
  border-radius: 30px 30px 0 0;
  background: #fffdf7;
  box-shadow: 0 -20px 60px rgba(20,33,30,.18);
  transform: translateY(105%);
  transition: transform .38s cubic-bezier(.2,.8,.2,1);
}
.settings-sheet.is-open { transform: none; }
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 17px; border-radius: 99px; background: #d5cdbf; }
.sheet-header { justify-content: space-between; margin-bottom: 22px; }
.close-button { background: #eee8dd; font-size: 28px; font-weight: 400; }
fieldset { margin: 0 0 20px; padding: 0; border: 0; }
legend { margin-bottom: 10px; font-size: 13px; font-weight: 800; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.segmented button { min-height: 92px; padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: #f5f0e7; cursor: pointer; }
.segmented button strong { display: block; font-family: "Noto Serif SC", serif; font-size: 28px; }
.segmented button span { display: block; margin-top: 2px; font-size: 11px; font-weight: 700; }
.segmented button.is-selected { border-color: var(--red); background: #fbe9e4; box-shadow: inset 0 0 0 1px var(--red); }
.segmented--sm { grid-template-columns: 1fr 1fr; }
.segmented--sm button { min-height: 58px; }
.segmented--sm button strong { font-size: 22px; }
.timer-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.timer-options button { min-height: 44px; border: 1px solid var(--line); border-radius: 14px; background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }
.timer-options button.is-selected { border-color: var(--ink); background: var(--ink); color: white; }
.start-button { display: flex; width: 100%; min-height: 56px; align-items: center; justify-content: center; padding: 0 20px; border: 0; border-radius: 18px; background: var(--red); color: white; font-weight: 800; cursor: pointer; }
.start-button span { font-size: 15px; }
.toast { position: absolute; z-index: 9; bottom: 24px; left: 50%; padding: 10px 14px; border-radius: 12px; background: var(--ink); color: white; font-size: 12px; font-weight: 700; opacity: 0; transform: translate(-50%, 10px); transition: .2s ease; pointer-events: none; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

button:focus-visible { outline: 3px solid rgba(223,85,63,.38); outline-offset: 3px; }
button:active { transform: scale(.97); transition: transform .08s ease; }
.flashcard:active { transform: none; }

@media (max-height: 740px) {
  .menu-intro { margin-block: 20px 18px; }
  .topic-button { min-height: 105px; }
  .progress-row { margin-block: 10px; }
  .score-strip { margin-top: 4px; }
}
@media (min-width: 461px) {
  body { padding-block: 20px; }
  .app-shell { height: calc(100dvh - 40px); min-height: 0; border-radius: 36px; box-shadow: 0 30px 80px rgba(35,40,35,.25); }
  .game-screen, .result-screen, .menu-screen { height: 100%; }
  .settings-sheet { border-radius: 30px; bottom: 10px; left: 10px; right: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
@media (hover: hover) and (pointer: fine) {
  .icon-button:hover, .close-button:hover { background: rgba(23,59,54,.08); }
  .answer-button--hit:hover { background: #24564e; }
  .answer-button--miss:hover { background: #dad1c2; }
  .start-button:hover { background: var(--red-dark); }
}

/* ================================================================== *
 * Learning product — new screens & components
 * ================================================================== */

.view { height: 100%; min-height: 0; }
.home-screen,
.collection-screen,
.detail-screen,
.confuse-screen {
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.home-screen { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.collection-screen, .detail-screen, .confuse-screen { height: 100%; }

.topbar__actions { display: flex; align-items: center; gap: 2px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -.02em; }
.telegram-profile { display: flex; min-width: 0; max-width: 132px; align-items: center; gap: 6px; margin-right: 2px; }
.telegram-avatar,
.telegram-avatar-fallback { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; }
.telegram-avatar { display: block; object-fit: cover; }
.telegram-avatar-fallback { display: grid; place-items: center; background: var(--jade); color: var(--ink); font-size: 11px; font-weight: 800; }
.telegram-user-name { overflow: hidden; color: var(--ink-soft); font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 370px) {
  .telegram-profile { max-width: 32px; }
  .telegram-user-name { display: none; }
}

/* --- home --- */
.home-hero { text-align: center; margin: 4px 0 10px; }
.mascot-slot { display: grid; place-items: center; }
.mascot-slot--hero { width: 100px; height: 100px; margin: 0 auto 2px; }
.mascot-slot--overlay { width: 118px; height: 118px; margin: 0 auto 6px; }
.mascot { width: 100%; height: 100%; object-fit: contain; }
.mascot--idle { animation: mascot-bob 3.4s ease-in-out infinite; }
.mascot--celebrating { animation: mascot-pop .6s ease-out; }
.mascot--watering { animation: mascot-tilt 1.6s ease-in-out infinite; }
@keyframes mascot-bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-3px) } }
@keyframes mascot-pop { 0% { transform: scale(.9) } 60% { transform: scale(1.06) } 100% { transform: scale(1) } }
@keyframes mascot-tilt { 0%,100% { transform: rotate(-3deg) } 50% { transform: rotate(3deg) } }
/* Bao's face (mascot.js): every Bao blinks on its own rhythm. */
.mascot .bao-eye { transform-box: fill-box; transform-origin: center; animation: bao-blink 4.4s var(--blink-delay, 0s) infinite; }
@keyframes bao-blink { 0%, 93%, 100% { transform: scaleY(1) } 95.5% { transform: scaleY(.08) } }

.streak-chip { display: inline-block; margin: 0 0 4px; padding: 4px 10px; border-radius: 999px; background: #fbe6d8; color: #a5432c; font-size: 11px; font-weight: 800; }
.home-hero h1 { font-size: clamp(26px, 7vw, 32px); }
.home-sub { margin: 4px 0 8px; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.home-counts { display: flex; justify-content: space-between; margin-top: 8px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }

.progress-track { height: 8px; overflow: hidden; border-radius: 99px; background: rgba(23,59,54,.11); }
.progress-track > span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--red); transform-origin: left; transform: scaleX(0); transition: transform .5s cubic-bezier(.2,.75,.25,1); }
.progress-track--lg { height: 9px; }

.today-card { position: relative; padding: 14px; margin-bottom: 8px; border-radius: 22px 22px 38px 22px; background: var(--ink); color: white; box-shadow: 0 16px 40px rgba(23,59,54,.16); }
.today-card .menu-kicker { color: #e7a89b; }
.today-card h2 { margin: 3px 0; color: white; font-size: 20px; }
.today-sub { margin: 0 0 10px; color: rgba(255,255,255,.72); font-size: 11px; font-weight: 600; }
.menu-primary { display: flex; width: 100%; min-height: 44px; align-items: center; justify-content: center; gap: 10px; padding: 0 18px; border: 0; border-radius: 15px; background: var(--red); color: white; font-size: 14px; font-weight: 800; text-align: center; cursor: pointer; }
.menu-primary span { font-size: inherit; }
.menu-primary:hover { background: var(--red-dark); }
.menu-secondary { display: flex; width: 100%; min-height: 42px; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,247,.6); color: var(--ink); font-size: 13px; font-weight: 800; text-align: center; cursor: pointer; }

.goal-card { padding: 14px 16px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,253,247,.7); }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 9px; font-size: 12px; font-weight: 800; }
.goal-head b { font-variant-numeric: tabular-nums; }

.garden-card { padding: 12px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,253,247,.7); }
.garden-card .section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.garden-card h2 { font-size: 18px; }
.garden-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.garden-stat { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 5px; border-radius: 14px; background: rgba(184,209,189,.22); }
.garden-icon { font-size: 18px; }
.garden-stat b { font-size: 20px; letter-spacing: -.03em; }
.garden-stat small { color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.link-button { padding: 4px 2px; border: 0; background: none; color: var(--red-dark); font-size: 12px; font-weight: 800; cursor: pointer; }

/* --- session --- */
.session-progress { flex: 1; height: 5px; margin: 0 12px; overflow: hidden; border-radius: 99px; background: rgba(23,59,54,.11); }
.session-progress > span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--red); transform-origin: left; transform: scaleX(0); transition: transform .35s ease-out; }
.session-counter { color: var(--ink-soft); font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.card-tag { position: absolute; top: 16px; left: 50%; z-index: 2; transform: translateX(-50%); padding: 4px 12px; border-radius: 999px; background: rgba(223,85,63,.12); color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.mnemonic { margin-top: 8px; color: var(--ink-soft); font-size: 12px; line-height: 1.4; text-align: center; }

.session-actions { display: flex; gap: 10px; height: 74px; align-items: center; }
.reveal-actions { display: flex; height: 74px; align-items: center; }
.reveal-continue { display: block; width: 100%; min-height: 52px; border: 0; border-radius: 16px; background: var(--ink); color: white; font-size: 15px; font-weight: 800; cursor: pointer; }

.probe { position: absolute; z-index: 5; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 22px; border-radius: 30px 30px 68px 30px; background: var(--white); box-shadow: var(--shadow); }
.probe__title { margin: 0; color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-align: center; text-transform: uppercase; }
.probe__question { margin: 0 0 6px; font-size: 20px; font-weight: 800; line-height: 1.2; text-align: center; }
.probe__options { display: grid; gap: 9px; }
.probe-option { min-height: 54px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 15px; background: #f7f2e8; font-size: 16px; font-weight: 700; cursor: pointer; }
.probe-option:hover { border-color: var(--red); background: #fbe9e4; }

/* --- result extras --- */
.result-breakdown { margin: 0 0 14px; padding: 14px 16px; border-radius: 16px; background: rgba(184,209,189,.4); font-size: 13px; font-weight: 700; }
.result-breakdown p { margin: 2px 0; }

/* --- collection --- */
.collection-count { color: var(--ink-soft); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.search-field { display: block; margin: 8px 0 10px; }
.search-field input { width: 100%; min-height: 46px; padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,247,.8); color: var(--ink); font: inherit; font-size: 14px; }
.search-field input:focus { outline: 2px solid rgba(223,85,63,.35); }
.filter-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.chip { padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,253,247,.6); font-size: 12px; font-weight: 700; cursor: pointer; }
.chip.is-selected { border-color: var(--ink); background: var(--ink); color: white; }
.character-grid { display: grid; flex: 1; min-height: 0; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; }
.character-tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,247,.72); cursor: pointer; }
.character-tile__hanzi { font-family: "Noto Serif SC", serif; font-size: 27px; line-height: 1; }
.character-tile__meta { color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.character-tile.state-new { opacity: .5; }
.character-tile.state-new .character-tile__hanzi { color: #8b8b82; }
.character-tile.state-familiar { border-color: #cfe0cf; background: rgba(207,224,207,.5); }
.character-tile.state-remembered { border-color: #b9d3bd; background: rgba(184,209,189,.5); }
.character-tile.state-mastered { border-color: var(--red); background: #fbe4dd; }
.character-tile.is-due { box-shadow: 0 0 0 2px rgba(223,85,63,.35); }
.character-tile__due { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 99px; background: var(--red); overflow: hidden; font-size: 0; }
.empty-state { padding: 30px 10px; color: var(--ink-soft); font-size: 14px; text-align: center; }

/* --- detail --- */
.detail-hero { padding: 4px 0 10px; text-align: center; }
.detail-pronunciation { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 6px; }
.detail-pronunciation__sep { color: var(--ink-soft); font-size: 19px; font-weight: 600; }
.detail-pronunciation:not(:has(.detail-speak:not([hidden]))) .detail-pronunciation__sep { display: none; }
.detail-speak { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 99px; color: #fff; cursor: pointer; background: linear-gradient(135deg, rgba(255,122,89,.82), rgba(223,85,63,.82) 55%, rgba(199,62,44,.82)); box-shadow: 0 4px 12px rgba(223,85,63,.3), inset 0 1px 0 rgba(255,255,255,.3); }
.detail-speak:hover { box-shadow: 0 6px 16px rgba(223,85,63,.42), inset 0 1px 0 rgba(255,255,255,.3); transform: translateY(-1px); }
.detail-speak:active { transform: scale(.94); }
.detail-bookmark { min-height: 34px; padding: 0 12px; border: 1px solid var(--red); border-radius: 12px; background: transparent; color: var(--red-dark); font-size: 11px; font-weight: 800; cursor: pointer; }
.detail-bookmark.is-active { background: var(--red); color: #fff; }
.detail-hanzi { display: block; margin: 0 auto; padding: 0; border: 0; background: none; font-family: "Noto Serif SC", serif; font-size: clamp(64px, 22vw, 100px); line-height: 1; font-weight: 600; cursor: pointer; }
.detail-pinyin { color: var(--ink-soft); font-size: 19px; font-weight: 600; }
.detail-translation { display: block; margin-top: 1px; font-size: 15px; font-weight: 700; }
.detail-rows { display: grid; gap: 1px; }
.detail-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 12px; }
.detail-row__label { color: var(--ink-soft); font-weight: 600; }
.detail-row__value { font-weight: 800; }
.detail-row__bar { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 99px; background: rgba(23,59,54,.11); }
.detail-row__bar > span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--red); transform-origin: left; }
.detail-sections { margin-top: 10px; }
.composition-row { display: flex; align-items: flex-start; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 4px 0 2px; }
.composition-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px; }
.composition-cell__glyph { font-family: "Noto Serif SC", serif; font-size: 44px; line-height: 1.15; font-weight: 600; }
.composition-cell__role { font-size: 9.5px; font-weight: 800; letter-spacing: .4px; text-transform: lowercase; color: var(--ink-soft); opacity: .85; }
.composition-cell__role--radical { color: var(--red-dark); opacity: 1; }
.composition-cell__role--phonetic { color: #3e6f91; opacity: 1; }
.composition-cell__role--semantic { color: #2f7061; opacity: 1; }
.composition-cell__gloss { color: var(--ink-soft); font-size: 11.5px; font-weight: 700; text-align: center; line-height: 1.3; }
.composition-plus { color: var(--ink-soft); font-size: 20px; font-weight: 600; padding: 12px 2px 0; }
.detail-section { margin-bottom: 8px; }
.detail-section h3 { margin: 0 0 3px; font-size: 12px; }
.detail-section p { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.4; }
.detail-examples { margin-top: 10px; }
.detail-screen {
  overflow-y: auto;
}
.detail-example {
  padding: 12px;
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 10px 26px rgba(37, 45, 34, .08), 0 2px 6px rgba(37, 45, 34, .05);
}
.detail-example h3 { margin-bottom: 8px; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
.detail-example__list { display: grid; gap: 10px; }
.detail-example__item + .detail-example__item { padding-top: 10px; border-top: 1px solid var(--line); }
.detail-example__zh { margin: 0; font-family: "Noto Serif SC", serif; font-size: 19px; line-height: 1.4; color: var(--ink); }
.detail-example__target { color: var(--red); font-weight: 700; }
.detail-example__pinyin { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 12px; letter-spacing: .01em; }
.detail-example__ru { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 12px; line-height: 1.4; }
.detail-example__more { width: 100%; min-height: 34px; margin-top: 10px; border: 0; border-radius: 12px; background: var(--paper-deep); color: var(--ink); font-size: 12px; font-weight: 800; cursor: pointer; }
.detail-example__more::after { content: " ↓"; }
.detail-screen .reveal-continue { margin-top: auto; }

.examples-modal { position: absolute; z-index: 12; inset: 0; display: flex; align-items: flex-end; }
.examples-modal[hidden] { display: none; }
.examples-modal__backdrop { position: absolute; inset: 0; background: rgba(20,33,30,.42); backdrop-filter: blur(3px); }
.examples-modal__sheet {
  position: relative;
  display: flex;
  width: 100%;
  max-height: calc(100% - max(20px, env(safe-area-inset-top)));
  flex-direction: column;
  padding: 18px 20px max(24px, env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--white);
  box-shadow: 0 -20px 60px rgba(20,33,30,.22);
}
.examples-modal__header { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.examples-modal__header h2 { font-size: 21px; }
.examples-modal__list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 2px 2px 8px; }

/* --- confusions --- */
.confuse-list { display: grid; gap: 10px; overflow-y: auto; }
.confuse-row { padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,253,247,.72); }
.confuse-chars { display: flex; align-items: center; justify-content: space-around; gap: 12px; }
.confuse-char { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.confuse-glyph { font-family: "Noto Serif SC", serif; font-size: 40px; line-height: 1; }
.confuse-char small { color: var(--ink-soft); font-size: 10px; font-weight: 700; text-align: center; }
.pro-teaser { margin-top: auto; padding: 16px; border-radius: 18px; background: rgba(223,85,63,.08); }
.pro-teaser p { margin: 0 0 12px; font-size: 13px; font-weight: 700; line-height: 1.45; }

/* --- overlays --- */
.overlay { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(20,33,30,.42); backdrop-filter: blur(3px); }
.overlay-card { width: 100%; max-width: 360px; padding: 24px; border-radius: 26px; background: #fffdf7; box-shadow: 0 26px 60px rgba(20,33,30,.28); text-align: center; }
.overlay-card h2 { margin: 4px 0 8px; font-size: 24px; }
.overlay-lead { margin: 0 0 10px; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.overlay-benefit { margin: 0 0 10px; font-size: 13px; font-weight: 700; line-height: 1.5; }
.overlay-note { margin: 12px 0 14px; color: #9a8f83; font-size: 11px; font-weight: 600; }
.overlay-card .menu-primary { justify-content: center; }
.overlay-card .link-button { display: block; margin: 10px auto 0; }

@media (prefers-reduced-motion: reduce) {
  .mascot--idle, .mascot--celebrating, .mascot--watering { animation: none !important; }
  .mascot .bao-eye, .result-bao__mascot .mascot, .result-bao__line { animation: none !important; }
}

/* layout fixes for inner headers + overlays */
.confuse-screen .topbar { align-items: center; gap: 6px; }
.confuse-screen .topbar h2 { flex: 1; font-size: 17px; line-height: 1.15; text-align: left; }
.collection-screen .topbar h2 { flex: 1; font-size: 19px; text-align: center; }
.collection-screen .topbar .icon-button { flex: 0 0 auto; }
.overlay { overflow-y: auto; }
@media (max-width: 460px) {
  .confuse-screen .topbar h2 { font-size: 15px; }
}

/* --- free play screen --- */
.play-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: max(16px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}
.play-screen .topbar { align-items: center; gap: 6px; margin-bottom: 4px; }
.play-screen .topbar h2 { flex: 1; font-size: 19px; text-align: center; }
.play-screen .topbar .icon-button { flex: 0 0 auto; }
.play-screen .random-panel { margin-top: 12px; }
.play-screen .topics-section { margin-top: 20px; }
.home-screen .menu-secondary { margin-bottom: 12px; }

/* scrolling screens must not shrink their sections */
.home-screen > *, .play-screen > * { flex: 0 0 auto; }

/* --- quiz mode --- */
.probe { justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; scroll-padding-block: 18px; }
.quiz-hanzi {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px 0 2px;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(64px, 26vw, 104px);
  font-weight: 600;
  line-height: 1;
}
.quiz-hanzi[data-length="2"] { font-size: clamp(48px, 20vw, 80px); }
.quiz-hanzi[data-length="3"] { font-size: clamp(38px, 15vw, 62px); }
.quiz-speak { flex: 0 0 auto; align-self: center; margin: 0 auto 4px; }
.probe-option.is-correct { border-color: #2f8a5a; background: #e2f3e7; color: #1f6440; box-shadow: inset 0 0 0 1px #2f8a5a; }
.probe-option.is-wrong { border-color: var(--red); background: #fbe4dd; color: var(--red-dark); box-shadow: inset 0 0 0 1px var(--red); }
.probe-option:disabled { cursor: default; opacity: 1; }
.quiz-feedback { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 4px; }
.quiz-image {
  width: 100%;
  max-height: min(24dvh, 180px);
  object-fit: contain;
  border-radius: 18px;
  background: #eee5d5;
}
.quiz-translation { font-size: 18px; font-weight: 800; text-align: center; }
.quiz-pinyin { color: var(--ink-soft); font-size: 14px; font-weight: 600; }
.quiz-bookmark { align-self: center; cursor: pointer; }

.result-stars { display: flex; justify-content: center; gap: 8px; margin: 4px 0 16px; font-size: 38px; line-height: 1; }
.result-stars .star { color: rgba(23,59,54,.16); transition: transform .2s ease; }
.result-stars .star.is-on { color: #e8a93a; text-shadow: 0 2px 6px rgba(232,169,58,.35); }

/* ghost CTA on the dark today-card + free-play mode picker */
.menu-ghost {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  padding: 0 18px;
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 16px;
  background: rgba(255,255,255,.08);
  color: white;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}
.all-cards-button { justify-content: center; text-align: center; }
.all-cards-copy { text-align: center; }

@media (max-height: 740px) {
  .home-screen { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .mascot-slot--hero { width: 76px; height: 76px; }
  .home-hero { margin-block: 0 7px; }
  .home-counts { margin-top: 5px; }
  .today-card { padding: 12px 14px; }
  .garden-stat { padding-block: 5px; }
}
.menu-ghost:hover { background: rgba(255,255,255,.16); }
.play-mode-card { padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,253,247,.7); }
.play-mode-card .section-heading { margin-bottom: 12px; }
.play-mode-card .section-heading span { color: var(--ink-soft); font-size: 11px; font-weight: 700; }

/* ================================================================== *
 * Mobile product shell — flow redesign
 * ================================================================== */

.app-shell { max-width: 430px; }

.screen-header {
  flex: 0 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  background: rgba(248, 243, 233, .92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.screen-header h2 { flex: 1; font-size: 18px; text-align: center; }
.header-spacer { width: 44px; height: 44px; }
.screen-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.screen-footer {
  flex: 0 0 auto;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(248, 243, 233, .96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Home: one clear daily action, progress, garden, then free practice. */
.home-screen { padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); }
.home-screen .topbar { flex: 0 0 auto; }
.home-practice { margin: 8px 0 0; padding: 9px 14px; min-height: 52px; }
.home-practice > span { display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 2px; }
.home-practice strong { font-size: 13px; }
.home-practice small { color: var(--ink-soft); font-size: 10px; font-weight: 600; }
.home-screen .garden-card { margin-top: 0; }

/* Free practice is a single configuration flow with one start action. */
.play-screen { display: flex; height: 100%; flex-direction: column; padding: 0; overflow: hidden; }
.practice-scroll { flex: 1 1 auto; padding: 8px 16px 18px; }
.screen-intro { padding: 6px 2px 12px; }
.screen-intro h1 { margin-top: 3px; font-size: 28px; }
.screen-intro p { margin: 6px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.config-card {
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,253,247,.76);
}
.config-card .section-heading { margin-bottom: 10px; }
.config-card .section-heading h2 { font-size: 17px; }
.source-control { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.source-control button {
  display: grid;
  min-height: 66px;
  place-items: center;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f5f0e7;
  cursor: pointer;
}
.source-control button > span { font-family: "Noto Serif SC", serif; font-size: 23px; line-height: 1; }
.source-control button strong { font-size: 11px; }
.source-control button.is-selected { border-color: var(--red); background: #fbe9e4; box-shadow: inset 0 0 0 1px var(--red); }
.deck-size-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.deck-size-row > span { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.deck-size { margin: 0; }
.deck-size button { min-width: 46px; min-height: 38px; border-color: var(--line); background: #f5f0e7; color: var(--ink); }
.deck-size button.is-selected { border-color: var(--ink); background: var(--ink); color: white; }
.config-card .toggle-row { margin-top: 8px; }
.topics-section.config-card { margin-top: 0; }
.topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.topic-button { display: grid; min-height: 72px; grid-template-columns: 38px 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 9px; padding: 9px; border-radius: 16px; }
.topic-button .topic-glyph { grid-row: 1 / 3; width: 38px; height: 38px; margin: 0; font-size: 19px; }
.topic-button strong, .topic-button small { align-self: end; }
.topic-button small { align-self: start; }
.topic-button.is-selected { border-color: var(--red); background: #fbe9e4; box-shadow: inset 0 0 0 1px var(--red); }
.selection-summary { min-height: 15px; margin: 0 0 7px; color: var(--ink-soft); font-size: 10px; font-weight: 700; text-align: center; }

/* Sessions reserve fixed chrome; only the card/probe owns overflow. */
.game-screen { padding: max(10px, env(safe-area-inset-top)) 14px max(8px, env(safe-area-inset-bottom)); }
.game-screen > .topbar { flex: 0 0 auto; }
.session-actions, .reveal-actions { flex: 0 0 auto; height: 66px; }
.probe { padding: 18px 16px 8px; }
.quiz-sticky-action {
  position: sticky;
  z-index: 7;
  bottom: -8px;
  margin-top: 12px;
  padding: 10px 0 8px;
  background: linear-gradient(180deg, rgba(255,253,247,0), var(--white) 22%);
}
.quiz-sticky-action .reveal-continue { box-shadow: 0 10px 24px rgba(23,59,54,.18); }

/* Results expose all meaningful next steps without hiding the mistake list. */
.result-screen { padding: max(18px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); }
.result-summary { margin: 14px 0 12px; }
.result-actions { flex: 0 0 auto; display: grid; gap: 8px; padding-top: 10px; }
.result-actions .result-home { min-height: 50px; margin: 0; }
.result-retry { min-height: 46px; border: 1px solid var(--ink); border-radius: 16px; background: transparent; color: var(--ink); font-size: 13px; font-weight: 800; cursor: pointer; }
.result-home-link { margin: 0 auto; min-height: 34px; }

/* Settings are a full-height mobile surface with independently scrolling content. */
.settings-sheet {
  top: 0;
  bottom: 0;
  display: flex;
  max-height: none;
  height: 100%;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: 0;
  transform: translateY(100%);
}
.settings-sheet .sheet-header {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  margin: 0;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: #fffdf7;
}
.settings-scroll { flex: 1 1 auto; min-height: 0; padding: 16px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.settings-scroll fieldset { margin-bottom: 18px; }
.settings-footer { flex: 0 0 auto; padding: 10px 16px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fffdf7; }
.settings-footer .start-button { min-height: 50px; }

@media (min-width: 461px) {
  .app-shell { max-width: 430px; }
  .settings-sheet { top: 0; right: 0; bottom: 0; left: 0; border-radius: 0; }
}

@media (max-height: 680px) {
  .home-hero h1 { font-size: 24px; }
  .mascot-slot--hero { width: 64px; height: 64px; }
  .today-card { padding-block: 10px; }
  .today-card .menu-primary, .today-card .menu-ghost { min-height: 38px; }
  .garden-card { padding: 10px; }
  .garden-stat { padding-block: 4px; }
  .home-practice { min-height: 46px; }
}

/* ================================================================== *
 * Calm mobile ritual — product shell v2
 * ================================================================== */
:root {
  --paper: #f3eddf;
  --paper-deep: #e7ddca;
  --ink: #173b36;
  --ink-soft: #4b625d;
  --red: #df553f;
  --red-dark: #be3e2d;
  --jade: #b8d1bd;
  --white: #fffdf7;
  --line: rgba(23,59,54,.14);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #17251e;
  --paper-deep: #293e31;
  --ink: #e5ebd9;
  --ink-soft: #a1af9e;
  --red: #e38a68;
  --red-dark: #eba183;
  --jade: #91ac7f;
  --white: #203329;
  --line: rgba(229,235,217,.14);
}
:root[data-theme="dark"] body { background: #111d17; }
:root[data-theme="dark"] .app-shell {
  background: radial-gradient(circle at 86% 4%, rgba(227,138,104,.1), transparent 30%), linear-gradient(155deg, #1b2c23, var(--paper));
}
:root[data-theme="dark"] .screen-header,
:root[data-theme="dark"] .screen-footer,
:root[data-theme="dark"] .bottom-nav { background: rgba(23,37,30,.94); }
:root[data-theme="dark"] .settings-sheet,
:root[data-theme="dark"] .settings-sheet .sheet-header,
:root[data-theme="dark"] .settings-footer { background: var(--white); }
:root[data-theme="dark"] .segmented button { background: var(--paper); color: var(--ink); }
:root[data-theme="dark"] .segmented button.is-selected { background: rgba(227,138,104,.2); color: var(--ink); }
:root[data-theme="dark"] .close-button { background: var(--paper-deep); color: var(--ink); }

.app-shell { padding-bottom: 76px; }
.view { height: calc(100dvh - 76px); min-height: 0; }
.game-screen, .result-screen, .detail-screen { height: 100dvh; }
/* In the framed desktop shell (≥461px, 40px shorter than the viewport) full
   screens must fit the frame, or their bottom actions are cut off. */
@media (min-width: 461px) { .game-screen, .result-screen, .detail-screen { height: 100%; } }
.home-screen { padding-bottom: 16px; }
.home-eyebrow { display: block; color: var(--ink-soft); font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.home-hero { margin-top: 4px; }
.home-hero h1 { margin: 5px 0 0; letter-spacing: -.045em; }
.mascot-slot--hero { width: 112px; height: 112px; margin-bottom: 1px; }
.today-card { background: var(--ink); border-radius: 24px; }
.today-card .menu-primary { background: var(--red); color: #fffef9; justify-content: center; }
.garden-card, .daily-word, .config-card, .activity-card, .memory-card, .metric-card { box-shadow: 0 8px 28px -22px rgba(41,73,59,.28); }
.daily-word {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 10px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--white);
}
.daily-word h2 { margin: 5px 0 1px; font-size: 18px; }
.daily-word h2 span { margin-right: 5px; font: 30px "Noto Serif SC", serif; }
.daily-word p { margin: 0; color: var(--ink-soft); font-size: 10px; }
.daily-word__open { width: 44px; height: 44px; flex: 0 0 auto; border: 0; border-radius: 14px; background: var(--paper-deep); color: var(--ink); font-size: 20px; }

.bottom-nav {
  position: absolute; z-index: 20; right: 0; bottom: 0; left: 0; display: grid;
  grid-template-columns: repeat(4,1fr); padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(255,254,249,.94);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.bottom-nav button { position: relative; display: flex; min-height: 52px; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; border-radius: 14px; background: transparent; color: var(--ink-soft); }
.bottom-nav button > span { display: grid; width: 34px; height: 25px; place-items: center; border-radius: 10px; font: 19px "Noto Serif SC", serif; }
.bottom-nav button > small { font-size: 9px; font-weight: 700; }
.bottom-nav button.is-active { color: var(--red-dark); }
.bottom-nav button.is-active > span { background: rgba(184,88,57,.12); }
.app-shell:has(.game-screen:not([hidden])) .bottom-nav,
.app-shell:has(.result-screen:not([hidden])) .bottom-nav,
.app-shell:has(.detail-screen:not([hidden])) .bottom-nav,
.app-shell:has(.onboarding:not([hidden])) .bottom-nav { display: none; }
.app-shell:has(.game-screen:not([hidden])),
.app-shell:has(.result-screen:not([hidden])),
.app-shell:has(.detail-screen:not([hidden])),
.app-shell:has(.onboarding:not([hidden])) { padding-bottom: 0; }

.quiz-direction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.quiz-direction-grid button { display: flex; min-height: 62px; flex-direction: column; justify-content: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); text-align: left; }
.quiz-direction-grid button:first-child { grid-column: 1 / -1; min-height: 52px; align-items: center; }
.quiz-direction-grid b { font: 15px "Noto Serif SC", serif; }
.quiz-direction-grid span { margin-top: 2px; color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.quiz-direction-grid button.is-selected { border-color: var(--red); background: rgba(184,88,57,.1); box-shadow: inset 0 0 0 1px var(--red); }
.quiz-hanzi.quiz-prompt--text { font-family: "Manrope", system-ui, sans-serif; font-size: clamp(24px, 8vw, 38px); line-height: 1.25; text-align: center; }
.probe-option--hanzi { font-family: "Noto Serif SC", serif; font-size: 28px; }

.stats-screen { display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 16px 10px; }
.stats-header { flex: 0 0 auto; }
.stats-header h1 { margin: 2px 0 0; font-size: 28px; }
.stats-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 0 18px; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.metric-card { position: relative; min-height: 112px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--white); }
.metric-card > span { position: absolute; top: 13px; right: 14px; font-size: 17px; }
.metric-card b { display: block; margin-top: 28px; font-size: 29px; letter-spacing: -.05em; }
.metric-card small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 9px; }
.activity-card, .memory-card { margin-top: 10px; padding: 17px; border: 1px solid var(--line); border-radius: 20px; background: var(--white); }
.activity-heatmap { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 4px; margin-top: 12px; overflow: hidden; }
.heat-cell { aspect-ratio: 1; min-width: 8px; border-radius: 3px; background: var(--paper-deep); }
.heat-cell[data-level="1"] { background: #d6e1cb; }.heat-cell[data-level="2"] { background: #adc39d; }.heat-cell[data-level="3"] { background: #7e9e70; }.heat-cell[data-level="4"] { background: #55784f; }
.memory-donut { display: grid; width: 146px; height: 146px; margin: 16px auto; place-items: center; border-radius: 50%; background: conic-gradient(var(--jade) 0 var(--strong), var(--red) var(--strong) var(--mastered), var(--paper-deep) var(--mastered)); }
.memory-donut > div { display: grid; width: 112px; height: 112px; place-items: center; align-content: center; border-radius: 50%; background: var(--white); }
.memory-donut b { font-size: 30px; }.memory-donut small { color: var(--ink-soft); font-size: 9px; }
.memory-legend { display: flex; justify-content: center; gap: 20px; color: var(--ink-soft); font-size: 11px; }

.onboarding { position: absolute; z-index: 50; inset: 0; display: flex; flex-direction: column; background: var(--paper); }
.onboarding__header { display: flex; min-height: 70px; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 20px 8px; }
.onboarding__progress { display: flex; gap: 6px; padding: 5px 20px; }
.onboarding__progress span { height: 5px; flex: 1; border-radius: 5px; background: var(--paper-deep); }
.onboarding__progress span.is-done { background: var(--red); }
.onboarding__body { display: flex; flex: 1; min-height: 0; flex-direction: column; align-items: center; justify-content: center; padding: 10px 28px; text-align: center; }
.onboarding__mascot { width: min(230px, 56vw); height: min(230px, 29dvh); margin-bottom: 12px; }
.onboarding__body h1 { max-width: 340px; margin: 12px 0 10px; font-size: 32px; line-height: 1.12; letter-spacing: -.05em; }
.onboarding__body > p { max-width: 330px; margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
.onboarding__demo { display: flex; min-width: 210px; margin-top: 24px; align-items: center; justify-content: center; gap: 9px; padding: 17px; border: 1px solid var(--line); border-radius: 22px; background: var(--white); }
.onboarding__demo span { font: 58px "Noto Serif SC", serif; }.onboarding__demo b { font-size: 18px; }.onboarding__demo small { color: var(--ink-soft); }
.onboarding__bookmark-demo { position: relative; display: flex; width: min(280px, 80vw); min-height: 104px; margin-top: 24px; align-items: center; justify-content: center; padding: 28px 24px 18px; border: 1px solid var(--line); border-radius: 22px; background: var(--white); }
.onboarding__bookmark-demo small { max-width: 190px; color: var(--ink-soft); font-size: 12px; font-weight: 700; line-height: 1.45; }
.bookmark-ribbon { position: absolute; top: -1px; right: 24px; width: 34px; height: 56px; border: 2px solid #326576; border-top: 0; background: #d9e8ec; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%); filter: drop-shadow(0 5px 5px rgba(37,45,34,.12)); }
.onboarding__footer { padding: 12px 20px max(16px, env(safe-area-inset-bottom)); }
.onboarding__footer .menu-primary { justify-content: center; background: var(--red); color: #fff; }

@media (max-height: 700px) {
  .daily-word { display: none; }
  .onboarding__mascot { width: 150px; height: 150px; }
  .onboarding__body h1 { font-size: 27px; }
}

/* Touch handwriting practice. */
#playModeControl, #gameModeControl { grid-template-columns: repeat(3, 1fr); }
.handwriting {
  position: absolute; z-index: 6; inset: 0; display: flex; min-height: 0;
  flex-direction: column; align-items: center; overflow-y: auto; padding: 14px 14px 10px;
  border-radius: 30px 30px 68px 30px; background: var(--white); box-shadow: var(--shadow);
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.handwriting__eyebrow { margin: 0; color: var(--red-dark); font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.handwriting__word { display: flex; min-height: 38px; align-items: center; justify-content: center; gap: 6px; margin-top: 4px; }
.handwriting__word span { color: var(--ink-soft); font: 25px "Noto Serif SC", serif; opacity: .38; }
.handwriting__word span.is-active { color: var(--ink); opacity: 1; transform: scale(1.14); }
.handwriting__word span.is-done { color: #2f8a5a; opacity: 1; }
.handwriting__meaning { margin: 1px 0 2px; color: var(--ink-soft); font-size: 11px; font-weight: 700; text-align: center; }
.handwriting__reference { min-height: 28px; margin: 0; color: var(--ink); font: 25px "Noto Serif SC", serif; }
.handwriting__canvas {
  position: relative; width: min(270px, calc(100vw - 64px)); height: min(270px, calc(100vw - 64px)); flex: 0 0 auto;
  border: 1px solid var(--line); border-radius: 18px; background-color: #fffdf7;
  background-image: linear-gradient(rgba(23,59,54,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(23,59,54,.08) 1px, transparent 1px);
  background-size: 50% 50%; overflow: hidden; touch-action: none;
}
.handwriting__canvas svg, .handwriting__canvas canvas { display: block; touch-action: none; }
.handwriting__writer-svg > g > path { filter: url(#handwritingLiveBrush); }
.handwriting__writer-svg.is-concealed { visibility: hidden; }
.handwriting__brush-overlay { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.handwriting__brush-stroke { fill: #df553f; filter: drop-shadow(0 .4px .35px rgba(80, 35, 22, .2)); }
.handwriting__comparison { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
.handwriting__comparison-side { display: flex; min-width: 0; flex-direction: column; align-items: center; justify-content: center; background: #fffdf7; }
.handwriting__comparison-side small { margin-bottom: 8px; color: var(--ink-soft); font-size: 8px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.handwriting__comparison-reference span { color: #173b36; font: clamp(72px, 24vw, 102px) "Noto Serif SC", serif; line-height: 1; }
.handwriting__comparison-drawing { padding: 8px 4px 4px; }
.handwriting__result-svg { width: 100%; height: auto; max-height: calc(100% - 24px); }
.handwriting__status { min-height: 18px; margin: 6px 0 4px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.handwriting__tools, .handwriting__complete { display: grid; width: 100%; grid-template-columns: 1fr 1fr; gap: 8px; }
.handwriting__tools button { min-height: 40px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); color: var(--ink); font-size: 10px; font-weight: 800; }
.handwriting__complete .menu-primary, .handwriting__complete .menu-secondary { min-height: 44px; margin: 0; justify-content: center; }
.handwriting-auto-hint { margin-top: 12px; text-align: left; }
.handwriting-auto-hint > span:first-child { display: grid; gap: 2px; }
.handwriting-auto-hint b { font-size: 11px; }
.handwriting-auto-hint small { color: var(--ink-soft); font-size: 9px; line-height: 1.35; }
@media (max-height: 690px) {
  .handwriting { padding-top: 8px; }
  .handwriting__canvas { width: min(220px, calc(100vw - 84px)); height: min(220px, calc(100vw - 84px)); }
  .handwriting__reference { min-height: 23px; font-size: 21px; }
}

/* ==================================================================
 * Roadmap: levels, path, achievements, cloze, exam, tutorials, paywall
 * ================================================================== */

.pro-badge { display: inline-block; margin-left: 5px; padding: 1px 6px; border-radius: 99px; background: var(--ink); color: var(--paper); font-size: 8px; font-style: normal; font-weight: 800; letter-spacing: .08em; vertical-align: middle; }
.segmented button .pro-badge { display: block; width: max-content; margin: 3px auto 0; }
.fieldset-hint { margin: -2px 2px 10px; color: var(--ink-soft); font-size: 11px; line-height: 1.4; }

/* --- hero level (home) --- */
.hero-level { display: grid; width: min(100%, 300px); gap: 5px; margin: 10px auto 0; padding: 9px 13px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,247,.66); color: var(--ink); text-align: left; cursor: pointer; }
.hero-level__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.hero-level__head b { font-size: 12px; }
.hero-level__head span { color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .04em; }
.hero-level small { color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.progress-track--xp { height: 6px; }
.progress-track--xp > span { background: linear-gradient(90deg, #e39b68, var(--red)); }

/* Bao grows: a ring and an emblem that change with the stage. */
.mascot-slot[data-stage] { position: relative; }
.mascot-slot[data-stage]::before { content: ""; position: absolute; inset: 6%; z-index: -1; border-radius: 50%; background: radial-gradient(circle, var(--stage-glow, transparent) 0 58%, transparent 70%); }
.mascot-slot[data-stage]::after { content: attr(data-level); position: absolute; top: 4%; right: 2%; display: grid; min-width: 28px; height: 28px; padding: 0 6px; place-items: center; border: 2px solid var(--white); border-radius: 99px; background: var(--stage-color, var(--paper-deep)); color: #fffdf7; font-size: 13px; font-weight: 800; box-shadow: 0 4px 10px rgba(37,45,34,.16); }
.mascot-slot[data-stage="dough"] { --stage-color: #c9bca6; --stage-glow: rgba(201,188,166,.18); }
.mascot-slot[data-stage="filling"] { --stage-color: #b8a07c; --stage-glow: rgba(184,160,124,.2); }
.mascot-slot[data-stage="folded"] { --stage-color: #8fb096; --stage-glow: rgba(143,176,150,.24); }
.mascot-slot[data-stage="steaming"] { --stage-color: #6f9fae; --stage-glow: rgba(111,159,174,.24); }
.mascot-slot[data-stage="fluffy"] { --stage-color: #a58bc4; --stage-glow: rgba(165,139,196,.24); }
.mascot-slot[data-stage="golden"] { --stage-color: #d9a441; --stage-glow: rgba(217,164,65,.28); }
.mascot-slot[data-stage="master"] { --stage-color: #df553f; --stage-glow: rgba(223,85,63,.24); }

/* --- path card (home) --- */
.path-card { margin-bottom: 8px; padding: 14px; border: 1px solid var(--line); border-radius: 20px; background: var(--white); box-shadow: 0 8px 28px -22px rgba(41,73,59,.28); }
.path-card .menu-kicker { color: var(--red-dark); }
.path-card__row { display: flex; align-items: center; gap: 12px; margin: 8px 0 10px; }
.path-card__glyph { display: grid; width: 48px; height: 48px; flex: 0 0 auto; place-items: center; border-radius: 16px 16px 16px 6px; background: var(--ink); color: var(--paper); font: 26px "Noto Serif SC", serif; }
.path-card__copy { min-width: 0; }
.path-card h2 { margin: 0; font-size: 16px; }
.path-card p { margin: 3px 0 0; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.path-card .menu-secondary { margin-top: 10px; }

/* --- path screen --- */
.path-screen, .achievements-screen { display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 16px 0; }
.path-heading { flex: 1; min-width: 0; text-align: center; }
.path-heading h2 { margin: 0; font-size: 19px; }
.path-heading small { color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.header-spacer { width: 44px; }
.path-scroll, .achievements-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 4px 24px; }
.path-level { margin: 6px 0 2px; color: var(--ink-soft); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-align: center; }
.path-map { position: relative; margin: 0; padding: 30px 0 8px; list-style: none; }
.path-node { position: relative; height: 92px; }
.path-trail { position: absolute; top: 0; left: 0; z-index: 0; overflow: visible; pointer-events: none; }
.path-trail path { fill: none; stroke-linecap: round; stroke-width: 3; }
.path-trail__base { stroke: var(--line); stroke-dasharray: 7 7; }
.path-trail__done { stroke: var(--red); stroke-dasharray: 7 7; opacity: .6; }
.path-node__button { position: absolute; top: 14px; left: calc(50% - 32px + var(--offset, 0px)); z-index: 1; width: 64px; height: 64px; padding: 0; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
.path-node__disc { position: relative; display: grid; width: 64px; height: 64px; place-items: center; border: 3px solid var(--line); border-radius: 50%; background: var(--white); font: 28px "Noto Serif SC", serif; box-shadow: 0 8px 18px -12px rgba(23,59,54,.5); }
.path-node__disc svg { position: absolute; inset: -3px; width: calc(100% + 6px); height: calc(100% + 6px); transform: rotate(-90deg); }
.path-node__disc circle { fill: none; stroke: var(--red); stroke-width: 3; stroke-linecap: round; }
.path-node__label { position: absolute; top: 50%; left: 76px; display: grid; width: 118px; gap: 1px; text-align: left; transform: translateY(-50%); }
.path-node.is-right .path-node__label { right: 76px; left: auto; text-align: right; }
.path-node__label b { font-size: 12px; line-height: 1.2; }
.path-node__label small { color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.path-node.is-done .path-node__disc { border-color: var(--red); background: #fbe9e4; }
.path-node.is-current .path-node__disc { border-color: var(--ink); background: var(--ink); color: var(--paper); transform: scale(1.08); }
.path-node.is-locked .path-node__disc { border-color: var(--paper-deep); background: var(--paper); color: rgba(75,98,93,.5); box-shadow: none; }
.path-node.is-locked .path-node__label { opacity: .6; }
.path-node__bao { position: absolute; bottom: -8px; left: -30px; z-index: 2; width: 44px; height: 44px; pointer-events: none; }
.path-node.is-right .path-node__bao { right: -30px; left: auto; }
.path-node__bao .mascot { width: 100%; height: 100%; }
.path-node__crown { position: absolute; top: -9px; right: -6px; font-size: 16px; }
.path-hint { margin: 8px 16px 0; color: var(--ink-soft); font-size: 11px; line-height: 1.45; text-align: center; }

/* --- chapter sheet --- */
.chapter-card { text-align: center; }
.chapter-card__glyph { display: grid; width: 64px; height: 64px; margin: 0 auto 8px; place-items: center; border-radius: 20px 20px 20px 8px; background: var(--ink); color: var(--paper); font: 34px "Noto Serif SC", serif; }
.chapter-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 12px; }
.chapter-stats div { padding: 9px 4px; border-radius: 14px; background: var(--paper); }
.chapter-stats b { display: block; font-size: 20px; }
.chapter-stats small { color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.chapter-words { display: flex; max-height: 76px; flex-wrap: wrap; justify-content: center; gap: 4px 7px; margin: 0 0 14px; overflow-y: auto; font: 17px "Noto Serif SC", serif; }
.chapter-words span { color: var(--ink-soft); opacity: .5; }
.chapter-words span.is-seen { color: var(--ink); opacity: .85; }
.chapter-words span.is-mastered { color: var(--red-dark); opacity: 1; }
.chapter-card .menu-secondary { margin-top: 8px; }

/* --- achievements --- */
.achievements-card { display: flex; width: 100%; align-items: center; gap: 12px; margin-top: 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--white); color: var(--ink); text-align: left; cursor: pointer; }
.achievements-card__icons { display: flex; gap: 4px; font: 18px "Noto Serif SC", serif; }
.achievements-card__icons span { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; background: #fbe9e4; color: var(--red-dark); }
.achievements-card__copy { display: grid; flex: 1; min-width: 0; }
.achievements-card__copy b { font-size: 14px; }
.achievements-card__copy small { color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.achievement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 0; padding: 0; list-style: none; }
.achievement { display: grid; justify-items: center; gap: 4px; padding: 14px 10px 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--white); text-align: center; }
.achievement__icon { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 50%; background: var(--paper-deep); color: var(--ink-soft); font: 22px "Noto Serif SC", serif; }
.achievement.is-unlocked .achievement__icon { background: var(--red); color: #fffdf7; box-shadow: 0 6px 14px -6px rgba(223,85,63,.6); }
.achievement b { font-size: 12px; line-height: 1.2; }
.achievement small { color: var(--ink-soft); font-size: 9.5px; line-height: 1.35; }
.achievement .progress-track { width: 80%; height: 5px; margin-top: 2px; }
.achievement__meta { color: var(--ink-soft); font-size: 9px; font-weight: 800; }
.achievement.is-unlocked .achievement__meta { color: var(--red-dark); }

/* --- session: reason line, cloze, exam --- */
.probe__reason { align-self: center; margin: 0 0 -4px; padding: 3px 10px; border-radius: 99px; background: rgba(23,59,54,.07); color: var(--ink-soft); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-align: center; }
.quiz-hanzi.quiz-prompt--phrase { font-family: "Noto Serif SC", serif; font-size: clamp(26px, 8vw, 36px); line-height: 1.35; letter-spacing: .02em; text-align: center; }
.quiz-hanzi .cloze-gap { display: inline-block; margin: 0 .08em; color: var(--red); letter-spacing: -.1em; }
.probe__question.is-hint { color: var(--ink-soft); font-size: 14px; font-style: italic; text-align: center; }
.cloze-full { margin: 0; font: 24px "Noto Serif SC", serif; text-align: center; }
.cloze-full b { color: var(--red-dark); }
.cloze-ru { margin: 0 0 6px; color: var(--ink-soft); font-size: 13px; text-align: center; }
.probe-option.is-picked { border-color: var(--ink); background: var(--paper-deep); box-shadow: inset 0 0 0 1px var(--ink); }
.result-sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
/* Bao reacts to the round once it is over (never during it). */
.result-bao { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.result-bao[hidden] { display: none; }
.result-bao__mascot { flex: none; width: 84px; height: 84px; }
.result-bao__mascot .mascot { animation: result-bao-hop .7s ease-out both; transform-origin: 50% 90%; }
.result-bao__line { margin: 0; padding: 12px 15px; border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; background: var(--white); color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1.4; animation: result-bao-line .4s .2s ease-out both; }
@keyframes result-bao-hop { 0% { opacity: 0; transform: translateY(14px) scale(.85) } 55% { opacity: 1; transform: translateY(-8px) scale(1.04) } 100% { transform: none } }
@keyframes result-bao-line { from { opacity: 0; transform: translateX(-8px) } }
.result-screen.is-exam-passed .result-heading h1 { color: #2f6659; }
.result-screen.is-exam-failed .result-heading h1 { color: var(--red-dark); }

/* --- tutorials --- */
.tutorial { position: absolute; z-index: 45; inset: 0; display: flex; flex-direction: column; padding-top: max(18px, env(safe-area-inset-top)); background: var(--paper); }
.tutorial__body { display: flex; flex: 1; min-height: 0; flex-direction: column; align-items: center; justify-content: center; overflow-y: auto; padding: 10px 26px; text-align: center; }
.tutorial__mascot { width: min(150px, 40vw); height: min(150px, 20dvh); margin-bottom: 6px; }
.tutorial__body h1 { max-width: 340px; margin: 10px 0 8px; font-size: 28px; line-height: 1.12; letter-spacing: -.04em; }
.tutorial__body > p { max-width: 330px; margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }
.tutorial__demo { width: min(320px, 100%); margin-top: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 22px; background: var(--white); }
.tutorial__prompt { margin: 0 0 4px; font: 40px "Noto Serif SC", serif; line-height: 1.2; }
.tutorial__prompt.is-phrase { font-size: 30px; }
.tutorial__hint { margin: 0 0 10px; color: var(--ink-soft); font-size: 13px; font-style: italic; }
.tutorial__options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tutorial__options .probe-option { min-height: 46px; }
.tutorial__options.is-hanzi .probe-option { font: 24px "Noto Serif SC", serif; }
.tutorial__write { width: 200px; height: 200px; margin: 0 auto; border: 1px solid var(--line); border-radius: 16px; background: #fffdf7; background-image: linear-gradient(rgba(23,59,54,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(23,59,54,.08) 1px, transparent 1px); background-size: 50% 50%; touch-action: none; }
.tutorial__feedback { min-height: 18px; margin: 10px 0 0; font-size: 12px; font-weight: 800; }
.tutorial__feedback.is-good { color: #2f6659; }
.tutorial__feedback.is-bad { color: var(--red-dark); }
.tutorial-list { display: flex; flex-wrap: wrap; gap: 7px; }
.tutorial-list button { padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink); font-size: 12px; font-weight: 800; cursor: pointer; }
.tutorial-list button.is-seen::after { content: " ✓"; color: #2f6659; }

/* --- paywall --- */
.paywall-card { max-width: 380px; padding: 20px 20px 16px; text-align: center; }
.paywall-card .mascot-slot--overlay { width: 84px; height: 84px; }
.paywall-benefits { display: grid; gap: 7px; margin: 4px 0 14px; padding: 0; list-style: none; text-align: left; }
.paywall-benefits li { position: relative; padding-left: 24px; font-size: 13px; font-weight: 700; line-height: 1.35; }
.paywall-benefits li::before { content: "✓"; position: absolute; left: 0; top: 0; display: grid; width: 17px; height: 17px; place-items: center; border-radius: 50%; background: rgba(47,102,89,.14); color: #2f6659; font-size: 10px; font-weight: 800; }
.plan-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.plan-option { position: relative; display: grid; gap: 2px; padding: 13px 8px 11px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); cursor: pointer; }
.plan-option b { font-size: 14px; }
.plan-option span { font-size: 12px; font-weight: 700; }
.plan-option small { color: var(--ink-soft); font-size: 10px; }
.plan-option.is-selected { border-color: var(--red); background: #fbe9e4; box-shadow: inset 0 0 0 1px var(--red); }
.plan-option__save { position: absolute; top: -9px; left: 50%; padding: 2px 8px; border-radius: 99px; background: var(--red); color: #fffdf7 !important; font-size: 9px !important; font-weight: 800; transform: translateX(-50%); white-space: nowrap; }
.paywall-fine { margin: 8px 0 4px; color: var(--ink-soft); font-size: 11px; line-height: 1.4; }
.paywall-free { margin: 6px 0 0; font-size: 11px; font-weight: 700; line-height: 1.4; }
.paywall-card .overlay-note { margin: 6px 0 2px; }

/* --- mode controls: five modes, three per row --- */
#playModeControl button, #gameModeControl button { position: relative; }

/* --- dark theme --- */
:root[data-theme="dark"] .hero-level,
:root[data-theme="dark"] .path-card,
:root[data-theme="dark"] .achievements-card,
:root[data-theme="dark"] .achievement,
:root[data-theme="dark"] .path-node__disc,
:root[data-theme="dark"] .tutorial__demo,
:root[data-theme="dark"] .tutorial__write { background: var(--white); }
:root[data-theme="dark"] .path-node.is-done .path-node__disc,
:root[data-theme="dark"] .plan-option.is-selected,
:root[data-theme="dark"] .achievements-card__icons span { background: rgba(227,138,104,.2); }
:root[data-theme="dark"] .path-node.is-current .path-node__disc,
:root[data-theme="dark"] .path-card__glyph,
:root[data-theme="dark"] .chapter-card__glyph { background: var(--ink); color: var(--paper); }
:root[data-theme="dark"] .paywall-card,
:root[data-theme="dark"] .chapter-card { background: var(--white); }
:root[data-theme="dark"] .tutorial__write { background-image: linear-gradient(rgba(229,235,217,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(229,235,217,.08) 1px, transparent 1px); }

@media (prefers-reduced-motion: reduce) {
  .path-node.is-current .path-node__disc { transform: none; }
}
:root[data-theme="dark"] .path-card .menu-secondary,
:root[data-theme="dark"] .chapter-card .menu-secondary { background: var(--paper); color: var(--ink); }

.tutorial__header { display: flex; align-items: center; gap: 8px; padding-right: 16px; }
.tutorial__header .onboarding__progress { flex: 1; }
/* Overlays sit above the bottom navigation. */
.overlay { z-index: 30; }
.toast { z-index: 60; }
