/* ── Reset & tokens ────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:         #0b0b0c;
  --surface:    #111115;
  --border:     #1d1d24;
  --muted:      #3a3a4a;
  --subtle:     #6b6b80;
  --text:       #d8d8e8;
  --accent:     #e8c547;
  --accent-dim: rgba(232, 197, 71, 0.15);
  --danger:     #e05c5c;
}

html, body {
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── UPLOAD SCREEN ─────────────────────────────────────────────── */
#upload-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 24px;
}

/* Decorative grid background */
#upload-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, black 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, black 30%, transparent 100%);
  opacity: 0.5;
  pointer-events: none;
}

.brand {
  position: relative;
  text-align: center;
  margin-bottom: 36px;
}
.brand h1 {
  font-size: clamp(32px, 8vw, 52px);
  font-weight: 800;
  letter-spacing: -2px;
}
.brand h1 span { color: var(--accent); }
.brand p {
  font-size: clamp(13px, 3vw, 15px);
  color: var(--subtle);
  margin-top: 10px;
}

.drop-zone {
  position: relative;
  width: min(460px, 100%);
  height: 220px;
  border: 1.5px dashed var(--muted);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--surface);
}
.drop-zone:hover,
.drop-zone.over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.drop-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-zone p   { color: var(--subtle); font-size: 14px; }
.drop-link     { color: var(--accent); font-weight: 600; }
#file-input    { display: none; }
#upload-error  {
  display: none;
  margin-top: 16px;
  color: var(--danger);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
}

/* ── READER SCREEN ─────────────────────────────────────────────── */
#reader-screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

/* ── HUD ───────────────────────────────────────────────────────── */
#hud {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 20;
}
.hud-btn {
  background: transparent;
  border: none;
  color: var(--subtle);
  cursor: pointer;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 6px;
  transition: color .15s;
  flex-shrink: 0;
}
.hud-btn:hover { color: var(--text); }
.hud-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}
#filename-label {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
#page-indicator {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--subtle);
  flex-shrink: 0;
}
#progress-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── WARNING BAR ───────────────────────────────────────────────── */
#warning-bar {
  display: none;
  background: #2a1800;
  border-bottom: 1px solid #5a3800;
  color: #e8a040;
  font-size: 12px;
  padding: 7px 14px;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

/* ── TOC DRAWER ────────────────────────────────────────────────── */
#toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
#toc-overlay.open {
  opacity: 1;
  pointer-events: all;
}

#toc-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(360px, 88vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 41;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.22, .61, .36, 1);
}
#toc-drawer.open { transform: translateX(0); }

#toc-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#toc-header h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
}
#toc-close {
  background: transparent;
  border: none;
  color: var(--subtle);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s;
  display: flex;
  align-items: center;
}
#toc-close:hover { color: var(--text); }

#toc-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
#toc-body::-webkit-scrollbar        { width: 4px; }
#toc-body::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 2px; }

#toc-empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--subtle);
  font-size: 13px;
  line-height: 1.6;
}

.toc-item {
  display: flex;
  align-items: baseline;
  padding: 6px 18px 6px 0;
  cursor: pointer;
  transition: background .12s;
}
.toc-item:hover            { background: rgba(255, 255, 255, .04); }
.toc-item:hover .toc-title { color: var(--accent); }
.toc-item:hover .toc-dot   { background: var(--accent); }
.toc-item:active           { background: var(--accent-dim); }

.toc-indent { flex-shrink: 0; /* width set per-item in JS */ }
.toc-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  margin-right: 10px;
  margin-top: 2px;
  transition: background .12s;
}
.toc-title {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  font-weight: 400;
  transition: color .12s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-title.depth-0 { font-weight: 600; font-size: 13.5px; }
.toc-title.depth-1 { font-size: 12.5px; }
.toc-title.depth-2 { font-size: 12px; color: var(--subtle); }

.toc-page {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: 8px;
}

/* ── PDF AREA ──────────────────────────────────────────────────── */
#pdf-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* Loading overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 12, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 30;
}
#loading-overlay.hidden { display: none; }
#loading-bar-wrap {
  width: min(300px, 80%);
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
#loading-bar {
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width .25s;
}
#loading-text {
  font-size: 13px;
  color: var(--subtle);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  padding: 0 16px;
}

/* PDF scroll container */
#pdf-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #222224;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 220px;
}
#pdf-scroll::-webkit-scrollbar        { width: 5px; }
#pdf-scroll::-webkit-scrollbar-track  { background: transparent; }
#pdf-scroll::-webkit-scrollbar-thumb  { background: var(--muted); border-radius: 3px; }

/* Page elements (created in JS) */
.page-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 16px;
}
.page-wrap {
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
}
.pdf-canvas     { display: block; }
.overlay-canvas { position: absolute; top: 0; left: 0; cursor: pointer; }
.page-label {
  font-size: 10px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  margin-top: 6px;
  letter-spacing: .1em;
  opacity: .45;
}

/* Seek tooltip */
#seek-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  background: rgba(0, 0, 0, .88);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  white-space: nowrap;
  display: none;
}

/* ── CAPTION BAR ───────────────────────────────────────────────── */
#caption-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(
    transparent 0%,
    rgba(0,0,0,0) 10%,
    rgba(0,0,0,.70) 48%,
    rgba(0,0,0,.90) 100%
  );
  padding:
    clamp(32px, 6vw, 60px)
    clamp(5%, 8%, 10%)
    clamp(12px, 3vw, 22px);
  pointer-events: none;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  opacity: 0;
  transition: opacity .35s;
}
#caption-bar.visible { opacity: 1; }

#caption-words {
  text-align: center;
  line-height: 1.5;
  max-width: min(860px, 100%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 5px;
  align-items: baseline;
}

/* All caption words same size — only colour differs */
.cap-word {
  font-family: 'Syne', sans-serif;
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 700;
  line-height: 1.5;
  transition: color .06s;
}
.cap-word.focus { color: var(--accent); }
.cap-word.chunk { color: rgba(232, 197, 71, .38); }

/* ── CONTROLS FOOTER ───────────────────────────────────────────── */
#controls {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
  z-index: 5;
}
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#play-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .12s;
}
#play-btn:hover:not(:disabled)  { transform: scale(1.08); }
#play-btn:active:not(:disabled) { transform: scale(.94); }
#play-btn:disabled { opacity: .35; cursor: not-allowed; }
#play-btn svg { fill: #000; }

.csep {
  width: 1px; height: 20px;
  background: var(--border);
  flex-shrink: 0;
}
.clabel {
  font-size: 10px;
  color: var(--subtle);
  letter-spacing: .06em;
  text-transform: uppercase;
  flex-shrink: 0;
}
#wpm-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  min-width: 56px;
  flex-shrink: 0;
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
  width: clamp(80px, 20vw, 130px);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.chunk-btns { display: flex; gap: 4px; flex-shrink: 0; }
.chunk-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--subtle);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  transition: all .15s;
  touch-action: manipulation;
}
.chunk-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

#restart-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--subtle);
  padding: 5px 13px;
  border-radius: 7px;
  cursor: pointer;
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  transition: all .15s;
  flex-shrink: 0;
  touch-action: manipulation;
}
#restart-btn:hover { border-color: var(--accent); color: var(--accent); }

.kbd {
  display: inline-flex;
  padding: 1px 6px;
  background: var(--border);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--muted);
}
.hint { font-size: 10px; color: var(--subtle); }

/* ── RESPONSIVE ────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .kbd, .hint, .clabel { display: none; }
}
