:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17201d;
  background: #f4f1e8;
  font-synthesis: none;
}

.tone-test { display:flex; min-height:100dvh; flex-direction:column; align-items:center; justify-content:center; gap:clamp(12px,2vh,24px); text-align:center; }
.tone-test-top { position:absolute; top:max(18px,env(safe-area-inset-top)); left:max(18px,env(safe-area-inset-left)); right:max(18px,env(safe-area-inset-right)); display:flex; align-items:center; justify-content:space-between; }
.tone-test-top > span { position:absolute; left:50%; transform:translateX(-50%); }
.tone-audio { display:grid; justify-items:center; gap:8px; }
.tone-replay { width:clamp(88px,15vw,128px); aspect-ratio:1; border:0; border-radius:50%; background:var(--green,#1f765f); color:white; font-size:clamp(2.6rem,7vw,4.5rem); box-shadow:0 10px 22px #1f765f33; }
.tone-answer-slots { display:flex; gap:12px; min-height:70px; }
.tone-answer-slot { display:grid; width:78px; height:70px; place-items:center; border:2px solid #d8d2c5; border-radius:14px; background:#fff; font-size:1.8rem; }
.tone-answer-slot.is-active { border-color:#1f765f; box-shadow:0 0 0 4px #1f765f1f; }
.tone-buttons { display:grid; width:min(660px,100%); grid-template-columns:repeat(4,1fr); gap:12px; }
.tone-buttons button { display:flex; min-height:112px; flex-direction:column; align-items:center; justify-content:center; gap:10px; border-radius:18px; }
.tone-contour { width:min(100%,112px); height:54px; overflow:visible; }
.tone-contour path { fill:none; stroke:#17201d; stroke-width:8; stroke-linecap:round; stroke-linejoin:round; }
.tone-contour-small { width:58px; height:28px; }
.tone-contour-small path { stroke-width:9; }
.tone-contour-inline { display:inline-block; width:42px; height:21px; vertical-align:middle; }
.tone-reveal { display:inline-flex; align-items:center; gap:8px; margin-left:8px; }
.tone-buttons small { font-size:1rem; }
.tone-feedback { min-height:48px; font-size:1.1rem; }
.tone-actions,.tone-live-settings { display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:12px; }
.tone-live-settings { padding:10px 14px; border:1px solid #ddd6c8; border-radius:14px; background:#fffaf2; }
.tone-live-settings label { display:flex; align-items:center; gap:8px; }
.tone-summary { width:min(520px,100%); padding:20px; border:1px solid #ddd6c8; border-radius:18px; background:white; }
.tone-complete { width:min(760px,calc(100% - 32px)); min-height:100dvh; padding-top:max(52px,env(safe-area-inset-top)); padding-bottom:max(40px,env(safe-area-inset-bottom)); }
.tone-complete > .eyebrow { margin:36px 0 8px; }
.tone-complete > h1 { max-width:100%; margin:0 0 clamp(28px,5vh,46px); font-size:clamp(2.1rem,6vw,4rem); line-height:1.08; text-wrap:balance; }
.tone-complete .tone-summary { display:grid; width:100%; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px 22px; padding:clamp(20px,4vw,30px); }
.tone-complete .tone-summary p { display:flex; min-height:30px; align-items:center; gap:7px; margin:0; }
.tone-complete .completion-actions { width:100%; margin-top:28px; }
@media(max-width:600px){.tone-buttons{gap:7px}.tone-buttons button{min-height:88px;padding:8px}.tone-live-settings{width:100%}.tone-live-settings label{width:100%}.tone-live-settings select,.tone-live-settings input{flex:1;min-width:0}}
@media(max-width:600px){.tone-complete .tone-summary{grid-template-columns:1fr}.tone-complete>h1{font-size:clamp(1.9rem,10vw,2.8rem)}}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body { margin: 0; min-width: 320px; overflow-x: hidden; }
#app,
#app * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#app img,
#app svg { -webkit-user-drag: none; }
button, select, input { font: inherit; }
button, a, select, input, label { -webkit-tap-highlight-color: transparent; }
button, a, select, input, .unit-option, .choice-row { touch-action: manipulation; }
:focus-visible { outline: 3px solid #147a9b; outline-offset: 3px; }

.language-button {
  position: fixed;
  z-index: 30;
  top: max(8px, env(safe-area-inset-top));
  right: max(54px, calc(env(safe-area-inset-right) + 54px));
  min-height: 38px;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgb(255 253 247 / 90%);
  box-shadow: 0 4px 14px rgb(52 44 31 / 10%);
  font-size: .82rem;
  backdrop-filter: blur(8px);
}

.fullscreen-help {
  width: min(420px, calc(100% - 32px));
  border: 1px solid #d4cdbd;
  border-radius: 20px;
  padding: 24px;
  color: #17201d;
  background: #fffdf7;
  box-shadow: 0 24px 80px rgb(23 32 29 / 28%);
}
.fullscreen-help::backdrop { background: rgb(23 32 29 / 52%); }
.fullscreen-help h2 { margin-top: 0; font-size: 1.45rem; }
.fullscreen-help li { margin-block: 10px; line-height: 1.4; }
.fullscreen-help button { width: 100%; }

.app-shell {
  width: min(760px, calc(100% - max(32px, env(safe-area-inset-left) + env(safe-area-inset-right) + 24px)));
  margin: 0 auto;
  padding: 56px 0;
}

.hero, .ting-xie > header { margin-bottom: 32px; }
h1 { margin: 4px 0 8px; font-size: clamp(2.3rem, 8vw, 4.5rem); line-height: .95; }
p { line-height: 1.55; }
.eyebrow { margin: 0; color: #a33b20; font-size: .8rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.module-grid { display: grid; gap: 16px; }
.module-card, .setup-card, .audio-prompt {
  border: 1px solid #d4cdbd;
  border-radius: 22px;
  background: #fffdf7;
  box-shadow: 0 16px 44px rgb(52 44 31 / 8%);
}
.module-card { display: grid; gap: 7px; padding: 24px; color: inherit; text-decoration: none; }
.module-card strong { font-size: 1.4rem; }
.module-card:hover, .module-card:focus-visible { border-color: #a33b20; transform: translateY(-2px); }
.journey-primary-card { grid-column: 1 / -1; border: 2px solid #1d6b57; background: linear-gradient(135deg,#eef8f4,#fffdf7); }
.journey-primary-card strong { color:#155544; font-size:clamp(1.55rem,4vw,2rem); }
.learning-journey progress { width:100%; height:14px; accent-color:#1d6b57; }
.journey-progress { margin-bottom:24px; }
.journey-progress h1 { font-size:clamp(2rem,6vw,3.5rem); }
.journey-prompt-host { min-height:420px; }
.journey-exercise { display:grid; justify-items:center; gap:20px; padding:clamp(24px,5vw,48px); border:1px solid #d4cdbd; border-radius:22px; background:#fffdf7; box-shadow:0 16px 44px rgb(52 44 31 / 8%); }
.journey-exercise-stage { display:grid; width:100%; justify-items:center; gap:20px; }
.journey-exercise h2 { min-height:1.3em; margin:0; font-size:clamp(2rem,7vw,4.5rem); text-align:center; }
.journey-introduction-word,.journey-recognition-character { font-size:clamp(5rem,18vw,10rem); font-weight:800; line-height:1; }
.journey-introduction-pinyin { margin:0; font-size:clamp(1.4rem,4vw,2rem); }
.journey-inline-actions { display:flex; width:min(680px,100%); flex-wrap:wrap; justify-content:center; gap:12px; }
.journey-inline-actions button { min-width:120px; min-height:52px; }
.journey-choice-grid { display:grid; width:min(620px,100%); grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.journey-choice-grid button { min-height:70px; font-size:clamp(1.15rem,4vw,1.6rem); }
.journey-choice-grid .is-supported-answer { outline:4px solid #e4a62d; outline-offset:2px; }
.journey-assembly-target { width:min(340px,70vw); aspect-ratio:1; border:2px solid #847c6e; border-radius:18px; background:#faf8f1; }
.journey-assembly-target svg,.journey-component-tray svg { display:block; width:100%; height:100%; }
.journey-assembly-target path,.journey-component-tray path { fill:#17201c; }
.journey-component-tray { display:grid; width:min(720px,100%); grid-template-columns:repeat(auto-fit,minmax(110px,1fr)); gap:12px; }
.journey-component-tray button { display:grid; min-height:130px; grid-template-rows:1fr auto; gap:4px; }
.journey-guided-square { width:min(520px,78vw); aspect-ratio:1; touch-action:none; }
.journey-guided-square svg { display:block; width:100%; height:100%; }
.journey-guided-model { fill:#d9d4ca; }
.journey-copy-layout { display:grid; width:min(760px,100%); grid-template-columns:minmax(120px,.45fr) minmax(240px,1fr); align-items:center; gap:24px; }
.journey-copy-model { font-size:clamp(5rem,16vw,10rem); text-align:center; }
.journey-writing-canvas { display:block; width:min(520px,100%); aspect-ratio:1; border:2px solid #847c6e; border-radius:16px; background:#fff; touch-action:none; }
.journey-feedback { min-height:32px; color:#8f321a; font-weight:800; }
.journey-assembly-answer { min-width:180px; min-height:64px; border-bottom:3px solid #1d6b57; font-size:2.5rem; letter-spacing:.25em; }
.journey-device-note { color:#666e6b; font-size:.85rem; text-align:center; }
.journey-summary { display:grid; gap:8px; margin:24px 0; padding:28px; border:1px solid #d4cdbd; border-radius:22px; background:#fffdf7; }
@media(max-width:600px){.journey-choice-grid{grid-template-columns:1fr}.journey-prompt-host{min-height:360px}.journey-exercise{padding:22px 16px}.journey-copy-layout{grid-template-columns:1fr}.journey-copy-model{font-size:5rem}}
@media (max-width:600px) {
  .learning-journey .journey-exercise { gap:8px; padding:12px 10px; }
  .learning-journey .journey-exercise-stage { gap:8px; }
  .learning-journey .journey-exercise h2 { min-height:0; font-size:1.5rem; }
  .learning-journey .journey-copy-layout { gap:6px; }
  .learning-journey .journey-copy-model { font-size:3.5rem; line-height:1; }
  .learning-journey .journey-copy-layout .journey-writing-canvas { width:min(280px,calc(100dvh - 510px)); min-width:220px; }
  .learning-journey .journey-inline-actions { gap:6px; }
  .learning-journey .journey-inline-actions button { min-width:105px; min-height:44px; }
  .learning-journey .journey-feedback { min-height:28px; }
}
@media (min-width:700px) and (max-height:700px) {
  .learning-journey { width:min(1000px,calc(100% - 24px)); height:100dvh; min-height:0; padding:6px 0; overflow:hidden; }
  .learning-journey > .text-button { align-self:flex-start; }
  .learning-journey .journey-progress { margin:0 0 4px; }
  .learning-journey .journey-progress h1 { font-size:1.55rem; }
  .learning-journey .journey-progress progress { height:8px; }
  .learning-journey .journey-prompt-host { min-height:0; flex:1 1 auto; }
  .learning-journey .journey-device-note { display:none; }
  .learning-journey .journey-exercise { height:100%; box-sizing:border-box; gap:4px; padding:7px 12px; overflow:hidden; }
  .learning-journey .journey-exercise-stage { gap:5px; }
  .learning-journey .journey-exercise h2 { min-height:0; font-size:1.35rem; }
  .learning-journey .journey-assembly-target { width:min(180px,25vh); }
  .learning-journey .journey-component-tray { width:min(620px,100%); grid-template-columns:repeat(auto-fit,minmax(85px,140px)); grid-auto-rows:86px; justify-content:center; gap:6px; }
  .learning-journey .journey-component-tray button { min-height:0; height:86px; padding:3px; overflow:hidden; }
  .learning-journey .journey-component-tray button svg { min-height:0; }
  .learning-journey .journey-guided-square,.learning-journey .journey-writing-canvas { width:min(300px,43vh); }
  .learning-journey .journey-copy-layout { width:min(640px,100%); gap:10px; }
  .learning-journey .journey-copy-model { font-size:5rem; }
  .learning-journey .journey-inline-actions button { min-height:38px; }
  .learning-journey .journey-feedback { min-height:24px; }
}

.setup-card { display: grid; gap: 0; padding: 0; overflow: hidden; }
label { font-weight: 750; }
select, button, input[type="number"] { min-height: 52px; border: 1px solid #b8b0a0; border-radius: 12px; padding: 11px 15px; background: white; }
button { cursor: pointer; font-weight: 750; }
button:disabled { cursor: not-allowed; opacity: .42; }
.primary-button { border-color: #a33b20; color: white; background: #a33b20; }
.text-button { min-height: 48px; border: 0; padding-left: 0; color: #6d2b18; background: transparent; }

.loading-state, .error-state { padding-top: 28px; }
.setup-section { display: grid; gap: 16px; margin: 0; padding: 28px; border: 0; border-bottom: 1px solid #e3ddcf; }
.setup-section legend { width: auto; max-width: 100%; margin: 0 0 12px; padding: 0; color: #a33b20; font-size: 1.05rem; font-weight: 850; }
.setup-section select { width: 100%; }
.selection-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.selection-summary { color: #4d5552; font-size: .9rem; font-weight: 700; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.small-button { min-height: 48px; padding: 9px 13px; font-size: .9rem; }
.unit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.unit-option, .choice-row { display: flex; align-items: center; gap: 11px; border: 1px solid #d4cdbd; border-radius: 14px; background: white; cursor: pointer; }
.unit-option { min-height: 64px; padding: 14px; }
.unit-option.is-selected { border-color: #1d6b57; background: #eef8f4; box-shadow: inset 0 0 0 1px #1d6b57; }
.unit-option input, .choice-row input { flex: 0 0 auto; width: 24px; height: 24px; accent-color: #1d6b57; }
.unit-option span, .choice-row span { display: grid; gap: 2px; }
.unit-option small, .choice-row small, .inline-setting small { color: #666e6b; font-weight: 500; }
.choice-row { min-height: 68px; padding: 15px; }
.inline-setting { display: grid; grid-template-columns: 1fr minmax(86px, 120px); align-items: center; gap: 4px 14px; margin-top: 2px; padding: 14px; border-radius: 14px; background: #f5f2e9; }
.inline-setting small { grid-column: 1 / -1; }
.inline-setting input:disabled { opacity: .55; }
.field-note, .voice-unavailable { margin: 0; color: #666e6b; font-size: .88rem; }
.voice-unavailable { padding: 12px 14px; border-left: 3px solid #a33b20; border-radius: 4px; background: #f8eee9; }
.range-setting { display: grid; gap: 8px; padding: 14px; border-radius: 14px; background: #f5f2e9; }
.range-setting > span { display: flex; justify-content: space-between; }
.range-setting output { color: #1d6b57; }
.range-setting input { width: 100%; min-height: 48px; accent-color: #1d6b57; }
.range-setting small { color: #666e6b; font-weight: 500; }
.preview-row { display: flex; align-items: center; gap: 14px; }
.preview-status { color: #555; font-size: .9rem; }
.validation-message { margin: 0; color: #a33b20; font-size: .9rem; font-weight: 750; }
.start-button { min-height: 62px; margin: 28px; font-size: 1.08rem; }

.practice { display: flex; min-height: 100svh; flex-direction: column; width: min(820px, calc(100% - max(32px, env(safe-area-inset-left) + env(safe-area-inset-right) + 24px))); padding-top: max(32px, env(safe-area-inset-top)); padding-bottom: 0; text-align: center; }
.practice > .text-button { align-self: flex-start; display: block; margin-bottom: 20px; }
.audio-prompt { padding: 38px 24px; }
.practice-prompt { width: min(100%, 780px); margin: 0 auto; }
.item-count { margin: 10px 0 20px; font-size: 1.2rem; }
.speaker { display: grid; width: 112px; height: 112px; margin: 20px auto; padding: 0; place-items: center; border: 0; border-radius: 50%; color: white; background: #1d6b57; font-size: 3.4rem; }
.speaker-replay { cursor: pointer; box-shadow: 0 8px 22px rgb(29 107 87 / 22%); }
.replay-controls { display: flex; align-items: center; justify-content: center; gap: 10px; }
.replay-controls .speaker { margin-inline: 0; }
.example-replay { width: 72px; height: 72px; background: #327b9a; font-size: 2rem; box-shadow: 0 8px 22px rgb(50 123 154 / 22%); }
.speaker-replay:hover { background: #175746; transform: translateY(-1px); }
.speaker-replay:focus-visible { outline: 4px solid rgb(42 168 121 / 38%); outline-offset: 3px; }
.handwriting-word-progress { display: flex; min-height: 58px; align-items: center; justify-content: center; gap: 8px; margin: 6px auto 2px; }
.timed-answer-reveal { position: fixed; z-index: 40; inset: 50% auto auto 50%; min-width: min(420px, calc(100vw - 32px)); max-width: calc(100vw - 32px); padding: 30px 38px; transform: translate(-50%, -50%); border: 4px solid #a33b20; border-radius: 20px; color: #6d2b18; background: #fffdf7; box-shadow: 0 24px 70px rgb(52 44 31 / 28%); font-family: "Noto Serif SC", "Songti SC", serif; font-size: clamp(5rem, 16vw, 10rem); font-weight: 800; line-height: 1.05; white-space: nowrap; }
.timed-answer-reveal[hidden] { display: none; }
.word-progress-slot { display: grid; width: clamp(46px, 8vw, 64px); min-height: 0; padding: 0; aspect-ratio: 1; place-items: center; border: 2px solid #bdb3a3; border-radius: 10px; background: #fffdf7; color: #173f35; font-family: "Noto Serif SC", "Songti SC", serif; font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; line-height: 1; }
.word-progress-slot.is-active { border-color: #1d6b57; box-shadow: 0 0 0 4px rgb(42 168 121 / 20%); background: #f0faf6; }
.word-progress-slot.is-complete { border-color: #72a793; background: #e8f5ef; }
.word-progress-slot.is-editing { border-color: #a33b20; box-shadow: 0 0 0 4px rgb(163 59 32 / 20%); background: #fff7ed; }
.word-progress-slot:disabled:not(.is-complete) { opacity: .58; cursor: default; }
.status { min-height: 25px; color: #555; }
.replay { min-width: 220px; min-height: 58px; font-size: 1.05rem; }
.practice-actions { position: sticky; z-index: 5; bottom: 0; width: 100%; margin-top: auto; padding: 18px 0 max(18px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, rgb(244 241 232 / 25%), #f4f1e8 18px); }
.practice-voice { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; margin-bottom: 10px; padding: 12px 16px; border: 1px solid #d4cdbd; border-radius: 18px; background: #fffdf7; box-shadow: 0 10px 30px rgb(52 44 31 / 8%); text-align: left; }
.practice-voice select { width: 100%; min-width: 0; }
.practice-volume { display: grid; grid-template-columns: auto auto minmax(160px, 1fr) 54px; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid #d4cdbd; border-radius: 18px; background: #fffdf7; box-shadow: 0 10px 30px rgb(52 44 31 / 8%); text-align: left; }
.practice-volume label { font-size: .95rem; }
.practice-volume input[type="range"] { width: 100%; min-height: 48px; accent-color: #1d6b57; }
.practice-volume output { min-width: 48px; color: #1d6b57; font-weight: 800; text-align: right; }

/* Ting Xie keeps secondary audio settings off the fixed-height practice canvas. */
.ting-xie .practice-audio-toolbar {
  position: fixed;
  z-index: 20;
  top: calc(max(8px, env(safe-area-inset-top)) + 46px);
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}
.practice-audio-control { position: relative; }
.audio-toolbar-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 13px; border-color: #c9c0af; background: #fffdf7; color: #29453d; box-shadow: 0 5px 16px rgb(52 44 31 / 8%); }
.ting-xie .audio-toolbar-button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 10px;
  backdrop-filter: blur(8px);
}
.ting-xie .audio-toolbar-button > span:not([aria-hidden="true"]) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.audio-toolbar-button [data-volume-summary] { color: #1d6b57; font-size: .82rem; font-weight: 800; }
.practice-audio-popover { position: absolute; right: 0; bottom: calc(100% + 8px); width: min(320px, calc(100vw - 28px)); padding: 14px; border: 1px solid #c9c0af; border-radius: 16px; background: #fffdf7; box-shadow: 0 18px 50px rgb(38 33 24 / 22%); text-align: left; }
.practice-audio-control:first-child .practice-audio-popover { right: auto; left: 0; }
.ting-xie .practice-audio-popover,
.ting-xie .practice-audio-control:first-child .practice-audio-popover {
  top: 0;
  right: calc(100% + 8px);
  bottom: auto;
  left: auto;
  width: min(320px, calc(100vw - 74px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-width: calc(100vw - 74px - env(safe-area-inset-left) - env(safe-area-inset-right));
  box-sizing: border-box;
}
.practice-audio-popover[hidden] { display: none; }
.practice-audio-popover h2 { margin: 0 0 10px; font-size: 1rem; }
.voice-pack-list { display: grid; gap: 7px; }
.voice-pack-list button { min-height: 48px; display: grid; gap: 2px; padding: 8px 11px; border-color: #d4cdbd; background: #fff; color: #333; text-align: left; }
.voice-pack-list button[aria-checked="true"] { border-color: #1d6b57; background: #e8f4ee; box-shadow: inset 0 0 0 1px #1d6b57; }
.voice-pack-list button span { color: #666e6b; font-size: .82rem; }
.practice-audio-popover .practice-volume { width: 100%; min-width: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.practice-audio-popover .practice-volume input[type="range"] { min-width: 0; max-width: 100%; }
.mute-button { display: inline-flex; min-width: 112px; min-height: 52px; align-items: center; justify-content: center; gap: 8px; padding-inline: 12px; }
.practice-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 18px; }
.practice-nav button { display: inline-flex; min-height: 78px; align-items: center; justify-content: space-between; border-width: 2px; border-radius: 20px; padding: 18px 26px; font-size: 1.3rem; font-weight: 850; box-shadow: 0 10px 24px rgb(52 44 31 / 10%); }
.practice-nav button span[aria-hidden="true"] { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; font-size: 1.45rem; }
.practice-nav .next-button { border-color: #1d6b57; color: white; background: #1d6b57; }
.practice-nav .next-button span[aria-hidden="true"] { background: rgb(255 255 255 / 18%); }
.practice-nav .previous-button { border-color: #9abbb1; color: #174e40; background: #f3fbf8; }
.practice-nav .previous-button span[aria-hidden="true"] { background: #dcefe9; }
.practice-nav button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 5px 12px rgb(52 44 31 / 10%); }
.practice-nav button:disabled { box-shadow: none; }
.timer { display: flex; justify-content: center; align-items: baseline; gap: 6px; margin: 8px 0 5px; }
.timer strong { color: #a33b20; font-size: 2.2rem; }
.timer span { color: #666; }
.timer-track { width: min(280px, 80%); height: 7px; margin: 0 auto 12px; overflow: hidden; border-radius: 999px; background: #e8e2d5; }
.timer-track span { display: block; height: 100%; background: #a33b20; transition: width .2s linear; }
.timed-note { margin: 12px 0 0; padding: 12px; color: #555; font-size: .95rem; }
.completion-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }

@media (max-width: 480px) {
  .app-shell { padding-top: 32px; }
  .unit-grid { grid-template-columns: repeat(2, 1fr); }
  .selection-toolbar { align-items: flex-start; flex-direction: column; }
  .preview-row { align-items: stretch; flex-direction: column; }
  .completion-actions { grid-template-columns: 1fr; }
  .setup-section { padding: 22px 18px; }
  .start-button { margin: 22px 18px; }
  .practice-volume { grid-template-columns: auto 1fr auto; }
  .practice-voice { grid-template-columns: 1fr; gap: 6px; }
  .practice-volume label { display: none; }
  .mute-button { min-width: 56px; }
  .mute-button span:last-child { display: none; }
  .practice-nav { gap: 12px; }
  .practice-nav button { min-height: 72px; padding-inline: 18px; font-size: 1.12rem; }
  .practice-nav button span[aria-hidden="true"] { width: 34px; height: 34px; }
}

@media (hover: hover) {
  .practice-nav button:hover:not(:disabled) { filter: brightness(.97); transform: translateY(-1px); }
}

@media (max-height: 700px) and (min-width: 700px) {
  .practice { padding-top: max(18px, env(safe-area-inset-top)); }
  .practice > .text-button { margin-bottom: 8px; }
  .practice-prompt { padding: 18px 24px; }
  .speaker { width: 78px; height: 78px; margin: 10px auto; font-size: 2.5rem; }
  .item-count { margin-bottom: 8px; }
  .status { margin: 8px 0; }
  .practice-actions { padding-top: 10px; }
  .practice-volume { padding-block: 8px; }
  .practice-nav { margin-top: 8px; }
}

input[type="range"]::-webkit-slider-thumb { width: 28px; height: 28px; }
input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #1d6b57; }

/* Pinyin Practice ---------------------------------------------------------
   Kept under a pinyin- namespace so the existing Ting Xie layout is not
   affected. Controls use a 48px minimum target and remain usable by touch. */
.pinyin-practice,
.renzi-practice {
  display: flex;
  min-height: 100svh;
  flex-direction: column;
  width: min(920px, calc(100% - max(24px, env(safe-area-inset-left) + env(safe-area-inset-right) + 16px)));
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom));
}

.pinyin-practice button,
.pinyin-practice label,
.pinyin-practice input { touch-action: manipulation; }
.renzi-practice button,
.renzi-practice label,
.renzi-practice input { touch-action: manipulation; }

.pinyin-practice > .text-button { align-self: flex-start; margin-bottom: 12px; }

.pinyin-prompt {
  display: grid;
  gap: 12px;
  padding: clamp(22px, 5vw, 40px) 20px;
  border: 1px solid #d4cdbd;
  border-radius: 22px;
  background: #fffdf7;
  box-shadow: 0 16px 44px rgb(52 44 31 / 8%);
  text-align: center;
}

.pinyin-character,
.pinyin-characters {
  margin: 0;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: clamp(3.5rem, 14vw, 7rem);
  font-weight: 800;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.pinyin-instruction { margin: 0; color: #555f5b; }

.pinyin-answers,
.pinyin-answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 18px 0;
}

.pinyin-answer-slot {
  display: grid;
  min-width: clamp(112px, 26vw, 190px);
  min-height: 64px;
  place-items: center;
  border: 2px solid #b8b0a0;
  border-radius: 14px;
  padding: 10px 14px;
  background: white;
  color: #17201d;
  font-size: clamp(1.2rem, 4vw, 1.65rem);
  font-weight: 800;
}

.pinyin-answer-slot.is-active { border-color: #147a9b; box-shadow: 0 0 0 3px rgb(20 122 155 / 18%); }
.pinyin-answer-slot.is-correct { border-color: #1d6b57; background: #eef8f4; color: #174e40; }
.pinyin-answer-slot.is-incorrect { border-color: #a33b20; background: #f8eee9; color: #7d2e18; }

.pinyin-builder { display: grid; gap: 16px; }
.pinyin-choice-group { display: grid; gap: 8px; }
.pinyin-choice-group > legend,
.pinyin-choice-label { color: #4d5552; font-size: .9rem; font-weight: 800; }

.pinyin-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}

.pinyin-choice,
.pinyin-choice-button,
.pinyin-key {
  min-width: 0;
  min-height: 52px;
  border: 1px solid #b8b0a0;
  border-radius: 12px;
  padding: 8px;
  background: white;
  color: #17201d;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.15;
  user-select: none;
  -webkit-user-select: none;
}

.pinyin-choice.is-selected,
.pinyin-choice-button.is-selected,
.pinyin-key.is-selected,
.pinyin-choice[aria-pressed="true"],
.pinyin-choice-button[aria-pressed="true"],
.pinyin-key[aria-pressed="true"] {
  border-color: #1d6b57;
  background: #eef8f4;
  color: #174e40;
  box-shadow: inset 0 0 0 1px #1d6b57;
}

.pinyin-choice-button.is-unavailable,
.pinyin-choice-button.is-unavailable:hover {
  border-color: #d8d3c9;
  background: #ece9e2;
  color: #9a968e;
  box-shadow: none;
  opacity: .55;
  text-decoration: line-through;
}

.pinyin-keyboard {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 18px;
  background: #eae5d9;
}

.pinyin-keyboard-shell { display: grid; gap: 8px; }
.pinyin-keyboard-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #4d5552; font-size: .9rem; font-weight: 800; }
.pinyin-layout-options { display: flex; gap: 6px; }
.pinyin-layout-options button { min-height: 36px; border-radius: 999px; padding: 6px 12px; font-size: .85rem; }
.pinyin-layout-options button[aria-pressed="true"] { border-color: #1d6b57; background: #eef8f4; color: #174e40; box-shadow: inset 0 0 0 1px #1d6b57; }
.pinyin-tone-row { display: grid; grid-template-columns: repeat(5, minmax(44px, 1fr)); gap: 8px; }
.pinyin-key-row { display: flex; justify-content: center; gap: 8px; }
.pinyin-key-row .pinyin-key { flex: 1 1 0; max-width: 76px; }
.pinyin-key-row--actions .pinyin-key--wide { flex-grow: 2; max-width: 160px; }
.pinyin-key--tone { border-color: #147a9b; background: #edf8fb; color: #105d75; }

.pinyin-key { min-height: 56px; box-shadow: 0 2px 0 #c5bcaa; }
.pinyin-key:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.pinyin-key--wide { grid-column: span 2; }
.pinyin-key--action { color: #6d2b18; background: #fff8f3; }

.pinyin-feedback {
  min-height: 54px;
  margin: 14px 0 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: #f5f2e9;
  color: #4d5552;
  font-weight: 750;
  text-align: center;
}

.pinyin-feedback.is-correct,
.pinyin-feedback--correct { background: #e5f5ef; color: #174e40; }
.pinyin-feedback.is-incorrect,
.pinyin-feedback--incorrect { background: #f8e8e1; color: #7d2e18; }

.pinyin-actions,
.pinyin-nav {
  position: sticky;
  z-index: 5;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: auto;
  padding: 18px 0 max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgb(244 241 232 / 15%), #f4f1e8 18px);
}

.pinyin-actions button,
.pinyin-nav button {
  min-height: 68px;
  border-radius: 18px;
  padding: 14px 20px;
  font-size: 1.12rem;
  font-weight: 850;
}

.pinyin-actions .advance-action { grid-column: 2; }

.fullscreen-button {
  position: fixed;
  z-index: 20;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: grid;
  width: 38px;
  min-height: 38px;
  padding: 0;
  place-items: center;
  border-radius: 10px;
  background: rgb(255 253 247 / 88%);
  box-shadow: 0 4px 14px rgb(52 44 31 / 10%);
  font-size: 1.15rem;
  backdrop-filter: blur(8px);
}

.renzi-answer { display: grid; gap: 14px; }
.renzi-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.renzi-choices button {
  min-height: 68px;
  border: 2px solid #b8b0a0;
  border-radius: 16px;
  padding: 14px;
  background: white;
  color: #17201d;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  font-weight: 800;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.renzi-choices button:focus-visible { border-color: #147a9b; box-shadow: 0 0 0 3px rgb(20 122 155 / 18%); }

@media (hover: hover) {
  .pinyin-choice:hover:not(:disabled),
  .pinyin-choice-button:hover:not(:disabled),
  .pinyin-key:hover:not(:disabled) { border-color: #1d6b57; }
}

@media (max-width: 700px) {
  .pinyin-key-row { gap: 6px; }
}

@media (max-width: 480px) {
  .pinyin-practice,
  .renzi-practice { width: min(100% - 20px, 920px); padding-top: max(16px, env(safe-area-inset-top)); }
  .pinyin-prompt { border-radius: 18px; padding-inline: 14px; }
  .pinyin-choice-grid { grid-template-columns: repeat(auto-fit, minmax(52px, 1fr)); gap: 7px; }
  .pinyin-keyboard { gap: 7px; padding: 8px; }
  .pinyin-keyboard-toolbar { align-items: stretch; flex-direction: column; }
  .pinyin-layout-options button { flex: 1; }
  .pinyin-key { min-height: 52px; padding-inline: 5px; }
  .pinyin-actions,
  .pinyin-nav { gap: 8px; padding-top: 12px; }
  .pinyin-actions button,
  .pinyin-nav button { min-height: 62px; padding-inline: 12px; font-size: 1rem; }
  .renzi-choices { grid-template-columns: 1fr; gap: 9px; }
  .renzi-choices button { min-height: 60px; }
}

@media (max-height: 700px) and (min-width: 700px) {
  .pinyin-practice { padding-top: max(12px, env(safe-area-inset-top)); }
  .pinyin-prompt { padding-block: 16px; }
  .pinyin-character,
  .pinyin-characters { font-size: clamp(3rem, 10vh, 5rem); }
  .pinyin-answers,
  .pinyin-answer { margin-block: 10px; }
  .pinyin-choice,
  .pinyin-choice-button,
  .pinyin-key { min-height: 48px; }
  .pinyin-actions,
  .pinyin-nav { padding-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .pinyin-practice * { scroll-behavior: auto !important; transition: none !important; }
}

.assembly-practice { width: min(100% - 32px, 980px); }
.assembly-header { text-align: center; }
.assembly-target-prompt { margin: 6px 0; font-size: clamp(1.8rem, 5vw, 2.6rem); }
.assembly-target-prompt [lang] { display: inline-block; margin-left: .2em; color: #174e40; font-size: 1.45em; line-height: 1; vertical-align: -.08em; }
.assembly-workspace { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(260px, 1fr); gap: 24px; align-items: start; }
.assembly-target { position: relative; aspect-ratio: 1; border: 3px dashed #b8b0a0; border-radius: 20px; overflow: hidden; background: linear-gradient(45deg, transparent 49.7%, #ddd6c9 50%, transparent 50.3%), linear-gradient(-45deg, transparent 49.7%, #ddd6c9 50%, transparent 50.3%), #fffdf7; }
.assembly-target.is-over { border-color: #147a9b; background-color: #edf8fb; }
.assembly-target > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.assembly-target > span { position: absolute; inset: auto 0 12px; color: #81796c; text-align: center; pointer-events: none; }
.assembly-target path { fill: #17201d; }
.stroke-box { padding: 16px; border-radius: 18px; background: #eae5d9; }
.stroke-box h2 { margin: 0 0 12px; font-size: 1rem; }
.stroke-pieces { display: grid; grid-template-columns: repeat(3, minmax(72px, 1fr)); gap: 10px; }
.stroke-piece { position: relative; aspect-ratio: 1; min-height: 72px; padding: 3px; border-radius: 12px; background: #fff; cursor: grab; touch-action: manipulation; }
.stroke-piece svg { width: 100%; height: 100%; pointer-events: none; }
.stroke-piece path { fill: #174e40; }
.stroke-piece small { position: absolute; right: 5px; bottom: 3px; padding: 1px 5px; border-radius: 8px; background: #f4f1e8; font-weight: 800; }
.stroke-piece.is-placed { opacity: .42; cursor: default; }
.stroke-piece.is-returning { border-color: #b9372b; background: #f8d8d2; opacity: .45; }
.component-box .stroke-pieces { grid-template-columns: repeat(2, minmax(96px, 1fr)); }
.component-piece { min-height: 108px; }
.component-piece small { max-width: calc(100% - 10px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rejected-stroke-ghost { position: absolute; z-index: 3; inset: 0; width: 100%; height: 100%; pointer-events: none; transform-origin: center; }
.rejected-stroke-ghost path { fill: #b9372b; filter: drop-shadow(0 0 8px rgb(185 55 43 / 45%)); }
.assembly-feedback { min-height: 52px; margin: 18px 0 0; padding: 14px; border-radius: 14px; background: #f5f2e9; text-align: center; font-weight: 750; }
.assembly-feedback.is-correct { background: #e5f5ef; color: #174e40; }
.assembly-feedback.is-incorrect { background: #f8e8e1; color: #7d2e18; }
.assembly-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.assembly-fallback { max-width: 620px; margin: 40px auto; padding: 30px; border-radius: 22px; background: white; text-align: center; }
.assembly-fallback [lang] { font-size: 8rem; line-height: 1.1; }
.assembly-loading { padding: 80px 20px; text-align: center; }

@media (max-width: 680px) {
  .assembly-workspace { grid-template-columns: 1fr; }
  .assembly-target { width: min(100%, 420px); margin-inline: auto; }
  .stroke-pieces { grid-template-columns: repeat(4, minmax(58px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .stroke-piece { animation: none !important; }
}

.guided-practice { width: min(100% - 32px, 880px); }
.guided-header { text-align: center; }
.guided-target-character { font-size: clamp(2.5rem, 8vh, 4.75rem); line-height: .95; font-weight: 800; color: #174e40; }
.guided-square { width: min(100%, 560px); aspect-ratio: 1; margin: 18px auto; border: 3px solid #b8b0a0; border-radius: 22px; overflow: hidden; background: linear-gradient(45deg,transparent 49.8%,#e4ded2 50%,transparent 50.2%),linear-gradient(-45deg,transparent 49.8%,#e4ded2 50%,transparent 50.2%),#fffdf7; touch-action: none; user-select: none; }
.guided-square svg { display: block; width: 100%; height: 100%; }
.guided-complete path,.guided-revealing { fill: #17201d; }
.guided-user-trace { fill: none; stroke: #207e68; stroke-width: 24; stroke-linecap: round; stroke-linejoin: round; opacity: .88; pointer-events: none; }
.guided-start { fill: #2aa879; stroke: #fff; stroke-width: 12; filter: drop-shadow(0 0 10px rgb(42 168 121 / 75%)); }
.guided-square.is-rejected { border-color: #c85e50; box-shadow: 0 0 0 4px rgb(200 94 80 / 14%); }
.guided-square.is-rejected .guided-user-trace { stroke: #b85a4d; }
.guided-feedback { box-sizing: border-box; height: 52px; min-height: 52px; padding: 8px 14px; overflow: hidden; border-radius: 14px; background: #f5f2e9; text-align: center; font-weight: 750; }
.guided-feedback.is-correct { background:#e5f5ef;color:#174e40; }.guided-feedback.is-incorrect { background:#f8e8e1;color:#7d2e18; }
.guided-actions { display:flex;justify-content:flex-end;gap:12px;margin-top:14px; }
.guided-fallback { max-width:620px;margin:40px auto;padding:30px;border-radius:22px;background:white;text-align:center; }.guided-fallback [lang] { font-size:8rem;line-height:1.1; }.guided-loading { padding:80px 20px;text-align:center; }
.loading-progress { display: grid; width: min(100%, 560px); gap: 14px; margin: auto; padding: 24px; border: 1px solid #d9d1c2; border-radius: 20px; background: #fffdf7; box-shadow: 0 12px 34px rgb(52 44 31 / 8%); }
.loading-progress h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.loading-progress-meter { display: grid; grid-template-columns: minmax(0, 1fr) 4ch; align-items: center; gap: 12px; }
.loading-progress progress { width: 100%; height: 18px; overflow: hidden; border: 0; border-radius: 999px; accent-color: #1d6b57; }
.loading-progress progress::-webkit-progress-bar { border-radius: 999px; background: #e4ded2; }
.loading-progress progress::-webkit-progress-value { border-radius: 999px; background: #1d6b57; }
.loading-progress output { color: #174e40; font-weight: 850; text-align: right; }
.loading-progress p { min-height: 1.35em; margin: 0; }
.loading-eta { color: #625a4e; font-size: .9rem; }
.loading-error { width: min(100%, 560px); margin: auto; padding: 24px; border: 1px solid #d9b6ae; border-radius: 20px; background: #fff9f7; text-align: center; }
@media (prefers-reduced-motion: reduce) { .handwriting-canvas-wrap.is-rejected-feedback { animation:none; } }
.handwriting-recognition { width: min(100%, 760px); margin: 10px auto 0; padding: 10px; border: 1px solid #d4cdbd; border-radius: 18px; background: #f7f2e7; }
.handwriting-canvas-wrap { position: relative; width: min(100%, 62dvh, 680px); aspect-ratio: 1; margin-inline: auto; overflow: hidden; border: 2px solid #766d5e; border-radius: 14px; background: #fffdf7; }
.handwriting-guide { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.handwriting-guide path { fill: none; stroke: #cdbfa9; stroke-width: .55; stroke-dasharray: 2 1.5; vector-effect: non-scaling-stroke; }
.handwriting-canvas-wrap.is-correct { border-color: #23834b; box-shadow: 0 0 0 4px rgba(35, 131, 75, .2); }
.handwriting-canvas-wrap.is-incorrect { border-color: #b9362d; box-shadow: 0 0 0 4px rgba(185, 54, 45, .2); }
.ting-xie .handwriting-canvas-wrap.is-incorrect { border-color: #e46f61; }
.handwriting-canvas-wrap.is-rejected-feedback { animation: tingxie-reject .46s ease-out; }
@keyframes tingxie-reject {
  0%, 100% { border-color: #e46f61; box-shadow: 0 0 0 0 rgb(228 111 97 / 0%); }
  42% { border-color: #d34f42; box-shadow: 0 0 0 7px rgb(228 111 97 / 32%); }
}
.handwriting-canvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; background: transparent; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: contain; }
.handwriting-actions { display: flex; justify-content: center; gap: 12px; margin-top: 12px; }
.handwriting-resolution-action { display: grid; min-width: 0; min-height: 48px; }
.handwriting-resolution-action > * { grid-area: 1 / 1; }
.handwriting-unknown-actions { display: grid; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.handwriting-unknown-actions button { min-width: 0; padding-inline: 5px; }
.handwriting-actions .handwriting-done { flex: 1 1 58%; min-height: 48px; font-size: 1.05rem; }
.handwriting-result { min-height: 1.5em; margin: 12px 0 0; text-align: center; }
.handwriting-result.is-correct { color: #176b3a; }
.handwriting-result.is-incorrect { color: #a42d25; }
.handwriting-result.is-loading { color: #5f5648; }

/* Ting Xie active practice -------------------------------------------------
   The writing surface and playback controls share a single fixed viewport.
   Let the canvas absorb height changes instead of allowing the sticky audio
   controls to cover the handwriting actions on phones and tablets. */
@media (min-width: 0px) {
  .ting-xie.practice {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(1000px, calc(100% - max(20px, env(safe-area-inset-left) + env(safe-area-inset-right) + 16px)));
  }
  .ting-xie.practice > .text-button { margin-bottom: 4px; }
  .ting-xie .practice-prompt {
    display: grid;
    min-height: 0;
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
    padding: 4px 8px;
    overflow: hidden;
    width: 100%;
  }
  .ting-xie .practice-prompt > .eyebrow { margin-block: 0 2px; }
  .ting-xie .item-count { margin: 2px 0; font-size: .9rem; }
  .ting-xie .handwriting-word-progress { min-height: 40px; gap: 5px; margin-block: 1px; }
  .ting-xie .word-progress-slot { width: clamp(38px, 7dvh, 52px); border-radius: 8px; font-size: clamp(1.6rem, 5dvh, 2.35rem); }
  .ting-xie .speaker {
    width: 46px;
    height: 46px;
    margin: 3px auto;
    font-size: 1.5rem;
  }
  .ting-xie .status { min-height: 17px; margin: 1px; font-size: .76rem; }
  .ting-xie .speaker-replay { width: 52px; height: 52px; }
  .ting-xie .example-replay { width: 48px; height: 48px; font-size: 1.25rem; }
  .ting-xie .handwriting-recognition {
    display: grid;
    align-self: stretch;
    width: 100%;
    max-width: none;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto auto;
    margin-top: 1px;
    padding: 4px;
    overflow: hidden;
  }
  .ting-xie .handwriting-canvas-wrap {
    width: min(100%, 940px);
    max-width: 100%;
    height: auto;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    align-self: start;
    justify-self: center;
  }
  .ting-xie .handwriting-canvas { height: 100%; min-height: 0; }
  .ting-xie .handwriting-recognition > .field-note { display: none; }
  .ting-xie .handwriting-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 5px;
    margin-top: 4px;
    position: relative;
    z-index: 2;
  }
  .ting-xie .handwriting-actions button { min-height: 44px; padding: 5px 8px; font-size: .82rem; }
  .ting-xie .handwriting-actions .handwriting-done { min-height: 44px; font-size: .95rem; }
  .ting-xie .handwriting-resolution-action { min-width: 0; min-height: 44px; }
  .ting-xie .handwriting-resolution-action button { width: 100%; height: 100%; }
  .ting-xie .handwriting-unknown-actions button { padding-inline: 3px; font-size: clamp(.58rem, 1.7vw, .72rem); line-height: 1.05; }
  .ting-xie .handwriting-result { display: flex; height: 32px; min-height: 32px; margin: 2px 0 0; align-items: center; justify-content: center; overflow: hidden; font-size: .72rem; line-height: 1.15; }
  .ting-xie .practice-actions {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px;
    margin-top: 4px;
    padding: 0 0 max(4px, env(safe-area-inset-bottom));
    background: none;
  }
  .ting-xie .practice-voice,
  .ting-xie .practice-volume { min-width: 0; margin: 0; box-shadow: none; }
  .ting-xie .practice-voice { grid-template-columns: auto minmax(0, 1fr); padding: 4px 6px; }
  .ting-xie .practice-volume {
    grid-template-columns: 38px minmax(48px, 1fr) 34px;
    gap: 3px;
    padding: 3px 5px;
  }
  .ting-xie .practice-volume label { display: none; }
  .ting-xie .practice-volume input[type="range"] { min-width: 0; min-height: 32px; }
  .ting-xie .practice-volume output { min-width: 0; font-size: .72rem; }
  .ting-xie .mute-button { min-width: 36px; min-height: 36px; padding: 3px; }
  .ting-xie .mute-button span:last-child { display: none; }
  .ting-xie .practice-nav { grid-column: 1 / -1; gap: 5px; margin-top: 0; }
  .ting-xie .practice-nav button { min-height: 42px; padding: 4px 8px; border-radius: 10px; font-size: .84rem; }
  .ting-xie .timed-note { grid-column: 1 / -1; margin: 0; padding: 5px; font-size: .72rem; }
}

@media (max-width: 600px) {
  .ting-xie .practice-voice { grid-template-columns: minmax(0, 1fr); }
  .ting-xie .practice-voice label { display: none; }
}

.study-review { width:min(820px,calc(100% - 28px)); min-height:100dvh; padding-block:max(54px,env(safe-area-inset-top)) max(34px,env(safe-area-inset-bottom)); }
.study-review header { margin-bottom:18px; }
.study-summary { display:grid; gap:10px; }
.study-summary-row { padding:0; overflow:hidden; border:1px solid var(--line,#d8d2c5); border-radius:16px; background:var(--surface,#fffdf8); }
.study-summary-heading { display:grid; width:100%; min-height:76px; grid-template-columns:minmax(130px,auto) 1fr auto; align-items:center; gap:12px; padding:12px 16px; border:0; text-align:left; background:transparent; }
.study-summary-heading > span { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.study-summary-heading > small { color:var(--accent,#176d5b); }
.study-word { display:inline-grid; min-width:52px; min-height:46px; align-content:center; justify-items:center; padding:4px 8px; border-radius:10px; background:#eef7f3; }
.study-word b { font-size:1.25rem; line-height:1.15; }
.study-pinyin { min-height:1.1em; margin-bottom:2px; color:#645f57; font-size:.68rem; line-height:1.1; white-space:nowrap; }
.study-list-actions,.study-share-actions { display:flex; justify-content:flex-end; gap:10px; padding:10px 16px; }
.study-share-actions { padding-inline:0; }
.study-share-status { min-height:1.5em; text-align:center; }
.study-empty { padding:14px; border-radius:14px; background:#fff3cf; }
.study-view-tabs { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin:0 0 18px; padding:5px; border:1px solid var(--line,#d8d2c5); border-radius:14px; background:#f3efe6; }
.study-view-tabs button { min-height:44px; border:0; border-radius:10px; background:transparent; }
.study-view-tabs button[aria-selected="true"] { color:#fff; background:var(--accent,#176d5b); box-shadow:0 3px 10px #1a5e4d24; }
.study-review-adult { width:min(1240px,calc(100% - 28px)); }
.study-metric-grid { display:grid; grid-template-columns:repeat(5,minmax(150px,1fr)); gap:10px; }
.study-metric-card { display:grid; min-height:112px; align-content:center; gap:6px; padding:14px; border:1px solid var(--line,#d8d2c5); border-radius:16px; text-align:left; background:var(--surface,#fffdf8); }
.study-metric-card strong { color:var(--accent,#176d5b); font-size:1.65rem; }
.study-metric-card small { color:var(--muted,#645f57); }
.study-metric-card[aria-expanded="true"] { outline:3px solid #75ad9e66; }
.study-drilldown { margin-top:12px; padding:16px; border:1px solid #75ad9e; border-radius:16px; background:#eef7f3; }
.study-drilldown h2 { margin-top:0; font-size:1.1rem; }
.study-drilldown > div { display:flex; flex-wrap:wrap; gap:8px; }
.study-table-tools { display:flex; align-items:end; gap:12px; margin:20px 0 10px; }
.study-table-tools label { display:grid; gap:5px; font-size:.82rem; }
.study-table-tools label:first-child { flex:1; }
.study-table-tools input,.study-table-tools select { min-height:44px; padding:8px 10px; border:1px solid var(--line,#d8d2c5); border-radius:10px; background:#fff; }
.study-table-wrap { max-width:100%; overflow:auto; border:1px solid var(--line,#d8d2c5); border-radius:16px; background:#fffdf8; -webkit-overflow-scrolling:touch; }
.study-table-wrap table { width:100%; min-width:1050px; border-collapse:collapse; font-variant-numeric:tabular-nums; }
.study-table-wrap th,.study-table-wrap td { padding:10px 12px; border-bottom:1px solid #e7e1d7; text-align:right; white-space:nowrap; }
.study-table-wrap th:first-child,.study-table-wrap td:first-child { position:sticky; left:0; z-index:1; text-align:left; background:#fffdf8; }
.study-table-wrap thead th { position:sticky; top:0; z-index:2; background:#f3efe6; }
.study-table-wrap thead th:first-child { z-index:3; background:#f3efe6; }
.study-table-wrap thead button { min-height:36px; padding:4px 6px; border:0; font:inherit; background:transparent; }
.study-table-wrap tr.is-priority td,.study-table-wrap tr.is-priority th { color:#782b23; background:#ffe0d9; }
.study-table-wrap tr.is-priority th:first-child { box-shadow:inset 5px 0 #c64738; }
.study-word-detail { display:grid; justify-items:start; min-width:92px; padding:4px 7px; border:0; background:transparent; }
.study-word-detail span { font-size:1.15rem; }
.study-word-detail small { color:var(--muted,#645f57); font-size:.7rem; }
.study-no-rows { padding:30px !important; text-align:center !important; }
.study-detail { position:fixed; z-index:20; inset:50% auto auto 50%; width:min(520px,calc(100% - 28px)); max-height:calc(100dvh - 40px); margin:0; padding:24px; overflow:auto; transform:translate(-50%,-50%); border:1px solid var(--line,#d8d2c5); border-radius:18px; background:#fffdf8; box-shadow:0 20px 70px #1d241f55; }
.study-detail::backdrop { background:#151a1766; }
.study-detail-close { position:absolute; top:10px; right:10px; width:40px; height:40px; border-radius:50%; }
.study-detail h2 { margin:0; font-size:2rem; }
.study-detail dl { display:grid; grid-template-columns:minmax(110px,auto) 1fr; gap:8px 14px; }
.study-detail dt { font-weight:700; }
.study-detail dd { margin:0; overflow-wrap:anywhere; }
@media (max-width:600px) {
  .study-review { width:calc(100% - 20px); }
  .study-summary-heading { grid-template-columns:1fr; gap:7px; min-height:unset; }
  .study-summary-heading > small { justify-self:end; }
  .study-word { min-width:46px; min-height:42px; padding:3px 6px; }
  .study-word b { font-size:1.1rem; }
  .study-review-adult { width:calc(100% - 18px); }
  .study-metric-grid { grid-template-columns:1fr 1fr; }
  .study-metric-card { min-height:94px; }
  .study-metric-card:last-child { grid-column:1/-1; }
  .study-table-tools { align-items:stretch; flex-direction:column; }
  .study-table-tools label { width:100%; }
}
@media (min-width:601px) and (max-width:1000px) { .study-metric-grid { grid-template-columns:repeat(3,1fr); } }

.account-gate { width: min(460px, calc(100% - 32px)); max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom))); margin: max(16px, env(safe-area-inset-top)) auto max(16px, env(safe-area-inset-bottom)); padding: clamp(20px, 4vw, 28px); overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line, #d5cbbb); border-radius: 22px; background: var(--panel, #fffdf7); box-shadow: 0 18px 48px #352f2420; -webkit-overflow-scrolling: touch; }
.account-gate form, .account-gate label { display: grid; gap: 10px; }
.account-gate form { gap: 18px; margin: 20px 0; }
.account-gate input, .account-gate button { min-height: 48px; padding: 10px 14px; border-radius: 12px; }
.account-gate button, .account-gate button > span { color: #17201d; -webkit-text-fill-color: #17201d; }
.account-gate .account-submit { width: 100%; color: #17201d; background: #fff; -webkit-appearance: none; appearance: none; -webkit-text-fill-color: #17201d; }
.account-gate .account-submit > span { display: inline; color: inherit; -webkit-text-fill-color: inherit; }
.account-gate .account-show-passwords { justify-self: start; min-height: 40px; padding: 6px 10px; border: 0; color: #6d2b18; background: transparent; }
.account-gate > button { width: 100%; margin-top: 10px; }
.account-gate .account-switch { background: transparent; border: 1px solid var(--line, #d5cbbb); }
.account-message:empty { display: none; }
.account-gate .student-list { display: grid; gap: 10px; margin: 18px 0; }
.account-note { color: var(--muted, #6a6256); font-size: .9rem; }
@media (max-height: 700px), (max-width: 520px) {
  .account-gate { width: min(460px, calc(100% - 16px)); max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))); margin-top: max(8px, env(safe-area-inset-top)); margin-bottom: max(8px, env(safe-area-inset-bottom)); padding: 16px; }
  .account-gate h1 { font-size: clamp(1.65rem, 7vw, 2.25rem); }
  .account-gate form { gap: 8px; margin-block: 10px; }
  .account-gate label { gap: 4px; }
  .account-gate input, .account-gate button { min-height: 44px; padding-block: 8px; }
  .account-gate .account-note { margin-block: 4px; }
}

/* App viewport and compact responsive layout -------------------------------- */
html,
body,
#app { width: 100%; min-height: 100%; overflow-x: hidden; }
body { min-height: 100dvh; }
.active-test-viewport {
  height: 100%;
  overflow: hidden !important;
  overscroll-behavior: none;
}
body.active-test-viewport {
  position: fixed;
  inset: 0;
  width: 100%;
}
body.active-test-viewport #app {
  width: 100%;
  height: var(--active-viewport-height, 100dvh);
  overflow: hidden;
}
.app-shell {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  overflow: visible;
}
.app-shell > header { flex: 0 0 auto; }
.menu .module-grid { display: grid; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: hidden; }
.menu .module-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
.practice { height: 100dvh; min-height: 0; overflow: hidden; }
.active-test-viewport .practice {
  position: fixed;
  top: var(--active-viewport-top, 0px);
  left: 50%;
  height: var(--active-viewport-height, 100dvh);
  max-height: var(--active-viewport-height, 100dvh);
  margin: 0;
  transform: translateX(-50%);
  overscroll-behavior: none;
}
.guided-square { width: min(100%, calc(100dvh - 250px), 560px); }

@media (max-width: 600px), (max-height: 760px) {
  .app-shell,
  .pinyin-practice,
  .renzi-practice {
    width: calc(100% - max(12px, env(safe-area-inset-left) + env(safe-area-inset-right) + 8px));
    padding-top: max(44px, env(safe-area-inset-top));
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  .hero,
  .ting-xie > header,
  .app-shell > header { margin-bottom: 6px; }
  .app-shell > header > p:last-child { display: none; }
  h1 { margin: 1px 0 3px; font-size: clamp(1.55rem, 7vw, 2.25rem); line-height: 1; }
  p { margin-block: 5px; line-height: 1.25; }
  .text-button { min-height: 34px; padding-block: 2px; }
  select,
  button,
  input[type="number"] { min-height: 38px; padding: 6px 9px; border-radius: 9px; }
  .setup-card { border-radius: 14px; }
  .setup-section { gap: 5px; padding: 7px; }
  .setup-section legend { margin-bottom: 2px; font-size: .78rem; }
  .selection-toolbar { align-items: center; flex-direction: row; gap: 4px; }
  .selection-summary { font-size: .72rem; }
  .toolbar-actions { flex-wrap: nowrap; gap: 3px; }
  .small-button { min-height: 32px; padding: 3px 6px; font-size: .72rem; }
  .unit-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .unit-option { min-height: 38px; gap: 4px; padding: 4px; border-radius: 8px; font-size: .76rem; }
  .unit-option input,
  .choice-row input { width: 17px; height: 17px; }
  .unit-option small,
  .choice-row small,
  .inline-setting small,
  .field-note,
  .range-setting small { display: none; }
  .choice-row { min-height: 38px; gap: 5px; padding: 5px; border-radius: 8px; font-size: .76rem; }
  .inline-setting,
  .range-setting { gap: 3px 6px; margin: 0; padding: 5px; border-radius: 8px; font-size: .78rem; }
  .range-setting input { min-height: 30px; }
  .voice-unavailable { display: none; }
  .setup-section label[for="voice"],
  .setup-section #voice { display: none; }
  .preview-row { align-items: center; flex-direction: row; gap: 5px; }
  .preview-status { font-size: .72rem; }
  .start-button { min-height: 40px; margin: 6px; font-size: .9rem; }
  .module-grid { gap: 6px; }
  .module-card { gap: 2px; padding: 10px; border-radius: 12px; }
  .module-card strong { font-size: 1rem; }
  .module-card span { font-size: .76rem; line-height: 1.2; }
  .practice > .text-button { margin-bottom: 2px; }
  .audio-prompt,
  .pinyin-prompt { padding: 7px; border-radius: 12px; }
  .item-count { margin: 3px 0; font-size: .9rem; }
  .speaker { width: 48px; height: 48px; margin: 4px auto; font-size: 1.6rem; }
  .status { min-height: 18px; margin: 2px; font-size: .78rem; }
  .replay { min-width: 150px; min-height: 38px; font-size: .85rem; }
  .practice-actions { padding: 4px 0 max(4px, env(safe-area-inset-bottom)); }
  .practice-voice { grid-template-columns: auto minmax(0, 1fr); gap: 5px; margin-bottom: 3px; padding: 4px 6px; border-radius: 10px; font-size: .76rem; }
  .practice-volume { grid-template-columns: auto minmax(80px, 1fr) 38px; gap: 4px; padding: 3px 5px; border-radius: 10px; }
  .practice-volume input[type="range"] { min-height: 30px; }
  .mute-button { min-width: 38px; min-height: 36px; }
  .practice-nav { gap: 6px; margin-top: 4px; }
  .practice-nav button { min-height: 44px; padding: 5px 8px; border-radius: 11px; font-size: .86rem; }
  .practice-nav button span[aria-hidden="true"] { width: 24px; height: 24px; font-size: 1rem; }
  .handwriting-recognition { margin-top: 5px; padding: 5px; border-radius: 10px; }
  .handwriting-canvas-wrap { border-radius: 8px; }
  .handwriting-canvas { height: min(28dvh, 240px); }
  .ting-xie .handwriting-canvas { height: 100%; }
  .handwriting-actions { gap: 5px; margin-top: 5px; }
  .handwriting-result { min-height: 1em; margin-top: 4px; font-size: .76rem; }
  .pinyin-prompt { gap: 5px; }
  .pinyin-character,
  .pinyin-characters { font-size: clamp(2.2rem, 10vw, 4rem); }
  .pinyin-answers,
  .pinyin-answer { margin: 4px 0; }
  .pinyin-answer-slot { min-height: 42px; padding: 4px 8px; }
  .pinyin-keyboard { gap: 4px; padding: 5px; }
  .pinyin-key-row,
  .pinyin-tone-row { gap: 3px; }
  .pinyin-key { min-height: 38px; padding: 3px; font-size: .85rem; }
  .pinyin-feedback { min-height: 38px; margin-top: 4px; padding: 6px; }
  .pinyin-actions,
  .pinyin-nav { gap: 5px; padding: 5px 0 max(4px, env(safe-area-inset-bottom)); }
  .pinyin-actions button,
  .pinyin-nav button,
  .renzi-choices button { min-height: 42px; padding: 5px 8px; border-radius: 10px; font-size: .85rem; }
  .renzi-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  .assembly-header,
  .guided-header { margin-bottom: 2px; font-size: .78rem; }
  .guided-target-character { font-size: clamp(2rem, 7vh, 3.25rem); }
  .guided-square { width: min(100%, calc(100dvh - 190px)); margin: 4px auto; border-radius: 12px; }
  .guided-feedback,
  .assembly-feedback { min-height: 36px; margin-top: 4px; padding: 6px; font-size: .78rem; }
  .guided-feedback { height: 36px; }
  .guided-loading,
  .assembly-loading { display: grid; min-height: 0; flex: 1 1 auto; padding: 8px; place-items: center; }
  .loading-progress { gap: 8px; padding: 14px; border-radius: 14px; }
  .loading-progress progress { height: 14px; }
  .guided-actions,
  .assembly-actions { gap: 5px; margin-top: 4px; }
  .assembly-workspace { grid-template-columns: 1fr; gap: 5px; min-height: 0; }
  .assembly-target { width: min(100%, 38dvh); border-radius: 12px; }
  .stroke-box { max-height: 25dvh; padding: 5px; overflow: auto; border-radius: 10px; }
  .stroke-box h2 { margin-bottom: 4px; font-size: .78rem; }
  .stroke-pieces { grid-template-columns: repeat(5, minmax(42px, 1fr)); gap: 3px; }
  .stroke-piece { min-height: 42px; border-radius: 7px; }
  .component-box { max-height: 31dvh; }
  .component-box .stroke-pieces { grid-template-columns: repeat(2, minmax(76px, 1fr)); gap: 6px; }
  .component-piece { min-height: 76px; }

  /* Setup/test-condition screens remain full, readable, and scroll normally. */
  .app-shell:has(.setup-card) {
    width: min(760px, calc(100% - max(32px, env(safe-area-inset-left) + env(safe-area-inset-right) + 24px)));
    min-height: 100dvh;
    padding-top: 32px;
    padding-bottom: 56px;
    overflow: visible;
  }
  .app-shell:has(.setup-card) > header { margin-bottom: 32px; }
  .app-shell:has(.setup-card) > header > p:last-child { display: block; }
  .app-shell:has(.setup-card) h1 { margin: 4px 0 8px; font-size: clamp(2.3rem, 8vw, 4.5rem); line-height: .95; }
  .app-shell:has(.setup-card) p { margin-block: 1em; line-height: 1.55; }
  .app-shell:has(.setup-card) .setup-card { display: grid; grid-template-columns: 1fr; overflow: hidden; border-radius: 22px; }
  .app-shell:has(.setup-card) select,
  .app-shell:has(.setup-card) button,
  .app-shell:has(.setup-card) input[type="number"] { min-height: 52px; padding: 11px 15px; border-radius: 12px; }
  .app-shell:has(.setup-card) .setup-section { gap: 16px; padding: 22px 18px; }
  .app-shell:has(.setup-card) .setup-section legend { margin-bottom: 12px; font-size: 1.05rem; }
  .app-shell:has(.setup-card) .selection-toolbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .app-shell:has(.setup-card) .selection-summary { font-size: .9rem; }
  .app-shell:has(.setup-card) .toolbar-actions { flex-wrap: wrap; gap: 8px; }
  .app-shell:has(.setup-card) .small-button { min-height: 48px; padding: 9px 13px; font-size: .9rem; }
  .app-shell:has(.setup-card) .unit-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .app-shell:has(.setup-card) .unit-option { min-height: 64px; gap: 11px; padding: 14px; border-radius: 14px; font-size: inherit; }
  .app-shell:has(.setup-card) .unit-option input,
  .app-shell:has(.setup-card) .choice-row input { width: 24px; height: 24px; }
  .app-shell:has(.setup-card) .unit-option small,
  .app-shell:has(.setup-card) .choice-row small,
  .app-shell:has(.setup-card) .inline-setting small,
  .app-shell:has(.setup-card) .field-note,
  .app-shell:has(.setup-card) .range-setting small { display: initial; }
  .app-shell:has(.setup-card) .choice-row { min-height: 68px; gap: 11px; padding: 15px; border-radius: 14px; font-size: inherit; }
  .app-shell:has(.setup-card) .inline-setting,
  .app-shell:has(.setup-card) .range-setting { gap: 4px 14px; padding: 14px; border-radius: 14px; font-size: inherit; }
  .app-shell:has(.setup-card) .voice-unavailable,
  .app-shell:has(.setup-card) .setup-section label[for="voice"],
.app-shell:has(.setup-card) .setup-section #voice { display: initial; }
  .app-shell:has(.setup-card) .preview-row { align-items: stretch; flex-direction: column; gap: 14px; }
  .app-shell:has(.setup-card) .preview-status { font-size: .9rem; }
  .app-shell:has(.setup-card) .start-button { min-height: 62px; margin: 22px 18px; font-size: 1.08rem; }
}

/* The launcher is a scrollable gallery, not a fixed practice viewport. */
.menu {
  width: min(680px, calc(100% - max(24px, env(safe-area-inset-left) + env(safe-area-inset-right) + 16px)));
  height: auto;
  min-height: 100dvh;
  padding-top: max(56px, env(safe-area-inset-top));
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  overflow: visible;
}
.menu .module-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  overflow: visible;
}
.menu .module-card,
.menu .module-card:last-child:nth-child(odd) {
  grid-column: auto;
  aspect-ratio: 1;
  align-content: center;
  gap: 10px;
  padding: clamp(16px, 4vw, 28px);
  border-radius: 22px;
}
.menu .module-card strong { font-size: clamp(1.15rem, 4vw, 1.5rem); }
.menu .module-card span { font-size: clamp(.82rem, 2.7vw, 1rem); line-height: 1.4; }

@media (max-width: 600px), (max-height: 760px) {
  .menu { padding-top: max(52px, env(safe-area-inset-top)); }
  .menu > header { margin-bottom: 20px; }
  .menu > header > p:last-child { display: block; }
  .menu .module-grid { gap: 10px; }
  .menu .module-card { border-radius: 18px; }
}

@media (max-width: 600px) {
  .ting-xie .practice-audio-toolbar { gap: 7px; }
  .ting-xie .audio-toolbar-button { min-height: 44px; padding: 6px 10px; font-size: .8rem; }
  .ting-xie .practice-audio-popover {
    position: fixed;
    z-index: 30;
    top: auto;
    right: max(62px, calc(env(safe-area-inset-right) + 62px));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    max-width: none;
    max-height: min(70dvh, 440px);
    overflow: auto;
    border-radius: 18px;
  }
  .ting-xie .practice-audio-control:first-child .practice-audio-popover { right: max(62px, calc(env(safe-area-inset-right) + 62px)); left: 10px; }
  .ting-xie .practice-audio-popover .practice-volume { grid-template-columns: auto minmax(0, 1fr) 42px; gap: 7px; padding: 0; }
}
