:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa1ad;
  --accent: #6c8cff;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f9;
    --panel: #ffffff;
    --border: #e2e4ea;
    --text: #1a1d24;
    --muted: #666d7a;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
  flex: none;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.topbar-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.file-btn {
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 19;
  flex: none;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.zoom-level {
  min-width: 44px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.search-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#search-input {
  width: 220px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

.search-count {
  font-size: 12px;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
}

.search-controls button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.layout {
  flex: 1;
  display: flex;
  width: 100%;
  min-height: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
}

.pdf-viewer {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: #525659;
}

.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.pdf-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Standard pdf.js text-layer integration rules (Apache-2.0, pdf.js project),
   repurposed here to host invisible word spans for highlight + click-to-jump
   instead of text selection. */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: clip;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 1;
  pointer-events: none;
  user-select: none;
}

.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
}

.textLayer span.markedContent {
  top: 0;
  height: 0;
}

.textLayer .word {
  pointer-events: auto;
  cursor: pointer;
  border-radius: 2px;
}

.textLayer .word.active {
  background: rgba(255, 214, 92, 0.65);
  mix-blend-mode: multiply;
}

.textLayer .word.search-hit {
  background: rgba(108, 140, 255, 0.35);
  mix-blend-mode: multiply;
}

.textLayer .word.search-hit-current {
  background: rgba(255, 140, 60, 0.65);
  mix-blend-mode: multiply;
}

.player {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}

#play-btn, #stop-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

#stop-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

.status-label {
  font-size: 12px;
  color: var(--muted);
}

.speed-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
