/* ═══════════════════════════════════════════════════
   1. RESET & BASE
═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--bg); /* fills any gap below bottom-nav on overscroll */
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none; /* prevent iOS rubber-band revealing background */
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input, textarea {
  font-family: inherit;
  color: inherit;
}

/* ═══════════════════════════════════════════════════
   2. CSS CUSTOM PROPERTIES — THEMES
═══════════════════════════════════════════════════ */
:root, [data-theme="dark"] {
  --bg:            #0f0f0f;
  --bg-card:       #1c1c1e;
  --bg-elevated:   #2c2c2e;
  --bg-sheet:      #1c1c1e;
  --bg-input:      #2c2c2e;
  --text:          #e8e8e8;
  --text-muted:    #8a8a8e;
  --text-faint:    #48484a;
  --accent:        #f5a623;
  --accent-glow:   rgba(245, 166, 35, 0.25);
  --accent-dim:    rgba(245, 166, 35, 0.15);
  --border:        #2c2c2e;
  --progress-bg:   #2c2c2e;
  --danger:        #ff453a;
  --sheet-handle:  #48484a;
}

[data-theme="sepia"] {
  --bg:            #f4efe6;
  --bg-card:       #ede8df;
  --bg-elevated:   #e3ddd4;
  --bg-sheet:      #e8e2d8;
  --bg-input:      #ddd8ce;
  --text:          #3c2f1e;
  --text-muted:    #7a6a52;
  --text-faint:    #b8a890;
  --accent:        #8b5e2a;
  --accent-glow:   rgba(139, 94, 42, 0.2);
  --accent-dim:    rgba(139, 94, 42, 0.1);
  --border:        #d4cbbf;
  --progress-bg:   #d4cbbf;
  --danger:        #c0392b;
  --sheet-handle:  #b8a890;
}

[data-theme="white"] {
  --bg:            #ffffff;
  --bg-card:       #f5f5f7;
  --bg-elevated:   #ebebed;
  --bg-sheet:      #f5f5f7;
  --bg-input:      #ebebed;
  --text:          #1a1a1a;
  --text-muted:    #6e6e73;
  --text-faint:    #b0b0b5;
  --accent:        #2563eb;
  --accent-glow:   rgba(37, 99, 235, 0.15);
  --accent-dim:    rgba(37, 99, 235, 0.08);
  --border:        #e5e5ea;
  --progress-bg:   #e5e5ea;
  --danger:        #dc2626;
  --sheet-handle:  #c7c7cc;
}

/* ═══════════════════════════════════════════════════
   3. LAYOUT — SCREENS & NAVIGATION
═══════════════════════════════════════════════════ */
.screen {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.screen.active { display: flex; }

.screen-slide-up {
  transform: translateY(100%);
  display: flex !important;
  bottom: 0;
  z-index: 10;
}

.screen-slide-up.active { transform: translateY(0); }

.screen-reader {
  bottom: 0;
  z-index: 20;
  display: flex !important;
  transform: translateX(100%);
  padding-top: 0; /* reader-top-bar handles safe area directly */
}

.screen-reader.active { transform: translateX(0); }

.screen-reader .reader-top-bar {
  padding-top: calc(10px + env(safe-area-inset-top));
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 5;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 20px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  min-width: 60px;
  transition: color 0.15s;
}

.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }

.nav-item-add {
  padding: 4px 20px;
}

.nav-add-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.nav-add-circle svg { width: 22px; height: 22px; }

/* Top bars */
.top-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-bar-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.top-bar-spacer { width: 36px; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s;
}

.icon-btn:active { background: var(--bg-elevated); }
.icon-btn svg { width: 20px; height: 20px; }

/* ═══════════════════════════════════════════════════
   4. LIBRARY SCREEN
═══════════════════════════════════════════════════ */
.library-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  padding: 16px;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); /* clear bottom nav */
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 32px;
  text-align: center;
}

.empty-state-icon { color: var(--text-faint); }
.empty-state-icon svg { width: 72px; height: 72px; }
.empty-state-title { font-size: 20px; font-weight: 600; color: var(--text); }
.empty-state-sub { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.empty-cta {
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 24px;
  margin-top: 8px;
}

/* Document grid */
.doc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.doc-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.1s, background 0.15s;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  min-height: 130px;
}

.doc-card:active { transform: scale(0.97); background: var(--bg-elevated); }

.doc-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 7px;
  border-radius: 6px;
  align-self: flex-start;
}

.doc-card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.doc-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.doc-card-progress {
  height: 3px;
  background: var(--progress-bg);
  border-radius: 2px;
  overflow: hidden;
}

.doc-card-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px var(--accent-glow);
  z-index: 4;
  transition: transform 0.15s;
}

.fab:active { transform: scale(0.93); }
.fab svg { width: 24px; height: 24px; }

/* ═══════════════════════════════════════════════════
   5. ADD SCREEN
═══════════════════════════════════════════════════ */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 12px 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  padding: 20px 16px;
  gap: 16px;
}

.tab-panel.active { display: flex; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group-grow { flex: 1; min-height: 0; }

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-label-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }

.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.form-input:focus { border-color: var(--accent); }

.form-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.55;
  outline: none;
  resize: none;
  flex: 1;
  min-height: 180px;
  width: 100%;
  transition: border-color 0.15s;
}

.form-textarea:focus { border-color: var(--accent); }

.paste-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.char-count {
  font-size: 12px;
  color: var(--text-faint);
}

.btn-clean {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--accent-dim);
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-clean:disabled { opacity: 0.35; pointer-events: none; }
.btn-clean:active   { opacity: 0.7; }

.form-footer {
  padding-top: 4px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.input-row { display: flex; gap: 8px; }
.input-row .form-input { flex: 1; }

/* Upload zone */
.upload-zone {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:active { border-color: var(--accent); background: var(--accent-dim); }
.upload-icon { color: var(--text-muted); }
.upload-icon svg { width: 48px; height: 48px; }
.upload-text { font-size: 16px; font-weight: 600; color: var(--text); }
.upload-subtext { font-size: 13px; color: var(--text-muted); }

.pdf-progress { display: flex; flex-direction: column; gap: 8px; }
.progress-label { font-size: 13px; color: var(--text-muted); }
.progress-bar-outer { height: 4px; background: var(--progress-bg); border-radius: 2px; overflow: hidden; }
.progress-bar-inner { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; width: 0%; }

.url-status { font-size: 13px; color: var(--text-muted); min-height: 18px; }
.url-preview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  max-height: 100px;
  overflow: hidden;
  position: relative;
}

/* Buttons */
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  border-radius: 12px;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active { transform: scale(0.98); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.38; pointer-events: none; }
.btn-primary.btn-danger { background: var(--danger); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════
   6. READER SCREEN
═══════════════════════════════════════════════════ */
.reader-top-bar {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1;
}

.reader-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* Font panel */
.font-panel {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.font-panel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.font-panel-label { font-size: 14px; font-weight: 500; color: var(--text-muted); flex-shrink: 0; }

.segmented-control {
  display: flex;
  background: var(--bg-elevated);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--bg-sheet);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.theme-control { display: flex; gap: 6px; }

.theme-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  transition: all 0.15s;
}

.theme-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Reading area */
.reader-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

.reader-content {
  padding: 24px 20px 32px;
  font-size: var(--reader-font-size, 18px);
  line-height: 1.7;
  color: var(--text);
  word-spacing: 2px;
}

/* Font size tokens */
.reader-size-S  { --reader-font-size: 15px; }
.reader-size-M  { --reader-font-size: 18px; }
.reader-size-L  { --reader-font-size: 22px; }
.reader-size-XL { --reader-font-size: 28px; }

/* Reader paragraphs */
.reader-para {
  margin-bottom: 1.3em;
  display: block;
}
.reader-para:last-child { margin-bottom: 0; }

/* Focus mode — dim non-active paragraphs */
.reader-content.focus-mode .reader-para {
  opacity: 0.2;
  transition: opacity 0.4s;
}
.reader-content.focus-mode .reader-para.para-active {
  opacity: 1;
}

/* Word spans */
.word {
  cursor: pointer;
  display: inline;
  border-radius: 3px;
  transition: color 0.1s, opacity 0.1s;
  padding: 0 1px;
}

.word-active {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

.word-spoken { opacity: 0.4; }

.word-skipped {
  opacity: 0.22;
  font-style: italic;
}

.word-highlight-yellow { text-decoration: underline 2px #f5c542; text-underline-offset: 3px; }
.word-highlight-blue   { text-decoration: underline 2px #5b9cf6; text-underline-offset: 3px; }
.word-highlight-green  { text-decoration: underline 2px #4ade80; text-underline-offset: 3px; }
.word-highlight-pink   { text-decoration: underline 2px #f472b6; text-underline-offset: 3px; }

/* Player bar */
.player-bar {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.player-row-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.player-row-secondary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: transform 0.1s, background 0.1s;
}

.player-btn:active { transform: scale(0.9); }

.player-btn-play {
  width: 60px;
  height: 60px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.player-btn-play svg { width: 24px; height: 24px; }

.player-btn-skip {
  width: 44px;
  height: 44px;
  color: var(--text);
  position: relative;
  flex-direction: column;
  gap: 1px;
}

.player-btn-skip svg { width: 22px; height: 22px; }

.skip-label {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  bottom: 5px;
}

.player-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 52px;
  flex-shrink: 0;
  gap: 4px;
}

.player-pill svg { width: 16px; height: 16px; }

.player-pill-sleep { min-width: 40px; padding: 6px 10px; }
.player-pill-sleep.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.player-progress-wrap {
  flex: 1;
}

.player-time-left {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 28px;
  text-align: right;
}

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

.player-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.5s linear;
}

/* iOS resume overlay */
.resume-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.resume-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 16px 32px;
  border-radius: 30px;
  box-shadow: 0 8px 24px var(--accent-glow);
}

.resume-btn svg { width: 22px; height: 22px; }

/* Word action popover */
.word-popover {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 50;
}

.word-popover-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-right: 1px solid var(--border);
}

.word-popover-btn:last-child { border-right: none; }
.word-popover-btn:active { background: var(--accent-dim); }

.color-picker {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 50;
}

.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.color-dot:active { transform: scale(1.2); }

/* ═══════════════════════════════════════════════════
   7. SETTINGS SCREEN
═══════════════════════════════════════════════════ */
.settings-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  padding: 16px 0;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); /* clear bottom nav */
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 16px 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.settings-row:first-of-type { border-top: 1px solid var(--border); }

.settings-label { font-size: 15px; font-weight: 500; }

.settings-value-btn {
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-action-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.settings-action-btn:first-of-type { border-top: 1px solid var(--border); }
.settings-action-btn:active { background: var(--bg-elevated); }
.settings-action-btn-danger { color: var(--danger); }

.settings-about-text {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 16px;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════
   8. BOTTOM SHEETS (shared)
═══════════════════════════════════════════════════ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(2px);
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-sheet);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-sheet.open { transform: translateY(0); }

.bottom-sheet-tall { max-height: 80vh; }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--sheet-handle);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

.sheet-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-title-row .sheet-title { margin-bottom: 0; }

.sheet-title-action {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.sheet-action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 4px;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.sheet-action-btn:last-child { border-bottom: none; }
.sheet-action-btn:active { color: var(--accent); }
.sheet-action-btn svg { width: 20px; height: 20px; color: var(--text-muted); }
.sheet-action-btn-danger { color: var(--danger); }

/* Speed grid */
.speed-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.speed-btn {
  padding: 12px 4px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  text-align: center;
  transition: background 0.15s, color 0.15s;
}

.speed-btn.active {
  background: var(--accent);
  color: #fff;
}

.speed-btn:active { opacity: 0.8; }

/* Voice list */
/* Voice item layout with preview button */
.voice-item-info { flex: 1; min-width: 0; }

.voice-preview-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 6px;
  transition: background 0.15s, color 0.15s;
}

.voice-preview-btn svg { width: 16px; height: 16px; }
.voice-preview-btn:active { background: var(--accent-dim); color: var(--accent); }

.voice-preview-btn.previewing {
  background: var(--accent-dim);
  color: var(--accent);
  animation: pulse-preview 1s ease-in-out infinite;
}

@keyframes pulse-preview {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.voice-filter-row {
  margin-bottom: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle-input { display: none; }

.toggle-track {
  width: 44px;
  height: 26px;
  background: var(--bg-elevated);
  border-radius: 13px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.toggle-input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle-input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }

.voice-list { display: flex; flex-direction: column; }

.voice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.voice-item:last-child { border-bottom: none; }
.voice-item:active { background: var(--accent-dim); }

.voice-item-name { font-size: 14px; font-weight: 500; }
.voice-item-lang { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-top: 2px; }

.voice-gender-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.voice-gender-female {
  background: rgba(244, 114, 182, 0.18);
  color: #f472b6;
}
.voice-gender-male {
  background: rgba(91, 156, 246, 0.18);
  color: #5b9cf6;
}

.voice-item-check {
  color: var(--accent);
  opacity: 0;
  flex-shrink: 0;
}

.voice-item-check svg { width: 18px; height: 18px; }
.voice-item.active .voice-item-check { opacity: 1; }

/* Bookmark list */
.bookmark-list { display: flex; flex-direction: column; }

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.bookmark-item:last-child { border-bottom: none; }
.bookmark-item:active { background: var(--accent-dim); }

.bookmark-icon { color: var(--accent); flex-shrink: 0; }
.bookmark-icon svg { width: 16px; height: 16px; }

.bookmark-label { font-size: 14px; font-weight: 500; flex: 1; }
.bookmark-context { font-size: 12px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

.bookmark-delete {
  color: var(--text-faint);
  padding: 4px 8px;
  flex-shrink: 0;
}

.bookmark-delete:active { color: var(--danger); }
.bookmark-delete svg { width: 16px; height: 16px; }

/* Notes list */
.notes-list { display: flex; flex-direction: column; }

.note-item {
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.note-item:last-child { border-bottom: none; }
.note-item:active { background: var(--accent-dim); }

.note-item-context { font-size: 12px; color: var(--text-muted); font-style: italic; }
.note-item-text { font-size: 14px; }
.note-item-empty { font-size: 13px; color: var(--text-faint); padding: 24px 4px; text-align: center; }

.note-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  resize: none;
  min-height: 100px;
  margin-bottom: 12px;
  color: var(--text);
}

.note-textarea:focus { border-color: var(--accent); }

/* Sort options */
.sort-option { position: relative; }
.sort-option.active { color: var(--accent); }

/* Confirm dialog */
.confirm-message {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ═══════════════════════════════════════════════════
   9. ANIMATIONS & UTILITIES
═══════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.fade-in { animation: fadeIn 0.2s ease-out; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Scrollbar hide (mobile webkit) */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }

/* ═══════════════════════════════════════════════════
   10. TOAST NOTIFICATIONS
═══════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1c1c1e;
  color: #e8e8e8;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 20px;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
