/* repo-story player component */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: #0f0f0f; color: #e0e0e0; min-height: 100vh; }

.library { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.library h1 { font-size: 1.5rem; font-weight: 300; margin-bottom: 2rem; color: #888; letter-spacing: 0.05em; }

.book-list { display: flex; flex-direction: column; gap: 0.5rem; }
.book-item { padding: 1rem 1.25rem; background: #1a1a1a; border-radius: 8px; cursor: pointer; transition: background 0.15s; display: flex; justify-content: space-between; align-items: center; }
.book-item:hover { background: #252525; }
.book-item .title { font-size: 1rem; }
.book-item .meta { font-size: 0.8rem; color: #666; }
.book-item .book-desc { font-size: 0.85rem; color: #999; margin-top: 0.35rem; }
.book-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.book-item .progress-dot { width: 8px; height: 8px; border-radius: 50%; background: #333; flex-shrink: 0; }
.book-item .progress-dot.in-progress { background: #4a9eff; }
.book-item .progress-dot.complete { background: #34d399; }

/* Download for offline button */
.dl-btn { background: none; border: 1px solid #333; color: #888; cursor: pointer; font-size: 0.85rem; padding: 0.3rem 0.7rem; border-radius: 6px; transition: all 0.15s; min-width: 8rem; text-align: center; white-space: nowrap; }
.dl-btn:hover { color: #4a9eff; border-color: #4a9eff; }
.dl-btn.downloading { color: #4a9eff; border-color: #4a9eff; cursor: default; }
.dl-btn.downloaded { color: #34d399; border-color: #34d399; cursor: default; }
.dl-btn.downloaded:hover { color: #34d399; border-color: #34d399; }

/* 90vw: use wide screens; pane split is the user's to drag. */
.player-view { max-width: 90vw; margin: 0 auto; padding: 2rem 1rem; display: none; }
.player-view.active { display: flex; flex-direction: column; height: 100vh; height: 100svh; }
@media (max-width: 480px) { .player-view { padding: 1rem 0.5rem 0.5rem; } }

.back-btn { background: none; border: none; color: #666; font-size: 0.9rem; cursor: pointer; padding: 0.5rem 0; margin-bottom: 1rem; flex-shrink: 0; }
.back-btn:hover { color: #e0e0e0; }

.now-playing { margin-bottom: 1rem; flex-shrink: 0; }
.now-playing .book-title { font-size: 1.3rem; font-weight: 400; margin-bottom: 0.25rem; }
.now-playing .chapter-title { font-size: 0.9rem; color: #4a9eff; }

/* Scrollbar theming: invisible at rest; the .scrolling class (added by the
   player on scroll, removed after idle) shows it. Colors route through
   registered custom properties so the show/hide is a real fade — scrollbar
   pseudo-elements can't transition, but registered properties can. */
@property --sb-thumb { syntax: '<color>'; inherits: false; initial-value: rgba(74, 158, 255, 0); }
@property --sb-track { syntax: '<color>'; inherits: false; initial-value: rgba(26, 26, 26, 0); }
.chapter-list,
.transcript-chunks {
  --sb-thumb: rgba(74, 158, 255, 0);
  --sb-track: rgba(26, 26, 26, 0);
  transition: --sb-thumb 0.5s, --sb-track 0.5s;
  scrollbar-width: thin;
  scrollbar-color: var(--sb-thumb) var(--sb-track);
}
.chapter-list.scrolling,
.transcript-chunks.scrolling {
  --sb-thumb: #4a9eff;
  --sb-track: #1a1a1a;
  transition: --sb-thumb 0.15s, --sb-track 0.15s;
}
.chapter-list::-webkit-scrollbar,
.transcript-chunks::-webkit-scrollbar { width: 6px; }
.chapter-list::-webkit-scrollbar-track,
.transcript-chunks::-webkit-scrollbar-track { background: var(--sb-track); border-radius: 3px; }
.chapter-list::-webkit-scrollbar-thumb,
.transcript-chunks::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: 3px; }
.chapter-list.scrolling::-webkit-scrollbar-thumb:hover,
.transcript-chunks.scrolling::-webkit-scrollbar-thumb:hover { background: #6bb3ff; }

/* Content area: chapters + transcript side by side */
.content-area { display: flex; flex: 1; min-height: 0; margin-bottom: 1rem; background: #0f0f0f; border-radius: 8px; overflow: hidden; }

/* Chapter list panel (left) */
.chapter-panel { display: flex; flex-direction: column; min-width: 80px; overflow: hidden; container-type: inline-size; }

.chapter-panel-header { display: flex; align-items: center; padding: 0.5rem 0.75rem; flex-shrink: 0; }
.chapter-panel-header h3 { font-size: 0.75rem; font-weight: 400; color: #555; text-transform: uppercase; letter-spacing: 0.1em; }

.chapter-list { list-style: none; overflow-y: auto; flex: 1; }
.chapter-list li { position: relative; padding: 0.6rem 0.75rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; overflow: hidden; user-select: none; -webkit-user-select: none; }
.chapter-list li:hover { background: #1a1a1a; }
.chapter-list li.active { background: #1a2a3a; color: #4a9eff; }
.chapter-list li .ch-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; position: relative; z-index: 1; pointer-events: none; }
.chapter-list li .ch-duration { color: #555; font-size: 0.75rem; flex-shrink: 0; margin-left: 0.5rem; position: relative; z-index: 1; pointer-events: none; }

/* Narrow chapter panel: hide title and duration, show only chapter number */
@container (max-width: 150px) {
  .chapter-list li .ch-title { display: none; }
  .chapter-list li .ch-duration { display: none; }
  .chapter-list li::before { content: "Ch " attr(data-ch); font-size: 0.7rem; color: #888; position: relative; z-index: 1; pointer-events: none; }
  .chapter-list li.active::before { color: #4a9eff; }
  .chapter-list li { justify-content: center; }
}

/* Chapter progress overlay — only on active chapter */
.ch-progress { position: absolute; top: 0; left: 0; height: 100%; pointer-events: none; width: 0%; }
.chapter-list li.active .ch-progress { background: rgba(74, 158, 255, 0.15); }

/* Chapter scrubber handle — only visible on active chapter hover */
.ch-scrubber { position: absolute; top: 0; width: 12px; height: 100%; z-index: 2; cursor: grab; opacity: 0; transition: opacity 0.15s; }
.ch-scrubber::after { content: ''; position: absolute; top: 0; left: 5px; width: 2px; height: 100%; background: #4a9eff; }
.chapter-list li.active:hover .ch-scrubber { opacity: 0.6; }
.chapter-list li.scrubbing .ch-scrubber { opacity: 1; cursor: grabbing; }

/* Draggable divider between panels */
.panel-divider { width: 5px; background: #222; cursor: col-resize; flex-shrink: 0; position: relative; transition: background 0.15s; touch-action: none; }
.panel-divider:hover, .panel-divider.dragging { background: #4a9eff; }
@media (pointer: coarse) { .panel-divider { width: 12px; } }

/* Transcript panel (right) */
.transcript-panel { display: flex; flex-direction: column; min-width: 80px; overflow: hidden; }

/* flex-wrap: at narrow widths (zoom, phones) the buttons wrap to a second
   row instead of overflowing the panel's hidden edge. */
.transcript-panel-header { display: flex; align-items: center; padding: 0.5rem 0.75rem; flex-shrink: 0; flex-wrap: wrap; row-gap: 0.25rem; }
.transcript-panel-header h3 { font-size: 0.75rem; font-weight: 400; color: #555; text-transform: uppercase; letter-spacing: 0.1em; }
.th-spacer { flex: 1; min-width: 0; }
.follow-btn, .reading-btn, .mini-play-btn, .mode-btn { white-space: nowrap; }
.mode-toggle { display: inline-flex; gap: 0.25rem; margin-left: 0.75rem; }
.mode-btn { background: none; border: 1px solid #333; color: #555; border-radius: 6px;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem; cursor: pointer; }
.mode-btn:hover { color: #999; }
.mode-btn.on { color: #4a9eff; border-color: #4a9eff; }
.follow-btn, .reading-btn { background: none; border: 1px solid #333; color: #555; border-radius: 6px;
  font-size: 0.7rem; line-height: 1; padding: 0.25rem 0.5rem; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.05em; transition: color 0.15s, border-color 0.15s; }
.follow-btn:hover, .reading-btn:hover { color: #999; }
.follow-btn.on, .reading-btn.on { color: #4a9eff; border-color: #4a9eff; }
.reading-btn { margin-left: 0.5rem; }

/* Reading mode: transcript only. Hide chapter panel, header chrome and the
   whole bottom control bar — a mini play/pause lives in the transcript
   header instead. The !important on flex overrides the divider-drag inline
   style. */
.player-view.reading-mode .back-btn,
.player-view.reading-mode .now-playing,
.player-view.reading-mode .chapter-panel,
.player-view.reading-mode .panel-divider,
.player-view.reading-mode .player-controls { display: none; }
/* Full-bleed: reading mode is "give me the text" — drop the 90vw margins,
   keep a thin fixed gutter so text doesn't touch the screen edge. */
.player-view.reading-mode { max-width: none; padding: 0.5rem 1rem; }
.player-view.reading-mode .content-area { margin-bottom: 0; }
.player-view.reading-mode .transcript-panel { flex: 1 1 auto !important; }
.player-view.reading-mode .transcript-chunk { font-size: calc(1rem * var(--ts-scale, 1)); }
.player-view.reading-mode .transcript-chunk .chunk-text { line-height: 1.65; }

/* Transcript text size: A−/A+ stepper sets --ts-scale inline on
   #transcript-chunks (1.25^n, n = -2..+3); composes with the reading-mode
   base bump via the calc() font-size rules. */
.ts-btn { background: none; border: 1px solid #333; color: #555; border-radius: 6px;
  line-height: 1; padding: 0.25rem 0.4rem; cursor: pointer;
  transition: color 0.15s, border-color 0.15s; white-space: nowrap; }
.ts-btn:hover { color: #999; }
.ts-btn:disabled { opacity: 0.35; cursor: default; }
.ts-btn:disabled:hover { color: #555; }
.ts-dec { font-size: 0.6rem; margin-right: 2px; }
.ts-inc { font-size: 0.8rem; margin-right: 0.5rem; }

/* Mini play/pause: reading mode only, left of the follow toggle. */
.mini-play-btn { display: none; background: none; border: 1px solid #333; color: #e0e0e0;
  border-radius: 6px; font-size: 0.8rem; line-height: 1; padding: 0.2rem 0.6rem;
  cursor: pointer; margin-right: 0.5rem; transition: color 0.15s, border-color 0.15s; }
.mini-play-btn:hover { color: #4a9eff; border-color: #4a9eff; }
.player-view.reading-mode .mini-play-btn { display: inline-block; }

/* Landscape phones: the header/controls chrome eats the screen — compact it
   even outside reading mode. */
@media (orientation: landscape) and (max-height: 500px) {
  .player-view { padding: 0.25rem 0.5rem 0.25rem; }
  .back-btn { margin-bottom: 0; padding: 0.15rem 0; }
  .now-playing { margin-bottom: 0.25rem; }
  .now-playing .book-title { font-size: 0.85rem; }
  .now-playing .chapter-title { font-size: 0.75rem; }
  .content-area { margin-bottom: 0.25rem; }
  .player-controls { padding: 0.2rem 0.5rem calc(0.2rem + env(safe-area-inset-bottom, 0)); }
  .time-display { margin-bottom: 0.2rem; }
  .controls { margin-top: 0.2rem; gap: 0.4rem; }
  .controls button { font-size: 0.85rem; padding: 0.2rem 0.5rem; }
  .play-btn { font-size: 1.1rem !important; width: 2.2rem; height: 2.2rem; }
}

.transcript-chunks { overflow-y: auto; flex: 1; scroll-behavior: smooth; padding: 0 0.25rem; }
.transcript-chunk { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 0.25rem; transition: background 0.15s; cursor: pointer; }
.transcript-chunk:hover { background: #1a1a1a; }
.transcript-chunk.active { background: #1a2a3a; }
/* font-size sits on the chunk (not .chunk-text) so the ch-based width cap
   scales with the text-size stepper too. */
.transcript-chunk { font-size: calc(0.85rem * var(--ts-scale, 1)); }
.transcript-chunk .chunk-text { font-size: 1em; line-height: 1.5; color: #999; flex: 1; }
.transcript-chunk.active .chunk-text { color: #e0e0e0; }
.transcript-chunk .chunk-flag { flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.transcript-chunk:hover .chunk-flag,
.transcript-chunk .chunk-flag.flagged { opacity: 1; }
/* Scene-transition divider ("* * *"): centered, spaced, non-interactive. */
.transcript-chunk.scene-break { justify-content: center; cursor: default; padding: 0.9rem 0; }
.transcript-chunk.scene-break .chunk-text { flex: 0; text-align: center; letter-spacing: 0.5em; color: #555; }
.transcript-chunk.scene-break.active .chunk-text { color: #4a9eff; }
.chunk-flag button { background: none; border: none; cursor: pointer; font-size: 0.9rem; padding: 0.2rem 0.4rem; border-radius: 4px; color: #555; }
.chunk-flag button:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.chunk-flag button.flagged { color: #ef4444; }

/* Player controls (bottom) */
.player-controls { flex-shrink: 0; padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0)); border-top: 1px solid #222; }
@media (max-width: 480px) { .player-controls { padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0)); } }
.time-display { display: flex; justify-content: space-between; font-size: 0.75rem; color: #666; margin-bottom: 0.5rem; }

.track-bar { position: relative; height: 6px; background: #333; border-radius: 3px; cursor: pointer; margin-bottom: 0.25rem; touch-action: none; }
.track-bar .progress { height: 100%; background: #4a9eff; border-radius: 3px; transition: width 0.1s; position: relative; }
.track-bar.dragging .progress { transition: none; }
.track-bar.dragging { cursor: grabbing; }
/* Thumb: rides the progress edge; grows in on hover/drag. */
.track-bar .progress::after { content: ''; position: absolute; right: -7px; top: 50%;
  width: 14px; height: 14px; border-radius: 50%; background: #4a9eff;
  transform: translateY(-50%) scale(0); transition: transform 0.15s; }
.track-bar:hover .progress::after,
.track-bar.dragging .progress::after { transform: translateY(-50%) scale(1); }
.track-bar .chapter-mark { position: absolute; top: -2px; width: 1px; height: 10px; background: #555; }

.controls { display: flex; align-items: center; justify-content: center; gap: 1.5rem; margin-top: 0.75rem; }
@media (max-width: 480px) { .controls { gap: 0.5rem; margin-top: 0.5rem; } }
.controls button { background: none; border: none; color: #e0e0e0; cursor: pointer; font-size: 1.2rem; padding: 0.5rem 0.75rem; border-radius: 6px; transition: background 0.15s, color 0.15s; }
.controls button:hover { color: #fff; background: #1a1a1a; }
.play-btn { font-size: 2rem !important; width: 3.5rem; height: 3.5rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.play-btn:hover { background: #1a2a3a !important; }
.speed-btn { font-size: 0.8rem !important; color: #888 !important; min-width: 3em; text-align: center; }
.speed-btn:hover { color: #4a9eff !important; }

/* Nested library groups. Only rendered when the payload carries a `tree`;
   consumers that send a flat books array never produce these. */
.lib-group { margin: 0.75rem 0; }
.lib-group-name {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
  margin: 0 0 0.35rem;
}
/* Indent by nesting rather than by depth arithmetic, so arbitrarily deep
   categories stay aligned without the renderer tracking pixel offsets. */
.lib-group-body { padding-left: 0.9rem; border-left: 1px solid rgba(128,128,128,0.22); }
