@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&display=swap');

:root {
  --bg: #f5f0e8;
  --surface: #ede8df;
  --surface2: #e3ddd3;
  --border: #ccc5b8;
  --text: #1a1713;
  --text-muted: #6b6459;
  --accent: #c0392b;
  --accent2: #e67e22;
  --highlight-fg: #1a1713;
  --highlight-bg: #e6b800;
  --other-fg: #6b6459;
  --other-bg: transparent;
  --display-bg: transparent;
  
  --panel-width: 720px;
  --font-size: clamp(1.2rem, 3.5vw, 1.4rem);
  --line-height: 1.85;
  --padding: 24px;
  --font-family: 'Fraunces', serif;
  
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.12);
  --transition: 0.2s ease-out;
  --glass-bg: rgba(237, 232, 223, 0.85);
}

[data-dark] {
  --bg: #141210;
  --surface: #1e1c19;
  --surface2: #252320;
  --border: #3a3730;
  --text: #f0ebe0;
  --text-muted: #8a8278;
  --accent: #e05a4a;
  --accent2: #e8903a;
  --highlight-fg: #141210;
  --highlight-bg: #e6b800;
  --other-fg: #8a8278;
  --display-bg: transparent;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.6);
  --glass-bg: rgba(30, 28, 25, 0.85);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
  touch-action: manipulation;
}

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#logo {
  font-family: 'Fraunces', serif;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: all 0.3s ease;
  user-select: none;
  margin-left: 12px;
}
.status-badge.online {
  color: #2ecc71;
  border-color: rgba(46, 204, 113, 0.2);
  background: rgba(46, 204, 113, 0.05);
}
.status-badge.online .status-dot {
  background: #2ecc71;
  box-shadow: 0 0 8px #2ecc71;
}
.status-badge.offline {
  color: #e67e22;
  border-color: rgba(230, 126, 34, 0.2);
  background: rgba(230, 126, 34, 0.05);
}
.status-badge.offline .status-dot {
  background: #e67e22;
  box-shadow: 0 0 8px #e67e22;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}
@media (max-width: 600px) {
  .status-badge {
    padding: 0;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    justify-content: center;
    margin-left: 8px;
  }
  .status-badge .status-text {
    display: none;
  }
}
#logo span { color: var(--accent); }
.header-controls { display: flex; gap: 12px; align-items: center; }

/* ─── BUTTONS & MICRO-INTERACTIONS ─── */
.btn {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--border); transform: translateY(-1px); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 500; box-shadow: var(--shadow); }
.btn.primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: var(--shadow-float); }
.btn.active { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.btn.icon { padding: 8px 12px; font-size: 16px; }

.btn-circular {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  display: flex; justify-content: center; align-items: center;
  transition: all var(--transition); font-size: 14px;
}
.btn-circular:hover { background: var(--border); transform: translateY(-1px); }
.btn-circular:active { transform: scale(0.96); }
.btn-circular.primary { background: var(--accent); color: white; border-color: var(--accent); box-shadow: var(--shadow-float); }
.btn-circular.primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-circular.large { width: 64px; height: 64px; font-size: 20px; }
.btn-circular.sub-icon { width: 36px; height: 36px; font-size: 12px; opacity: 0.7;}

#btn-skip-back, #btn-skip-fwd { opacity: 0.5; transition: opacity 0.2s; }
#btn-skip-back:hover, #btn-skip-fwd:hover { opacity: 1; }

/* Audio Toggle in Control Bar */
#btn-audio-toggle {
  position: relative;
  transition: all var(--transition);
  font-size: 14px;
}
#btn-audio-toggle.audio-on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  opacity: 1;
  box-shadow: 0 0 12px rgba(192, 57, 43, 0.35);
}
#btn-audio-toggle.audio-on:hover {
  box-shadow: 0 0 20px rgba(192, 57, 43, 0.5);
}
/* ─── MAIN LAYOUT ─── */
#app {
  display: flex;
  justify-content: center;
  width: 100%;
  padding-bottom: 140px; /* Safe padding for floating bar */
}
#main-canvas {
  width: 100%;
  max-width: var(--panel-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 80px);

}

/* ─── TEXT INPUT AREA ─── */
#input-section {
  padding: var(--padding);
  transition: max-height 0.4s ease-in-out, opacity 0.3s ease;
  opacity: 1;
  max-height: 800px;
  overflow: hidden;
  transform-origin: top;
}

#input-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
#input-tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 12px 16px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  transition: all var(--transition);
  background: transparent;
  border-top: none; border-left: none; border-bottom: none;
}
@media (max-width: 500px) {
  .tab { padding: 10px 8px; font-size: 10px; letter-spacing: 0.05em; }
}
.tab:last-child { border-right: none; }
.tab.active { color: var(--text); background: var(--surface2); font-weight: 500; }
.tab-panel { display: none; padding: 16px; }
.tab-panel.active { display: block; }
#text-input {
  width: 100%;
  min-height: 200px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  padding: 12px;
  overflow-y: auto;
}
#text-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  display: block;
}
.upload-zone:hover { border-color: var(--accent); color: var(--text); background: var(--surface2); }
.upload-zone input { display: none; }
.upload-zone .upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.loading-text { font-size: 12px; color: var(--text-muted); font-style: italic; padding: 12px 0; text-align: center;}

/* ─── FOCUS MODE TRANSITION ─── */
body.reading-active #input-section #input-area {
  padding: 0; max-height: 0; opacity: 0; border: none; overflow: hidden;
}
body.reading-active #input-section {
  padding-bottom: 0; padding-top: 12px;
}
body.reading-active #edit-return-banner {
  display: flex !important;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease forwards;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── READING DISPLAY ─── */
#display-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}
#display-panel {
  flex: 1;
  padding: var(--padding);
  background: var(--display-bg);
  transition: background var(--transition);
  border-radius: var(--radius);
  position: relative;
  overflow-x: auto;
}
/* Content Zoom: clip overflow when zoomed */
body.content-zoom-active #display-panel {
  overflow: hidden;
}
#display-panel.focus-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.empty-state-msg {
  position: absolute; top: 50%; left: 50%; width: 80%; transform: translate(-50%, -50%);
  text-align: center; color: var(--text-muted); opacity: 0.6;
}
.empty-state-msg .empty-icon { font-size: 2.5rem; margin-bottom: 12px;}
.empty-state-msg h3 { font-family: 'Fraunces', serif; font-size: 1.5rem; color: var(--text); margin-bottom: 8px;}
.empty-state-msg p { font-size: 13px; line-height: 1.6;}

#reading-text {
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--other-fg);
  margin: 0 auto;
  word-wrap: break-word;
  white-space: pre-wrap;
  padding-bottom: 48px; /* Breathing room */
}
/* Content Zoom: scale reading text and smoothly pan to active word */
body.content-zoom-active #reading-text {
  transform: scale(var(--content-zoom, 1));
  transform-origin: var(--zoom-origin-x, 50%) var(--zoom-origin-y, 50%);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
              transform-origin 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform, transform-origin;
}

/* Highlight System - Signature Feature */
#reading-text span.word {
  display: inline-block; /* strictly block for smooth scale transforms */
  border-radius: 4px;
  cursor: default;
  transform-origin: center center;
  will-change: transform, background, color;
  transition: background 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), 
              color 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), 
              transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#reading-text span.word.active {
  background: var(--highlight-bg);
  color: var(--highlight-fg);
  transform: scale(1.12);
  border-radius: 4px;
  z-index: 5;
  position: relative;
}
#reading-text span.word.active.highlighted {
  background: var(--highlight-bg);
  color: var(--highlight-fg);
}
#reading-text span.word:not(.active) {
  color: var(--other-fg);
  transform: scale(1);
}

/* Focus mode words */
#focus-display { text-align: center; }
.focus-prev, .focus-next {
  font-family: var(--font-family);
  font-size: calc(var(--font-size) * 0.75);
  color: var(--text-muted);
  opacity: 0.5;
}
.focus-current {
  font-family: var(--font-family);
  font-size: calc(var(--font-size) * 1.6);
  background: var(--highlight-bg);
  color: var(--highlight-fg);
  padding: 0.1em 0.3em;
  border-radius: 8px;
  display: inline-block;
  margin: 12px 0;
  transform-origin: center center;
  will-change: transform;
  transform: scale(1.12);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
              background 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
              color 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ─── FLOATING CONTROL BAR ─── */
.glass-bar {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  width: 90%; max-width: 600px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-float);
  z-index: 90;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#progress-bar-wrap { width: 100%; height: 6px; background: rgba(0,0,0,0.05); }
[data-dark] #progress-bar-wrap { background: rgba(255,255,255,0.05); }
#progress-bar { height: 100%; background: var(--accent); width: 0%; border-radius: 4px; transition: width 0.15s linear; }

.floating-controls-inner {
  padding: 16px 24px;
  display: flex; flex-direction: column; gap: 16px;
  align-items: center;
}
.play-actions { display: flex; align-items: center; justify-content: center; gap: 16px; }

.speed-actions {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid rgba(128,128,128,0.1); padding-top: 16px; width: 100%;
}
.speed-label { font-size: 10px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1px;}
.minimal-input {
  width: 55px; background: transparent; border: none; color: var(--text); font-family: 'DM Mono', monospace; font-size: 14px; font-weight: bold; text-align: center; border-bottom: 1px dashed var(--border); outline: none;
}
.minimal-select {
  background: transparent; border: none; color: var(--text); font-family: 'DM Mono', monospace; font-size: 13px; font-weight: bold; outline: none; cursor: pointer; border-bottom: 1px dashed var(--border);
}
.combo-input { display: flex; align-items: center; gap: 8px;}

.mini-stat { font-family: 'DM Mono', monospace; font-size: 12px; font-weight: bold; color: var(--text-muted); padding: 4px 8px; border-radius: 12px; background: var(--surface2); }

/* ─── SETTINGS DRAWER ─── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 100; opacity: 0; pointer-events: none; transition: 0.3s ease; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 400px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: -10px 0 40px rgba(0,0,0,0.1);
  display: grid;
  grid-template-rows: auto 1fr;
}
body.settings-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
body.settings-open .drawer { transform: translateX(0); }

.drawer-header { padding: 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--surface2); }
.drawer-content {
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: 60px;
}
.drawer-section-title {
  padding: 16px 24px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
}

.panel-section { border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); transition: background var(--transition); font-weight: bold;}
.panel-header:hover { background: var(--surface2); color: var(--text); }
.panel-header .toggle-icon { transition: transform 0.2s; font-size: 14px; }
.panel-header.collapsed .toggle-icon { transform: rotate(-90deg); }
.panel-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; border-top: 1px solid var(--border); }
.panel-body.hidden { display: none; }

.field { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 120px; }
.field-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.field label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.field input[type=number], .field input[type=text], .field select, .field textarea {
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: inherit; font-size: 13px; padding: 12px; outline: none; transition: 0.2s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.color-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.color-field { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.color-field label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.color-field input[type=color] { width: 100%; height: 36px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; padding: 2px; background: transparent; }

.toggle-row { display: flex; align-items: center; gap: 12px; }
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 10px; cursor: pointer; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-label { font-size: 12px; color: var(--text); }
.mini-toggle .toggle { width: 28px; height: 16px; }
.mini-toggle .toggle-slider::before { width: 12px; height: 12px; left: 2px; top: 2px;}
.mini-toggle input:checked + .toggle-slider::before { transform: translateX(12px); }

/* ─── OVERLAYS ─── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); z-index: 200; display: flex; justify-content: center; align-items: center; padding: 24px; opacity: 1; transition: 0.3s; }
.overlay.hidden { opacity: 0; pointer-events: none; }
.onboarding-card, .completion-card { background: var(--surface); border-radius: 16px; padding: 32px; width: 100%; max-width: 450px; box-shadow: var(--shadow-float); border: 1px solid var(--border); position: relative; overflow: visible; }
/* Overlay must be scrollable so content is never clipped on small screens */
.overlay { overflow-y: auto; align-items: flex-start; padding: 24px; }
@media (min-height: 600px) { .overlay { align-items: center; } }

/* Intent Selection Buttons */
#intent-overlay .btn { transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); border-color: rgba(0,0,0,0.05); background: var(--surface2); }
#intent-overlay .btn:hover { background: var(--border); transform: translateY(-4px); box-shadow: var(--shadow-float); border-color: var(--accent); }
#intent-overlay .btn strong { color: var(--text); }
#intent-overlay .btn span[aria-hidden] { transition: transform 0.3s ease; }
#intent-overlay .btn:hover span[aria-hidden] { transform: scale(1.2) rotate(5deg); }

/* Range Slider Styling */
.styled-slider {
  -webkit-appearance: none;
  appearance: none; /* Standard property for compatibility */
  height: 6px;
  background: var(--border);
  border-radius: 5px;
  outline: none;
  transition: background 0.2s;
}
.styled-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.styled-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.15), var(--shadow-float);
}
.styled-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

#advanced-speed-settings {
  animation: slideDown 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.completion-card { animation: slideUpFade 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes slideUpFade { from { opacity: 0; transform: translateY(30px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.completion-stats > div:first-child > div:first-child { color: var(--highlight-bg) !important; text-shadow: 0 0 20px rgba(230, 184, 0, 0.5); }
.onboarding-steps { margin-bottom: 24px; display: flex; flex-direction: column; gap: 16px; }
.ob-step { display: flex; gap: 16px; align-items: flex-start; padding: 16px; border-radius: var(--radius-sm); border: 1px solid transparent; opacity: 0.4; transition: 0.3s; }
.ob-step.active { opacity: 1; background: var(--surface2); border-color: var(--border); box-shadow: var(--shadow); }
.ob-icon { font-size: 1.8rem; }
.onboarding-actions { display: flex; justify-content: space-between; align-items: center; }

@media (max-width: 768px) {
  #app { padding-bottom: 160px; }
  #header { padding: 12px 16px; }
  #logo { font-size: 1.3rem; }
  .btn { padding: 8px 12px; }
  .btn.primary { padding: 8px 12px; }
  #main-canvas { padding: 0; }
  #input-section { padding: 16px; }
  #display-panel { padding: 16px; }
  .glass-bar { bottom: 16px; width: 92%; border-radius: 20px;}
  .floating-controls-inner { padding: 12px 16px; gap: 12px;}
  .play-actions { gap: 12px; }
  .btn-circular.large { width: 56px; height: 56px; }
}

@media (max-width: 600px) {
  .speed-actions { flex-direction: column; gap: 12px; padding-top: 12px; }
  .combo-input { width: 100%; justify-content: space-between; border-bottom: 1px solid rgba(128,128,128,0.1); padding-bottom: 8px;}
  #speed-multiplier, .mini-toggle { align-self: center; width: 100%; text-align: center; justify-content: center; }
}

/* ─── ERROR FEEDBACK ANIMATIONS ─── */
@keyframes shake-error {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.input-error {
  animation: shake-error 0.3s ease-in-out;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.2) !important;
}

/* ─── TOAST NOTIFICATIONS ─── */
#toast-container {
  position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
  pointer-events: none;
}
.toast-msg {
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-float);
  color: var(--text); padding: 12px 24px; border-radius: 30px; font-family: 'DM Mono', monospace; font-size: 13px; font-weight: bold;
  opacity: 0; transform: translateY(20px);
  animation: toastFade 2s ease-out forwards;
}
@keyframes toastFade {
  0% { opacity: 0; transform: translateY(20px); }
  10% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ─── PDF READING SURFACE ─── */
#reading-text.pdf-active {
  font-family: initial;
  font-size: initial;
  line-height: initial;
  color: initial;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.pdf-page-container {
  position: relative;
  margin-bottom: 2px;
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  max-width: none;
  zoom: var(--doc-scale, 1);
}

[data-dark] .pdf-page-container {
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

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

.pdf-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.pdf-word {
  position: absolute;
  color: transparent;
  pointer-events: auto;
  cursor: default;
  border-radius: 3px;
  transform-origin: center center;
  will-change: transform, background;
  transition: background 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), 
              box-shadow 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), 
              transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1;
}

.pdf-word.active {
  background: rgba(230, 184, 0, 0.45);
  box-shadow: 0 0 0 2px rgba(230, 184, 0, 0.4), 0 4px 12px rgba(0,0,0,0.1);
  transform: scale(1.12);
  z-index: 10;
}

[data-dark] .pdf-word.active {
  background: rgba(230, 184, 0, 0.5);
  box-shadow: 0 0 0 2px rgba(230, 184, 0, 0.3), 0 0 12px rgba(230, 184, 0, 0.2);
}

/* Lazy loading: hidden words are invisible until revealed by playback */
.pdf-word.lazy-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.3s ease;
}

.pdf-page-label {
  text-align: center;
  padding: 8px 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#pdf-focus-overlay {
  display: none;
  width: 100%;
  min-height: 300px;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ─── PERFECT SYNC WIZARD ─── */
.sync-wizard-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 0;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-float);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  animation: slideUpFade 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* Progress Bar */
.sync-wizard-progress {
  padding: 20px 28px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.sync-progress-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.sync-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sync-progress-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 500;
}

/* Steps Container */
.sync-step {
  display: none;
  padding: 28px 28px 16px;
  text-align: center;
  animation: fadeSlideIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.sync-step.active { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sync-step-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}
.sync-step-title {
  font-family: 'Fraunces', serif;
  font-size: 1.4rem;
  color: var(--text);
  margin-bottom: 8px;
  font-weight: 600;
}
.sync-step-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Provider Selection Grid */
.sync-provider-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sync-provider-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  text-align: left;
  font-family: 'DM Mono', monospace;
  position: relative;
  overflow: hidden;
}
.sync-provider-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.sync-provider-card.selected {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.15), var(--shadow);
}
.sync-provider-card.selected::after {
  content: '✓';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 18px;
  font-weight: bold;
}
.sync-provider-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.sync-provider-card strong {
  font-size: 13px;
  color: var(--text);
  display: block;
}
.sync-provider-info {
  flex: 1;
  min-width: 0;
}
.sync-provider-detail {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}
.sync-provider-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.sync-provider-badge.best {
  color: #27ae60;
  background: rgba(39, 174, 96, 0.1);
}
.sync-provider-badge.great {
  color: var(--accent2);
  background: rgba(230, 126, 34, 0.1);
}
.sync-provider-badge.good {
  color: var(--text-muted);
  background: rgba(128, 128, 128, 0.08);
}
.sync-provider-card.selected .sync-provider-badge {
  display: none;
}
.sync-provider-card.recommended {
  border-color: rgba(39, 174, 96, 0.3);
}
.sync-provider-card.recommended:hover {
  border-color: #27ae60;
  box-shadow: 0 0 0 1px rgba(39,174,96,0.15), var(--shadow);
}

/* Quality Bar */
.sync-quality-bar {
  display: block;
  height: 3px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
  width: 100%;
  max-width: 120px;
}
.sync-quality-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), #27ae60);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* Voice Picker */
.sync-voice-picker {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(128,128,128,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sync-voice-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: bold;
  white-space: nowrap;
}
.sync-voice-select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.sync-voice-select:focus { border-color: var(--accent); }

/* Generating State */
.sync-generating {
  animation: syncPulse 1.5s ease-in-out infinite !important;
  pointer-events: none;
}
@keyframes syncPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(192,57,43,0.3); }
  50% { opacity: 0.7; box-shadow: 0 0 0 12px rgba(192,57,43,0); }
}

/* Instructions Box */
.sync-instructions-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  text-align: left;
  margin-bottom: 16px;
}
.sync-instruction-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}
.sync-instruction-step + .sync-instruction-step {
  border-top: 1px solid rgba(128,128,128,0.08);
}
.sync-instruction-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 2px;
}

/* External Link */
.sync-external-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all var(--transition);
  margin-bottom: 8px;
}
.sync-external-link:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: var(--shadow-float);
}

/* Hint Text */
.sync-hint {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0.7;
}
.sync-hint-arrow {
  font-size: 14px;
  animation: bounceUp 1.5s ease-in-out infinite;
}
@keyframes bounceUp {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* API Key Input */
.sync-key-input-wrap {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border);
  background: var(--bg);
  transition: border-color 0.2s;
}
.sync-key-input-wrap:focus-within {
  border-color: var(--accent);
}
.sync-key-input {
  flex: 1;
  padding: 14px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  outline: none;
  letter-spacing: 0.02em;
}
.sync-key-input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}
.sync-key-toggle {
  padding: 14px 16px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: all var(--transition);
}
.sync-key-toggle:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Key Validation Status */
.sync-key-status {
  min-height: 20px;
  font-size: 11px;
  margin-bottom: 12px;
  font-family: 'DM Mono', monospace;
  transition: all 0.3s;
}
.sync-key-status.valid {
  color: #27ae60;
}
.sync-key-status.invalid {
  color: var(--accent);
}
.sync-key-status.checking {
  color: var(--accent2);
}

/* Security Note */
.sync-security-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  padding: 8px 0;
}

/* Summary Box */
.sync-summary-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 16px;
  text-align: left;
}
.sync-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 12px;
}
.sync-summary-row + .sync-summary-row {
  border-top: 1px solid rgba(128,128,128,0.08);
}
.sync-summary-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
}
.sync-summary-value {
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}
.sync-summary-value.success {
  color: #27ae60;
}

/* Activate Button */
.sync-activate-btn {
  position: relative;
  overflow: hidden;
}
.sync-activate-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transform: translateX(-100%);
  transition: none;
}
.sync-activate-btn:hover::after {
  animation: shimmer 1s ease forwards;
}
@keyframes shimmer {
  to { transform: translateX(100%); }
}

.sync-activate-status {
  min-height: 24px;
  font-size: 12px;
  text-align: center;
  margin-top: 8px;
  font-family: 'DM Mono', monospace;
}
.sync-activate-status.success {
  color: #27ae60;
  animation: fadeSlideIn 0.3s ease forwards;
}

/* Wizard Navigation */
.sync-wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px 24px;
  border-top: 1px solid rgba(128,128,128,0.08);
}
.sync-nav-skip {
  opacity: 0.6;
  font-size: 11px;
  border: none !important;
  background: transparent !important;
  padding: 8px 4px !important;
}
.sync-nav-skip:hover { opacity: 1; }
.sync-nav-actions {
  display: flex;
  gap: 8px;
}

/* Sync Mode Indicator in TTS Panel */
.sync-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.sync-mode-badge.active {
  background: rgba(39, 174, 96, 0.1);
  color: #27ae60;
  border: 1px solid rgba(39, 174, 96, 0.2);
}
.sync-mode-badge.inactive {
  background: rgba(128,128,128,0.05);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Mobile */
@media (max-width: 600px) {
  .sync-wizard-card { max-width: 100%; border-radius: 16px; }
  .sync-step { padding: 20px 20px 12px; }
  .sync-wizard-nav { padding: 12px 20px 20px; }
  .sync-wizard-progress { padding: 16px 20px 0; }
  .sync-provider-card { padding: 12px 14px; }
  .sync-step-title { font-size: 1.2rem; }
}

/* ─── SPOTIFY MINI PLAYER ─── */
.spotify-player {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 320px;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-float);
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: bottom left;
}
.spotify-player.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9) translateY(10px);
}
.spotify-player.minimized .spotify-body {
  display: none;
}

.spotify-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
}
.spotify-header:active { cursor: grabbing; }

.spotify-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
}
.spotify-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 50%;
  font-size: 12px;
}
.spotify-controls {
  display: flex;
  gap: 4px;
}
.spotify-ctrl-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-family: 'DM Mono', monospace;
  line-height: 1;
}
.spotify-ctrl-btn:hover {
  background: var(--border);
  color: var(--text);
}

.spotify-search {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.spotify-search input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.2s;
}
.spotify-search input::placeholder { color: var(--text-muted); }
.spotify-search input:focus { border-color: var(--accent); }
.spotify-load-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.spotify-load-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.spotify-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-float);
}
.spotify-search-results.hidden {
  display: none;
}
.spotify-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.spotify-result-item:last-child {
  border-bottom: none;
}
.spotify-result-item:hover {
  background: var(--surface);
}
.spotify-result-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: var(--bg);
  object-fit: cover;
}
.spotify-result-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.spotify-result-title {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.spotify-result-artist {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spotify-search-message {
  padding: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

.spotify-embed {
  padding: 8px;
  background: var(--bg);
}

.spotify-volume-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.spotify-vol-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
}
.spotify-vol-icon:hover { color: var(--text); }
.spotify-vol-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.spotify-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s;
}
.spotify-vol-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.spotify-vol-value {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  width: 24px;
  text-align: right;
}

.spotify-presets {
  display: flex;
  gap: 4px;
  padding: 8px 10px 10px;
  flex-wrap: wrap;
}
.spotify-preset {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spotify-preset:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--accent);
}
.spotify-preset.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Header button active state */
#btn-spotify-toggle.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
  transform: translateY(20px) scale(0.97);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(128,128,128,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; color: var(--text); font-family: 'Fraunces', serif; }
.btn-close { background: transparent; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); transition: color 0.2s; }
.btn-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-body label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 20px;
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}
.modal-body textarea {
  resize: vertical;
  min-height: 110px;
}

@media (max-width: 768px) {
  .spotify-player {
    width: calc(100% - 32px);
    left: 16px;
    top: 75px;
    bottom: auto;
  }
  
  /* Header Optimization */
  #header { padding: 12px 16px; }
  #logo { font-size: 1.25rem; }
  .header-controls { gap: 8px; }
  .header-controls .btn { 
    padding: 8px; 
    font-size: 16px; 
    border-radius: 50%; 
    width: 38px; 
    height: 38px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
  }
  .header-controls .btn-text, .btn-text, .hide-mobile { display: none !important; }
  
  /* Main Container */
  #input-section { padding: 12px; }
  #display-panel { padding: 0px 16px 16px 16px; }
  #app { padding-bottom: 180px; }
  
  /* PDF Mobile Optimizations */
  #reading-text.pdf-active {
    overflow-x: auto;
    align-items: flex-start;
    width: 100%;
    padding-bottom: 16px;
  }
  .pdf-page-container {
    max-width: none;
    margin: 0 auto 12px 0;
  }
  
  /* Floating Playback Bar */
  .glass-bar { width: 95%; bottom: 16px; }
  .floating-controls-inner { padding: 12px; gap: 10px; }
  .play-actions { gap: 10px; }
  .speed-actions { gap: 8px; padding-top: 10px; border-top: 1px solid rgba(128,128,128,0.15); flex-wrap: nowrap; align-items: center; justify-content: center; width: 100%; margin-top: 4px; }
  
  /* Button Sizing */
  .btn-circular.large { width: 50px; height: 50px; font-size: 18px; }
  .btn-circular { width: 38px; height: 38px; font-size: 14px; }
  
  /* Typography & Forms */
  #text-input { font-size: 13px; min-height: 150px; }
  .upload-zone { padding: 16px; }
  .speed-label { display: none; }
  
  /* Settings Drawer */
  .drawer { max-width: 100%; border-left: none; }
  
  /* Tabs */
  .tab { padding: 10px 8px; font-size: 10px; }
}

/* ─── OCR UX BLUR-UP & SKELETON LOADER ─── */
.hidden {
  display: none !important;
}

#ocr-preview-container {
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ocr-blur {
  filter: blur(8px) grayscale(20%);
}

@keyframes shimmer-wave {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── BIOFLOW FOCUS TYPOGRAPHY ─── */
.bioflow-anchor {
  font-weight: 700;
  letter-spacing: 0.01em;
  opacity: 1;
}

/* Subtle typographic contrast for unanchored parts of words */
.word, .pdf-word, .focus-prev, .focus-current, .focus-next {
  font-weight: 400;
}

/* ─── ZEN MODE ─── */
body.zen-mode {
  cursor: none;
}
body.zen-mode.show-zen-controls {
  cursor: auto;
}
body.zen-mode:not(.show-zen-controls) #header {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}
body.zen-mode:not(.show-zen-controls) .glass-bar {
  transform: translate(-50%, 150%);
  opacity: 0;
  pointer-events: none;
}
body.zen-mode:not(.show-zen-controls) #zoom-control-container {
  transform: translate(150%, -50%) !important;
  opacity: 0;
  pointer-events: none;
}
body.zen-mode #app {
  padding-bottom: 0;
}
body.zen-mode #main-canvas {
  min-height: 100vh;
}
#header, .glass-bar, #zoom-control-container {
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Mobile Bottom Sheet Modals */
@media (max-width: 600px) {
  .overlay { padding: 0; align-items: flex-end; }
  .onboarding-card, .completion-card, .sync-wizard-card, .modal-content {
    border-radius: 24px 24px 0 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border: none !important;
    border-top: 1px solid var(--border) !important;
  }
}
