/* ============================================================
   The Story Player — a warm, paper-and-ink reading room.
   ============================================================ */
:root {
  --paper:    #f5efe3;
  --paper-2:  #efe7d7;
  --ink:      #211d17;
  --ink-soft: #5b5346;
  --ink-faint:#8b8172;
  --line:     #ddd3c0;
  --accent:   #b23a2e;   /* oxblood / record-label red */
  --accent-2: #8a2d24;
  --gold:     #a8791f;
  --shadow:   rgba(40,32,20,0.14);
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper:    #17140f;
    --paper-2:  #1f1b15;
    --ink:      #ece3d2;
    --ink-soft: #b3a894;
    --ink-faint:#7d7360;
    --line:     #322c22;
    --accent:   #e0674f;
    --accent-2: #c9503a;
    --gold:     #d3a24a;
    --shadow:   rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 22px calc(96px + env(safe-area-inset-bottom));
  padding-top: max(18px, env(safe-area-inset-top));
}

/* ---------- Views ---------- */
.view { display: none; animation: fade .3s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Masthead ---------- */
.masthead { padding: 26px 0 20px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.masthead.small { padding: 18px 0 14px; }
.mast-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.gear-btn {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: var(--paper-2); border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 19px; cursor: pointer; margin-top: 4px;
  display: flex; align-items: center; justify-content: center;
}
.gear-btn:active { transform: scale(.95); }

/* ---------- Settings sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,16,10,0.55); backdrop-filter: blur(2px); }
.sheet-card {
  position: relative; width: 100%; max-width: 560px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 22px 22px calc(28px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px -12px var(--shadow);
  animation: sheetUp .25s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sheet-title { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.sheet-close {
  width: 36px; height: 36px; border-radius: 50%; background: var(--paper-2);
  border: 1px solid var(--line); color: var(--ink-soft); font-size: 15px; cursor: pointer;
}
.sheet-close:active { transform: scale(.95); }
.wordmark {
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05;
}
.masthead.small .wordmark { font-size: 24px; }
.tagline { font-family: var(--sans); font-size: 12.5px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); margin-top: 8px; }

/* ---------- Feature card (home) ---------- */
.feature-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 24px 28px;
  box-shadow: 0 10px 30px -18px var(--shadow);
  position: relative;
  overflow: hidden;
}
.feature-card::before {
  /* faint record-groove arc in the corner */
  content: ""; position: absolute; top: -70px; right: -70px;
  width: 190px; height: 190px; border-radius: 50%;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 12px transparent, inset 0 0 0 10px transparent,
              0 0 0 24px var(--paper), inset 0 0 0 20px var(--paper);
  opacity: .5; pointer-events: none;
}
.kicker { font-family: var(--sans); font-size: 11.5px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--accent); font-weight: 700; }
.feature-title { font-size: 33px; line-height: 1.08; margin: 12px 0 6px; letter-spacing: -0.02em; }
.feature-meta { font-family: var(--sans); font-size: 13px; color: var(--ink-faint);
  letter-spacing: 0.02em; margin-bottom: 14px; }
.feature-dek { font-size: 18px; color: var(--ink-soft); margin: 0 0 24px; max-width: 34em; }

.big-play {
  display: inline-flex; align-items: center; gap: 12px;
  background: var(--accent); color: #fff; border: none;
  font-family: var(--sans); font-size: 17px; font-weight: 600;
  padding: 14px 26px 14px 22px; border-radius: 999px; cursor: pointer;
  box-shadow: 0 8px 20px -8px var(--accent-2);
  transition: transform .12s ease, box-shadow .12s ease;
}
.big-play:active { transform: scale(.97); }
.tri { width: 0; height: 0; border-style: solid;
  border-width: 8px 0 8px 14px; border-color: transparent transparent transparent #fff; }
.tri.small { border-width: 6px 0 6px 10px; }

/* ---------- Voice bar (home) ---------- */
.voice-bar { padding: 0 2px; }
.voice-label { font-family: var(--sans); font-size: 11.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 700; margin-bottom: 10px; }
.voice-row { display: flex; gap: 8px; }
.voice-select {
  flex: 1; min-width: 0; text-overflow: ellipsis;
  font-family: var(--sans); font-size: 15px; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px 14px; outline: none; appearance: none;
  -webkit-appearance: none; cursor: pointer;
}
.voice-select:focus { border-color: var(--accent); }
.voice-test {
  font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 0 18px; cursor: pointer; white-space: nowrap;
}
.voice-test:active { transform: scale(.97); }
.voice-hint { font-family: var(--sans); font-size: 12px; line-height: 1.5;
  color: var(--ink-faint); margin: 10px 2px 0; }

/* ---------- Reader ---------- */
.reader { padding-bottom: 40px; }
.reader-head { padding: 22px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.reader-title { font-size: 27px; line-height: 1.12; margin: 0 0 6px; letter-spacing: -0.01em; }
.reader-meta { font-family: var(--sans); font-size: 12.5px; letter-spacing: 0.03em; color: var(--ink-faint); }

.stack { padding: 20px 0 30px; min-height: 40vh; }
.line {
  font-size: 21px; line-height: 1.62; margin: 0 0 15px;
  color: var(--ink-faint); opacity: .55;
  transition: color .5s ease, opacity .5s ease, transform .5s ease;
}
.line:not(.current) { color: var(--ink-soft); opacity: 1; }
.line.current {
  color: var(--ink); opacity: 1; font-weight: 500;
}
.line.current::after {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 6px;
  border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite; vertical-align: middle;
}
@keyframes pulse { 0%,100% { opacity: .3; transform: scale(.8);} 50% { opacity: 1; transform: scale(1);} }

/* ---------- What next ---------- */
.next-screen { border-top: 1px dashed var(--line); padding-top: 30px; margin-top: 10px; }
.next-kicker { font-family: var(--sans); font-size: 11.5px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--gold); font-weight: 700; }
.next-title { font-size: 30px; margin: 8px 0 4px; letter-spacing: -0.02em; }
.next-sub { font-family: var(--sans); font-size: 14px; color: var(--ink-faint); margin: 0 0 22px; }

.doors { display: grid; gap: 12px; margin-bottom: 22px; }
.door {
  text-align: left; background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 15px 18px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  transition: transform .12s ease, border-color .2s ease, background .2s ease;
}
.door:active { transform: scale(.99); }
.door.picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--paper-2)); }
.door-kind { font-family: var(--sans); font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent); font-weight: 700; }
.door-label { font-size: 18px; line-height: 1.3; color: var(--ink); }

/* ---------- Type bar ---------- */
.type-bar { display: flex; gap: 8px; }
.type-bar.standalone { margin-bottom: 22px; }
.type-input {
  flex: 1; font-family: var(--sans); font-size: 15px; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 13px 15px; outline: none;
}
.type-input:focus { border-color: var(--accent); }
.type-input::placeholder { color: var(--ink-faint); }
.type-add {
  font-family: var(--sans); font-size: 15px; font-weight: 600; color: #fff;
  background: var(--ink); border: none; border-radius: 11px; padding: 0 20px; cursor: pointer;
}
.type-add:active { transform: scale(.97); }

/* ---------- Reader controls (floating) ---------- */
.reader-controls {
  position: fixed; left: 0; right: 0;
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 0 22px; pointer-events: none;
}
.reader-controls > * { pointer-events: auto; }
.ctrl-spacer { width: 48px; }
.ctrl-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--paper-2); border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 22px; cursor: pointer; box-shadow: 0 6px 18px -8px var(--shadow);
}
.play-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--accent); color: #fff; border: none;
  font-family: var(--sans); font-size: 16px; font-weight: 600;
  padding: 13px 26px; border-radius: 999px; cursor: pointer;
  box-shadow: 0 10px 26px -8px var(--accent-2);
  min-width: 130px; justify-content: center;
}
.play-btn:active { transform: scale(.97); }
.play-label { line-height: 1; }
.ico-play, .ico-pause { display: inline-block; }
.ico-play { width: 0; height: 0; border-style: solid;
  border-width: 7px 0 7px 12px; border-color: transparent transparent transparent #fff; }
.ico-pause { width: 12px; height: 14px; position: relative; }
.ico-pause::before, .ico-pause::after {
  content: ""; position: absolute; top: 0; width: 4px; height: 14px; background: #fff; border-radius: 1px; }
.ico-pause::before { left: 0; } .ico-pause::after { right: 0; }

/* ---------- Library ---------- */
.library-list { display: grid; gap: 12px; }
.lib-item {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 16px 18px; cursor: pointer; width: 100%;
  transition: transform .12s ease, border-color .2s ease;
}
.lib-item:active { transform: scale(.99); }
.lib-main { flex: 1; min-width: 0; }
.lib-title { font-size: 19px; line-height: 1.2; margin-bottom: 3px; }
.lib-meta { font-family: var(--sans); font-size: 12.5px; color: var(--ink-faint); }
.lib-status { font-family: var(--sans); font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-faint); }
.lib-item .lib-play {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex: none; }

/* ---------- Topics ---------- */
.topics-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.topic-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 13px 15px;
}
.topic-text { flex: 1; font-size: 17px; }
.topic-del { background: none; border: none; color: var(--ink-faint); font-size: 15px; cursor: pointer; padding: 4px; }

/* ---------- Empty / misc ---------- */
.empty { font-family: var(--sans); color: var(--ink-faint); font-size: 15px;
  text-align: center; padding: 40px 20px; line-height: 1.6; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 130px; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; color: var(--ink-faint); font-family: var(--sans);
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab-label { font-size: 11px; letter-spacing: 0.05em; }
.tab.active { color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--paper);
  font-family: var(--sans); font-size: 14px; padding: 11px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .3s ease, transform .3s ease; z-index: 30;
  box-shadow: 0 10px 30px -10px var(--shadow); max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
