:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --ink: #1d2422;
  --muted: #6b716c;
  --line: #e2dccf;
  --accent: #1f3a34;
  --accent-ink: #f4efe6;
  --mark: #e0a43c;
  --again: #b5483b;
  --hard: #b07a2a;
  --good: #2f6b55;
  --easy: #2c5a85;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif", serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a18;
    --surface: #1e2522;
    --ink: #e9e4da;
    --muted: #9aa09a;
    --line: #2f3834;
    --accent: #cfe3d8;
    --accent-ink: #13201b;
    --mark: #e8b459;
    --again: #e07a6c;
    --hard: #d9a556;
    --good: #7cc4a2;
    --easy: #86b2dc;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}
.view { display: flex; flex-direction: column; gap: 16px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: baseline; justify-content: space-between; }
.top h1 { font: italic 600 28px/1 var(--serif); margin: 8px 0; color: var(--accent); }
.date { color: var(--muted); font-size: 14px; }

.hero { text-align: center; padding: 28px 0 12px; }
.hero-num { font: 600 72px/1 var(--serif); color: var(--accent); font-variant-numeric: tabular-nums; }
.hero-label { color: var(--muted); margin-top: 8px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; display: flex; flex-direction: column;
}
.tile b { font: 600 24px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }

.btn {
  font: 500 16px/1 var(--sans); border-radius: 12px; padding: 14px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn kbd {
  font: 12px/1 ui-monospace, monospace; opacity: .55; border: 1px solid currentColor;
  border-radius: 4px; padding: 2px 4px;
}
@media (pointer: coarse) { .btn kbd { display: none; } }

.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; min-width: 40px; min-height: 40px;
}
.bar { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px 20px; position: relative; min-height: 260px;
}
.badge {
  position: absolute; top: 14px; right: 14px; font-size: 12px; color: var(--mark);
  border: 1px solid var(--mark); border-radius: 999px; padding: 1px 8px;
}
.word-row { display: flex; align-items: center; gap: 4px; }
.word { font: 600 40px/1.15 var(--serif); margin: 0; word-break: break-word; }
.phonetic { color: var(--muted); font-family: var(--serif); min-height: 1.4em; }
.sentence { font: 20px/1.55 var(--serif); margin: 20px 0 0; }
.sentence mark { background: none; color: inherit; box-shadow: inset 0 -0.38em 0 color-mix(in srgb, var(--mark) 45%, transparent); }
.sentence .say { font-size: 15px; vertical-align: middle; }
.back { border-top: 1px dashed var(--line); margin-top: 20px; padding-top: 16px; }
.trans { white-space: pre-line; font-size: 17px; }
.trans .dim { color: var(--muted); font-size: 14px; }
.sentence-zh { color: var(--muted); margin: 12px 0 0; }
.meta { color: var(--muted); font-size: 12px; margin-top: 12px; }

.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
.actions .wide { flex: 1; }
.rate .btn { flex-direction: column; gap: 4px; font-size: 15px; padding: 10px 4px; }
.rate .r1 { color: var(--again); }
.rate .r2 { color: var(--hard); }
.rate .r3 { color: var(--good); }
.rate .r4 { color: var(--easy); }

.done { text-align: center; padding: 40px 0; }
.done h2 { font: 600 32px var(--serif); color: var(--accent); }

.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.center { text-align: center; }
#t-ask { display: flex; flex-direction: column; gap: 12px; padding-top: 40px; }
#t-ask .word { font-size: 48px; }
#t-ask .trans { min-height: 3em; }
.center-row { justify-content: center; }
.t-sent { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 12px; }
.t-sent .sentence { font-size: 18px; margin-top: 12px; }

.bands { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.band { display: grid; grid-template-columns: 92px 1fr 40px; align-items: center; gap: 8px; color: var(--muted); }
.band .track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.band .track i { display: block; height: 100%; background: var(--accent); }
.band .pct { text-align: right; font-variant-numeric: tabular-nums; }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.chip {
  font: 16px/1.2 var(--serif); padding: 12px 4px; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); hyphens: auto; overflow-wrap: anywhere;
}
.chip.unknown {
  border-color: var(--again); color: var(--again);
  background: color-mix(in srgb, var(--again) 10%, var(--surface));
}
.btn small { color: var(--muted); font-size: 12px; }

textarea {
  font: 15px/1.5 var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; resize: vertical; width: 100%;
}
.sources { display: flex; flex-direction: column; gap: 8px; }
.source {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  color: var(--ink); font: inherit; cursor: pointer;
}
.source .t { font-family: var(--serif); font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source .m { color: var(--muted); font-size: 12px; grid-column: 1; }
.source .cov { grid-row: 1 / span 2; grid-column: 2; font: 600 18px var(--serif); font-variant-numeric: tabular-nums; }
.cov.good { color: var(--good); }
.cov.ok { color: var(--hard); }
.cov.hard { color: var(--again); }

.a-title { font: 600 26px/1.3 var(--serif); margin: 0; }
.prelearn { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.prelearn summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.nw { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.nw:first-child { border-top: none; }
.nw .l { font: 17px var(--serif); }
.nw .b { display: block; color: var(--muted); font: 13px var(--sans); }
.nw .btn { min-height: 36px; padding: 8px 10px; font-size: 13px; }

.article { font: 19px/1.75 var(--serif); }
.article p { margin: 0 0 1em; }
.article .w { cursor: pointer; border-radius: 3px; }
.article .w.new { text-decoration: underline dotted var(--again) 2px; text-underline-offset: 4px; }
.article .w.learning { background: color-mix(in srgb, var(--mark) 22%, transparent); }
.article .w.active { outline: 2px solid var(--accent); }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgb(0 0 0 / .12); border-radius: 18px 18px 0 0;
}
.sheet-inner {
  max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom)); max-height: 60dvh; overflow-y: auto;
}
.word.sm { font-size: 28px; }
.sheet .actions { display: grid; grid-template-columns: 1fr 1fr; }
.sheet .close { margin-left: auto; }
.status-tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.explain { border-left: 3px solid var(--mark); padding: 4px 0 4px 12px; font-size: 15px; }
.explain b { font-size: 17px; }
.explain .zh { color: var(--muted); margin-top: 6px; }
body.sheet-open #app { padding-bottom: 50dvh; }

.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.field input {
  font: 16px var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 48px;
}
.date { display: inline-flex; align-items: center; gap: 4px; }
.sync {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--hard); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 10px; z-index: 5;
}

.modes { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.mode {
  flex: none; font: 14px var(--sans); padding: 8px 12px; border-radius: 999px; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
.mode.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.task { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.task .tw { display: inline-block; margin: 4px 8px 0 0; }
.task .tw b { font: 17px var(--serif); }
.task .tw span { color: var(--muted); font-size: 12px; margin-left: 4px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.review { display: flex; flex-direction: column; gap: 12px; }
.review section { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.review h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.review .prose { font: 18px/1.6 var(--serif); margin: 0; }
.edit { padding: 8px 0; border-top: 1px solid var(--line); }
.edit:first-of-type { border-top: none; padding-top: 0; }
.edit del { color: var(--again); text-decoration-thickness: 1px; font-family: var(--serif); }
.edit ins { color: var(--good); text-decoration: none; font-family: var(--serif); font-weight: 600; }
.edit .why { color: var(--muted); font-size: 14px; margin-top: 2px; }
.tag { font-size: 11px; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-right: 6px; color: var(--muted); }
.wc { padding: 4px 0; font-size: 14px; }
.wc .ok { color: var(--good); }
.wc .bad { color: var(--again); }
.hist {
  display: block; width: 100%; text-align: left; background: none; border: none; border-top: 1px solid var(--line);
  padding: 10px 0; color: var(--ink); font: inherit; cursor: pointer;
}
.hist small { color: var(--muted); display: block; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.shadow-card { min-height: 0; }
.shadow-card .sentence { margin-top: 12px; }
.sentence .bad { color: var(--again); text-decoration: underline wavy var(--again) 1px; text-underline-offset: 4px; cursor: pointer; }
.sentence .good { color: var(--good); }
.sh-result { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; font-size: 14px; color: var(--muted); }
.sh-result .score { font: 600 32px var(--serif); color: var(--accent); margin-right: 6px; }
.btn.rec { min-height: 64px; font-size: 18px; border-radius: 999px; background: var(--surface); border: 2px solid var(--accent); color: var(--accent); }
.btn.rec.on { background: var(--again); border-color: var(--again); color: #fff; }
.btn.rec.small { min-height: 48px; min-width: 48px; padding: 0; font-size: 20px; }
.btn:disabled { opacity: .45; cursor: default; }

.chat { display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; font: 17px/1.5 var(--serif); }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg .say { font-size: 14px; }
.fix { align-self: flex-end; max-width: 88%; font-size: 14px; border-left: 3px solid var(--mark); padding: 4px 0 4px 10px; }
.fix b { font-family: var(--serif); font-size: 16px; }
.fix div { color: var(--muted); }
.talk-input { display: flex; gap: 8px; align-items: center; }
.talk-input input {
  flex: 1; min-width: 0; font: 16px var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 48px;
}

.ph-group h3 { font-size: 13px; color: var(--muted); font-weight: 500; margin: 8px 0; }
.ph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.ph {
  font: 22px/1 var(--serif); padding: 14px 0; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
.ph.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ph-detail { min-height: 0; padding: 16px; }
.ph-detail .sym { font: 600 40px var(--serif); color: var(--accent); }
.ph-detail .exs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ph-detail .exs .btn { min-height: 40px; padding: 8px 12px; font-family: var(--serif); }
.phon-big { font: 36px/1.3 var(--serif); text-align: center; padding: 24px 0 8px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opts .btn, #mp-opts .btn { font-family: var(--serif); font-size: 18px; flex-direction: column; gap: 2px; }
.opts .btn small, #mp-opts .btn small { font-size: 13px; color: var(--muted); }
.btn.right { border-color: var(--good); color: var(--good); }
.btn.wrong { border-color: var(--again); color: var(--again); }

.roots { margin-top: 12px; font-size: 14px; }
.roots .parts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.roots .part { border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; background: var(--bg); }
.roots .part b { font: 16px var(--serif); margin-right: 4px; }
.roots .part.root { border-color: var(--mark); }
.roots .plus { color: var(--muted); }
.roots .logic { margin-top: 6px; }
.roots .rel { color: var(--muted); margin-top: 4px; }
.ph.m { font-size: 16px; padding: 12px 4px; }
.rt-ex { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.rt-ex .l { font: 17px var(--serif); cursor: pointer; }
.rt-ex .b { display: block; color: var(--muted); font: 13px var(--sans); }
.rt-ex .btn { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.st { font-size: 11px; border-radius: 999px; padding: 0 6px; margin-left: 6px; border: 1px solid var(--line); color: var(--muted); }
.st.known { color: var(--good); border-color: var(--good); }
.st.learning { color: var(--hard); border-color: var(--hard); }

.hint { color: var(--muted); font-size: 14px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px);
}
