:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e3de;
  --accent: #b5442f;      /* 朱色 */
  --accent-text: #ffffff;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --danger: #b42318;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #1f2125;
    --text: #e8e6e3;
    --muted: #9aa0a6;
    --line: #2e3136;
    --accent: #e0735d;
    --accent-text: #16171a;
    --ok: #5cb87f;
    --warn: #e0a84f;
    --danger: #f07167;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "PingFang SC",
        "Noto Sans JP", "Noto Sans SC", "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 17px; }
.topbar nav { display: flex; gap: 16px; font-size: 15px; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active { color: var(--accent); font-weight: 600; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }

/* 按钮：手机上要大 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 20px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
  font-size: 16px; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }

/* 表单 */
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=password] {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text);
  font-size: 16px;  /* 小于 16px 时 iOS 会自动放大页面 */
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
form .btn { margin-top: 18px; }

.flash, .error {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 15px;
}
.flash { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* 登录页 */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.auth h1 { font-size: 24px; margin: 0 0 4px; }

/* 首页入口 */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 16px; color: var(--text);
}
.tile .t { font-size: 17px; font-weight: 700; }
.tile .d { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile.soon { opacity: .5; }
.tile.main { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tile.main .d { color: inherit; opacity: .85; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.temp-pw { font: 600 22px/1.4 ui-monospace, Menlo, monospace; letter-spacing: 2px; }

@media (min-width: 900px) {
  main { padding: 24px; }
}

/* 单词本 */
.small { font-size: 13px; }
textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; resize: vertical;
}
input[type=search] {
  width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 16px; -webkit-appearance: none; appearance: none;
}
.bar { display: flex; gap: 8px; align-items: center; }
.bar > input, .bar > .search { flex: 1; min-width: 0; }
.bar .btn { margin-top: 0; flex-shrink: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; -webkit-overflow-scrolling: touch; }
.chip {
  flex-shrink: 0; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 14px; white-space: nowrap;
}
.chip span { color: var(--muted); font-size: 12px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.on span { color: inherit; opacity: .8; }
.word-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.word-row { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--text); }
.word-row:last-child { border-bottom: 0; }
.wl-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wl-word { font-size: 18px; font-weight: 600; }
.wl-reading { color: var(--muted); font-size: 14px; }
.wl-meaning { color: var(--muted); font-size: 14px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 16px 0; }
.word-card .wc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.wc-word { font-size: 30px; font-weight: 700; line-height: 1.3; }
.wc-reading { color: var(--muted); font-size: 17px; }
.wc-meaning { font-size: 18px; margin-top: 10px; }
.wc-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.wc-example { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
details summary { cursor: pointer; font-weight: 600; }
.note { padding: 12px 14px; border-radius: 12px; margin-top: 12px; font-size: 14px; white-space: pre-line;
  background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); }
#lookup-msg.error { margin: 12px 0 0; }
.card form + form .btn { margin-top: 10px; }

/* 今日练习 */
.pr-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.pr-card { min-height: 46vh; display: flex; flex-direction: column; cursor: pointer; }
.pr-badges { min-height: 22px; }
.pr-front { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 0; }
.pr-word { font-size: 44px; font-weight: 700; line-height: 1.25; text-align: center; word-break: keep-all; }
#pr-back { border-top: 1px solid var(--line); padding-top: 14px; cursor: auto; }
.pr-reading { font-size: 20px; color: var(--muted); }
.pr-meaning { font-size: 20px; margin-top: 6px; }
.pr-rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pr-rate .btn { flex-direction: column; min-height: 60px; padding: 0 4px; line-height: 1.25; }
.pr-rate small { font-size: 12px; font-weight: 400; color: var(--muted); }
.pr-rate .r1 { color: var(--danger); }
.pr-rate .r2 { color: var(--warn); }
.pr-rate .r3 { color: var(--ok); }
.pr-speak { margin-top: 12px; }
.kbd { font-size: 12px; font-weight: 400; opacity: .7; margin-left: 6px; }
@media (hover: none) { .kbd { display: none; } }
.tile .n { font-size: 30px; font-weight: 700; line-height: 1.2; margin-top: 6px; }
input[type=number] {
  width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font-size: 16px;
}

/* 对话 */
.section-title { font-size: 16px; margin: 20px 0 10px; }
.scn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.scn-grid .scn {
  margin: 0; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer; display: flex; flex-direction: column;
}
.scn .t { font-weight: 700; font-size: 15px; }
.scn .d { font-size: 12px; color: var(--muted); }
.scn-custom { margin-top: 14px; }
.chat-opts { display: flex; gap: 12px; }
.chat-opts label { margin: 0; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.chat-scn { margin: 0 0 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-log { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.ai { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 16px; font-size: 17px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
.msg.ai .bubble { background: var(--card); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.me .bubble { background: var(--accent); color: var(--accent-text); border-top-right-radius: 4px; line-height: 1.6; }
.bubble rt { font-size: 10px; color: var(--muted); }
.no-ruby rt { display: none; }
.msg-tools { display: flex; gap: 6px; margin-top: 6px; }
.msg-tools .btn { min-height: 32px; }
.msg-zh { margin-top: 6px; font-size: 14px; }
.msg-words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-word { font-weight: 400; min-height: 32px; font-size: 13px; text-align: left; }
.chip-word b { margin-right: 4px; }
.chip-word .plus { color: var(--accent); margin-left: 4px; }
.fb { margin-top: 6px; font-size: 14px; }
.fb.good { color: var(--ok); font-size: 13px; }
.fb.fixed, .fb.translated { padding: 10px 12px; border-radius: 12px; text-align: left;
  background: color-mix(in srgb, var(--warn) 12%, transparent); }
.fb.translated { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.fb-label { font-size: 12px; color: var(--muted); }
.fb-ja { font-size: 16px; font-weight: 600; }
.fb-zh { color: var(--muted); margin-top: 2px; }
.chat-wait { margin-top: 12px; }
.chat-form { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 0 calc(8px + env(safe-area-inset-bottom)); background: var(--bg); margin-top: 12px; }
.chat-form textarea { flex: 1; min-height: 48px; max-height: 160px; }
.chat-form .btn { margin-top: 0; }

/* 快速筛选 */
.sc-table td, .sc-table th { padding: 8px 4px; }
.sc-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.sc-btns .btn { min-height: 64px; font-size: 18px; }
.sc-hint { text-align: center; margin: 0; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--text); font-weight: 600; cursor: pointer; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

/* 进度：同一个朱色由浅到深表示阶段（未学 → 学习中 → 熟练 → 已掌握） */
:root {
  --stage-known: var(--accent);
  --stage-mature: color-mix(in srgb, var(--accent) 62%, var(--card));
  --stage-learning: color-mix(in srgb, var(--accent) 30%, var(--card));
  --stage-rest: var(--line);
}
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px; }
.stat-n { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw-known, .seg-known { background: var(--stage-known); }
.sw-mature, .seg-mature { background: var(--stage-mature); }
.sw-learning, .seg-learning { background: var(--stage-learning); }
.sw-rest, .seg-rest { background: var(--stage-rest); }
.lv { margin-top: 14px; }
.lv-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stack { display: flex; gap: 2px; height: 14px; margin-top: 6px; }
.stack span { flex-basis: 0; min-width: 3px; }
.stack span:first-child { border-radius: 4px 0 0 4px; }
.stack span:last-child { border-radius: 0 4px 4px 0; }
.stack span:only-child { border-radius: 4px; }
.lv-nums { display: flex; flex-wrap: wrap; gap: 0 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.readout { min-height: 22px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--line); }
.bar-hit { flex: 1; height: 100%; display: flex; align-items: flex-end; padding: 0; border: 0;
  background: none; cursor: pointer; min-width: 0; }
.bar { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; }
.bar-hit.on .bar, .bar-hit:hover .bar { background: color-mix(in srgb, var(--accent) 70%, var(--text)); }
.bar-hit.on { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.bar-axis { display: flex; justify-content: space-between; margin-top: 4px; }
.fc-row { display: grid; grid-template-columns: 44px 1fr 40px; align-items: center; gap: 8px; margin: 6px 0; }
.fc-track { height: 12px; }
.fc-bar { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.fc-n { text-align: right; font-variant-numeric: tabular-nums; }

/* 朗读声音 */
.voice-list { display: flex; flex-direction: column; }
.voice-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 15px; cursor: pointer; }
.voice-row:last-child { border-bottom: 0; }
.voice-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.voice-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.voice-tip { margin-top: 12px; }

/* 练习：读出来 */
.pr-front-btns { display: grid; grid-template-columns: 1fr; gap: 8px; }
.pr-front-btns:has(#pr-mic:not([hidden])) { grid-template-columns: 1fr 1fr; }
.pr-front-btns .btn { margin: 0; }
#pr-mic.listening { border-color: var(--accent); color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { background: color-mix(in srgb, var(--accent) 12%, var(--card)); } }
@media (prefers-reduced-motion: reduce) { #pr-mic.listening { animation: none; } }
.pr-heard { margin: 0 0 12px; padding: 8px 12px; border-radius: 10px; font-size: 15px; }
.pr-heard.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pr-heard.ng { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.pr-tools { display: flex; gap: 8px; margin-top: 12px; }
.chat-opts { align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chat-opts .rate-btn { min-height: 30px; font-size: 13px; }
.voice-group { margin: 12px 0 0; font-weight: 600; }
.voice-group:first-child { margin-top: 0; }
