/* 倾得埋 — calm, warm, quiet. Mobile first. */
:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1b1e1c;
  --ink-2: #4d534f;
  --ink-3: #848a86;
  --line: #e6e2d9;
  --accent: #2e6a5c;
  --accent-press: #24564a;
  --accent-soft: #e3eee9;
  --accent-ink: #ffffff;
  --warn: #93602a;
  --warn-soft: #f5eadb;
  --quiet-soft: #ecebe6;
  --ref: #a3a8a4;
  --danger: #a3473a;
  --shadow: 0 1px 2px rgba(27, 30, 28, .04), 0 8px 24px rgba(27, 30, 28, .05);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-yue: "PingFang HK", "PingFang TC", "Noto Sans HK", "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
  --font-latin: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1b1f1d;
    --surface-2: #232825;
    --ink: #eef0ec;
    --ink-2: #b8beb9;
    --ink-3: #868d88;
    --line: #2b312e;
    --accent: #7fc2af;
    --accent-press: #96cebf;
    --accent-soft: #1d3430;
    --accent-ink: #0e1916;
    --warn: #e2ab6c;
    --warn-soft: #3a2d1c;
    --quiet-soft: #262a28;
    --ref: #6c736f;
    --danger: #e08d80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
p { margin: 0; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ layout */
.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 max(var(--gutter), env(safe-area-inset-left)) calc(40px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-right));
}
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding-top: env(safe-area-inset-top);
  margin: 0 calc(-1 * var(--gutter));
  padding-left: var(--gutter);
  padding-right: var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .bar { background: var(--bg); }
}
.bar-title { max-width: 56vw; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.bar-side { min-width: 0; display: flex; align-items: center; }
.bar-side.end { justify-content: flex-end; }
.back {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
  min-height: 44px; padding: 0 4px 0 0; color: var(--ink-2); font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back svg { width: 20px; height: 20px; }
.icon-link { display: inline-grid; place-items: center; width: 44px; height: 44px; color: var(--ink-2); border-radius: 50%; }
.icon-link svg { width: 22px; height: 22px; }

.page-head { padding: 8px 2px 18px; }
.page-head h1 { font-size: 26px; line-height: 1.3; }
.page-head .sub { color: var(--ink-2); margin-top: 6px; }
.page-head .yue-title { font-family: var(--font-yue); color: var(--ink-3); font-size: 15px; margin-top: 2px; }

.brand { padding: 18px 2px 20px; display: flex; align-items: flex-end; justify-content: space-between; }
.brand-name { font-size: 28px; font-weight: 650; letter-spacing: .06em; }
.brand-yue { font-family: var(--font-yue); color: var(--ink-3); font-size: 13px; margin-top: 2px; letter-spacing: .02em; }
.brand-yue .jp { font-family: var(--font-latin); margin-left: 6px; }

.section-title { font-size: 13px; font-weight: 600; color: var(--ink-3); letter-spacing: .08em; margin: 28px 4px 10px; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.soft { background: var(--surface-2); box-shadow: none; }
a.card { display: block; color: inherit; transition: transform .15s ease; }
a.card:active { transform: scale(.985); }
.card-row { display: flex; align-items: center; gap: 12px; }
.card-title { font-size: 18px; font-weight: 600; line-height: 1.35; }
.card-title .tag { margin-left: 8px; vertical-align: 2px; }
.card .yue-sub { font-family: var(--font-yue); color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.card .desc { color: var(--ink-2); font-size: 14px; margin-top: 8px; }
.card .meta { color: var(--ink-3); font-size: 13px; margin-top: 10px; }
.chev { margin-left: auto; color: var(--ink-3); flex: none; }
.chev svg { width: 18px; height: 18px; display: block; }
.kicker { font-size: 12px; font-weight: 600; letter-spacing: .1em; color: var(--accent); margin-bottom: 10px; }

.tag {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; background: var(--quiet-soft); color: var(--ink-2);
}
.tag.accent { background: var(--accent-soft); color: var(--accent); }

.days { display: flex; align-items: baseline; gap: 6px; color: var(--ink-2); font-size: 14px; padding: 14px 4px 0; }
.days b { font-size: 22px; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Cantonese text */
.yue { font-family: var(--font-yue); font-size: 23px; line-height: 1.5; letter-spacing: .02em; word-break: break-all; }
.yue.lg { font-size: 26px; }
.yue.sm { font-size: 19px; }
.yue ruby { ruby-position: over; -webkit-ruby-position: before; margin: 0 1px; }
.yue rt {
  font-family: var(--font-latin); font-size: 11px; letter-spacing: 0; color: var(--ink-3);
  font-weight: 450; line-height: 1.1; padding-bottom: 1px;
}
.yue.no-jp rt { display: none; }
.yue .ok { color: var(--accent); }
.yue .miss { color: var(--ink-3); text-decoration: underline dotted var(--ink-3); text-underline-offset: 5px; }
.yue .miss rt { text-decoration: none; }
.jp-line { font-family: var(--font-latin); color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.zh { color: var(--ink-2); margin-top: 6px; font-size: 15px; }
.note { color: var(--ink-3); font-size: 13px; margin-top: 4px; }

/* ------------------------------------------------------------ buttons */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:active { background: var(--accent-press); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0 8px; }
.btn.block { width: 100%; min-height: 50px; font-size: 16px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.playing { border-color: var(--accent); color: var(--accent); }
.btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.busy { opacity: .7; pointer-events: none; }

/* ------------------------------------------------------------ practice result */
.result { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.result-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.result-label { font-size: 12px; color: var(--ink-3); letter-spacing: .06em; min-width: 52px; }
.result .heard { font-family: var(--font-yue); font-size: 17px; }
.result .score { font-size: 14px; color: var(--ink-2); }
.result .score b { color: var(--ink); font-variant-numeric: tabular-nums; }
.result .block { margin-top: 12px; }
.verdict {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.verdict.close { background: var(--accent-soft); color: var(--accent); }
.verdict.different { background: var(--warn-soft); color: var(--warn); }
.verdict.unsure { background: var(--quiet-soft); color: var(--ink-2); }
.verdict-text { color: var(--ink-2); font-size: 14px; margin-top: 6px; }
.pitch-canvas { width: 100%; height: 132px; display: block; margin-top: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--ink-3); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.legend .ref i { background: var(--ref); }
.legend .you i { background: var(--accent); }
.fine { font-size: 12px; color: var(--ink-3); margin-top: 8px; line-height: 1.5; }
.rec-status { font-size: 13px; color: var(--ink-3); margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.level { flex: 1; max-width: 160px; height: 4px; border-radius: 2px; background: var(--quiet-soft); overflow: hidden; }
.level > span { display: block; height: 100%; width: 0; background: var(--danger); transition: width .08s linear; }

/* ------------------------------------------------------------ role-play */
.goal { color: var(--ink-2); font-size: 14px; }
.chat { padding: 6px 0 calc(250px + env(safe-area-inset-bottom)); }
.msg { display: flex; margin-top: 14px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 86%; padding: 12px 14px; border-radius: 18px; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 6px; box-shadow: var(--shadow); }
.msg.user .bubble { background: var(--accent-soft); border-top-right-radius: 6px; }
.msg.user .bubble .yue { font-size: 19px; }
.msg .tools { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.msg .tools .btn { min-height: 34px; padding: 0 10px; font-size: 13px; }
.msg .hint { color: var(--ink-2); font-size: 14px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.msg.pending .bubble { color: var(--ink-3); font-size: 14px; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 10px max(var(--gutter), env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-right));
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .dock { background: var(--bg); }
}
.dock-inner { max-width: 600px; margin: 0 auto; }
.suggest-label { font-size: 12px; color: var(--ink-3); letter-spacing: .06em; margin-bottom: 6px; }
.suggest { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.suggest::-webkit-scrollbar { display: none; }
.chip {
  flex: none; max-width: 78%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px;
}
.chip .yue { font-size: 16px; line-height: 1.4; }
.chip .jp-line { font-size: 12px; }
.chip .zh { font-size: 12px; margin-top: 2px; }
.chip.playing { border-color: var(--accent); }
.ptt-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ptt {
  flex: 1; min-height: 56px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .12s ease, background .15s ease;
}
.ptt svg { width: 20px; height: 20px; }
.ptt.recording { background: var(--danger); transform: scale(1.02); }
.ptt.busy { opacity: .6; }
.ptt[disabled] { opacity: .4; }
.round {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.round svg { width: 20px; height: 20px; }
.type-row { display: flex; gap: 8px; margin-top: 8px; }
.type-row input {
  flex: 1; min-width: 0; min-height: 46px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 0 16px; font: 16px var(--font-yue);
}
.turns { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 8px; }

/* ------------------------------------------------------------ lessons */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.item-tile {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px 6px 8px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 74px; line-height: 1.25; transition: border-color .15s ease, background .15s ease;
}
.item-tile .c { font-family: var(--font-yue); font-size: 24px; }
.item-tile .j { font-family: var(--font-latin); font-size: 12px; color: var(--ink-3); }
.item-tile.on { border-color: var(--accent); background: var(--accent-soft); }
.item-tile.on .j { color: var(--accent); }
.stage { margin-top: 12px; }
.consent-state { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.tone-chart { width: 100%; height: 190px; display: block; }
.tone-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tone-key {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 6px;
  text-align: center; cursor: pointer; line-height: 1.3;
}
.tone-key.on { border-color: var(--accent); background: var(--accent-soft); }
.tone-key .n { font-size: 11px; color: var(--ink-3); }
.tone-key .c { font-family: var(--font-yue); font-size: 20px; }
.tone-key .j { font-family: var(--font-latin); font-size: 12px; color: var(--ink-3); }
.item-head { display: flex; align-items: center; gap: 14px; }
.item-head .yue { font-size: 34px; line-height: 1.2; }
.item-head .info { min-width: 0; }
.item-head .jp { font-family: var(--font-latin); font-size: 17px; }
.quiz-q { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.quiz-opt {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 8px;
  text-align: center; cursor: pointer; line-height: 1.3;
}
.quiz-opt .c { font-family: var(--font-yue); font-size: 26px; }
.quiz-opt .j { font-family: var(--font-latin); color: var(--ink-3); font-size: 14px; }
.quiz-opt.right { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt.wrong { border-color: var(--warn); background: var(--warn-soft); }
.quiz-opt[disabled] { cursor: default; }
.quiz-feedback { font-size: 14px; color: var(--ink-2); margin-top: 10px; min-height: 22px; }
.explain { color: var(--ink-2); font-size: 15px; line-height: 1.75; }

/* ------------------------------------------------------------ settings */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 54px; }
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .val { color: var(--ink-3); font-size: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--ink-2);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--quiet-soft); transition: background .15s; pointer-events: none; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.qr { width: 160px; height: 160px; margin: 12px auto 0; border-radius: 12px; }
.todo { color: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------ member card */
.member .card-title { font-size: 16px; }
.member .desc { margin-top: 4px; }

/* ------------------------------------------------------------ sheet + toast */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(15, 18, 16, .36);
  opacity: 0; transition: opacity .2s ease;
}
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 600px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet.show { transform: none; }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 16px; }
.sheet h2 { font-size: 20px; margin-bottom: 12px; }
.sheet .body { color: var(--ink-2); font-size: 15px; line-height: 1.7; }
.sheet .body ul { padding-left: 1.2em; margin: 8px 0 0; }
.sheet .body li + li { margin-top: 6px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet .actions .btn { flex: 1; min-height: 48px; font-size: 16px; }

.toast {
  position: fixed; left: 50%; top: calc(62px + env(safe-area-inset-top)); z-index: 50;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); font-size: 14px; padding: 10px 16px; border-radius: 999px;
  max-width: calc(100% - 40px); text-align: center; transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: .94; transform: translate(-50%, 0); }

.loading { color: var(--ink-3); padding: 40px 0; text-align: center; font-size: 14px; }
.empty { color: var(--ink-3); padding: 28px 0; text-align: center; }
.footer { text-align: center; color: var(--ink-3); font-size: 12px; margin-top: 36px; }
.footer a { color: var(--ink-3); }
.footer .dot { margin: 0 8px; }
.mock-badge { display: inline-block; margin-top: 8px; font-size: 11px; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 999px; }

/* ------------------------------------------------------------ share */
.share-preview { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); background: var(--surface); }

/* ------------------------------------------------------------ documents */
.doc { padding-bottom: 20px; }
.doc h1 { font-size: 24px; margin: 6px 0 4px; }
.doc h2 { font-size: 17px; margin: 26px 0 8px; }
.doc p, .doc li { color: var(--ink-2); font-size: 15px; line-height: 1.8; }
.doc ul { padding-left: 1.2em; }
.doc .draft { display: inline-block; font-size: 12px; color: var(--warn); background: var(--warn-soft); padding: 2px 10px; border-radius: 999px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.doc th, .doc td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--ink-2); }
.doc th { color: var(--ink); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (min-width: 640px) {
  .page-head h1 { font-size: 30px; }
  .yue { font-size: 25px; }
}
