:root {
  --bg: #f6efe6;
  --surface: #fffaf4;
  --surface-2: #efe5d8;
  --text: #2b2126;
  --muted: #7a6a6f;
  --line: #e3d6c6;
  --accent: #b5473a;
  --accent-ink: #ffffff;
  --accent-soft: #f3d9d2;
  --hl: #fbe7c6;
  --shadow: 0 10px 30px rgba(80, 40, 30, .10);
  --radius: 20px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1719;
    --surface: #272023;
    --surface-2: #33292d;
    --text: #f2e9e4;
    --muted: #b3a3a6;
    --line: #3d3236;
    --accent: #e0796a;
    --accent-ink: #1c1719;
    --accent-soft: #4a2d2a;
    --hl: #4a3a24;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    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);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 0; padding-top: max(16px, env(safe-area-inset-top)); }

/* ---------- player card ---------- */
.player {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
}
.player-head { display: flex; gap: 14px; align-items: center; }
.cover { width: 84px; height: 84px; border-radius: 14px; object-fit: cover; flex: none; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.meta { min-width: 0; }
.book-title { font-size: 13px; color: var(--muted); letter-spacing: .02em; }
.part { font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; margin-top: 2px; }
.chapter { font: 600 21px/1.25 var(--serif); margin: 4px 0 0; overflow-wrap: anywhere; }

.seek { margin-top: 16px; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; margin: 0; cursor: pointer;
  --p: 0%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--surface-2) var(--p));
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-2); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); margin-top: -6px; border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); }
.times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -2px; }

.controls { display: flex; align-items: center; justify-content: space-between; margin: 8px auto 6px; max-width: 380px; }
.ctl {
  position: relative; width: 52px; height: 52px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; touch-action: manipulation;
}
.ctl svg { width: 28px; height: 28px; fill: var(--text); }
.ctl:active { background: var(--surface-2); }
.ctl-num { position: absolute; font-size: 9px; font-weight: 700; top: 55%; left: 50%; transform: translate(-50%, -50%); }
.ctl.play { width: 76px; height: 76px; background: var(--accent); box-shadow: 0 8px 20px rgba(181, 71, 58, .35); }
.ctl.play svg { width: 36px; height: 36px; fill: var(--accent-ink); }
.ctl.play:active { transform: scale(.96); background: var(--accent); }
.i-pause { display: none; }
.playing .i-play { display: none; }
.playing .i-pause { display: block; }
.spinner { display: none; position: absolute; inset: -4px; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--accent); animation: spin 1s linear infinite; }
.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.row-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; cursor: pointer; touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}
.pill svg { width: 16px; height: 16px; fill: currentColor; }
.pill.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }

.book-progress { margin-top: 14px; }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); opacity: .55; transition: width .4s; }
.bp-text { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }

/* ---------- tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; margin: 18px -16px 0; padding: 8px 16px;
  background: var(--bg);
}
.tab {
  flex: 1; height: 40px; border: 0; border-radius: 12px; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.tab[aria-selected=true] { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.panel { padding-top: 6px; }

/* ---------- chapters ---------- */
.chapters { list-style: none; margin: 0; padding: 0; }
.part-h { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 700; margin: 18px 4px 6px; }
.ch {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; width: 100%;
  padding: 12px 12px; border: 0; border-radius: 14px; background: transparent; text-align: left; cursor: pointer;
}
.ch:active { background: var(--surface-2); }
.ch.current { background: var(--surface); box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.ch-ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: var(--muted); background: var(--surface-2); }
.ch.current .ch-ico { background: var(--accent); color: var(--accent-ink); }
.ch.done .ch-ico { background: var(--accent-soft); color: var(--accent); }
.ch-ico svg { width: 14px; height: 14px; fill: currentColor; }
.ch-title { font: 500 16px/1.3 var(--serif); overflow-wrap: anywhere; }
.ch-sub { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; }
.ch-bar { flex: 0 0 60px; height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.ch-bar > div { height: 100%; background: var(--accent); }
.ch-dur { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- reader ---------- */
.text-tools { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.font-size { display: flex; gap: 4px; }
.icon-btn.dl { display: inline-flex; align-items: center; text-decoration: none; color: var(--muted); font-size: 13px; margin-left: auto; margin-right: 4px; }
.reader { --fs: 19px; font: var(--fs)/1.65 var(--serif); padding: 4px 4px 40px; }
.reader p { margin: 0 0 .9em; padding: 4px 8px; margin-left: -8px; margin-right: -8px; border-radius: 8px; cursor: pointer; transition: background .3s; }
.reader p.h { font-weight: 700; font-size: 1.1em; margin-top: 1.2em; }
.reader p.now { background: var(--hl); }
.reader .no-sync p { cursor: default; }

/* ---------- bookmarks ---------- */
.marks { list-style: none; margin: 0; padding: 0; }
.mark { display: flex; gap: 8px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--surface); margin-bottom: 8px; }
.mark-main { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 0; cursor: pointer; }
.mark-h { font-size: 13px; color: var(--accent); font-weight: 600; }
.mark-note { font-weight: 600; margin-top: 2px; }
.mark-snip { font: 15px/1.4 var(--serif); color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

.icon-btn { min-width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; padding: 0 8px; }

.foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; padding: 30px 4px 20px; }
.foot a { color: var(--muted); }

/* ---------- mini player ---------- */
.mini {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); box-shadow: 0 -6px 20px rgba(0,0,0,.10);
}
.mini-play { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: var(--accent); display: grid; place-items: center; cursor: pointer; }
.mini-play svg { width: 24px; height: 24px; fill: var(--accent-ink); }
.mini-info { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 0; cursor: pointer; }
.mini-title { display: block; font: 600 15px/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-time { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-bar { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--surface-2); }
.mini-bar > div { height: 100%; width: 0; background: var(--accent); }

/* ---------- in-app browser banner ---------- */
.iab { background: #2b2126; color: #fff; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); font-size: 14px; display: flex; flex-direction: column; gap: 10px; }
.iab-actions { display: flex; gap: 8px; align-items: center; }
.iab .icon-btn { margin-left: auto; background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.btn-small { height: 34px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 14px; display: inline-flex; align-items: center; text-decoration: none; cursor: pointer; }
.btn-small.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }

/* ---------- sheet ---------- */
.sheet { border: 0; border-radius: 20px; padding: 18px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(0,0,0,.35); }
.sheet h2 { margin: 0 0 12px; font: 600 19px var(--serif); }
.sheet-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.sheet-body .pill { justify-content: center; height: auto; min-height: 44px; padding: 8px 10px; line-height: 1.2; text-align: center; }
.sheet form > .btn-small { width: 100%; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sync { font-size: 12px; }

@media (min-width: 640px) {
  .cover { width: 112px; height: 112px; }
  .chapter { font-size: 25px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
