*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #17181c;
  --surface: #1e2024;
  --surface-2: #26282e;
  --border: #34363d;
  --text: #e8e9ec;
  --text-muted: #8b8d96;
  --text-faint: #55575f;
  --accent: #5b7cfa;
  --accent-soft: rgba(91, 124, 250, 0.14);
  --danger: #e5534b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

:root[data-theme="light"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --border: #dde0e5;
  --text: #1c1d21;
  --text-muted: #6b6d76;
  --text-faint: #a3a5ad;
  --accent: #3b5bdb;
  --accent-soft: rgba(59, 91, 219, 0.10);
  --danger: #d1403a;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); overflow: hidden; }

#theme-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 300;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
#theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Upload screen */

#upload-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 28px; background: var(--bg); z-index: 100;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#upload-screen.hidden { opacity: 0; transform: translateY(-12px); pointer-events: none; }

.brand { font-size: 13px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.01em; }

.upload-copy { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.upload-copy h1 { font-size: clamp(22px, 3.4vw, 30px); font-weight: 600; letter-spacing: -0.01em; }
.upload-copy p { font-size: 14px; color: var(--text-muted); }

#drop-zone {
  width: min(440px, 90vw); height: 200px;
  border: 1.5px dashed var(--border); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
  background: var(--surface);
}
#drop-zone:hover, #drop-zone.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { color: var(--text-muted); }
#drop-zone:hover .drop-icon, #drop-zone.drag-over .drop-icon { color: var(--accent); }
.drop-label { font-size: 14px; color: var(--text-muted); text-align: center; display: flex; flex-direction: column; gap: 4px; }
.drop-label strong { color: var(--text); font-weight: 600; }

#upload-error { font-size: 13px; color: var(--danger); min-height: 18px; }

/* Reader screen */

#reader-screen { position: fixed; inset: 0; display: flex; flex-direction: column; opacity: 0; pointer-events: none; transition: opacity 0.3s ease 0.08s; }
#reader-screen.visible { opacity: 1; pointer-events: all; }

#top-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; gap: 12px; }
.bar-brand { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
#doc-name { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: center; }

.bar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }

.mode-switch { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; flex-shrink: 0; }
.mode-btn { font-size: 12px; color: var(--text-muted); background: none; border: none; padding: 4px 10px; border-radius: 4px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--accent); color: #fff; }

.toggle-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none;
  white-space: nowrap;
}
.toggle-label:hover { color: var(--text); }
.toggle-label input[type=checkbox] { display: none; }
.toggle-track {
  width: 30px; height: 16px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative; transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: ''; position: absolute;
  left: 2px; top: 2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--text-muted);
  transition: left 0.15s, background 0.15s;
}
.toggle-label input:checked + .toggle-track { background: var(--accent-soft); border-color: var(--accent); }
.toggle-label input:checked + .toggle-track::after { left: 16px; background: var(--accent); }

#reset-btn {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); background: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 12px; cursor: pointer; transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#reset-btn:hover { color: var(--text); border-color: var(--text-faint); }

/* Main layout: RSVP pane + PDF pane */

#main-body { flex: 1; display: flex; overflow: hidden; min-height: 0; }

#rsvp-pane {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 28px; position: relative; overflow: hidden;
  transition: flex 0.3s ease;
  min-width: 0;
}

#guide-line {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: linear-gradient(to bottom, transparent 0%, var(--border) 20%, var(--border) 80%, transparent 100%);
  pointer-events: none; opacity: 0.15;
}

#word-box {
  position: relative; z-index: 1;
  width: min(560px, 92%);
  padding: 32px 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 4px 24px rgba(0,0,0,0.35); overflow: hidden;
}
#word-box::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0;
  width: 1px; background: var(--accent); opacity: 0.2;
  transform: translateX(-50%); pointer-events: none;
}

#current-word {
  font-family: var(--font-mono); font-size: var(--word-size, 48px);
  font-weight: 500; line-height: 1.2; min-height: 1.2em;
  white-space: nowrap; transition: font-size 0.15s ease;
  display: flex; align-items: baseline; justify-content: center;
}
.pre-letter  { color: var(--text); display: inline-block; width: 50%; text-align: right; }
.orp-letter  { color: var(--accent); display: inline-block; flex-shrink: 0; }
.post-letter { color: var(--text); display: inline-block; width: 50%; text-align: left; }

#context-strip {
  display: flex; align-items: baseline; gap: 10px; justify-content: center;
  font-family: var(--font-mono); font-size: 14px;
  max-width: min(560px, 92%); overflow: hidden; flex-wrap: nowrap;
  position: relative; z-index: 1;
}
.ctx-word { color: var(--text-muted); opacity: 0.55; white-space: nowrap; }
.ctx-current { color: var(--text); opacity: 0.9; font-weight: 500; }
.ctx-fade-l { opacity: 0.25 !important; }
.ctx-fade-ll { opacity: 0.12 !important; }

/* Bionic reading pane */

#bionic-pane {
  flex: 1; display: flex; overflow: hidden; min-width: 0;
}

#bionic-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  display: flex; justify-content: center;
  padding: 48px 24px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#bionic-scroll::-webkit-scrollbar { width: 4px; }
#bionic-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#bionic-text-content {
  max-width: 640px; width: 100%;
  font-size: 19px; line-height: 1.9;
  color: var(--text-muted);
}

.bionic-page-divider {
  font-size: 11px; color: var(--text-faint);
  padding: 14px 0 8px; border-top: 1px solid var(--border);
  margin-top: 16px;
}
.bionic-page-divider:first-child { border-top: none; margin-top: 0; padding-top: 0; }

#bionic-text-content b { color: var(--text); font-weight: 700; }

/* PDF pane */

#pdf-pane {
  width: 0; flex-shrink: 0; overflow: hidden;
  border-left: 1px solid transparent;
  background: var(--surface);
  transition: width 0.3s ease, border-color 0.3s ease;
  display: flex; flex-direction: column;
}
#pdf-pane.open {
  width: 420px;
  border-left-color: var(--border);
}
@media (max-width: 900px) {
  #pdf-pane.open { width: 320px; }
}

#pdf-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 12px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#pdf-scroll::-webkit-scrollbar { width: 4px; }
#pdf-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#pdf-text-content {
  font-family: var(--font-ui); font-size: 13px; line-height: 1.7;
  color: var(--text-muted); white-space: pre-wrap; word-break: break-word;
}

.pdf-page-divider {
  font-size: 11px; color: var(--text-faint);
  padding: 10px 0 6px; border-top: 1px solid var(--border);
  margin-top: 12px;
}
.pdf-page-divider:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.pdf-word {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
  display: inline;
}
.pdf-word:hover { background: var(--surface-2); color: var(--text); }
.pdf-word.active {
  background: var(--accent);
  color: #fff;
}

/* Controls */

#controls { flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 0 20px 16px; }

#progress-wrap { width: 100%; padding: 14px 0 6px; cursor: pointer; position: relative; }
#progress-track { width: 100%; height: 3px; background: var(--surface-2); border-radius: 3px; position: relative; overflow: visible; }
#progress-fill { height: 100%; background: var(--accent); border-radius: 3px; width: 0%; transition: width 0.1s linear; position: relative; }
#progress-fill::after { content: ''; position: absolute; right: -5px; top: -4px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity 0.15s; }
#progress-wrap:hover #progress-fill::after { opacity: 1; }

#stats-row { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); padding: 4px 0 10px; }

#controls-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }

#play-btn { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.12s, box-shadow 0.12s; box-shadow: 0 2px 10px rgba(0,0,0,0.35); flex-shrink: 0; }
#play-btn:hover { transform: scale(1.05); box-shadow: 0 3px 14px rgba(0,0,0,0.4); }
#play-btn:active { transform: scale(0.96); }
#play-btn svg { pointer-events: none; }

.slider-group { display: flex; flex-direction: column; gap: 6px; min-width: 170px; flex: 1; }
.slider-label { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; }
.slider-label span { color: var(--text); font-weight: 500; }

.slider-control { display: flex; align-items: center; gap: 8px; }

.step-btn {
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); font-size: 15px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.step-btn:hover { color: var(--text); border-color: var(--text-faint); background: var(--border); }
.step-btn:active { transform: scale(0.94); }

input[type=range] { -webkit-appearance: none; width: 100%; height: 6px; border-radius: 4px; background: var(--surface-2); outline: none; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--text); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,0.4); transition: transform 0.1s, background 0.1s; }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.1); background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--surface); background: var(--text); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 4px; background: var(--surface-2); }

/* Loading overlay */

#loading-overlay { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#loading-overlay.visible { opacity: 1; pointer-events: all; }
.loading-bar { width: 200px; height: 2px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.loading-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width 0.3s; animation: load-pulse 1.2s ease-in-out infinite; }
@keyframes load-pulse { 0%{opacity:1} 50%{opacity:0.4} 100%{opacity:1} }
.loading-text { font-size: 12px; color: var(--text-muted); }

#done-flash { position: absolute; inset: 0; background: var(--accent-soft); border-radius: var(--radius-lg); opacity: 0; pointer-events: none; transition: opacity 0.3s; }

#kb-hint { position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--text-faint); pointer-events: none; }
