/* Campfire — night-reading palette, ember accent, bookish serif for titles. */
:root {
  --bg: #161a2e;          /* night ink */
  --surface: #1f2440;
  --surface-2: #2a3052;
  --text: #eceaf5;
  --muted: #a4a6c2;
  --line: rgb(236 234 245 / .1);
  --ember: #f0a04b;
  --ember-ink: #2b1904;   /* text on ember */
  --danger: #ff8a7a;
  --book: #3a4170;        /* replaced per book from its cover */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Noto Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --radius-cover: 6px;
  --radius-panel: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f1f7;
    --surface: #ffffff;
    --surface-2: #e6e5ef;
    --text: #1c1f33;
    --muted: #5b5e7c;
    --line: rgb(28 31 51 / .1);
    --ember: #b4600f;
    --ember-ink: #ffffff;
    --danger: #b3261e;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
img { display: block; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; border-radius: 6px; }

.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: .95rem; cursor: pointer; white-space: nowrap;
  background: var(--surface-2);
}
.btn .icon { width: 20px; height: 20px; }
.btn.primary { background: var(--ember); color: var(--ember-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.large { min-height: 52px; padding: 0 24px; font-size: 1.05rem; }
.btn:hover { filter: brightness(1.08); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--line); }

/* ---------- library ---------- */
#app { max-width: 1120px; margin: 0 auto; padding: 0 16px calc(120px + var(--safe-b)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 4px 14px;
}
.wordmark { display: flex; align-items: center; gap: 8px; font: 600 1.4rem/1 var(--serif); letter-spacing: -.01em; }
.wordmark .flame { color: var(--ember); width: 26px; height: 26px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 420px) {
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 40px; padding: 0; }
}

.empty { max-width: 34rem; margin: 12vh auto 0; text-align: center; display: grid; justify-items: center; gap: 16px; }
.empty-flame { width: 64px; height: 64px; color: var(--ember); stroke-width: 1.2; }
.empty h1 { font: 600 1.75rem/1.2 var(--serif); }
.empty p { color: var(--muted); }
.hint { font-size: .9rem; }
@media (hover: none) { .desktop-only { display: none; } }

.current {
  display: grid; grid-template-columns: 116px 1fr; gap: 18px; align-items: center;
  padding: 16px; margin: 4px 0 32px; border-radius: var(--radius-panel);
  background: color-mix(in oklab, var(--book) 30%, var(--surface));
}
.current .cover { width: 116px; }
.current-text { display: grid; gap: 4px; min-width: 0; }
.current-label { color: var(--muted); font-size: .85rem; }
.current-title { font: 600 1.35rem/1.2 var(--serif); }
.current-chapter { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current .btn { justify-self: start; margin-top: 8px; }
@media (min-width: 700px) {
  .current { grid-template-columns: 160px 1fr; gap: 28px; padding: 20px; }
  .current .cover { width: 160px; }
  .current-title { font-size: 1.7rem; }
}

.section-title { font: 600 1.15rem/1.3 var(--serif); margin: 0 0 14px; }
.shelf {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 24px 16px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
@media (max-width: 380px) { .shelf { grid-template-columns: 1fr 1fr; } }
.card { position: relative; display: grid; gap: 6px; }
.card-open { all: unset; cursor: pointer; display: grid; gap: 8px; border-radius: var(--radius-cover); }
.card-open:focus-visible { outline: 2px solid var(--ember); outline-offset: 3px; }
.card-title { font: 600 .98rem/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: .82rem; }
.card.off .cover { filter: grayscale(.85) brightness(.6); }
.card.off .card-title { color: var(--muted); }
.sub-note { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.card-more {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px;
  background: rgb(10 12 24 / .55); color: #fff; backdrop-filter: blur(6px);
}
.card-more .icon { width: 20px; height: 20px; }

.cover { position: relative; width: 100%; aspect-ratio: 1; border-radius: var(--radius-cover); overflow: hidden; background: var(--book); box-shadow: 0 6px 18px rgb(0 0 0 / .25); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback {
  position: absolute; inset: 0; display: grid; align-content: end; padding: 12% 10%;
  background: linear-gradient(160deg, color-mix(in oklab, var(--book) 75%, white), var(--book));
  color: #fff; font: 600 clamp(.8rem, 4cqi, 1.6rem)/1.15 var(--serif); container-type: inline-size;
  text-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
.bar { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ember); }

/* ---------- mini player ---------- */
.mini {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b));
  width: min(640px, calc(100% - 24px)); z-index: 10;
  display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 6px;
  border-radius: 14px; overflow: hidden;
  background: color-mix(in oklab, var(--surface-2) 88%, transparent); backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgb(0 0 0 / .3);
}
.mini-open { all: unset; cursor: pointer; display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; border-radius: 10px; }
.mini-open:focus-visible { outline: 2px solid var(--ember); }
.mini img { width: 46px; height: 46px; border-radius: 4px; object-fit: cover; background: var(--book); }
.mini-text { display: grid; min-width: 0; }
.mini-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mini-title { font: 600 .95rem/1.3 var(--serif); }
#mini-chapter { color: var(--muted); font-size: .82rem; }
.mini-toggle .icon { width: 26px; height: 26px; }
.mini-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--line); }
.mini-progress > span { display: block; height: 100%; width: 0; background: var(--ember); }

/* ---------- player ---------- */
.player {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg);
  padding: max(8px, env(safe-area-inset-top)) 16px calc(20px + var(--safe-b));
}
.player-wash {
  position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 70% at 50% 0%, color-mix(in oklab, var(--book) 70%, transparent), transparent 70%),
    linear-gradient(var(--bg), var(--bg));
  opacity: .9; z-index: -1;
}
.player > * { position: relative; }
.player-top { display: flex; align-items: center; justify-content: space-between; max-width: 1040px; margin: 0 auto; }
.cast-badge { font-size: .85rem; padding: 4px 12px; border-radius: 999px; background: color-mix(in srgb, var(--ember) 22%, transparent); color: var(--text); }
.player-body {
  max-width: 460px; margin: 0 auto; display: grid; gap: clamp(12px, 2.4vh, 22px); justify-items: center;
  padding-top: clamp(0px, 1.5vh, 20px);
}
.art { position: relative; width: min(100%, 36vh, 400px); aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--book); box-shadow: 0 24px 60px rgb(0 0 0 / .45); }
.art img { width: 100%; height: 100%; object-fit: cover; }
.art .cover-fallback { font-size: 2rem; }
.deck { width: 100%; display: grid; gap: clamp(8px, 1.6vh, 14px); }
.titles { text-align: center; display: grid; gap: 4px; }
#p-title { font: 600 1.5rem/1.2 var(--serif); letter-spacing: -.01em; text-wrap: balance; }
#p-author { color: var(--muted); }
.chapter-name {
  justify-self: center; max-width: 100%; border: 0; background: transparent; cursor: pointer;
  font-weight: 600; padding: 4px 10px; border-radius: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chapter-name:hover { background: var(--line); }

/* scrubber */
.scrub input { width: 100%; margin: 0; height: 28px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; --p: 0%; }
.scrub input::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--text) var(--p), var(--line) var(--p)); }
.scrub input::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--text) var(--p), var(--line) var(--p)); }
.scrub input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--text); border: 0; }
.scrub input::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--text); border: 0; }
.scrub-times { display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; margin-top: -2px; }

/* chapter ribbon: every chapter drawn to scale; the current one is lit */
.ribbon-wrap { display: grid; gap: 8px; }
.ribbon { display: flex; gap: 2px; height: 14px; align-items: center; cursor: pointer; touch-action: none; }
.ribbon > span { flex: var(--w) 1 0; min-width: 3px; height: 6px; border-radius: 2px; background: var(--line); transition: height .2s; }
.ribbon > .done { background: color-mix(in srgb, var(--text) 38%, transparent); }
.ribbon > .now { height: 14px; background: linear-gradient(to right, var(--ember) var(--p), color-mix(in srgb, var(--ember) 30%, transparent) var(--p)); }
.book-left { text-align: center; color: var(--muted); font-size: .85rem; }

.transport { display: flex; align-items: center; justify-content: space-between; max-width: 380px; width: 100%; margin: 4px auto 0; }
.transport .icon-btn { width: 52px; height: 52px; }
.transport .icon-btn .icon { width: 28px; height: 28px; }
.skip { position: relative; }
.skip .icon { width: 38px !important; height: 38px !important; stroke-width: 1.6; }
.skip-n { position: absolute; inset: 0; display: grid; place-items: center; font-size: .72rem; font-weight: 700; padding-top: 2px; }
.play {
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--ember); color: var(--ember-ink);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--ember) 35%, transparent);
}
.play .icon { width: 34px; height: 34px; }
.play:active { transform: scale(.96); }

.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 6px; }
.tool {
  display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 60px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; color: var(--muted); font-size: .75rem;
}
.tool:hover { background: var(--line); color: var(--text); }
.tool .icon { width: 22px; height: 22px; }
.tool.on { color: var(--ember); }
.tool-value { font-weight: 700; font-size: .95rem; color: var(--text); height: 22px; display: grid; place-items: center; }

@media (min-width: 900px) {
  .player-body { max-width: 1040px; grid-template-columns: 1fr 1fr; gap: 56px; align-items: center; padding-top: 6vh; }
  .art { width: min(100%, 70vh, 460px); justify-self: end; }
  .deck { max-width: 440px; }
}

/* ---------- sheet ---------- */
.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: 100%; max-width: 560px; max-height: 85dvh;
  margin: auto auto 0; border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgb(0 0 0 / .35);
}
.sheet::backdrop { background: rgb(6 8 18 / .55); }
.sheet[open] { animation: sheet-in .22s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet-inner { display: flex; flex-direction: column; max-height: 85dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font: 600 1.2rem/1.3 var(--serif); }
.sheet-body { overflow-y: auto; padding: 4px 20px calc(20px + var(--safe-b)); display: grid; gap: 16px; }
.sheet-body h3 { font-size: .9rem; color: var(--muted); font-weight: 600; margin-top: 4px; }
.sheet-body p { color: var(--muted); }
.sheet-body a { color: var(--ember); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--ember); color: var(--ember-ink); border-color: var(--ember); }
.big-readout { font: 600 2.6rem/1 var(--serif); text-align: center; font-variant-numeric: tabular-nums; }
.range { width: 100%; accent-color: var(--ember); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.list { list-style: none; margin: 0 -8px; padding: 0; display: grid; }
.list-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; width: 100%;
  text-align: left; padding: 10px 8px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
}
.list-item:hover { background: var(--line); }
.list-item .main { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { grid-column: 1; color: var(--muted); font-size: .82rem; }
.list-item .side { grid-row: 1 / span 2; grid-column: 2; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.list-item.now .main { color: var(--ember); font-weight: 700; }
.list-item.played .main { color: var(--muted); }
.bookmark-row { display: grid; grid-template-columns: 1fr auto; align-items: center; }

.field { display: grid; gap: 6px; }
.field input[type="text"], .field input[type="number"], .field textarea {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--ember); flex: none; }
.output-option {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; width: 100%; text-align: left;
  padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: transparent; cursor: pointer;
}
.output-option[disabled] { cursor: default; opacity: .7; }
.output-option .sub { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.output-option.on { border-color: var(--ember); }
.output-option .state { color: var(--ember); font-size: .85rem; font-weight: 600; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.description { white-space: pre-line; max-height: 40vh; overflow: auto; }
.tip-links { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- overlays ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + var(--safe-b)); z-index: 40;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: .92rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / .3);
}
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }
.importing {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40;
  display: grid; gap: 8px; width: min(420px, calc(100% - 32px));
  padding: 12px 16px; border-radius: 12px; background: var(--surface-2); box-shadow: 0 10px 30px rgb(0 0 0 / .3); font-size: .9rem;
}
.importing-bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
#importing-fill { display: block; height: 100%; width: 0; background: var(--ember); transition: width .2s; }
.drop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent); border: 3px dashed var(--ember);
  font: 600 1.4rem var(--serif); pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
