/* Layout: one phone-width column. Screens swap in place: gate, home, chat, result.
   Every label is a .zh/.en span pair; body[data-ui] shows Chinese, English or both. The dragon itself only ever speaks Chinese. */
:root {
  --bg: #fff3f6;
  --surface: #ffffff;
  --ink: #2b2540;
  --muted: #6b6585;
  --pink: #f2799f;
  --pink-soft: #ffd9e4;
  --blue: #4a8fe7;
  --blue-soft: #d9e8ff;
  --lilac: #b9a6f2;
  --gold: #f4c46a;
  --line: #f0d9e2;
  --action: #c93a72;
  --on-action: #ffffff;
  --font-display: "ZCOOL KuaiLe", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-util: "Nunito", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1830; --surface: #2a2342; --ink: #f6eefb; --muted: #b5abd0;
    --pink: #ff8fb1; --pink-soft: #4a2b47; --blue: #7db2ff; --blue-soft: #243a66;
    --lilac: #c9b8ff; --gold: #f4c46a; --line: #3c3459; --action: #ff8fb1; --on-action: #2b2540;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 17px; line-height: 1.55;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(32px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.app { max-width: 560px; margin: 0 auto; display: grid; gap: 16px; }
[hidden] { display: none !important; }
h1, h2, .display { font-family: var(--font-display); font-weight: 400; margin: 0; text-wrap: balance; }
h1 { font-size: 2.4rem; line-height: 1.15; }
h2 { font-size: 1.6rem; line-height: 1.2; }
h3 { font-family: var(--font-display); font-weight: 400; font-size: 1.15rem; margin: 10px 0 4px; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* Language: .zh and .en come in pairs. both = Chinese with a small English line under it. */
.en { display: none; }
body[data-ui="both"] .en { display: block; font-family: var(--font-util); font-size: .74em; font-weight: 400; line-height: 1.3; opacity: .85; }
body[data-ui="both"] h1 .en, body[data-ui="both"] h2 .en { font-size: .38em; letter-spacing: .02em; }
body[data-ui="en"] .en { display: inline; font-family: var(--font-util); }
body[data-ui="en"] .zh { display: none; }
body[data-ui="en"] h1, body[data-ui="en"] h2, body[data-ui="en"] h3, body[data-ui="en"] .who { font-family: var(--font-util); font-weight: 700; }
.uibar { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }

.d-blue { fill: var(--blue); }
.d-pink { fill: var(--pink-soft); }
.d-cheek { fill: var(--pink); opacity: .55; }
.d-lilac { fill: var(--lilac); }
.d-gold { fill: var(--gold); }
.d-white { fill: #fff; }
.d-dark { fill: #2b2540; }
.d-mouth { stroke: #2b2540; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.dragon { display: block; height: auto; transform-origin: 50% 90%; }
.dragon.speaking { animation: bob .7s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0) rotate(-1.5deg); } to { transform: translateY(-5px) rotate(1.5deg); } }
@media (prefers-reduced-motion: reduce) { .dragon.speaking { animation: none; } .dots i { animation: none !important; } .mic { transition: none !important; } }

.btn {
  min-height: 48px; padding: 8px 24px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--action); color: var(--on-action); font-weight: 700;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.2;
}
.btn.soft { background: var(--blue-soft); color: var(--ink); }
.btn.small { min-height: 44px; padding: 6px 16px; font-size: .95rem; }
.btn[aria-pressed="true"] { background: var(--blue); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

/* Home and gate */
.hero { display: grid; justify-items: center; gap: 10px; text-align: center; padding-top: 4px; }
.hero .dragon { width: min(56vw, 210px); }
.sub { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 18px; display: grid; gap: 14px; }
.card input { min-height: 48px; padding: 8px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); width: 100%; }
.streak-line { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; text-align: center; }
.streak-num { font-family: var(--font-display); font-size: 2.6rem; line-height: 1; color: var(--action); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.day { display: grid; gap: 4px; justify-items: center; font-size: .85rem; color: var(--muted); }
.day .dot { width: 34px; height: 34px; border-radius: 50%; border: 2px dashed var(--line); display: grid; place-items: center; }
.day.done .dot { border: 0; background: var(--pink-soft); }
.day.today .dot { border-color: var(--blue); border-style: solid; }
.day.done.today .dot { border: 2px solid var(--blue); }
.dot svg { width: 20px; height: 20px; fill: var(--gold); }
.start-row { display: grid; justify-items: center; gap: 8px; }
.start-row .btn { min-width: 220px; min-height: 56px; font-size: 1.2rem; }
details.parent { background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; padding: 10px 14px; font-family: var(--font-util); font-size: .88rem; color: var(--muted); }
details.parent summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
details.parent ul { margin: 6px 0 4px; padding-left: 18px; display: grid; gap: 4px; }
details.parent h3 { font-family: var(--font-util); font-weight: 700; font-size: .95rem; color: var(--ink); }
#learnedList li { display: flex; gap: 8px; align-items: center; justify-content: space-between; list-style: none; margin-left: -18px; }
#learnedList button { min-height: 32px; border: 0; background: var(--blue-soft); color: var(--ink); border-radius: 999px; padding: 2px 12px; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.row.left { justify-content: flex-start; margin-top: 8px; }

/* Chat */
.chat-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.chat-head .dragon { width: 52px; }
.chat-head .who { font-family: var(--font-display); font-size: 1.4rem; line-height: 1.1; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .95rem; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.log { display: grid; gap: 12px; }
.msg { display: flex; gap: 8px; align-items: flex-end; }
.msg.her { justify-content: flex-end; }
.bubble { padding: 10px 15px; max-width: min(86%, 440px); overflow-wrap: anywhere; }
.msg.tutor .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 20px 20px 20px 6px; font-size: 1.12rem; }
.msg.her .bubble { background: var(--blue-soft); border-radius: 20px 20px 6px 20px; font-size: 1.12rem; }
.msg.pending .bubble { opacity: .6; }
.say { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--pink-soft); color: var(--action); display: grid; place-items: center; cursor: pointer; }
.say svg { width: 22px; height: 22px; fill: currentColor; }
.dots { display: inline-flex; gap: 5px; padding: 6px 2px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--lilac); animation: blink 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
.hint { font-size: .92rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 46px; padding: 8px 16px; border-radius: 999px; border: 2px solid var(--blue); background: var(--surface); cursor: pointer; font-size: 1.05rem; text-align: left; }
.banner { background: var(--pink-soft); border-radius: 14px; padding: 10px 14px; }
.problem { background: var(--surface); border: 2px solid var(--pink); border-radius: 14px; padding: 10px 14px; display: grid; gap: 8px; justify-items: start; }

/* Microphone: the main control. It stays at the bottom of the screen while the chat scrolls. */
.mic-area {
  position: sticky; bottom: 0; display: grid; justify-items: center; gap: 8px;
  padding: 18px 0 max(8px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, transparent, var(--bg) 24%);
}
.mic {
  --lvl: 0;
  width: 112px; height: 112px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--action); color: var(--on-action); display: grid; place-items: center;
  box-shadow: 0 0 0 calc(4px + var(--lvl) * 30px) var(--pink-soft);
  transition: box-shadow .08s linear, background .2s;
}
.mic svg { width: 52px; height: 52px; fill: currentColor; grid-area: 1 / 1; }
.mic .ico-stop { display: none; }
.mic[data-state="recording"] { background: var(--blue); color: #fff; }
.mic[data-state="recording"] .ico-mic, .mic[data-state="speaking"] .ico-mic { display: none; }
.mic[data-state="recording"] .ico-stop, .mic[data-state="speaking"] .ico-stop { display: block; }
.mic[data-state="speaking"] { background: var(--lilac); color: #2b2540; }
.mic[data-state="thinking"] { opacity: .55; cursor: default; }
.mic[data-state="nomic"] { display: none; }
.mic-label { text-align: center; color: var(--muted); font-size: .95rem; min-height: 1.6em; }
.typebox { width: 100%; font-size: .95rem; color: var(--muted); }
.typebox summary { cursor: pointer; text-align: center; min-height: 36px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 6px; }
.composer input { min-height: 48px; padding: 8px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); min-width: 0; }

/* Result */
.stars { display: flex; justify-content: center; gap: 6px; }
.stars svg { width: 44px; height: 44px; fill: var(--line); }
.stars svg.on { fill: var(--gold); }
.result ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.words { display: grid; gap: 10px; }
.word { display: flex; gap: 12px; align-items: baseline; }
.word b { font-family: var(--font-display); font-weight: 400; font-size: 1.4rem; color: var(--action); flex: none; }
.cheer { text-align: center; font-size: 1.15rem; }
