:root {
  /* a warm, light palette: morning light in Chiang Mai, gold and teal */
  --bg: #f4f7fc;
  --surface: #ffffff;
  --surface-2: #eaf0f9;
  --line: #dde5f0;
  --text: #22262b;
  --muted: #6b6f75;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --accent-2: #0e7490;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --good: #15803d;
  --bad: #b91c1c;
  --teacher: #ffffff;
  --learner: #dbeafe;
  --shadow: 0 1px 2px rgb(20 40 90 / 0.05), 0 10px 30px rgb(20 40 90 / 0.08);
  /* tones, tuned to the warm palette: still five clearly different hues, each with its contour icon */
  --tone-mid: #5f6670;
  --tone-low: #2457c5;
  --tone-falling: #c0392b;
  --tone-high: #0f8a5f;
  --tone-rising: #8b3fd1;
  --radius: 18px;
  --thai: "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Thonburi", sans-serif;
  --ui: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}

/* Dark only when chosen in Settings: the default is light, whatever the device says */
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1e2125; --surface-2: #262a2f; --line: #343941; --text: #ecebe7; --muted: #9aa0a8;
  --accent: #60a5fa; --accent-ink: #061a3a; --accent-soft: #1a2e4f; --accent-2: #22d3ee; --warn: #f59e0b; --warn-soft: #3a2a10;
  --good: #4ade80; --bad: #f87171; --teacher: #1e2125; --learner: #1a2e4f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  --tone-mid: #aab3bd; --tone-low: #6ea8ff; --tone-falling: #ff7a7a; --tone-high: #4fd69c; --tone-rising: #c29bff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--ui); -webkit-text-size-adjust: 100%; position: relative; }
/* soft moving colour behind everything: gold, teal, rose */
body::before { content: ""; position: fixed; inset: -20%; z-index: -1; pointer-events: none;
  background: radial-gradient(40% 35% at 15% 10%, rgb(96 165 250 / 0.22), transparent 70%),
              radial-gradient(35% 35% at 85% 20%, rgb(34 211 238 / 0.18), transparent 70%),
              radial-gradient(45% 40% at 50% 95%, rgb(129 140 248 / 0.16), transparent 70%);
  animation: drift 24s ease-in-out infinite alternate; }
:root[data-theme="dark"] body::before { opacity: 0.5; }
@keyframes drift { from { transform: translate3d(0, 0, 0) scale(1); } to { transform: translate3d(3%, -3%, 0) scale(1.06); } }
h2 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; font-size: 28px; margin: 0; }
.brand { font-family: var(--display); }
.card, .unit-card, .start, .plan-item, .option, .stat, .msg .bubble { animation: rise 0.45s cubic-bezier(.2,.7,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card { transition: transform 0.2s, box-shadow 0.2s; }
.unit-card, .start, .plan-item { transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s; }
.unit-card:hover, .start:hover, .plan-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #3b82f6); box-shadow: 0 6px 18px rgb(29 78 216 / 0.25); transition: transform 0.15s, box-shadow 0.2s; }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgb(29 78 216 / 0.3); }
.level-tag { background: linear-gradient(135deg, var(--accent-2), #06b6d4); }
.ring-fill { stroke: url(#ringGrad); }
.top { backdrop-filter: blur(10px); background: color-mix(in srgb, var(--surface) 80%, transparent); position: relative; }
.top::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.55;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='36' viewBox='0 0 72 36'%3E%3Cg fill='none' stroke='%231d4ed8' stroke-opacity='0.16' stroke-width='1.2'%3E%3Cpath d='M0 30c10-14 18-14 24 0 6-14 14-14 24 0 6-14 14-14 24 0'/%3E%3Cpath d='M12 18c3-7 8-7 10 0M48 18c3-7 8-7 10 0'/%3E%3Ccircle cx='36' cy='8' r='2'/%3E%3C/g%3E%3C/svg%3E");
  mask-image: linear-gradient(to bottom, black, transparent); }
:root[data-theme="dark"] .top::after { opacity: 0.35; }
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } .card, .unit-card, .start, .plan-item, .option, .stat, .msg .bubble { animation: none; } }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app { display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; max-width: 1100px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font: 600 13px var(--thai); }
.top h1 { flex: 1; margin: 0; font-size: 15px; font-weight: 500; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.tabs { display: flex; justify-content: space-around; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); order: 3; }
.tab { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 500; }
.tab[aria-current="page"] { color: var(--accent); }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; line-height: 18px; }

#screen { overflow-y: auto; padding: 4px 16px 24px; outline: none; }
#screen.flush { padding: 0; overflow: hidden; }

@media (min-width: 900px) {
  #app { grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; }
  .tabs { order: 0; flex-direction: column; justify-content: flex-start; gap: 4px; border: 0; background: transparent; padding: 8px; }
  .tab { flex: 0; flex-direction: row; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
  .tab[aria-current="page"] { background: var(--accent-soft); }
  .badge { position: static; margin-left: auto; }
  #screen { padding: 4px 24px 32px; }
  #screen.flush { padding: 0; }
}

/* building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 12px; }
.stack > * { min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h2 { font-size: 20px; margin: 8px 0 4px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.error { color: var(--bad); }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.field input, label.field select { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 15px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Thai text: each written syllable is coloured by its tone */
.th { font-family: var(--thai); }
.thai-line { font-family: var(--thai); font-size: 26px; line-height: 1.6; }
.thai-line.big { font-size: 38px; }
.thai-line.mid { font-size: 22px; }
.w { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.w:hover { background: var(--surface-2); }
.notone .w .s { color: inherit !important; }
.s.mid { color: var(--tone-mid); } .s.low { color: var(--tone-low); } .s.falling { color: var(--tone-falling); }
.s.high { color: var(--tone-high); } .s.rising { color: var(--tone-rising); }
.roman { color: var(--muted); font-size: 15px; letter-spacing: 0.01em; }
.english { font-size: 16px; }
.reveal { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; }
.note { font-size: 13px; color: var(--muted); }
.tone-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.tone-icon { width: 28px; height: 18px; stroke-width: 2.2; }
.t-mid { color: var(--tone-mid); } .t-low { color: var(--tone-low); } .t-falling { color: var(--tone-falling); }
.t-high { color: var(--tone-high); } .t-rising { color: var(--tone-rising); }

/* talk */
.talk { display: grid; grid-template-rows: auto 1fr auto; height: 100%; min-height: 0; }
.talk .messages { min-height: 0; }
.talk-head { display: flex; align-items: center; gap: 8px; padding: 6px 16px 8px; border-bottom: 1px solid var(--line); }
.talk-head .title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { max-width: 640px; }
.msg.teacher { align-self: flex-start; width: min(100%, 640px); }
.msg.learner { align-self: flex-end; background: var(--learner); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: 10px 14px; }
.bubble { background: var(--teacher); border: 1px solid var(--line); border-radius: 4px var(--radius) var(--radius) var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 6px; }
.who { font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; }
.play-row { display: flex; gap: 6px; align-items: center; }
.play { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--accent); }
.play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.play.slow svg { fill: none; stroke: currentColor; }
.play.playing { background: var(--accent); color: var(--accent-ink); }
.explain { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.feedback { border-radius: 10px; padding: 8px 10px; display: grid; gap: 4px; font-size: 15px; background: var(--surface-2); border-left: 4px solid var(--muted); }
.feedback .verdict { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.feedback.v-good { border-color: var(--good); } .feedback.v-good .verdict { color: var(--good); }
.feedback.v-almost { border-color: var(--warn); } .feedback.v-almost .verdict { color: var(--warn); }
.feedback.v-wrong { border-color: var(--bad); } .feedback.v-wrong .verdict { color: var(--bad); }
.feedback.v-english { border-color: var(--accent); } .feedback.v-english .verdict { color: var(--accent); }
.feedback .play, .explain .play { width: 28px; height: 28px; flex: none; }
.task { border: 1px dashed var(--accent); border-radius: 10px; padding: 8px 10px; background: var(--accent-soft); }
.task .label { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.hints { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.hint { display: grid; gap: 0; text-align: left; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.hint b { font-size: 14px; }
.hint .roman { font-size: 13px; }
.lesson-done { border-radius: 10px; padding: 10px; background: color-mix(in srgb, var(--good) 14%, var(--surface)); display: grid; gap: 8px; }
.teach { padding: 8px 0 4px; border-bottom: 1px solid var(--line); }
.teach:last-child { border-bottom: 0; }
.teach h4 { margin: 4px 0; font-size: 15px; }
.bar.stacked { display: flex; }
.bar.stacked > i.good { background: var(--good); } .bar.stacked > i.almost { background: var(--warn); } .bar.stacked > i.wrong { background: var(--bad); }
.correction { border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 10px 10px 0; padding: 8px 10px; display: grid; gap: 4px; }
.correction .label { font-size: 12px; font-weight: 600; color: var(--warn); text-transform: uppercase; letter-spacing: 0.04em; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest button { display: grid; text-align: left; gap: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); max-width: 100%; }
.suggest button .th { font-size: 16px; }
.suggest button .small { color: var(--muted); }
.words { display: flex; flex-wrap: wrap; gap: 6px; }
.typing { display: inline-flex; gap: 4px; padding: 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.dock { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.dock-row { display: flex; align-items: flex-end; gap: 8px; }
.dock textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font: 16px/1.4 var(--thai); }
.mic { position: relative; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); flex: none; }
.mic svg { width: 24px; height: 24px; }
.mic.listening { background: var(--bad); color: #fff; }
.mic.listening::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { from { transform: scale(0.9); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
.send { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--accent); flex: none; }
.dock-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.heard { font-family: var(--thai); color: var(--muted); font-size: 14px; }

.starts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.start { text-align: left; display: grid; gap: 4px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.start:hover { border-color: var(--accent); }
.start strong { font-size: 16px; }
.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; width: 100%; }

/* lessons */
.units { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.unit-card { text-align: left; display: grid; gap: 4px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.unit-card:hover { border-color: var(--accent); }
.unit-num { font-size: 12px; color: var(--muted); font-weight: 600; }
.done { color: var(--good); font-size: 13px; font-weight: 600; }
.phrase { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.phrase:last-child { border-bottom: 0; }
.phrase .actions { display: flex; gap: 6px; align-items: flex-start; }
.word-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.word { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: grid; gap: 2px; }

/* quiz, review, tones */
.big-card { text-align: center; display: grid; gap: 12px; justify-items: center; padding: 24px 16px; }
.options { display: grid; gap: 8px; width: 100%; max-width: 480px; }
.option { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; }
.option.off { opacity: 0.75; }
.option.row { gap: 10px; }
.option.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--surface)); }
.option.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; max-width: 480px; }
.grades .btn { flex-direction: column; gap: 0; font-size: 14px; }
.grades .btn small { font-size: 11px; color: var(--muted); font-weight: 400; }
.tone-cards { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tone-card { display: grid; gap: 4px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.tone-card .name { font-weight: 600; display: flex; align-items: center; gap: 6px; text-transform: capitalize; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.progress-strip { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; width: 100%; max-width: 480px; }
.progress-strip > i { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

/* today */
.today-head { display: flex; align-items: center; gap: 16px; }
.ring-box { position: relative; width: 112px; height: 112px; flex: none; }
.ring { width: 112px; height: 112px; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 12; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray 0.6s; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring-label b { font-size: 28px; }
.ring-label span { font-size: 12px; color: var(--muted); }
.streak { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.plan { display: grid; gap: 6px; }
.plan-item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; width: 100%; }
.plan-item:hover { border-color: var(--accent); }
.plan-item .spacer { display: grid; gap: 2px; }
.plan-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
.plan-item.done { opacity: 0.7; }
.plan-item.done .plan-icon { background: var(--good); color: #fff; }
.plan-item.done b { text-decoration: line-through; text-decoration-thickness: 1px; }
.level { display: grid; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.level:last-child { border-bottom: 0; }
.level-tag { display: inline-grid; place-items: center; min-width: 34px; height: 24px; padding: 0 6px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.level-head { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.path { display: flex; flex-wrap: wrap; gap: 8px; }
.stop { position: relative; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; font-size: 13px; }
.stop.taught { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stop.next { border-color: var(--accent); color: var(--accent); animation: glow 1.8s infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 40%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }
.badge-dot { position: absolute; right: -2px; top: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--warn); border: 2px solid var(--surface); }
.memory { padding: 4px 0; border-bottom: 1px solid var(--line); }
.burst { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.burst i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall 2s ease-in forwards, spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .burst { display: none; } .stop.next { animation: none; } }

/* hearing your tones */
.rec { min-height: 52px; min-width: 200px; border-radius: 26px; font-size: 16px; }
.rec.listening { background: var(--bad); border-color: var(--bad); color: #fff; }
.meter { width: 200px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.08s; }
.tone-check { justify-items: stretch; }
.tone-score { text-align: center; font-weight: 700; font-size: 18px; color: var(--warn); }
.tone-score.all { color: var(--good); }
.tone-row { display: block; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); }
.tone-row.ok b { color: var(--good); } .tone-row.bad b { color: var(--bad); }
.chart-box { display: grid; gap: 4px; }
.pitch-chart { width: 100%; height: auto; max-height: 220px; background: var(--surface-2); border-radius: 10px; }
.pitch-chart polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.pitch-chart .model { stroke: var(--muted); stroke-width: 2; stroke-dasharray: 5 4; }
.pitch-chart .you { stroke-width: 3.5; }
.pitch-chart .you.ok { stroke: var(--good); } .pitch-chart .you.bad { stroke: var(--bad); }
.pitch-chart .zero { stroke: var(--line); stroke-width: 1.5; }
.pitch-chart .divider { stroke: var(--line); stroke-width: 1; }
.pitch-chart text { font-size: 12px; fill: var(--muted); stroke: none; }
.pitch-chart text.ok { fill: var(--good); font-weight: 700; } .pitch-chart text.bad { fill: var(--bad); font-weight: 700; }
.pitch-chart text.th { font-family: var(--thai); font-size: 14px; fill: var(--text); }
.key { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--good); margin-left: 8px; }
.key.model { border-top: 2px dashed var(--muted); } .key.zero { border-top: 1.5px solid var(--line); }
.big-card .name { display: flex; align-items: center; gap: 6px; font-size: 14px; }

/* progress */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.chart svg { width: 100%; height: 150px; }
.chart text { font-size: 10px; fill: var(--muted); stroke: none; }
.report { display: grid; gap: 8px; }
.report ul { margin: 0; padding-left: 20px; }

/* sheet (word details, settings) */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 85dvh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgb(0 0 0 / 0.2); }
@media (min-width: 700px) { .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 460px; border-radius: 18px; } }
.sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet > :nth-child(2) { padding-right: 40px; }
.syllables { display: flex; flex-wrap: wrap; gap: 8px; }
.syl { display: grid; justify-items: center; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); min-width: 64px; }
.syl .th { font-size: 22px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 20; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); font-size: 14px; box-shadow: var(--shadow); }

/* the reading course */
.reading-row { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; color: inherit; font: inherit; cursor: pointer; }
.reading-row:hover b { color: var(--accent); }
.script-card { border-color: var(--accent); }
.unit-card.next-card { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.letters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.letter { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.letter:last-child { border-bottom: 0; }
.glyph { font-size: 40px; line-height: 1; min-width: 48px; text-align: center; }
.glyph.big { font-size: 64px; line-height: 1.2; }
.class-tag { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.class-tag.mid { color: var(--tone-mid); } .class-tag.high { color: var(--tone-rising); } .class-tag.low { color: var(--tone-low); }
.options.tones { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.options.tones .option { text-align: center; font-weight: 600; }

/* text size: the whole page scales, like browser zoom, so nothing is laid out twice */
:root[data-text="large"] body { zoom: 1.12; }
:root[data-text="larger"] body { zoom: 1.25; }
.glyph.muted { opacity: 0.5; }

/* Thai-only mode */
.start.flow { border-color: var(--accent); }
.bubble.debrief { display: grid; gap: 6px; }
.bubble.debrief ul { margin: 0; padding-left: 18px; }
.bubble.debrief .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-top: 6px; }
.bubble.debrief .words { display: grid; gap: 4px; }

/* version 2: missions and listening */
.mission { display: grid; gap: 8px; border-color: var(--accent); }
.mission textarea { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }

/* the single session */
.session-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--line); }

.level-meter { margin-top: 8px; display: grid; gap: 6px; }
.level-head-btn { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; color: inherit; font: inherit; cursor: pointer; }
.today-line { padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); display: grid; gap: 2px; }
.phrase.him { border-left: 3px solid var(--tone-low); padding-left: 10px; }

/* ---- final polish pass: hero, glass, stagger, tabs, bubbles ---- */
.today-head { padding: 18px; border-radius: 24px; color: #fff;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 45%, #06b6d4 100%); box-shadow: 0 14px 40px rgb(29 78 216 / 0.28); position: relative; overflow: hidden; }
.today-head::after { content: "ก ข ค ง จ ฉ ช"; position: absolute; right: -8px; bottom: -22px; font: 600 84px/1 var(--thai); color: rgb(255 255 255 / 0.10); letter-spacing: 0.1em; pointer-events: none; }
.today-head .muted, .today-head .small, .today-head .streak, .today-head h2 { color: #fff; }
.today-head .level-tag { background: rgb(255 255 255 / 0.22); color: #fff; }
.today-head .bar { background: rgb(255 255 255 / 0.25); } .today-head .bar > i { background: #fff; }
.today-head .ring-track { stroke: rgb(255 255 255 / 0.25); } .today-head .ring-fill { stroke: #fff; }
.today-head .ring-label { color: #fff; } .today-head .ring-label span { color: rgb(255 255 255 / 0.85); }
.today-head .btn.small.primary { background: #fff; color: var(--accent); box-shadow: none; }
.card, .unit-card, .start, .stat { background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px); }
.stack > *:nth-child(2) { animation-delay: 0.05s; } .stack > *:nth-child(3) { animation-delay: 0.1s; }
.stack > *:nth-child(4) { animation-delay: 0.15s; } .stack > *:nth-child(5) { animation-delay: 0.2s; } .stack > *:nth-child(n+6) { animation-delay: 0.25s; }
.units > *:nth-child(even), .starts > *:nth-child(even) { animation-delay: 0.08s; }
.btn { border-radius: 12px; transition: transform 0.15s, box-shadow 0.2s, background 0.2s; }
.btn:active { transform: scale(0.97); }
.tabs { background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(12px); }
.tab { transition: color 0.2s, transform 0.2s; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] svg { transform: translateY(-2px) scale(1.1); transition: transform 0.25s cubic-bezier(.2,.7,.2,1); }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 50%; width: 28px; height: 3px; transform: translateX(-50%); border-radius: 0 0 3px 3px; background: var(--accent); }
.msg.learner { background: linear-gradient(135deg, var(--learner), color-mix(in srgb, var(--learner) 70%, #fff)); box-shadow: 0 2px 10px rgb(29 78 216 / 0.1); }
.msg.teacher .bubble { border-radius: 4px var(--radius) var(--radius) var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.thai-line .s { transition: transform 0.12s; display: inline-block; }
.thai-line .s:hover { transform: translateY(-2px); }
.stat b { font-family: var(--display); font-weight: 600; background: linear-gradient(135deg, var(--accent), #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.plan-icon { background: linear-gradient(135deg, var(--accent-soft), #fff); }
.plan-item.done .plan-icon { background: linear-gradient(135deg, var(--good), #4ade80); }
.option { border-radius: 14px; transition: transform 0.12s, border-color 0.2s, background 0.2s; }
.option:not(.off):hover { transform: translateX(3px); border-color: var(--accent); }
.option.right { animation: pop 0.35s cubic-bezier(.2,.7,.2,1); }
@keyframes pop { 50% { transform: scale(1.03); } }
.empty { font-family: var(--display); font-size: 18px; }
.progress-strip > i, .bar > i { background: linear-gradient(90deg, var(--accent), #06b6d4); }
.typing i { background: var(--accent); }
h3 { font-family: var(--display); font-weight: 600; font-size: 17px; }
.unit-num { color: var(--accent); letter-spacing: 0.08em; }
.unit-card strong { font-family: var(--display); font-size: 17px; }
.start strong { font-family: var(--display); font-size: 18px; }
.brand-mark { background: linear-gradient(135deg, var(--accent), #06b6d4); box-shadow: 0 4px 12px rgb(29 78 216 / 0.3); }
:root[data-theme="dark"] .today-head { background: linear-gradient(135deg, #172554, #1d4ed8 60%, #0e7490); }
@media (prefers-reduced-motion: reduce) { .stack > * { animation-delay: 0s !important; } .option.right { animation: none; } }

/* ---- blue pass extras ---- */
::selection { background: var(--accent-soft); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 8px; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
textarea, input, select { transition: border-color 0.2s, box-shadow 0.2s; }
textarea:focus, input:focus, select:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent); outline: none; }
.chip { transition: background 0.2s, border-color 0.2s, transform 0.12s; }
.chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.toast { border-radius: 14px; box-shadow: 0 10px 30px rgb(20 40 90 / 0.25); backdrop-filter: blur(8px); }
.sheet { border-radius: 24px 24px 0 0; box-shadow: 0 -10px 40px rgb(20 40 90 / 0.18); }
.play, .mic, .send { transition: transform 0.12s, box-shadow 0.2s; }
.play:hover, .send:hover { transform: scale(1.06); }
.mic { background: linear-gradient(135deg, var(--accent), #06b6d4); color: #fff; border: 0; box-shadow: 0 6px 16px rgb(29 78 216 / 0.3); }
.mic.listening, .mic[aria-pressed="true"] { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgb(29 78 216 / 0.45); } 50% { box-shadow: 0 0 0 14px rgb(29 78 216 / 0); } }
.dock { background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.feedback { border-radius: 14px; }
.correction, .task { border-radius: 14px; background: var(--surface-2); padding: 10px 12px; }
.task .label, .correction .label, .bubble.debrief .label { color: var(--accent); }
.level-head-btn .level-tag { font-size: 14px; min-width: 44px; height: 30px; border-radius: 10px; }
.today-head h2 { font-size: 30px; }
.streak .flame { filter: drop-shadow(0 2px 6px rgb(0 0 0 / 0.25)); }
.session-bar { background: linear-gradient(90deg, var(--accent-soft), transparent); }
.reading-row .level-tag { font-family: var(--thai); font-size: 15px; }
.stop.taught { background: linear-gradient(135deg, var(--accent), #06b6d4); border-color: transparent; }
.stop.next { box-shadow: 0 0 0 4px var(--accent-soft); }
.hint { border-radius: 12px; transition: transform 0.12s; } .hint:hover { transform: translateY(-2px); }
.letter .glyph { color: var(--accent); }
.phrase .actions .play { border-color: transparent; background: var(--accent-soft); color: var(--accent); }

/* ---- magnificent pass: screen transitions, talk room, review cards, charts, settings ---- */
#screen { animation: screenIn 0.35s cubic-bezier(.2,.7,.2,1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#screen > .stack { max-width: 860px; margin: 0 auto; }
@media (min-width: 900px) { #screen { padding: 12px 24px 32px; } .talk { max-width: 920px; margin: 0 auto; width: 100%; } }
/* talk room: a soft stage behind the conversation */
.messages { background: radial-gradient(60% 40% at 50% 0%, var(--accent-soft), transparent 70%); }
.msg.teacher .who { display: flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; }
.msg.teacher .who::before { content: "ครู"; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; font: 600 9px var(--thai); color: #fff; background: linear-gradient(135deg, var(--accent), #06b6d4); }
.msg.teacher .bubble { padding: 14px 16px; }
.msg.learner { padding: 12px 16px; }
.msg.teacher .thai-line { font-size: 28px; }
.play-row .play { background: var(--accent-soft); color: var(--accent); border: 0; }
.feedback.v-good { background: color-mix(in srgb, var(--good) 10%, var(--surface)); }
.feedback.v-almost { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.feedback.v-wrong { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.suggest button { border-radius: 999px; transition: transform 0.12s, border-color 0.2s, background 0.2s; }
.suggest button:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.dock-row { padding: 10px 14px; }
#say-box { border-radius: 16px; padding: 12px 14px; font-size: 16px; }
.send { background: linear-gradient(135deg, var(--accent), #06b6d4); color: #fff; border: 0; box-shadow: 0 6px 16px rgb(29 78 216 / 0.25); }
.talk-head { background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(10px); }
.talk-head .title { font-family: var(--display); font-size: 17px; }
/* review cards: a real flashcard */
.big-card { border-radius: 24px; padding: 32px 20px; background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--accent-soft) 40%, var(--surface))); position: relative; overflow: hidden; }
.big-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: linear-gradient(90deg, var(--accent), #06b6d4); }
.big-card .thai-line.big { font-size: 44px; }
.grades .btn { border-radius: 14px; min-height: 56px; }
.grades .btn:nth-child(1) { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.grades .btn:nth-child(4) { border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }
.progress-strip { height: 8px; border-radius: 4px; }
/* lesson tiles: numbered, with a left accent */
.unit-card { padding: 16px 16px 16px 18px; position: relative; overflow: hidden; }
.unit-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: linear-gradient(180deg, var(--accent), #06b6d4); opacity: 0.6; }
.unit-card .done { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.level-head { padding: 14px 0 6px; }
.level-head b { font-family: var(--display); font-size: 19px; }
/* course path stops: little coins */
.stop { width: 40px; height: 40px; box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.06); transition: transform 0.15s; }
.stop:hover { transform: translateY(-2px) scale(1.05); }
/* charts and progress */
.pitch-chart { border-radius: 16px; background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line); }
.tone-score { font-family: var(--display); font-size: 22px; }
.stats { gap: 12px; }
.stat { padding: 14px; border-radius: 16px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; right: -20px; bottom: -20px; width: 70px; height: 70px; border-radius: 50%; background: var(--accent-soft); opacity: 0.6; }
.stat b { position: relative; font-size: 30px; }
.bar { height: 10px; border-radius: 5px; }
/* settings sheet */
.sheet { padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet h3 { font-size: 20px; }
.sheet::before { content: ""; display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
label.field select, label.field input { border-radius: 12px; padding: 11px 12px; }
.toggle { padding: 10px 0; border-bottom: 1px solid var(--line); }
.toggle:last-of-type { border-bottom: 0; }
.toggle input { width: 22px; height: 22px; }
/* tone gym & drills */
.options.tones .option { padding: 16px; font-size: 17px; border-width: 2px; }
.option.right { border-width: 2px; } .option.wrong { border-width: 2px; }
.letter { border-radius: 14px; padding: 10px; transition: background 0.2s; }
.letter:hover { background: var(--surface-2); }
.letters { gap: 8px; }
.glyph { font-size: 44px; }
/* empty states and loading */
.empty { padding: 48px 16px; }
.typing { gap: 5px; } .typing i { width: 8px; height: 8px; }
/* header */
.top { padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 12px; }
.brand { font-size: 17px; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; }
.top h1 { font-family: var(--display); font-weight: 600; color: var(--text); font-size: 17px; }
.icon-btn { transition: transform 0.15s, background 0.2s; border-radius: 10px; }
.icon-btn:hover { background: var(--accent-soft); transform: rotate(15deg); }
/* mission & call cards */
.mission { background: linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 60%, var(--surface)), var(--surface)); }
.today-line { background: color-mix(in srgb, var(--surface) 70%, transparent); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
/* debrief */
.debrief-msg .bubble { border-top: 4px solid var(--accent); }
@media (prefers-reduced-motion: reduce) { #screen { animation: none; } }

/* ---- daily pass: the sky changes with the time of day; the flame breathes; the ring draws itself ---- */
.today-head.sky-dawn { background: linear-gradient(135deg, #312e81 0%, #2563eb 45%, #f472b6 100%); }
.today-head.sky-day { background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 45%, #06b6d4 100%); }
.today-head.sky-dusk { background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 45%, #f59e0b 100%); }
.today-head.sky-night { background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #0e7490 100%); }
.today-head::before { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(2px 2px at 20% 30%, rgb(255 255 255 / 0.6), transparent), radial-gradient(2px 2px at 70% 20%, rgb(255 255 255 / 0.5), transparent),
              radial-gradient(1.5px 1.5px at 85% 60%, rgb(255 255 255 / 0.5), transparent), radial-gradient(2px 2px at 40% 75%, rgb(255 255 255 / 0.4), transparent);
  opacity: 0; transition: opacity 1s; }
.today-head.sky-night::before, .today-head.sky-dusk::before { opacity: 1; animation: twinkle 3s ease-in-out infinite alternate; }
@keyframes twinkle { to { opacity: 0.4; } }
.flame { display: inline-block; animation: breathe 1.6s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15) rotate(-3deg); } }
.ring-fill { animation: draw 1.2s cubic-bezier(.2,.7,.2,1); }
@keyframes draw { from { stroke-dasharray: 0 999; } }
.today-head .spacer h2 { text-shadow: 0 2px 12px rgb(0 0 0 / 0.2); }
.plan-item { border-radius: 16px; padding: 12px; }
.plan-item b { font-size: 15px; }
.plan-item:not(.done):first-child { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--surface)); }
@media (prefers-reduced-motion: reduce) { .flame, .ring-fill, .today-head::before { animation: none; } }

/* ---- fifth pass: skeleton loading, word of the day, little moments ---- */
.skeleton .sk { border-radius: 16px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.skeleton .hero { height: 150px; border-radius: 24px; } .skeleton .line { height: 18px; } .skeleton .w60 { width: 60%; } .skeleton .card { height: 120px; } .skeleton .short { height: 80px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.wotd { margin-top: 10px; display: inline-grid; gap: 2px; text-align: left; padding: 10px 14px; border-radius: 14px; border: 1px solid rgb(255 255 255 / 0.3); background: rgb(255 255 255 / 0.14); color: #fff; font: inherit; cursor: pointer; backdrop-filter: blur(6px); transition: background 0.2s, transform 0.15s; }
.wotd:hover { background: rgb(255 255 255 / 0.22); transform: translateY(-1px); }
.wotd .th { font-size: 26px; font-family: var(--thai); }
.wotd .small { opacity: 0.9; }
.btn.primary:active { transform: scale(0.98); }
.tab span { transition: font-weight 0.2s; } .tab[aria-current="page"] span { font-weight: 700; }
.msg { animation: rise 0.35s cubic-bezier(.2,.7,.2,1) both; }
.toast { font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .skeleton .sk { animation: none; } }

/* ---- sixth pass: lesson pages, review list, progress, talk start ---- */
.teach { padding: 14px 0 10px; }
.teach h4 { font-family: var(--display); font-size: 17px; margin: 0 0 6px; color: var(--accent); }
.teach .phrase { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; border: 0; margin-top: 8px; }
.phrase { transition: background 0.2s; border-radius: 12px; }
.phrase:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.phrase .actions .icon-btn, .phrase .actions .play { transition: transform 0.12s; }
.phrase .actions .play:hover { transform: scale(1.08); }
.hints { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hint { background: var(--surface); border: 1px solid var(--line); padding: 6px 10px; display: grid; gap: 1px; text-align: left; }
.hint b { color: var(--accent); font-size: 13px; }
.correction { border-left: 4px solid var(--accent); }
.list { display: grid; gap: 8px; }
.list-item { border-radius: 14px; transition: transform 0.12s, border-color 0.2s, background 0.2s; }
.list-item:hover { border-color: var(--accent); transform: translateX(3px); }
.starts .start { position: relative; padding: 18px 18px 18px 20px; }
.starts .start::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 2px; background: linear-gradient(180deg, var(--accent), #06b6d4); }
.start.flow::before { background: linear-gradient(180deg, #7c3aed, var(--accent)); }
.start:nth-child(1)::before { background: linear-gradient(180deg, #06b6d4, var(--accent)); }
.report { background: linear-gradient(180deg, var(--surface), var(--surface-2)); border-radius: 18px; padding: 16px; border: 1px solid var(--line); }
.report h4 { font-family: var(--display); color: var(--accent); }
svg.chart, .chart svg { border-radius: 14px; }
.chart rect, .chart .bar-fill { rx: 3; }
.memory { padding: 8px 0; }
.note { line-height: 1.4; }
.english { color: var(--text); }
.roman { font-variant-numeric: tabular-nums; }
.row.memory .icon-btn:hover { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); transform: none; }
/* make long pages breathe */
.stack { gap: 14px; }
.card { padding: 18px; }
h2 + .muted { margin-top: -6px; }
/* print-friendly lessons */
@media print { .tabs, .top, .dock, body::before, .session-bar { display: none !important; } .card { box-shadow: none; break-inside: avoid; } }

/* ---- the front door: a landing page that is also the sign-in ---- */
.landing { max-width: 920px; margin: 0 auto; display: grid; gap: 18px; padding-bottom: 32px; }
.landing-hero { display: grid; gap: 10px; padding: 28px 24px 24px; border-radius: 28px; }
.landing-hero h2 { font-size: clamp(28px, 5vw, 44px); line-height: 1.1; max-width: 16ch; }
.landing-hero p { margin: 0; max-width: 52ch; font-size: 16px; color: rgb(255 255 255 / 0.9); }
.landing-brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 18px; font-weight: 600; }
.landing-brand .brand-mark { background: rgb(255 255 255 / 0.2); box-shadow: none; }
.landing-thai { margin-top: 10px; padding: 16px 18px; border-radius: 18px; background: rgb(255 255 255 / 0.14); backdrop-filter: blur(8px); border: 1px solid rgb(255 255 255 / 0.25); min-height: 120px; display: grid; gap: 2px; align-content: center; animation: rise 0.6s both; }
.landing-thai .thai-line.big { font-size: 40px; }
.landing-thai .roman, .landing-thai .english { color: rgb(255 255 255 / 0.9); }
.landing-thai .s { text-shadow: 0 1px 0 rgb(255 255 255 / 0.4); }
.pitch { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.pitch-point { display: grid; gap: 4px; padding: 16px; border-radius: 18px; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise 0.5s both; }
.pitch-point:nth-child(2) { animation-delay: 0.06s; } .pitch-point:nth-child(3) { animation-delay: 0.12s; } .pitch-point:nth-child(4) { animation-delay: 0.18s; } .pitch-point:nth-child(5) { animation-delay: 0.24s; } .pitch-point:nth-child(6) { animation-delay: 0.3s; }
.pitch-point b { font-family: var(--display); font-size: 18px; color: var(--accent); }
.pitch-point span { color: var(--muted); font-size: 14px; line-height: 1.45; }
.landing-form { max-width: 420px; margin: 0 auto; width: 100%; padding: 22px; border-radius: 22px; }
.landing-form input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; background: var(--surface); color: var(--text); }
@media (min-width: 760px) { .landing-hero { grid-template-columns: 1.1fr 1fr; align-items: center; } .landing-hero .landing-brand, .landing-hero h2, .landing-hero p { grid-column: 1; } .landing-thai { grid-column: 2; grid-row: 1 / span 3; margin: 0; } }

/* landing fix: with the tab column hidden, the page must span the whole grid */
#app:has(.tabs[hidden]) { grid-template-columns: 1fr; }
#app:has(.tabs[hidden]) #screen { grid-column: 1 / -1; }
.landing { width: 100%; }
@media (min-width: 900px) { .landing { padding: 16px 0 40px; } .landing-hero { padding: 40px 36px; } .landing-hero h2 { font-size: 44px; } .pitch { grid-template-columns: repeat(3, 1fr); } }

/* ---- final desktop pass ---- */
@media (min-width: 900px) {
  #app { max-width: 1200px; grid-template-columns: 220px 1fr; }
  .tabs { padding: 16px 12px; gap: 6px; }
  .tab { padding: 12px 14px; border-radius: 14px; font-size: 15px; font-weight: 500; }
  .tab svg { width: 22px; height: 22px; }
  .tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
  .tab[aria-current="page"]::before { display: none; }
  .tab:hover:not([aria-current="page"]) { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
  .tabs::after { content: "ภาษาไทย ทุกวัน"; margin-top: auto; padding: 12px 14px; font: 500 13px var(--thai); color: var(--muted); opacity: 0.8; }
  .tabs { display: flex; flex-direction: column; height: 100%; }
  #screen { padding: 20px 32px 40px; }
  #screen > .stack { max-width: 900px; }
  .today-head { padding: 28px; border-radius: 28px; }
  .today-head h2 { font-size: 34px; }
  .ring-box, .ring { width: 132px; height: 132px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .units { grid-template-columns: repeat(3, 1fr); }
  .starts { grid-template-columns: repeat(2, 1fr); }
  .msg.teacher { width: min(100%, 700px); }
  .big-card { max-width: 640px; margin: 0 auto; width: 100%; }
}
/* keyboard users and tiny phones */
@media (max-width: 380px) { .today-head { padding: 14px; } .today-head h2 { font-size: 24px; } .ring-box, .ring { width: 96px; height: 96px; } .ring-label b { font-size: 22px; } }
.btn:focus-visible, .tab:focus-visible, .option:focus-visible { outline-offset: 3px; }

.idiom { display: grid; gap: 4px; text-align: left; padding: 18px 20px; border-radius: 24px; border: 1px solid var(--line); background: linear-gradient(135deg, var(--accent-soft), var(--surface)); color: inherit; font: inherit; cursor: pointer; box-shadow: var(--shadow); animation: rise 0.4s both; }
.idiom .thai-line { font-size: 26px; }
