/* ============================================================
   Audiobook library
   Palette is built for listening at night: a dark warm room,
   brass lamplight for anything interactive, and covers doing
   all the shouting.
   ============================================================ */

:root {
  --night:      #14161d;
  --night-2:    #1b1e28;
  --night-3:    #232733;
  --night-line: #2e3342;

  --paper:      #ece7dc;
  --paper-dim:  #9a9488;
  --paper-faint:#6b675e;

  --lamp:       #e5a54f;
  --lamp-warm:  #f0bd76;
  --lamp-soft:  rgba(229, 165, 79, 0.14);
  --sage:       #86a98f;

  --display: Spectral, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --ui:      "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 3px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.85);
  --gutter: clamp(16px, 4vw, 44px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--night);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  /* A faint pool of lamplight from the top left. */
  background-image: radial-gradient(120% 80% at 12% -10%, rgba(229, 165, 79, 0.07), transparent 60%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--lamp);
  outline-offset: 3px;
  border-radius: 2px;
}

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) 96px;
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
  padding: 40px 0 26px;
  border-bottom: 1px solid var(--night-line);
  margin-bottom: 34px;
}

.masthead-title {
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 400;
  letter-spacing: -0.015em;
  margin: 0;
}

.masthead-count {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-dim);
}

.masthead-tools {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search {
  background: var(--night-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius);
  padding: 9px 13px;
  width: 200px;
  transition: border-color 0.18s, width 0.18s;
}
.search::placeholder { color: var(--paper-faint); }
.search:focus { border-color: var(--lamp); outline: none; width: 240px; }

.filters { display: flex; gap: 2px; }

.filter {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--paper-dim);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.18s, background 0.18s;
}
.filter:hover { color: var(--paper); background: var(--night-2); }
.filter[aria-pressed="true"] { color: var(--night); background: var(--lamp); font-weight: 500; }

/* ------------------------------------------------------------ continue card */

.continue {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 26px;
  background: var(--night-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 42px;
  align-items: center;
  position: relative;
  overflow: hidden;
}
.continue::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--lamp);
}

.continue-cover {
  width: 168px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: var(--shadow);
  background: var(--night-3);
}

.continue-eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--lamp);
  margin: 0 0 10px;
}

.continue-title {
  font-family: var(--display);
  font-size: clamp(22px, 3vw, 31px);
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 6px;
}

.continue-author { color: var(--paper-dim); margin: 0 0 4px; font-size: 15px; }

.continue-where {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--paper-dim);
  margin: 14px 0 18px;
}
.continue-where strong { color: var(--paper); font-weight: 500; }

.resume {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--lamp);
  color: #17181c;
  border: none;
  border-radius: var(--radius);
  padding: 11px 20px;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}
.resume:hover { background: var(--lamp-warm); }
.resume:active { transform: translateY(1px); }

/* --------------------------------------------------- who recommended a book
   A quiet, conversational note rather than a badge: the point is to remind you
   there's a person to go and talk to. */

.recommend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--lamp);
  background: var(--lamp-soft);
  border: 1px solid rgba(229, 165, 79, 0.28);
  border-radius: 100px;
  padding: 6px 14px 6px 12px;
  margin: 16px 0 0;
  line-height: 1.3;
}
.recommend svg { flex: 0 0 auto; opacity: 0.85; }

.continue .recommend { margin: 12px 0 0; }

.tile-rec {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--lamp);
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-rec::before {
  content: "rec. ";
  color: var(--paper-faint);
}

/* -------------------------------------------------------------------- grid */

.shelf-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper-faint);
  margin: 0 0 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: clamp(18px, 2.4vw, 30px) clamp(14px, 2vw, 24px);
}

.tile { display: block; position: relative; }

.tile-art {
  position: relative;
  aspect-ratio: 1;
  border-radius: 2px;
  overflow: hidden;
  background: var(--night-2);
  box-shadow: var(--shadow);
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.tile:hover .tile-art,
.tile:focus-visible .tile-art { transform: translateY(-4px); }

.tile-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Progress reads as a bookmark ribbon laid across the bottom of the cover. */
.tile-ribbon {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: var(--lamp);
  box-shadow: 0 0 12px rgba(229, 165, 79, 0.55);
}

.tile-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(20, 22, 29, 0.88);
  backdrop-filter: blur(6px);
  color: var(--sage);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 4px 7px;
  border-radius: 2px;
}

.tile-title {
  font-family: var(--display);
  font-size: 15.5px;
  line-height: 1.3;
  margin: 11px 0 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-author {
  font-size: 13px;
  color: var(--paper-dim);
  margin: 0 0 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-meta {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--paper-faint);
}

.tile.is-pending .tile-art { animation: breathe 2s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.75; } }

/* ------------------------------------------------------------ empty states */

.empty {
  border: 1px dashed var(--night-line);
  border-radius: var(--radius);
  padding: 56px 32px;
  text-align: center;
}
.empty-title {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 400;
  margin: 0 0 10px;
}
.empty p { color: var(--paper-dim); margin: 0 0 6px; line-height: 1.6; }
.empty code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--night-2);
  padding: 2px 7px;
  border-radius: 2px;
  color: var(--lamp);
}

.scanning {
  display: none;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--paper-dim);
  margin-bottom: 20px;
}
.scanning.is-on { display: flex; }
.scanning::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lamp);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ============================================================ player page */

.player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 52px;
  align-items: start;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--paper-dim);
  padding: 28px 0 24px;
  transition: color 0.18s;
}
.back:hover { color: var(--lamp); }

.book-head { display: flex; gap: 26px; margin-bottom: 34px; align-items: flex-start; }

.book-cover {
  width: 200px;
  flex: 0 0 200px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: var(--shadow);
  background: var(--night-2);
}

.book-title {
  font-family: var(--display);
  font-size: clamp(24px, 3.4vw, 36px);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
}

.book-author { font-size: 16px; color: var(--paper); margin: 0 0 3px; }
.book-narrator { font-size: 14px; color: var(--paper-dim); margin: 0; }

.book-facts {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--paper-faint);
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.book-facts span::after { content: " ·"; color: var(--night-line); }
.book-facts span:last-child::after { content: ""; }

.blurb {
  color: var(--paper-dim);
  font-size: 14.5px;
  line-height: 1.65;
  margin: 0 0 30px;
  max-width: 62ch;
}

/* ------------------------------------------------- the chapter track (hero)
   Each segment is one chapter, sized to its real length. The shape of the
   book — long chapters, short ones, where you are — is legible at a glance. */

.track {
  margin: 0 0 10px;
  cursor: pointer;
  padding: 12px 0;
  touch-action: none;
}

.track-bar {
  display: flex;
  gap: 2px;
  height: 34px;
  align-items: stretch;
}

.seg {
  position: relative;
  background: var(--night-3);
  border-radius: 1px;
  overflow: hidden;
  min-width: 2px;
  transition: background 0.18s;
}
.seg::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  background: var(--lamp);
  opacity: 0.85;
}
.seg.is-done::after { opacity: 0.32; }
.seg.is-current { background: var(--night-line); }
.seg.is-current::after { box-shadow: 0 0 14px rgba(229, 165, 79, 0.6); }
.track:hover .seg { background: var(--night-line); }

.track-head {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: var(--paper);
  border-radius: 2px;
  pointer-events: none;
  box-shadow: 0 0 10px rgba(236, 231, 220, 0.5);
}

.track-outer { position: relative; }

.track-times {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--paper-dim);
  margin-bottom: 4px;
}
.track-times .now { color: var(--paper); }

.track-chapter {
  font-size: 14px;
  color: var(--paper-dim);
  margin: 0 0 26px;
  min-height: 1.2em;
}
.track-chapter strong { color: var(--paper); font-weight: 500; }

.scrub-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--night);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.14s;
  z-index: 5;
}
.scrub-bubble.is-on { opacity: 1; }

/* ---------------------------------------------------------------- controls */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 26px);
  margin-bottom: 26px;
}

.ctl {
  background: none;
  border: none;
  color: var(--paper);
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: color 0.16s, background 0.16s, transform 0.12s;
}
.ctl:hover { color: var(--lamp); background: var(--lamp-soft); }
.ctl:active { transform: scale(0.93); }
.ctl svg { display: block; }
.ctl:disabled { opacity: 0.25; cursor: default; }
.ctl:disabled:hover { color: var(--paper); background: none; }

.ctl-skip { position: relative; }
.ctl-skip span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  padding-top: 3px;
  pointer-events: none;
}

.ctl-play {
  background: var(--lamp);
  color: #17181c;
  width: 68px;
  height: 68px;
}
.ctl-play:hover { background: var(--lamp-warm); color: #17181c; }

/* ------------------------------------------------------------------ pillbox */

.pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding-bottom: 8px;
}

.pill {
  background: var(--night-2);
  border: 1px solid var(--night-line);
  border-radius: 100px;
  padding: 8px 15px;
  font-size: 13px;
  color: var(--paper-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
  white-space: nowrap;
}
.pill:hover { color: var(--paper); border-color: var(--paper-faint); }
.pill.is-on { color: var(--lamp); border-color: var(--lamp); background: var(--lamp-soft); }
.pill b { font-family: var(--mono); font-weight: 500; color: var(--paper); }

/* -------------------------------------------------------------- chapter list */

.aside {
  background: var(--night-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky;
  top: 22px;
}

.aside-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--night-line);
}
.aside-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper-dim);
  margin: 0;
}
.aside-count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--paper-faint); }

.chapters {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: min(62vh, 620px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--night-line) transparent;
}
.chapters::-webkit-scrollbar { width: 8px; }
.chapters::-webkit-scrollbar-thumb { background: var(--night-line); border-radius: 4px; }

.chapter {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 2px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--paper-dim);
  transition: background 0.14s, color 0.14s;
}
.chapter:hover { background: var(--night-3); color: var(--paper); }
.chapter-num { font-family: var(--mono); font-size: 11px; color: var(--paper-faint); }
.chapter-name { font-size: 14px; line-height: 1.35; }
.chapter-len { font-family: var(--mono); font-size: 11px; color: var(--paper-faint); }

.chapter.is-current { background: var(--lamp-soft); color: var(--paper); }
.chapter.is-current .chapter-num { color: var(--lamp); }
.chapter.is-played { opacity: 0.55; }

/* ------------------------------------------------------------------ sheets */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  background: var(--night-2);
  border-top: 1px solid var(--night-line);
  border-radius: 10px 10px 0 0;
  padding: 20px var(--gutter) calc(20px + env(safe-area-inset-bottom));
  transform: translateY(101%);
  transition: transform 0.26s cubic-bezier(0.2, 0.7, 0.3, 1);
  z-index: 40;
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, 0.9);
}
.sheet.is-open { transform: translateY(0); }
.sheet-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper-dim);
  margin: 0 0 16px;
}
.sheet-row { display: flex; gap: 8px; flex-wrap: wrap; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 15, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s;
  z-index: 39;
}
.scrim.is-open { opacity: 1; pointer-events: auto; }

.speed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}
.speed-opt {
  background: var(--night-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 6px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--paper-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.speed-opt:hover { color: var(--paper); }
.speed-opt.is-on { background: var(--lamp); color: #17181c; font-weight: 600; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--night-line);
  border-radius: 2px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--lamp);
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--lamp);
  cursor: pointer;
}

/* --------------------------------------------------------------- bookmarks */

.marks { list-style: none; margin: 0; padding: 0; }
.marks:empty::after {
  content: "No bookmarks yet. Press B while listening to drop one.";
  display: block;
  color: var(--paper-faint);
  font-size: 13px;
  padding: 4px 0 8px;
}
.mark {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--night-3);
}
.mark:last-child { border-bottom: none; }
.mark-time {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--lamp);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.mark-label { font-size: 13px; color: var(--paper-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark-drop {
  background: none;
  border: none;
  color: var(--paper-faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
}
.mark-drop:hover { color: var(--paper); }

/* ------------------------------------------------------------------ toasts */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: var(--paper);
  color: var(--night);
  padding: 11px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 60;
  max-width: calc(100vw - 40px);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------- login */

.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  background: var(--night-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius);
  padding: 34px;
  width: min(360px, 100%);
}
.gate-title { font-family: var(--display); font-weight: 400; font-size: 28px; margin: 0 0 8px; }
.gate-note { color: var(--paper-dim); font-size: 14px; margin: 0 0 22px; }
.gate-error { color: var(--lamp); font-size: 13.5px; margin: 0 0 14px; }
.gate-input {
  width: 100%;
  background: var(--night);
  border: 1px solid var(--night-line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.gate-input:focus { border-color: var(--lamp); outline: none; }
.gate-button {
  width: 100%;
  background: var(--lamp);
  color: #17181c;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .player { grid-template-columns: 1fr; gap: 30px; }
  .aside { position: static; }
  .chapters { max-height: none; }
}

@media (max-width: 620px) {
  .book-head { gap: 18px; }
  .book-cover { width: 122px; flex-basis: 122px; }
  .continue { grid-template-columns: 108px 1fr; gap: 18px; padding: 16px; }
  .continue-cover { width: 108px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .masthead { padding: 26px 0 18px; }
  .masthead-tools { width: 100%; margin-left: 0; }
  .search { flex: 1; width: auto; }
  .search:focus { width: auto; }
  .track-bar { height: 40px; }  /* easier to hit with a thumb */
  .ctl-play { width: 74px; height: 74px; }
  .aside-desktop { display: none; }
}

@media (min-width: 621px) {
  .pill-chapters { display: none; }  /* the list is already on screen */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
