:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --surface-2: #efe8da;
  --text: #29251f;
  --muted: #736a5d;
  --line: #e2d9c8;
  --accent: #2b3557;
  --accent-text: #fffcf6;
  --gold: #b7862f;
  --gold-soft: #f1e2c2;
  --good: #3f7a4f;
  --danger: #a3402f;
  --shadow: 0 1px 2px rgb(60 45 20 / .06), 0 6px 20px rgb(60 45 20 / .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --surface: #1d2029;
    --surface-2: #262a35;
    --text: #ece6da;
    --muted: #a39b8d;
    --line: #2f3340;
    --accent: #e7b864;
    --accent-text: #1a1b20;
    --gold: #e7b864;
    --gold-soft: #3a3324;
    --good: #7cbf8c;
    --danger: #e38a78;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  max-width: 640px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; }
.brand img { border-radius: 7px; }
.net { font-size: .8rem; background: var(--surface-2); color: var(--muted); padding: 2px 10px; border-radius: 99px; }

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 24px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.eyebrow { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 10px 16px; cursor: pointer; text-decoration: none; font-weight: 550;
  min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; }
.linkish { background: none; border: 0; padding: 0; color: var(--gold); cursor: pointer; font-weight: 550; }

input[type=text], input[type=number] {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); min-height: 44px;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .3s; }

/* ---------- Player ---------- */
.session-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.now-title { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; margin: 6px 0 2px; }
.scrub { width: 100%; margin: 14px 0 2px; height: 28px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.scrub::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: linear-gradient(to right, var(--gold) var(--p, 0%), var(--surface-2) var(--p, 0%)); }
.scrub::-moz-range-track { height: 6px; border-radius: 99px; background: var(--surface-2); }
.scrub::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--gold); }
.scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--gold); border: 0; }
.scrub::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--gold); border: 0; }
.times { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 14px 0 6px; }
.ctrl {
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; position: relative;
}
.ctrl svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctrl .num { position: absolute; font-size: 9px; font-weight: 700; top: 19px; }
.ctrl.play { width: 76px; height: 76px; background: var(--accent); color: var(--accent-text); border: 0; }
.ctrl.play svg { width: 32px; height: 32px; fill: currentColor; stroke: none; }
.speed { font-variant-numeric: tabular-nums; font-weight: 650; font-size: .9rem; }

.chapters { list-style: none; margin: 0; padding: 0; }
.chapters li {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line);
}
.chapters li:first-child { border-top: 0; }
.chapters li.done { color: var(--muted); }
.chapters li.current { font-weight: 650; }
.chapters .dot {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; font-size: 12px;
}
.chapters li.done .dot { background: var(--good); border-color: var(--good); color: #fff; }
.chapters li.current .dot { border-color: var(--gold); background: var(--gold-soft); }
.chapters li button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; flex: 1; }
.chapters .dur { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.complete { text-align: center; padding: 28px 18px; }
.complete .btn { margin: 4px; }
.complete .big { font-size: 3rem; line-height: 1; margin-bottom: 8px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-family: var(--serif); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }

/* ---------- Plans ---------- */
.plan-item { display: block; text-decoration: none; }
.badge { font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--gold-soft); color: var(--text); white-space: nowrap; }
.badge.done { background: var(--good); color: #fff; }
.choices { display: grid; gap: 10px; }
.choice {
  display: block; text-align: left; width: 100%; cursor: pointer; padding: 14px 16px;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface);
}
.choice:hover { border-color: var(--gold); }
.choice[aria-pressed=true] { border-color: var(--gold); background: var(--gold-soft); }
.choice .t { font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px; padding: 8px 14px;
  cursor: pointer; font-weight: 550; min-height: 40px; font-variant-numeric: tabular-nums;
}
.chip[aria-pressed=true] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.books label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: .92rem; }
.books label:hover { background: var(--surface-2); }
.books input { width: 18px; height: 18px; accent-color: var(--gold); }
.sticky-foot {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.book-prog { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.book-prog .bar { grid-column: 1 / -1; height: 5px; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

/* ---------- Progress ---------- */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 14px; height: 14px; border-radius: 3px; background: var(--surface-2); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--gold) 35%, var(--surface-2)); }
.heat i.l2 { background: color-mix(in srgb, var(--gold) 65%, var(--surface-2)); }
.heat i.l3 { background: var(--gold); }
.heat i.future { visibility: hidden; }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { padding: 10px 0; border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }

/* ---------- Auth ---------- */
.hero { text-align: center; padding: 28px 8px 8px; }
.hero img { width: 88px; height: 88px; border-radius: 22px; box-shadow: var(--shadow); }
.hero h1 { margin-top: 16px; font-size: 2rem; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin-top: 8px; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; text-decoration: none; font-size: .72rem; color: var(--muted); font-weight: 600;
}
.tabs a.on { color: var(--text); }
.tabs a.on svg { stroke: var(--gold); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20;
  max-width: calc(100% - 32px); font-size: .92rem; box-shadow: var(--shadow);
}
.spinner { text-align: center; padding: 40px; color: var(--muted); }
