:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f2ede5;
  --text: #2a2522;
  --muted: #7a716a;
  --line: #e6dfd5;
  --accent: #c8402f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7e3;
  --good: #2f8a57;
  --good-soft: #e3f3e9;
  --warn: #b7791f;
  --bad: #c53030;
  --partner: #ffffff;
  --me: #2d5d7b;
  --me-ink: #ffffff;
  --shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 4px 14px rgba(40, 30, 20, 0.06);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-zh: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f1ebe4;
    --muted: #a59b92;
    --line: #3a332e;
    --accent: #e0604d;
    --accent-soft: #3a221d;
    --good: #5cc28a;
    --good-soft: #1d3326;
    --warn: #e0a84a;
    --bad: #f07070;
    --partner: #26211e;
    --me: #3c7396;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #171412; --surface: #221e1b; --surface-2: #2c2723; --text: #f1ebe4; --muted: #a59b92;
  --line: #3a332e; --accent: #e0604d; --accent-soft: #3a221d; --good: #5cc28a; --good-soft: #1d3326;
  --warn: #e0a84a; --bad: #f07070; --partner: #26211e; --me: #3c7396; --shadow: 0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--bad); }

.view { min-height: 100dvh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.view.chat { padding-bottom: 0; display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .title, .brand { font-weight: 650; }
.brand { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: none; border: 0; padding: 6px 4px; color: var(--accent); font-weight: 600; }

.page { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.note { background: var(--accent-soft); border-color: transparent; box-shadow: none; font-size: 14px; }

.logo {
  display: inline-grid; place-items: center; width: 72px; height: 72px; border-radius: 20px;
  background: var(--accent); color: var(--accent-ink); font-family: var(--font-zh); font-size: 28px; font-weight: 700;
}
.logo.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 13px; }

.login-box { max-width: 360px; margin: 0 auto; padding: 18vh 24px 24px; text-align: center; display: grid; gap: 6px; }
.login-box form { display: grid; gap: 10px; margin-top: 16px; }

input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
input[type="file"] { width: 100%; font-size: 14px; }
.field { display: grid; gap: 6px; margin: 12px 0; font-size: 14px; font-weight: 600; }
.field .muted { font-weight: 400; }
.switch { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 15px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { width: 100%; padding: 15px; font-size: 17px; margin-top: 8px; }
.btn:disabled { opacity: 0.5; }
.btn.danger-outline { background: none; border-color: var(--bad); color: var(--bad); width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: none; padding: 9px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 8px; }
.stats .num { font-size: 26px; font-weight: 700; }
.stats .lbl { font-size: 12px; color: var(--muted); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; grid-column: 1 / -1; }
.progress > div { height: 100%; background: var(--good); border-radius: 99px; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 4px; }
.tabbar button span { font-size: 20px; }
.tabbar button.on { color: var(--accent); font-weight: 600; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); }
.msg.partner { align-self: flex-start; background: var(--partner); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; }
.hanzi { font-family: var(--font-zh); font-size: 24px; line-height: 1.5; letter-spacing: 0.02em; }
.msg.me .hanzi { font-size: 20px; }
.pinyin { color: var(--muted); font-size: 15px; margin-top: 2px; }
.english { font-size: 14px; margin-top: 6px; color: var(--muted); font-style: italic; }
.actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 5px 11px; font-size: 13px; }
.new-word { text-decoration: underline dotted var(--accent) 2px; text-underline-offset: 5px; cursor: help; }
.off-list { text-decoration: underline wavy var(--warn) 1.5px; text-underline-offset: 5px; }
.w-bad { color: #ffb4a8; text-decoration: underline wavy #ffb4a8 1.5px; text-underline-offset: 5px; }
.w-meh { color: #ffe1a1; }
.score { display: inline-block; margin-top: 6px; font-size: 12px; background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 99px; }

.feedback { align-self: flex-end; max-width: 88%; font-size: 14px; border-radius: 14px; padding: 10px 12px; }
.feedback.ok { background: var(--good-soft); color: var(--good); padding: 6px 12px; font-weight: 600; }
.feedback.fix { background: var(--accent-soft); }
.feedback .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.feedback .hanzi { font-size: 20px; }
.feedback .why { margin-top: 4px; }

.typing { align-self: flex-start; color: var(--muted); font-size: 14px; padding: 4px 6px; }
.typing::after { content: "…"; animation: dots 1.2s steps(3) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }

.focus-panel { padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.focus-panel .chip { font-family: var(--font-zh); font-size: 15px; }

.hint-card { margin: 0 16px 8px; background: var(--surface); border: 1px dashed var(--accent); border-radius: 14px; padding: 10px 12px; }
.hint-card .hanzi { font-size: 20px; }

.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.composer-row { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 12px; }
.round-btn { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); font-size: 20px; }
.mic {
  height: 64px; border-radius: 32px; border: 0; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 16px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.mic-icon { font-size: 22px; }
.mic.listening { background: var(--bad); box-shadow: 0 0 0 calc(var(--lvl, 0) * 14px) color-mix(in srgb, var(--bad) 35%, transparent); transition: box-shadow 80ms linear; }
.mic:disabled { opacity: 0.55; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.live-text { font-family: var(--font-zh); font-size: 20px; text-align: center; min-height: 1.5em; color: var(--muted); }
.type-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

/* words */
.steps { margin: 0 0 4px; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-between h2 { margin: 0; }
.search { max-width: 160px; padding: 8px 12px !important; }
.deck-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.deck-row:last-child { border-bottom: 0; }
.word-list { display: grid; }
.word-row { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.word-row .zh { font-family: var(--font-zh); font-size: 20px; }
.word-row .py { color: var(--muted); font-size: 14px; }
.word-row .en { grid-column: 2 / 3; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.said { background: var(--good-soft); color: var(--good); }
.preview-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 12px; }
.preview-table td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.preview-table td:first-child { font-family: var(--font-zh); font-size: 17px; }

.status-list { display: grid; gap: 10px; font-size: 15px; }
.status-list div { display: flex; justify-content: space-between; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
