:root {
  --paper: #f3ecdd;
  --paper-light: #fffaf0;
  --paper-deep: #dfd2b9;
  --ink: #172126;
  --muted: #69716d;
  --red: #d64a32;
  --red-dark: #a93222;
  --jade: #147b75;
  --gold: #c99931;
  --line: rgba(23, 33, 38, .14);
  --shadow: 0 22px 70px rgba(64, 45, 25, .13);
  --serif: Georgia, "Noto Serif CJK SC", "Source Han Serif SC", "STKaiti", "KaiTi", serif;
  --sans: "Trebuchet MS", "Noto Sans CJK SC", sans-serif;
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #101719;
  --paper-light: #192225;
  --paper-deep: #273236;
  --ink: #f3ead9;
  --muted: #aab5b1;
  --red: #e45d43;
  --red-dark: #f08368;
  --jade: #42b9ae;
  --gold: #ddb34e;
  --line: rgba(236, 226, 207, .15);
  --shadow: 0 22px 70px rgba(0, 0, 0, .34);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; margin: 0; color: var(--ink); font-family: var(--sans); background:
  radial-gradient(circle at 8% 2%, rgba(214, 74, 50, .10), transparent 28rem),
  radial-gradient(circle at 92% 88%, rgba(20, 123, 117, .12), transparent 30rem),
  linear-gradient(135deg, #f8f1e4 0%, #eee3cf 100%); }
html[data-theme="dark"] body { background:
  radial-gradient(circle at 8% 2%, rgba(228,93,67,.13), transparent 30rem),
  radial-gradient(circle at 92% 88%, rgba(66,185,174,.11), transparent 32rem),
  linear-gradient(135deg, #101719 0%, #182124 100%); }
button, input, select { font: inherit; }
button { color: inherit; }
.paper-noise { position: fixed; inset: 0; opacity: .24; pointer-events: none; z-index: -1; background-image: repeating-linear-gradient(93deg, transparent 0 7px, rgba(72, 52, 25, .035) 8px, transparent 9px 16px); }

.topbar { min-height: calc(102px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 32px; padding: calc(18px + env(safe-area-inset-top)) clamp(18px, 4vw, 64px) 18px; border-bottom: 1px solid var(--line); background: rgba(255, 250, 240, .72); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-seal { width: 51px; height: 51px; display: grid; place-items: center; border: 2px solid var(--red-dark); color: white; background: var(--red); font: 700 27px/1 var(--serif); box-shadow: inset 0 0 0 3px rgba(255,255,255,.22); transform: rotate(-2deg); }
.brand strong { display: block; font: 700 23px/1.05 var(--serif); letter-spacing: .02em; }
.brand small { color: var(--muted); letter-spacing: .08em; }
.header-stats { display: flex; align-items: center; margin-left: auto; }
.header-stats div { min-width: 74px; padding: 0 20px; border-right: 1px solid var(--line); text-align: center; }
.header-stats div:first-child { border-left: 1px solid var(--line); }
.header-stats strong, .header-stats span { display: block; }
.header-stats strong { font: 700 21px var(--serif); }
.header-stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.icon-button, .close-button { border: 0; background: transparent; cursor: pointer; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.icon-button { width: 50px; height: 50px; border: 1px solid var(--line); border-radius: 50%; font-size: 22px; transition: transform .2s, background .2s; }
.icon-button:hover { transform: rotate(12deg); background: var(--paper-light); }
.mode-menu-button { flex: none; color: var(--jade); font-size: 20px; font-weight: 800; }
.mode-menu-button:hover { transform: none; }

.mode-nav { display: grid; gap: 5px; padding: 13px; border: 1px solid var(--line); background: rgba(255,250,240,.72); box-shadow: var(--shadow); }
.mode-button { width: 100%; border: 0; border-left: 3px solid transparent; padding: 9px 12px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; letter-spacing: .03em; text-align: left; }
.mode-button span { display: inline-grid; place-items: center; width: 29px; height: 29px; margin-right: 7px; border-radius: 50%; background: rgba(23,33,38,.07); font-family: var(--serif); }
.mode-button.active { color: var(--red-dark); border-left-color: var(--red); background: rgba(214,74,50,.06); }
.mode-button.active span { color: white; background: var(--red); }

.app-shell { width: min(1180px, calc(100% - 36px)); margin: 24px auto 55px; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(285px, .72fr); gap: 24px; align-items: start; }
.right-rail { display: grid; gap: 18px; position: sticky; top: 18px; }
.study-panel, .progress-panel { background: rgba(255, 250, 240, .86); border: 1px solid rgba(91,70,39,.16); box-shadow: var(--shadow); }
.study-panel { min-height: 590px; position: relative; overflow: hidden; animation: rise .45s ease both; }
.study-panel::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: linear-gradient(var(--red), var(--gold)); }
.progress-panel { padding: 28px; animation: rise .45s .08s ease both; }

.card-topline { display: flex; align-items: center; justify-content: space-between; padding: 24px 31px 0; }
.eyebrow { margin: 0; color: var(--red-dark); font-size: 11px; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
.card-counter { color: var(--muted); font-size: 12px; }
.prompt-card { min-height: 500px; padding: clamp(25px, 5vw, 54px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.hanzi { margin: 0; font: 500 clamp(72px, 11vw, 132px)/1.08 var(--serif); letter-spacing: .04em; color: var(--ink); text-wrap: balance; }
.hanzi.phrase { font-size: clamp(40px, 7vw, 78px); }
.pinyin { margin: 13px 0 0; color: var(--jade); font: italic 21px var(--serif); letter-spacing: .08em; }
.meaning { margin: 16px 0 0; font: 700 clamp(24px, 4vw, 38px) var(--serif); }
.subcopy { max-width: 580px; color: var(--muted); line-height: 1.7; }
.audio-orb { width: 120px; height: 120px; display: grid; place-items: center; margin: 8px 0 25px; border: 1px solid rgba(20,123,117,.28); border-radius: 50%; color: var(--jade); background: radial-gradient(circle, rgba(20,123,117,.14), rgba(20,123,117,.02) 67%); position: relative; }
.audio-orb::before, .audio-orb::after { content: ""; position: absolute; border: 1px solid rgba(20,123,117,.25); border-radius: 50%; animation: pulse 2.4s infinite; }
.audio-orb::before { inset: -9px; }
.audio-orb::after { inset: -19px; animation-delay: .5s; }
.audio-orb span { font-size: 46px; transform: translateX(3px); }
.prompt-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 23px 0 18px; }
.ghost-button, .text-button { border: 0; cursor: pointer; background: transparent; }
.ghost-button { padding: 11px 16px; border: 1px solid var(--line); border-radius: 4px; background: rgba(255,255,255,.48); font-weight: 700; }
.ghost-button:hover { border-color: var(--jade); color: var(--jade); }
.answer-form { width: min(510px, 100%); display: flex; gap: 9px; margin-top: 15px; }
.answer-input { min-width: 0; flex: 1; padding: 15px 17px; border: 1px solid rgba(23,33,38,.25); border-radius: 3px; outline: none; background: rgba(255,255,255,.7); font-size: 17px; }
.answer-input:focus { border-color: var(--jade); box-shadow: 0 0 0 3px rgba(20,123,117,.11); }
.primary-button { border: 0; border-radius: 3px; padding: 14px 23px; color: white; background: var(--red); cursor: pointer; font-weight: 800; box-shadow: 0 7px 18px rgba(169,50,34,.18); }
.primary-button:hover { background: var(--red-dark); }
.feedback { width: min(510px, 100%); margin-top: 18px; padding: 15px 18px; border-left: 4px solid; text-align: left; }
.feedback.correct { border-color: var(--jade); background: rgba(20,123,117,.09); }
.feedback.wrong { border-color: var(--red); background: rgba(214,74,50,.09); }
.feedback strong { display: block; margin-bottom: 4px; }
.derivation { width: 100%; margin-top: 13px; padding: 12px 14px; border: 1px solid var(--line); background: rgba(255,255,255,.28); text-align: left; }
.derivation-main { font: 700 18px var(--serif); }
.derivation-main b { display: inline; font-size: 25px; }
.derivation-parts { display: flex; align-items: stretch; gap: 7px; margin-top: 10px; flex-wrap: wrap; }
.derivation-part { flex: 1 1 115px; padding: 8px 10px; border-left: 3px solid var(--gold); background: rgba(201,153,49,.07); }
.derivation-part b { display: inline; font: 500 22px var(--serif); }
.derivation-part em { display: block; color: var(--jade); font: italic 13px var(--serif); }
.derivation-part span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.derivation-note { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.intro-mark { display: grid; place-items: center; width: 38px; height: 38px; margin-bottom: 17px; color: white; background: var(--gold); border-radius: 50%; font: 700 18px var(--serif); }
.parts { width: min(570px, 100%); display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 26px 0; }
.part { padding: 15px 10px; border: 1px solid var(--line); background: rgba(255,255,255,.42); }
.part b { display: block; font: 500 32px var(--serif); }
.part span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }

.progress-heading { display: flex; gap: 16px; align-items: center; }
.progress-heading small, .dialog-heading small { color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.progress-heading h2 { margin: 4px 0 0; font: 700 22px var(--serif); }
.progress-ring { --progress: 0deg; flex: 0 0 auto; width: 67px; height: 67px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--jade) var(--progress), rgba(20,123,117,.12) 0); position: relative; }
.progress-ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--paper-light); }
.progress-ring span { position: relative; font-weight: 800; font-size: 13px; }
.progress-bar { height: 5px; margin: 25px 0 17px; background: rgba(23,33,38,.1); }
.progress-bar span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--jade), #36aaa1); transition: width .5s; }
.progress-panel > p { min-height: 50px; color: var(--muted); line-height: 1.55; font-size: 14px; }
.next-list { margin-top: 27px; padding-top: 20px; border-top: 1px solid var(--line); }
.next-list h3 { margin: 0 0 13px; font: 700 17px var(--serif); }
.next-item { display: flex; align-items: center; gap: 11px; padding: 9px 0; }
.next-item b { width: 37px; height: 37px; display: grid; place-items: center; border: 1px solid var(--line); font: 500 21px var(--serif); background: rgba(255,255,255,.35); }
.next-item span { display: block; font-size: 13px; }
.next-item small { color: var(--muted); }
.progress-panel blockquote { margin: 26px 0 0; padding: 15px 0 0; border-top: 1px solid var(--line); color: var(--muted); font: italic 15px/1.5 var(--serif); }

.empty-state { min-height: 570px; padding: 55px; display: grid; place-items: center; text-align: center; }
.empty-state > div { max-width: 520px; }
.empty-state .stamp { display: inline-grid; place-items: center; width: 74px; height: 74px; border: 2px solid var(--jade); border-radius: 50%; color: var(--jade); font: 500 37px var(--serif); }
.empty-state h2 { margin: 22px 0 8px; font: 700 32px var(--serif); }

.draw-wrap { min-height: 555px; padding: 27px clamp(20px, 5vw, 52px) 38px; text-align: center; }
.draw-title h2 { margin: 8px 0 0; font: 500 clamp(44px, 8vw, 75px) var(--serif); }
.draw-title p { margin: 2px 0 18px; color: var(--muted); }
.canvas-shell { width: min(440px, 88vw); aspect-ratio: 1; margin: 0 auto; position: relative; border: 2px solid rgba(169,50,34,.6); background-color: rgba(255,255,255,.5); background-image: linear-gradient(rgba(169,50,34,.17) 1px, transparent 1px), linear-gradient(90deg, rgba(169,50,34,.17) 1px, transparent 1px), linear-gradient(45deg, transparent 49.8%, rgba(169,50,34,.13) 50%, transparent 50.2%), linear-gradient(-45deg, transparent 49.8%, rgba(169,50,34,.13) 50%, transparent 50.2%); background-size: 50% 50%, 50% 50%, 100% 100%, 100% 100%; }
.canvas-guide { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(23,33,38,.12); font: 500 min(68vw, 330px)/1 var(--serif); pointer-events: none; transition: opacity .2s; }
.canvas-guide.hidden { opacity: 0; }
#drawCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.draw-actions, .grade-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 15px; }
.grade-actions .primary-button.good { background: var(--jade); }

.story-setup { min-height: 570px; padding: clamp(30px, 6vw, 64px); display: grid; align-content: center; }
.story-setup-inner { width: min(620px, 100%); margin: auto; text-align: center; }
.story-setup .story-mark { width: 88px; height: 88px; display: grid; place-items: center; margin: 0 auto 20px; border: 2px solid var(--gold); color: var(--red-dark); background: rgba(201,153,49,.08); font: 500 46px var(--serif); transform: rotate(-2deg); }
.story-setup h1 { margin: 0; font: 700 clamp(30px, 5vw, 45px) var(--serif); }
.story-setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 27px 0 20px; text-align: left; }
.story-field { display: block; padding: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.42); }
.story-field span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.story-field select { width: 100%; padding: 10px; border: 1px solid var(--line); background: white; }
.engine-status { min-height: 25px; margin: 4px 0 18px; color: var(--muted); font-size: 13px; }
.engine-status.online { color: var(--jade); }
.engine-status.error { color: var(--red-dark); }
.loading-brush { width: 190px; height: 4px; margin: 24px auto; overflow: hidden; background: rgba(23,33,38,.1); }
.loading-brush::after { content: ""; display: block; width: 45%; height: 100%; background: var(--red); animation: brushload 1.15s infinite ease-in-out; }

.story-reader { min-height: 590px; display: flex; flex-direction: column; outline: none; }
.story-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 29px 16px; border-bottom: 1px solid var(--line); }
.story-title small { display: block; color: var(--red-dark); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.story-title h2 { margin: 4px 0 0; font: 700 22px var(--serif); }
.story-dots { display: flex; align-items: center; gap: 5px; }
.story-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(23,33,38,.18); }
.story-dots i.past { background: var(--gold); }
.story-dots i.current { width: 19px; border-radius: 8px; background: var(--red); }
.story-page { flex: 1; min-height: 420px; padding: clamp(30px, 7vw, 70px) clamp(22px, 7vw, 72px) 28px; display: flex; flex-direction: column; justify-content: center; text-align: center; overflow: hidden; touch-action: pan-y; }
.story-number { color: var(--muted); font: italic 14px var(--serif); }
.story-sentence { margin: 22px 0 13px; display: flex; justify-content: center; align-items: baseline; flex-wrap: wrap; gap: 3px; }
.story-word { border: 0; border-bottom: 2px solid transparent; padding: 2px 3px 5px; color: var(--ink); background: transparent; cursor: pointer; font: 500 clamp(39px, 7vw, 70px)/1.25 var(--serif); transition: color .15s, border-color .15s, transform .15s; }
.story-word:hover, .story-word:focus { color: var(--jade); border-color: var(--jade); outline: 0; transform: translateY(-2px); }
.story-word.new-word { color: var(--red-dark); text-decoration: decoration-skip-ink; }
.story-punctuation { font: 500 clamp(39px, 7vw, 70px)/1.25 var(--serif); }
.story-hint { color: var(--muted); font-size: 13px; }
.word-gloss { width: min(500px, 100%); min-height: 83px; margin: 17px auto 0; padding: 13px 17px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; background: rgba(255,255,255,.35); }
.word-gloss.empty { display: grid; place-items: center; text-align: center; color: var(--muted); }
.word-gloss b { font: 500 25px var(--serif); }
.word-gloss em { margin-left: 10px; color: var(--jade); font: italic 15px var(--serif); }
.word-gloss p { margin: 5px 0 0; }
.word-gloss .new-label { float: right; padding: 4px 7px; color: white; background: var(--red); font-size: 9px; font-style: normal; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.word-gloss .queue-word { float: right; border: 0; padding: 6px 9px; color: white; background: var(--jade); cursor: pointer; font-size: 11px; font-weight: 700; }
.story-translation { min-height: 28px; margin: 18px 0 0; font: italic 18px/1.45 var(--serif); }
.story-translation.concealed { color: transparent; user-select: none; }
.story-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 25px 22px; }
.story-controls .center-controls { display: flex; gap: 8px; }
.round-nav { width: 47px; height: 47px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.48); cursor: pointer; font-size: 22px; }
.round-nav:disabled { opacity: .3; cursor: default; }

.build-lab { min-height: 590px; display: flex; flex-direction: column; }
.build-header { padding: 22px 28px 15px; border-bottom: 1px solid var(--line); }
.build-header-top { display: flex; align-items: end; justify-content: space-between; gap: 15px; }
.build-header h2 { margin: 4px 0 0; font: 700 24px var(--serif); }
.build-lesson-tabs { display: flex; gap: 7px; margin-top: 16px; overflow-x: auto; scrollbar-width: thin; }
.build-lesson-tab { flex: 0 0 auto; border: 1px solid var(--line); padding: 8px 11px; background: rgba(255,255,255,.35); cursor: pointer; font-size: 12px; }
.build-lesson-tab.active { border-color: var(--red); color: white; background: var(--red); }
.build-lesson-tab.complete::after { content: " ✓"; color: var(--jade); }
.build-lesson-tab.active.complete::after { color: white; }
.build-steps { display: flex; gap: 5px; align-items: center; }
.build-steps i { width: 24px; height: 4px; background: rgba(23,33,38,.12); }
.build-steps i.done { background: var(--jade); }
.build-body { flex: 1; min-height: 430px; padding: clamp(26px, 5vw, 52px); display: flex; flex-direction: column; justify-content: center; text-align: center; }
.build-body h1 { margin: 5px 0 9px; font: 700 clamp(29px, 5vw, 43px) var(--serif); }
.build-body > .subcopy { margin-inline: auto; }
.base-grid { width: min(680px, 100%); display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 11px; margin: 27px auto; }
.base-piece { border: 1px solid var(--line); padding: 16px 9px; background: rgba(255,255,255,.42); cursor: pointer; }
.base-piece:hover { border-color: var(--jade); }
.base-piece b { display: block; font: 500 45px var(--serif); }
.base-piece em { display: block; color: var(--jade); font: italic 14px var(--serif); }
.base-piece span { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.character-equation { display: flex; justify-content: center; align-items: center; gap: clamp(10px, 3vw, 26px); margin: 28px 0; flex-wrap: wrap; }
.equation-piece { min-width: 116px; padding: 18px; border: 2px solid; background: rgba(255,255,255,.45); }
.equation-piece.semantic { border-color: var(--jade); }
.equation-piece.phonetic { border-color: var(--gold); }
.equation-piece.result { border-color: var(--red); background: rgba(214,74,50,.07); }
.equation-piece b { display: block; font: 500 58px var(--serif); }
.equation-piece small { display: block; margin-top: 6px; color: var(--muted); }
.equation-sign { color: var(--muted); font: 700 29px var(--serif); }
.role-key { display: flex; justify-content: center; gap: 18px; margin: 0 0 20px; color: var(--muted); font-size: 12px; }
.role-key i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; }
.role-key .semantic-key { background: var(--jade); }
.role-key .phonetic-key { background: var(--gold); }
.family-grid { width: min(740px, 100%); display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin: 25px auto; }
.family-card { border: 1px solid var(--line); padding: 14px 10px; background: rgba(255,255,255,.44); cursor: pointer; text-align: center; }
.family-card:hover { transform: translateY(-2px); border-color: var(--red); }
.family-card b { display: block; font: 500 43px var(--serif); }
.family-card em { color: var(--red-dark); font: italic 15px var(--serif); }
.family-card span, .family-card small { display: block; }
.family-card span { margin-top: 5px; font-weight: 700; }
.family-card small { min-height: 28px; margin-top: 6px; color: var(--muted); line-height: 1.3; }
.sound-panel { width: min(680px, 100%); margin: 22px auto; }
.sound-rule { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 13px; padding: 13px 15px; border-top: 1px solid var(--line); text-align: left; }
.sound-rule:last-child { border-bottom: 1px solid var(--line); }
.sound-rule b { color: var(--red-dark); font: 700 20px var(--serif); }
.sound-rule span { color: var(--muted); line-height: 1.4; }
.sound-rule button { border: 1px solid var(--line); width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.45); cursor: pointer; }
.sound-caution { width: min(680px, 100%); margin: 14px auto; padding: 14px 17px; border-left: 4px solid var(--gold); background: rgba(201,153,49,.09); text-align: left; line-height: 1.5; }
.build-quiz { width: min(610px, 100%); margin: 16px auto; }
.build-question { margin: 8px 0 22px; font: 700 25px/1.35 var(--serif); }
.quiz-options { display: grid; gap: 9px; }
.quiz-option { border: 1px solid var(--line); padding: 13px 15px; background: rgba(255,255,255,.48); cursor: pointer; text-align: left; }
.quiz-option:hover { border-color: var(--jade); }
.quiz-option.incorrect { border-color: var(--red); background: rgba(214,74,50,.08); }
.build-feedback { margin-top: 15px; padding: 13px; border-left: 4px solid var(--red); background: rgba(214,74,50,.08); text-align: left; }
.build-footer { display: flex; justify-content: center; gap: 10px; padding: 0 24px 26px; }

@keyframes brushload { from { transform: translateX(-110%); } to { transform: translateX(330%); } }

.settings-dialog { width: min(610px, calc(100% - 26px)); padding: 0; border: 1px solid var(--line); color: var(--ink); background: var(--paper-light); box-shadow: 0 30px 90px rgba(23,33,38,.32); }
.settings-dialog::backdrop { background: rgba(23,33,38,.48); backdrop-filter: blur(3px); }
.settings-dialog form { padding: 27px 30px 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 16px; }
.dialog-heading h2 { margin: 3px 0 0; font: 700 30px var(--serif); }
.close-button { font-size: 30px; color: var(--muted); }
.toggle-row, .field-row { min-height: 68px; display: flex; align-items: center; gap: 18px; border-top: 1px solid var(--line); }
.toggle-row > span, .field-row > span { flex: 1; }
.toggle-row strong, .toggle-row small, .field-row strong, .field-row small { display: block; }
.toggle-row small, .field-row small { margin-top: 3px; color: var(--muted); }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { width: 46px; height: 25px; border-radius: 20px; background: #c9c7bd; position: relative; transition: .2s; }
.toggle-row i::after { content: ""; position: absolute; width: 19px; height: 19px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: .2s; }
.toggle-row input:checked + i { background: var(--jade); }
.toggle-row input:checked + i::after { transform: translateX(21px); }
.field-row select, .field-row input[type="number"] { max-width: 160px; padding: 8px; border: 1px solid var(--line); background: white; }
.field-row input[type="range"] { width: 150px; accent-color: var(--jade); }
.voice-row .text-button { display: block; padding: 5px 0 0; font-size: 12px; }
.voice-row select { width: min(245px, 46%); max-width: 245px; }
.voice-controls { width: min(270px, 50%); display: grid; gap: 7px; }
.voice-controls select { width: 100%; max-width: none; }
.voice-controls .ghost-button { padding-block: 8px; }
.draw-assessment { width: min(440px, 88vw); min-height: 48px; margin: 13px auto 0; padding: 11px 14px; border-left: 4px solid var(--jade); background: rgba(20,123,117,.08); text-align: left; }
.draw-assessment.error { border-color: var(--red); background: rgba(214,74,50,.09); }
.draw-assessment strong { display: block; margin-bottom: 3px; }
.dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding-top: 21px; border-top: 1px solid var(--line); }
.text-button { padding: 9px 0; color: var(--jade); font-weight: 700; }
.text-button.danger { color: var(--red-dark); }

html[data-theme="dark"] .paper-noise { opacity: .12; }
html[data-theme="dark"] .topbar { background: rgba(16,23,25,.84); }
html[data-theme="dark"] .mode-nav { background: rgba(25,34,37,.94); }
html[data-theme="dark"] .study-panel,
html[data-theme="dark"] .progress-panel,
html[data-theme="dark"] .settings-dialog { background: rgba(25,34,37,.94); border-color: rgba(236,226,207,.14); }
html[data-theme="dark"] .progress-ring::before { background: var(--paper-light); }
html[data-theme="dark"] .answer-input,
html[data-theme="dark"] .field-row select,
html[data-theme="dark"] .field-row input[type="number"],
html[data-theme="dark"] .story-field select { color: var(--ink); background: #222d30; border-color: var(--line); }
html[data-theme="dark"] .ghost-button,
html[data-theme="dark"] .round-nav,
html[data-theme="dark"] .base-piece,
html[data-theme="dark"] .family-card,
html[data-theme="dark"] .quiz-option,
html[data-theme="dark"] .part,
html[data-theme="dark"] .next-item b,
html[data-theme="dark"] .story-field,
html[data-theme="dark"] .word-gloss,
html[data-theme="dark"] .equation-piece { background: rgba(255,255,255,.045); }
html[data-theme="dark"] .derivation { background: rgba(255,255,255,.035); }
html[data-theme="dark"] .answer-input { background: rgba(255,255,255,.06); }
html[data-theme="dark"] .audio-orb { background: radial-gradient(circle, rgba(66,185,174,.18), rgba(66,185,174,.02) 67%); }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: .12; transform: scale(.95); } 50% { opacity: .52; transform: scale(1.04); } }
@media (max-width: 820px) {
  body { padding-bottom: calc(75px + env(safe-area-inset-bottom)); }
  .topbar { min-height: calc(96px + env(safe-area-inset-top)); padding: calc(15px + env(safe-area-inset-top)) 16px 15px; gap: 12px; }
  .brand-seal { width: 43px; height: 43px; font-size: 23px; }
  .brand strong { font-size: 20px; }
  .brand small { display: none; }
  .header-stats div { min-width: 53px; padding: 0 8px; }
  .header-stats div:first-child { border-left: 0; }
  .header-stats span { font-size: 9px; }
  .icon-button { width: 47px; height: 47px; }
  .app-shell { width: min(100% - 20px, 700px); grid-template-columns: 1fr; margin-top: 14px; }
  .right-rail { display: contents; }
  .progress-panel { order: 2; }
  .study-panel { min-height: 520px; }
  .prompt-card { min-height: 450px; padding: 26px 20px; }
  .mode-nav { position: fixed; z-index: 50; inset: auto 0 0; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; padding: 7px 5px calc(7px + env(safe-area-inset-bottom)); border-width: 1px 0 0; background: rgba(255,250,240,.94); backdrop-filter: blur(18px); }
  .mode-button { min-width: 0; padding: 4px 1px; border: 0; text-align: center; font-size: 11px; }
  .mode-button.active { border: 0; background: transparent; }
  .mode-button span { display: block; margin: 0 auto 3px; }
}
@media (max-width: 520px) {
  .header-stats div:nth-child(2) { display: none; }
  .header-stats div:nth-child(3) { display: none; }
  .top-actions { gap: 6px; }
  .brand-seal { width: 46px; height: 46px; }
  .mode-button { font-size: 12px; }
  .mode-button span { width: 26px; height: 26px; }
  .answer-form { flex-direction: column; }
  .answer-form .primary-button { width: 100%; }
  .card-topline { padding: 20px 20px 0; }
  .progress-panel { padding: 22px; }
  .settings-dialog form { padding: 23px 20px; }
  .field-row { align-items: flex-start; flex-direction: column; gap: 8px; padding: 13px 0; }
  .field-row select, .field-row input[type="range"] { width: 100%; max-width: none; }
  .voice-row select { width: 100%; max-width: none; }
  .voice-controls { width: 100%; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .story-setup-grid { grid-template-columns: 1fr; }
  .story-reader { min-height: 540px; }
  .story-header { padding: 17px 18px 13px; }
  .story-dots i { display: none; }
  .story-dots i.current { display: block; width: auto; height: auto; color: var(--muted); background: transparent; font-style: normal; }
  .story-page { min-height: 385px; padding-inline: 15px; }
  .story-controls { padding-inline: 16px; }
  .build-header { padding-inline: 18px; }
  .build-header-top { align-items: start; }
  .build-steps i { width: 15px; }
  .build-body { padding-inline: 16px; }
  .sound-rule { grid-template-columns: 78px 1fr auto; padding-inline: 8px; }
  .sound-rule b { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; } }
.progression-trigger {
  cursor: pointer;
}

.progression-trigger:focus-visible {
  outline: 3px solid var(--accent, #f0a33a);
  outline-offset: 4px;
}

.progression-dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(46rem, calc(100dvh - 2rem));
  padding: 0;
  overflow: hidden;
  color: var(--text, #f7f1e5);
  background: var(--surface, #18201d);
  border: 1px solid color-mix(in srgb, var(--text, #fff) 16%, transparent);
  border-radius: 1.25rem;
  box-shadow: 0 2rem 6rem rgb(0 0 0 / 45%);
}

.progression-dialog::backdrop {
  background: rgb(5 8 7 / 68%);
  backdrop-filter: blur(5px);
}

.progression-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid color-mix(in srgb, var(--text, #fff) 12%, transparent);
}

.progression-dialog__header h2 {
  margin: 0;
}

.progression-dialog__close {
  min-height: 2.75rem;
  padding-inline: 1rem;
}

.progression-dialog__content {
  max-height: calc(100dvh - 8rem);
  padding: 1.15rem;
  overflow: auto;
  overscroll-behavior: contain;
}

.progression-dialog__content > * {
  margin: 0;
}

@media (max-width: 640px) {
  .progression-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
    border-radius: 1rem;
  }
}
.dictionary-view {
  width: min(62rem, 100%);
  margin-inline: auto;
}

.dictionary-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dictionary-heading h1,
.dictionary-heading p {
  margin-block: .2rem;
}

.dictionary-count {
  flex: none;
  padding: .5rem .75rem;
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: 999px;
  font-size: .85rem;
}

.dictionary-search {
  display: grid;
  gap: .45rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

.dictionary-search input {
  width: 100%;
  min-height: 3.25rem;
  padding: .75rem 1rem;
  color: inherit;
  background: color-mix(in srgb, var(--surface, #18201d) 88%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: .85rem;
  font: inherit;
}

.dictionary-results {
  display: grid;
  gap: .7rem;
}

.dictionary-entry {
  overflow: hidden;
  background: color-mix(in srgb, var(--surface, #18201d) 92%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 13%, transparent);
  border-radius: 1rem;
}

.dictionary-entry summary {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: .9rem 1rem;
  cursor: pointer;
  list-style: none;
}

.dictionary-entry summary::-webkit-details-marker {
  display: none;
}

.dictionary-hanzi {
  min-width: 2.5rem;
  font-size: 1.8rem;
  font-weight: 800;
  text-align: center;
}

.dictionary-summary {
  display: grid;
  gap: .15rem;
}

.dictionary-summary small,
.dictionary-kind,
.dictionary-actions span,
.dictionary-part small {
  opacity: .7;
}

.dictionary-kind {
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.dictionary-detail {
  display: grid;
  gap: 1rem;
  padding: 0 1rem 1rem;
}

.dictionary-actions,
.dictionary-formula {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .65rem;
}

.dictionary-construction,
.dictionary-notes {
  padding: .9rem;
  background: color-mix(in srgb, currentColor 5%, transparent);
  border-radius: .8rem;
}

.dictionary-construction > strong {
  display: block;
  margin-bottom: .65rem;
}

.dictionary-construction p,
.dictionary-notes p {
  margin: 0;
}

.dictionary-part {
  display: grid;
  gap: .1rem;
  padding: .45rem .6rem;
  border: 1px solid color-mix(in srgb, currentColor 14%, transparent);
  border-radius: .65rem;
}

.dictionary-notes {
  display: grid;
  gap: .7rem;
}

.dictionary-notes strong {
  display: block;
  margin-bottom: .15rem;
}

.dictionary-empty {
  display: grid;
  gap: .35rem;
  padding: 2rem;
  text-align: center;
  border: 1px dashed color-mix(in srgb, currentColor 24%, transparent);
  border-radius: 1rem;
}

@media (max-width: 640px) {
  .dictionary-heading {
    align-items: start;
  }

  .dictionary-entry summary {
    grid-template-columns: auto 1fr;
  }

  .dictionary-kind {
    display: none;
  }
}
.pinyin-audio,
.dictionary-pinyin,
.hanzi-reveal {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.pinyin-audio {
  display: block;
  width: fit-content;
  margin-inline: auto;
  padding: .35rem .65rem;
  color: #63cfc2;
  font-size: .9rem;
  font-weight: 700;
  border-radius: 999px;
}

.pinyin-audio:focus-visible,
.dictionary-pinyin:focus-visible,
.hanzi-reveal:focus-visible {
  outline: 3px solid var(--accent, #f0a33a);
  outline-offset: 3px;
}

.hanzi-reveal {
  display: block;
  width: 100%;
  font-size: clamp(4.5rem, 18vw, 9rem);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -.04em;
}

.hanzi-reveal.phrase {
  font-size: clamp(2.2rem, 9vw, 4.5rem);
}

.draw-context {
  display: grid;
  gap: .65rem;
  margin-top: .4rem;
}

.draw-context > p {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
}

.dictionary-pinyin {
  width: fit-content;
  padding: .15rem 0;
  color: #63cfc2;
  text-align: left;
}

[data-theme="light"] .pinyin-audio,
[data-theme="light"] .dictionary-pinyin {
  color: #086c67;
}
html {
  font-size: calc(16px * var(--text-scale, 1));
}
.conversation-view, .pronunciation-view { width:min(46rem, 100%); margin-inline:auto; }
.conversation-bubble { display:grid; justify-items:center; gap:.5rem; padding:clamp(1.4rem, 5vw, 3rem); background:color-mix(in srgb, var(--surface, #18201d) 92%, transparent); border:1px solid color-mix(in srgb, currentColor 14%, transparent); border-radius:1.5rem 1.5rem 1.5rem .35rem; }
.conversation-mandarin { appearance:none; border:0; background:transparent; color:inherit; font:inherit; font-size:clamp(2.4rem, 9vw, 5.5rem); font-weight:800; line-height:1.1; cursor:pointer; }
.conversation-mandarin.hidden-prompt { font-size:clamp(4.5rem, 18vw, 9rem); }
.conversation-response { display:grid; gap:.8rem; margin-top:1rem; }
.conversation-controls { display:flex; flex-wrap:wrap; gap:.65rem; }
.conversation-hint { padding:.8rem 1rem; border-radius:.8rem; background:color-mix(in srgb, #63cfc2 12%, transparent); }
.pronunciation-view { display:grid; justify-items:center; gap:1rem; text-align:center; }
.pronunciation-mic { min-width:10rem; min-height:3.5rem; }
.feedback span { display:block; margin-top:.35rem; }
.auto-mode-settings {
  display: grid;
  gap: .35rem;
  margin: 1rem 0;
  padding: .75rem;
  border: 1px solid color-mix(in srgb, currentColor 14%, transparent);
  border-radius: 1rem;
}

.auto-mode-settings legend {
  padding-inline: .4rem;
  font-weight: 800;
}

.learning-view {
  min-height: 590px;
  display: flex;
  flex-direction: column;
}

.learning-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 1.8rem 1rem;
}

.learning-header h1 {
  margin: .25rem 0 0;
  font: 700 clamp(1.5rem, 4vw, 2.2rem) var(--serif);
}

.learning-step-count {
  color: var(--muted);
  font-size: .78rem;
  text-align: right;
}

.learning-progress {
  height: 4px;
  margin-inline: 1.8rem;
  overflow: hidden;
  background: color-mix(in srgb, currentColor 10%, transparent);
  border-radius: 999px;
}

.learning-progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--jade), var(--gold));
  transition: width .3s ease;
}

.learning-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: clamp(1.4rem, 5vw, 3.5rem);
  text-align: center;
}

.learning-body > h2 { margin: 0; font: 700 clamp(1.35rem, 4vw, 2.15rem) var(--serif); }
.learning-method-icon { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; color: white; background: var(--jade); border-radius: 50%; font: 700 1.15rem var(--serif); }
.learning-hanzi { margin: 0; font: 600 clamp(5rem, 18vw, 9rem)/1 var(--serif); }
.learning-hanzi.compact { font-size: clamp(3.7rem, 13vw, 7rem); }
.inline-hanzi { color: var(--red-dark); font: 700 1.4em var(--serif); }
.learning-meaning { margin: 0; font: 700 clamp(1.4rem, 4vw, 2.2rem) var(--serif); }
.learning-reassurance { max-width: 35rem; margin: 0; color: var(--muted); line-height: 1.55; }
.learning-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .75rem; margin-top: .5rem; }

.learning-parts,
.assembled-character {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .7rem;
}

.learning-parts span { display: grid; gap: .2rem; min-width: 7rem; padding: .8rem; border: 1px solid var(--line); border-radius: .8rem; }
.learning-parts b { font: 600 2rem var(--serif); }
.learning-parts small { color: var(--muted); }
.learning-parts i { color: var(--gold); font-size: 1.4rem; }
.assembled-character { min-height: 4.5rem; color: var(--muted); font: 500 clamp(2rem, 8vw, 4rem) var(--serif); }
.assembled-character b { color: var(--ink); }
.assembled-character i { color: var(--gold); }

.learning-choices { width: min(36rem, 100%); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.learning-choices button { min-height: 4rem; padding: .8rem; color: inherit; background: color-mix(in srgb, currentColor 5%, transparent); border: 1px solid var(--line); border-radius: .85rem; cursor: pointer; }
.learning-choices button:hover { border-color: var(--jade); }
.hanzi-choices button { min-height: 5.5rem; font: 600 clamp(2.2rem, 8vw, 4rem) var(--serif); }
.component-choices button { display: grid; gap: .25rem; }
.component-choices b { font: 600 2.5rem var(--serif); }
.component-choices small { color: var(--muted); }
.learning-choices .right-choice { color: var(--jade); border-color: var(--jade); background: color-mix(in srgb, var(--jade) 12%, transparent); }
.learning-choices .try-again { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, transparent); }
.learning-feedback { min-height: 1.6rem; margin: 0; color: var(--muted); line-height: 1.5; }
.learning-feedback strong { color: var(--jade); }
.learning-audio { margin: 0; cursor: pointer; }

.trace-board { position: relative; width: min(72vw, 22rem); aspect-ratio: 1; overflow: hidden; background: color-mix(in srgb, currentColor 4%, transparent); border: 1px solid var(--line); border-radius: 1rem; }
.trace-board span { position: absolute; inset: 0; display: grid; place-items: center; color: color-mix(in srgb, currentColor 14%, transparent); font: 600 min(56vw, 17rem)/1 var(--serif); pointer-events: none; }
.trace-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.production-meaning,
.draw-meaning {
  font-size: clamp(2rem, 8vw, 4.5rem);
  line-height: 1.05;
  text-align: center;
}

.mode-nav {
  position: fixed !important;
  inset: calc(112px + env(safe-area-inset-top)) auto auto max(1rem, env(safe-area-inset-left)) !important;
  z-index: 1000;
  display: grid !important;
  grid-template-columns: repeat(2, minmax(8rem, 1fr));
  width: min(22rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 6.5rem);
  padding: .75rem !important;
  overflow: auto;
  background: var(--surface, #18201d);
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
  border-radius: 1rem;
  box-shadow: 0 1.5rem 4rem rgb(0 0 0 / 35%);
}

.mode-nav[hidden] { display: none !important; }
.brand { cursor: pointer; }

@media (max-width: 720px) {
  body { padding-bottom: 0 !important; }
  .mode-nav { bottom: auto !important; }
  .learning-header { align-items: start; padding-inline: 1.2rem; }
  .learning-progress { margin-inline: 1.2rem; }
  .learning-body { padding-inline: 1.1rem; }
}

/* Intermediate, consequence-free learning supports */
.context-sentence{font-family:"Noto Serif SC","Songti SC",serif;font-size:clamp(2.2rem,10vw,4.8rem);line-height:1.2;color:var(--text,#eef4ef)}
.context-meaning{margin:.15rem 0 0;color:var(--muted,#9aa9a0);font-size:1.05rem}
.context-choices button{display:grid;gap:.18rem;min-width:7rem}
.context-choices b{font-family:"Noto Serif SC","Songti SC",serif;font-size:2rem}
.context-choices small,.target-memory small,.completion-word small,.tone-word small{color:var(--accent,#e6a15c);font-weight:700}
.target-memory,.completion-word,.tone-word{display:grid;justify-items:center;gap:.15rem}
.target-memory span,.completion-word span,.tone-word span{font-family:"Noto Serif SC","Songti SC",serif;font-size:clamp(3.6rem,17vw,6.8rem);line-height:1}
.form-choice-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:.7rem;width:100%}
.form-choice{min-height:7rem;border:1px solid var(--line,rgba(255,255,255,.16));border-radius:1.2rem;background:var(--panel,#17221d);color:var(--text,#eef4ef);font-family:"Noto Serif SC","Songti SC",serif;font-size:3.8rem;box-shadow:0 12px 30px rgba(0,0,0,.12);cursor:pointer}
.form-choice.right-choice{border-color:#4cae89;background:rgba(76,174,137,.15)}
.form-choice.try-again{border-color:var(--accent,#e6a15c);animation:gentle-nudge .28s ease}
.completion-canvas,.tone-canvas{display:block;width:100%;height:auto;border:1px solid var(--line,rgba(255,255,255,.16));border-radius:1.35rem;background:var(--paper,#f2eee2);touch-action:none;box-shadow:inset 0 0 0 1px rgba(0,0,0,.04)}
.completion-canvas{max-height:min(50vh,520px)}
.tone-canvas{max-height:300px}
.tone-legend{display:flex;justify-content:center;gap:1.3rem;color:var(--muted,#9aa9a0);font-size:.86rem}
.tone-legend span::before{content:"";display:inline-block;width:1.7rem;margin-right:.42rem;vertical-align:middle;border-top:4px solid}
.tone-legend .target-line::before{border-color:#d88b3d;border-top-style:dashed}
.tone-legend .voice-line::before{border-color:#237866}
.tone-caveat{max-width:34rem;margin:0 auto;color:var(--muted,#9aa9a0);font-size:.88rem}
.method-reason{max-width:36rem;margin:.1rem auto;color:var(--muted,#9aa9a0);font-size:.88rem}
.method-reason summary{cursor:pointer}
.method-reason p{margin:.45rem 0 0}
@keyframes gentle-nudge{35%{transform:translateX(-4px)}70%{transform:translateX(4px)}}
@media(max-width:560px){
  .form-choice-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .form-choice{min-height:5.5rem;font-size:3rem}
  .completion-canvas{max-height:44vh}
}
