:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --ink: #2a2622;
  --muted: #7a7064;
  --line: #e4dccd;
  --accent: #b5552b;
  --accent-soft: #f3dccd;
  --phrase: #e9e2c4;
  --good: #3f7d4e;
  --hard: #b0852a;
  --again: #b5403a;
  --read-size: 19px;
  --serif: "Literata", "Georgia", "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Noto Sans SC", "PingFang SC", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #25231f;
    --ink: #e8e2d6;
    --muted: #9c9385;
    --line: #37342e;
    --accent: #e0875a;
    --accent-soft: #4a3226;
    --phrase: #3a3622;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar h1 {
  flex: 1; margin: 0; font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-actions { display: flex; gap: 4px; }
.icon-btn {
  min-width: 40px; height: 40px; padding: 0 10px;
  border: 0; background: none; border-radius: 10px; font-size: 22px; line-height: 1;
}
.icon-btn:active { background: var(--line); }
.icon-btn.small { font-size: 15px; }

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

/* Shelf */
.install-banner {
  display: block; width: 100%; padding: 14px 16px; margin-bottom: 12px; text-align: left;
  border: 1.5px solid var(--accent); border-radius: 14px; background: var(--accent-soft); color: var(--accent);
  font-size: 16px; font-weight: 600;
}
.install-banner small { display: block; font-weight: 400; font-size: 12px; margin-top: 2px; }
.review-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 16px; margin-bottom: 20px;
  border: 0; border-radius: 14px; text-align: left;
  background: var(--accent); color: #fff;
}
.review-banner.empty { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.review-banner strong { font-size: 28px; font-weight: 700; }
.section-label { font-size: 13px; color: var(--muted); margin: 24px 4px 8px; letter-spacing: .04em; }
.book {
  display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.book .t { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.book .o { color: var(--muted); font-size: 14px; margin-top: 2px; }
.book .meta { color: var(--muted); font-size: 12px; margin-top: 8px; display: flex; gap: 10px; }
.lang-tag { background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.ghost-btn {
  width: 100%; padding: 14px; border-radius: 14px; background: none;
  border: 1.5px dashed var(--line); color: var(--muted);
}
.note { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 16px 4px; }

/* Chapter list */
.chapters button {
  display: flex; justify-content: space-between; width: 100%; padding: 14px 4px;
  background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left;
}
.chapters .o { color: var(--muted); font-size: 14px; }

/* Reading */
.reading { font-family: var(--serif); font-size: var(--read-size); line-height: 1.75; }
.reading h2 { font-size: 1.3em; margin: 8px 0 4px; }
.reading .ch-orig { color: var(--muted); font-family: var(--sans); font-size: 14px; margin-bottom: 24px; }
.para { margin: 0 0 1.1em; }
.w { cursor: pointer; border-radius: 4px; transition: background .12s; }
.w.known { text-decoration: underline dotted var(--accent) 1.5px; text-underline-offset: 4px; }
.w.sel { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.w.ph-sel { background: var(--phrase); }
.orig-btn {
  display: inline-block; margin-left: 6px; padding: 0 8px; vertical-align: 2px;
  font-family: var(--sans); font-size: 12px; line-height: 20px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted);
}
.orig-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.orig {
  margin: 8px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 10px 10px 0;
  font-family: var(--sans); font-size: 16px; line-height: 1.8; color: var(--ink);
}
.ch-nav { display: flex; gap: 10px; margin-top: 32px; font-family: var(--sans); }
.ch-nav button {
  flex: 1; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.ch-nav button:disabled { opacity: .4; }

/* Word sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 9; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-width: 680px; margin: 0 auto;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgb(0 0 0 / .12);
  animation: up .16s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet .head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sheet .word { font-family: var(--serif); font-size: 26px; font-weight: 600; }
.sheet .lemma { color: var(--muted); font-size: 14px; }
.sheet .meaning { font-size: 18px; margin: 8px 0 4px; line-height: 1.5; }
.sheet .phrase { margin-top: 12px; padding: 10px 12px; background: var(--phrase); border-radius: 10px; font-size: 15px; line-height: 1.5; }
.sheet .phrase b { font-family: var(--serif); }
.sheet .row { display: flex; gap: 8px; margin-top: 14px; }
.pill {
  padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line); background: none; font-size: 14px;
}
.pill.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Review */
.rv-progress { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 16px; }
.rv-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px 20px; min-height: 300px;
}
.rv-sentence { font-family: var(--serif); font-size: 20px; line-height: 1.7; }
.rv-sentence mark { background: var(--accent-soft); color: inherit; padding: 0 3px; border-radius: 4px; font-weight: 600; }
.rv-hint { color: var(--muted); font-size: 14px; margin-top: 24px; text-align: center; }
.rv-answer { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--line); }
.rv-answer .meaning { font-size: 20px; margin: 6px 0; }
.rv-answer .lemma { color: var(--muted); font-size: 14px; }
.rv-answer .orig { margin-top: 14px; font-size: 15px; }
.rv-actions { display: flex; gap: 10px; margin-top: 18px; }
.rv-actions button {
  flex: 1; padding: 16px 0; border: 0; border-radius: 14px; font-size: 16px; font-weight: 600; color: #fff;
}
.rv-actions .show { background: var(--ink); color: var(--bg); }
.rv-actions .again { background: var(--again); }
.rv-actions .hard { background: var(--hard); }
.rv-actions .good { background: var(--good); }
.rv-actions small { display: block; font-weight: 400; font-size: 11px; opacity: .85; margin-top: 2px; }
.done { text-align: center; padding: 48px 0; }
.done .big { font-size: 48px; }

/* Settings */
.setting { display: flex; align-items: center; justify-content: space-between; padding: 16px 4px; border-bottom: 1px solid var(--line); gap: 16px; }
.setting small { display: block; color: var(--muted); margin-top: 2px; }

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