:root {
  --paper: #eef3f0;
  --surface: #ffffff;
  --mist: #dce6e1;
  --line: #c9d6d0;
  --ink: #1c2a33;
  --ink-soft: #4f6370;
  --harbor: #24465e;
  --harbor-ink: #ffffff;
  --leaf: #3d7a68;
  --leaf-soft: #e2efe9;
  --butter: #f2cf63;
  --butter-soft: #fbf1cc;
  --sky-soft: #e6eef4;
  --zh: "LXGW WenKai TC", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --en: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #132028;
    --surface: #1b2b35;
    --mist: #22343f;
    --line: #2f4552;
    --ink: #e7efeb;
    --ink-soft: #a6b8b1;
    --harbor: #8fb8d6;
    --harbor-ink: #10202b;
    --leaf: #7cc3ab;
    --leaf-soft: #1e3a33;
    --butter: #f2cf63;
    --butter-soft: #3a3420;
    --sky-soft: #1f3341;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--zh);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--harbor); outline-offset: 2px; border-radius: 6px; }
.en { font-family: var(--en); }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* ---------- Home ---------- */
.home { padding-top: max(28px, env(safe-area-inset-top)); padding-bottom: 48px; }
.home-top { display: flex; justify-content: space-between; align-items: center; }
.home-top .today { color: var(--ink-soft); font-size: 15px; }
.icon-btn {
  border: 0; background: transparent; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--ink-soft);
  min-width: 44px; min-height: 44px; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--mist); }

.hero { margin: 28px 0 24px; }
.hero h1 { font-size: clamp(40px, 11vw, 56px); line-height: 1.12; margin: 0; font-weight: 700; letter-spacing: 0.02em; }
.hero p { margin: 10px 0 0; color: var(--ink-soft); max-width: 30em; }

.start {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; width: 100%;
  background: var(--harbor); color: var(--harbor-ink); border: 0; border-radius: var(--r-lg);
  padding: 22px 22px; text-align: left; cursor: pointer;
}
.start .what { font-size: 22px; font-weight: 700; display: block; }
.start .detail { opacity: 0.85; font-size: 15px; display: block; margin-top: 2px; }
.start .go {
  width: 56px; height: 56px; border-radius: 999px; background: var(--butter); color: #1c2a33;
  display: grid; place-items: center;
}

.speak-today { display: flex; gap: 16px; margin: 18px 4px 0; color: var(--ink-soft); font-size: 15px; flex-wrap: wrap; }
.speak-today b { color: var(--ink); font-family: var(--en); font-size: 17px; }

.section-title { font-size: 19px; margin: 36px 0 12px; font-weight: 700; }
.scenarios { display: grid; gap: 10px; }
.scenario {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center;
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 14px 16px; cursor: pointer;
}
.scenario:hover { border-color: var(--harbor); }
.scenario .emo { font-size: 28px; line-height: 1; }
.scenario .name { font-weight: 700; display: block; }
.scenario .sub { color: var(--ink-soft); font-size: 14px; font-family: var(--en); display: block; }
.dots { display: flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 999px; background: var(--line); display: block; }
.dots i.on { background: var(--leaf); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.stat { background: var(--surface); padding: 14px 16px; }
.stat .v { font-family: var(--en); font-size: 26px; font-weight: 700; display: block; line-height: 1.2; }
.stat .k { color: var(--ink-soft); font-size: 14px; }
.stat .v.empty { color: var(--ink-soft); font-weight: 400; font-size: 18px; }

.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 15px; cursor: pointer; }
.word-chip .en { font-weight: 700; }
.muted { color: var(--ink-soft); font-size: 15px; }
.setup-note { background: var(--butter-soft); border: 1px solid var(--butter); border-radius: var(--r-md); padding: 14px 16px; margin: 0 0 16px; }
.setup-note p { margin: 0 0 8px; font-size: 15px; }
.more-btn { justify-self: start; color: var(--harbor); }
.listen-btn { width: auto; gap: 4px; padding: 6px 10px; display: inline-flex; color: var(--harbor); font-size: 14px; border: 1px solid var(--line); border-radius: 999px; min-height: 40px; }
.listen-offer { background: var(--sky-soft); border: 1px solid var(--line); }
.listen-offer .head { font-weight: 700; margin: 0 0 4px; }
.speakers { display: flex; flex-wrap: wrap; gap: 8px; }
.sp { font-size: 14px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.sp-a { --sp: var(--harbor); } .sp-b { --sp: var(--leaf); } .sp-c { --sp: #a0681f; }
.sp b { color: var(--sp); }
.keyp { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 14px; }
.keyp summary { cursor: pointer; font-weight: 700; }
.keyp ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 6px; }
#listen-feed { scroll-behavior: auto; }
.lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.line { width: 100%; text-align: left; display: grid; gap: 2px; padding: 10px 12px 10px 14px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; cursor: pointer; border-left: 4px solid var(--sp); }
.line .who { font-size: 13px; font-weight: 700; color: var(--sp); }
.line .en { font-size: 18px; line-height: 1.45; }
.line .zh { color: var(--ink-soft); font-size: 15px; }
.line.now { background: var(--butter-soft); border-color: var(--butter); border-left-color: var(--sp); }
.hide-text .line .en, .hide-text .line .zh { filter: blur(6px); }
.hide-text .line.now .en { filter: none; }
.listen-opts { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; min-height: 36px; }
.chip-btn[aria-pressed="true"] { background: var(--sky-soft); border-color: var(--harbor); }
.listen-side { display: grid; justify-items: center; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sp-c { --sp: #e0a85a; } }
@media (prefers-reduced-motion: reduce) { .line.now { scroll-behavior: auto; } }
.gen { display: flex; gap: 8px; }
.gen input { flex: 1; min-width: 0; font: inherit; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.gen-ideas { margin-top: 8px; }
.custom-row { display: grid; grid-template-columns: 1fr auto; gap: 4px; align-items: center; }
.foot { margin-top: 36px; color: var(--ink-soft); font-size: 13px; }

/* ---------- Practice ---------- */
.practice { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); height: 100dvh; }
.bar { padding: max(10px, env(safe-area-inset-top)) 8px 8px; background: var(--paper); border-bottom: 1px solid var(--line); }
.bar-row { display: flex; align-items: center; gap: 4px; max-width: 560px; margin: 0 auto; }
.bar-row .title { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.engine { font-size: 12px; color: var(--ink-soft); font-family: var(--en); padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.stages { display: flex; gap: 6px; max-width: 560px; margin: 8px auto 0; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.stages::-webkit-scrollbar { display: none; }
.stage-tab {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 14px;
  white-space: nowrap; cursor: pointer; color: var(--ink-soft);
}
.stage-tab .n { font-family: var(--en); margin-right: 4px; }
.stage-tab.done { color: var(--leaf); border-color: var(--leaf); }
.stage-tab[aria-current="step"] { background: var(--harbor); color: var(--harbor-ink); border-color: var(--harbor); }

.feed { overflow-y: auto; padding: 16px 0 24px; scroll-behavior: smooth; }
.feed .wrap { display: grid; gap: 12px; }

.prompt {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px;
}
.prompt .hint { color: var(--ink-soft); font-size: 14px; margin: 0 0 6px; }
.prompt .big { font-family: var(--en); font-size: 24px; line-height: 1.35; margin: 0; font-weight: 700; }
.prompt .big-zh { font-size: 22px; margin: 0; font-weight: 700; }
.prompt .sub { color: var(--ink-soft); margin: 6px 0 0; }
.prompt .pattern { font-family: var(--en); font-size: 22px; font-weight: 700; margin: 0; }
.pattern .blank { display: inline-block; min-width: 3.2em; border-bottom: 3px solid var(--butter); }
.opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.opt { font-size: 14px; background: var(--sky-soft); border-radius: 999px; padding: 3px 10px; }
.reveal { margin-top: 10px; border: 0; background: none; color: var(--harbor); padding: 0; cursor: pointer; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
.reveal-text { font-family: var(--en); margin-top: 6px; }

.msg { max-width: 88%; overflow-wrap: anywhere; padding: 10px 14px; border-radius: var(--r-md); }
.msg.ai { background: var(--surface); border: 1px solid var(--line); justify-self: start; border-bottom-left-radius: 6px; }
.msg.me { background: var(--sky-soft); justify-self: end; border-bottom-right-radius: 6px; }
.msg .en { font-size: 19px; display: block; }
.msg .zh { color: var(--ink-soft); font-size: 15px; display: block; }
.msg .zh[hidden] { display: none; }
.msg .tools { display: flex; gap: 2px; margin: 4px -6px -4px; }
.msg .tools button { border: 0; background: none; color: var(--ink-soft); font-size: 13px; padding: 4px 6px; cursor: pointer; border-radius: 6px; }
.msg .tools button:hover { background: var(--mist); }
.msg.me .heard-label { font-size: 12px; color: var(--ink-soft); display: block; }

.ok { justify-self: end; display: inline-flex; align-items: center; gap: 6px; color: var(--leaf); font-size: 14px; font-weight: 700; }
.ok svg { flex: none; }

.card { border-radius: var(--r-md); padding: 14px 16px; }
.fix { background: var(--butter-soft); border: 1px solid color-mix(in srgb, var(--butter) 60%, transparent); }
.fix .head { font-weight: 700; margin: 0 0 4px; }
.fix .say { font-family: var(--en); font-size: 20px; font-weight: 700; }
.fix .tip { margin: 4px 0 0; font-size: 15px; }
.fix .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.extras { margin-top: 12px; border-top: 1px dashed color-mix(in srgb, var(--butter) 70%, transparent); padding-top: 8px; }
.extras summary { cursor: pointer; color: var(--ink-soft); font-size: 15px; min-height: 32px; display: flex; align-items: center; }
.extras ul { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.extras .full-label { margin: 10px 0 2px; font-size: 14px; color: var(--ink-soft); }
.extras .say { margin-bottom: 8px; }
.suggest { background: var(--leaf-soft); }
.suggest .en { font-size: 18px; font-weight: 700; }

.rescue { background: var(--surface); border: 2px solid var(--harbor); }
.rescue .head { margin: 0 0 10px; }
.cands { display: grid; gap: 8px; }
.cand {
  text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: var(--r-sm);
  padding: 12px 14px; cursor: pointer; display: grid; gap: 2px; min-height: 52px;
}
.cand:hover { border-color: var(--harbor); }
.cand .zh { font-size: 18px; font-weight: 700; }
.cand .en { font-size: 15px; color: var(--ink-soft); }
.rescue .alt { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; cursor: pointer; min-height: 44px;
}
.btn.primary { background: var(--harbor); color: var(--harbor-ink); border-color: var(--harbor); }
.btn.quiet { background: transparent; }

.done-card { background: var(--leaf-soft); text-align: left; }
.done-card h2 { margin: 0 0 6px; font-size: 22px; }
.done-card .nums { display: flex; gap: 18px; flex-wrap: wrap; margin: 8px 0 12px; }
.done-card .nums b { font-family: var(--en); font-size: 22px; display: block; }
.done-card .nums span { font-size: 14px; color: var(--ink-soft); }
.done-card .row { display: flex; gap: 8px; flex-wrap: wrap; }

.status { justify-self: center; color: var(--ink-soft); font-size: 14px; }
.error { background: #fde8e4; color: #6b2216; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .error { background: #4a2420; color: #ffd9d1; } }

/* ---------- Dock (mic) ---------- */
.dock { border-top: 1px solid var(--line); background: var(--paper); padding: 10px 0 max(14px, env(safe-area-inset-bottom)); }
.dock .wrap { display: grid; gap: 8px; }
.timer { display: flex; justify-content: center; gap: 14px; color: var(--ink-soft); font-size: 13px; }
.timer b { font-family: var(--en); color: var(--ink); font-size: 15px; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.side { border: 0; background: none; cursor: pointer; display: grid; justify-items: center; gap: 2px; color: var(--ink-soft); font-size: 13px; padding: 6px; min-height: 52px; }
.side:hover { color: var(--ink); }
.side:disabled { opacity: 0.4; cursor: default; }

.mic {
  --level: 0;
  position: relative; width: 84px; height: 84px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--harbor); color: var(--harbor-ink); display: grid; place-items: center;
}
.mic::before {
  content: ""; position: absolute; inset: -6px; border-radius: 999px; background: var(--butter);
  transform: scale(calc(0.92 + var(--level) * 0.45)); opacity: calc(var(--level) * 0.9); z-index: -1;
  transition: transform 60ms linear, opacity 120ms linear;
}
.mic { isolation: isolate; }
.mic.rec { background: var(--ink); color: var(--paper); }
.mic.busy { opacity: 0.6; cursor: progress; }
.mic-label { text-align: center; font-size: 14px; color: var(--ink-soft); min-height: 1.6em; }

.typebox { display: flex; gap: 8px; }
.typebox input {
  flex: 1; min-width: 0; font: inherit; font-family: var(--en); padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.presets { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.presets::-webkit-scrollbar { display: none; }
.preset { white-space: nowrap; border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--ink-soft); }

/* ---------- Settings ---------- */
.sheet-back { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); display: grid; align-items: end; z-index: 10; }
.sheet { background: var(--paper); border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; overflow-y: auto; padding: 20px 0 max(24px, env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.field { display: grid; gap: 4px; margin-top: 16px; }
.field label { font-weight: 700; }
.field input, .field select { font: inherit; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.field .muted { font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 15px; margin-top: 8px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; font-family: var(--en); }

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