/* ═══════════════════════════════════════════
   PUSTAKA — EPUB READER
   style.css
═══════════════════════════════════════════ */

:root {
  --cream: #F5EFE0;
  --cream-dark: #EDE4CF;
  --parchment: #D4C5A9;
  --warm-brown: #8B6914;
  --deep-brown: #4A3728;
  --ink: #1C1208;
  --red-accent: #A63D2F;
  --gold: #C9962A;
  --gold-light: #E8C46A;
  --shelf: #6B4C2A;
  --shelf-shadow: #3D2B16;
  --page-bg: #FDFAF4;
  --spine-1: #8B3A3A;
  --spine-2: #2E5E4E;
  --spine-3: #3A5A8B;
  --spine-4: #6B4E8B;
  --spine-5: #8B6B3A;
}

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

body {
  font-family: 'Crimson Pro', serif;
  background: var(--deep-brown);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(92deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px),
    repeating-linear-gradient(180deg, transparent, transparent 8px, rgba(255,255,255,0.01) 8px, rgba(255,255,255,0.01) 9px);
  pointer-events: none;
  z-index: 0;
}

/* ── HEADER ── */
header {
  position: relative;
  z-index: 10;
  background: linear-gradient(180deg, #2A1A0A 0%, var(--deep-brown) 100%);
  border-bottom: 3px solid var(--gold);
  padding: 20px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.logo { display: flex; align-items: baseline; gap: 12px; }

.logo-title {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 900;
  color: var(--gold-light);
  letter-spacing: -0.02em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.logo-subtitle {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--parchment);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.7;
}

.header-actions { display: flex; gap: 12px; align-items: center; }

.btn-import {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--warm-brown) 100%);
  color: var(--ink);
  border: none;
  padding: 10px 22px;
  border-radius: 2px;
  font-family: 'Crimson Pro', serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
  letter-spacing: 0.03em;
}

.btn-import:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
  filter: brightness(1.1);
}

.btn-import svg { width: 16px; height: 16px; }

#file-input { display: none; }

/* ── MAIN LAYOUT ── */
.main-container {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 83px);
}

.view { display: none; }
.view.active { display: block; }

/* ── LIBRARY VIEW ── */
#library-view {
  padding: 48px;
  background: linear-gradient(180deg, var(--deep-brown) 0%, #3A2516 100%);
  min-height: calc(100vh - 83px);
}

.library-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 32px;
}

.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  color: var(--parchment);
  font-style: italic;
  font-weight: 400;
}

.book-count {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--parchment);
  opacity: 0.5;
  letter-spacing: 0.1em;
}

/* ── BOOKSHELF ── */
.bookshelf-wrapper {
  background: linear-gradient(180deg, #5C3D1E 0%, var(--shelf) 60%, var(--shelf-shadow) 100%);
  border-radius: 4px;
  padding: 32px 32px 0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.08), inset 0 -2px 0 rgba(0,0,0,0.3);
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.bookshelf-wrapper::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 12px;
  background: linear-gradient(180deg, #7A5230 0%, #5C3D1E 100%);
  border-radius: 4px 4px 0 0;
}

.books-row {
  display: flex;
  gap: 4px;
  align-items: flex-end;
  min-height: 200px;
  padding-top: 20px;
  flex-wrap: wrap;
}

.shelf-floor {
  height: 18px;
  background: linear-gradient(180deg, var(--shelf-shadow) 0%, #2A1A08 100%);
  margin: 0 -32px;
  box-shadow: inset 0 4px 8px rgba(0,0,0,0.4);
  border-radius: 0 0 4px 4px;
}

/* ── BOOK SPINE ── */
.book-spine {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 44px;
  min-height: 160px;
  max-height: 220px;
  border-radius: 2px 0 0 2px;
  cursor: pointer;
  position: relative;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 2px 0 4px rgba(0,0,0,0.4), inset -3px 0 6px rgba(0,0,0,0.2), inset 2px 0 4px rgba(255,255,255,0.07);
  flex-shrink: 0;
  padding: 12px 4px;
  overflow: visible;
}

.book-spine::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,0.12) 0%, transparent 100%);
  border-radius: 2px 0 0 2px;
}

.book-spine::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(90deg, transparent 0%, rgba(0,0,0,0.3) 100%);
}

.book-spine:hover { transform: translateY(-16px) scale(1.05); z-index: 10; }

.book-spine-title {
  font-family: 'Crimson Pro', serif;
  font-size: 0.62rem;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  text-align: center;
  line-height: 1.2;
  letter-spacing: 0.05em;
  max-height: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.book-spine-author {
  font-family: 'DM Mono', monospace;
  font-size: 0.45rem;
  color: rgba(255,255,255,0.5);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-spine-ornament { font-size: 0.7rem; color: rgba(255,255,255,0.4); }

/* ── SPINE COVER PREVIEW ── */
.spine-cover-preview {
  position: absolute;
  left: 54px;
  bottom: 0;
  width: 130px;
  background: var(--deep-brown);
  border: 1px solid rgba(201,150,42,0.4);
  border-radius: 4px;
  box-shadow: 4px 4px 20px rgba(0,0,0,0.7);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateX(-6px);
  z-index: 50;
}

.spine-cover-preview img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}

.spine-preview-title {
  font-family: 'Crimson Pro', serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--parchment);
  padding: 6px 8px 2px;
  line-height: 1.3;
}

.spine-preview-author {
  font-family: 'Crimson Pro', serif;
  font-style: italic;
  font-size: 0.63rem;
  color: var(--parchment);
  opacity: 0.6;
  padding: 0 8px 8px;
}

.book-spine:hover .spine-cover-preview { opacity: 1; transform: translateX(0); pointer-events: auto; }

/* ── EMPTY SHELF ── */
.empty-shelf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 200px;
  gap: 12px;
  padding-bottom: 20px;
}

.empty-shelf-icon { font-size: 3rem; opacity: 0.3; }

.empty-shelf-text {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  color: var(--parchment);
  opacity: 0.4;
  font-size: 1.1rem;
  text-align: center;
}

/* ── BOOK GRID ── */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 28px;
  margin-top: 8px;
}

.book-card {
  cursor: pointer;
  transition: transform 0.2s ease;
  position: relative;
}

.book-card:hover { transform: translateY(-4px); }

.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  border-radius: 2px 6px 6px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  box-shadow: -3px 0 0 rgba(0,0,0,0.4), 6px 6px 20px rgba(0,0,0,0.5), inset 3px 0 8px rgba(255,255,255,0.1);
  overflow: hidden;
}

.book-cover::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 8px;
  background: linear-gradient(90deg, rgba(0,0,0,0.3) 0%, transparent 100%);
}

.book-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
  border-radius: 2px 6px 6px 2px;
  display: block;
}

.book-cover-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  text-align: center;
  line-height: 1.3;
  z-index: 1;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.book-cover-author {
  font-family: 'Crimson Pro', serif;
  font-style: italic;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.65);
  text-align: center;
  margin-top: 8px;
  z-index: 1;
}

.book-cover-divider { width: 40px; height: 1px; background: rgba(255,255,255,0.3); margin: 8px 0; z-index: 1; }

.book-info { margin-top: 10px; padding: 0 4px; }

.book-info-title {
  font-family: 'Crimson Pro', serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--parchment);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-info-author {
  font-family: 'Crimson Pro', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: var(--parchment);
  opacity: 0.5;
}

.book-progress-bar { height: 2px; background: rgba(255,255,255,0.1); border-radius: 1px; margin-top: 6px; overflow: hidden; }
.book-progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold) 0%, var(--gold-light) 100%); border-radius: 1px; transition: width 0.3s ease; }

.book-delete {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(166,61,47,0.8);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 0.7rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: background 0.15s;
}

.book-card:hover .book-delete { display: flex; }
.book-delete:hover { background: var(--red-accent); }

/* ── VIEW TOGGLE ── */
.view-toggle { display: flex; gap: 4px; background: rgba(0,0,0,0.3); padding: 4px; border-radius: 4px; }

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--parchment);
  opacity: 0.5;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 2px;
  transition: all 0.15s ease;
  font-size: 0.9rem;
}

.toggle-btn.active { background: rgba(255,255,255,0.1); opacity: 1; }

/* ── WELCOME SCREEN ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 83px);
  padding: 48px;
  text-align: center;
  gap: 20px;
}

.welcome-icon {
  font-size: 5rem;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.4));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.welcome-title {
  font-family: 'Playfair Display', serif;
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

.welcome-subtitle {
  font-family: 'Crimson Pro', serif;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--parchment);
  opacity: 0.7;
  max-width: 420px;
  line-height: 1.6;
}

.drop-zone {
  margin-top: 12px;
  border: 2px dashed rgba(201,150,42,0.4);
  border-radius: 8px;
  padding: 40px 60px;
  color: var(--parchment);
  opacity: 0.5;
  font-family: 'Crimson Pro', serif;
  font-size: 1rem;
  font-style: italic;
  transition: all 0.2s ease;
  cursor: pointer;
}

.drop-zone:hover, .drop-zone.drag-over {
  opacity: 1;
  border-color: var(--gold);
  background: rgba(201,150,42,0.05);
}

.drop-zone-sm {
  display: inline-block;
  margin-top: 16px;
  border: 1px dashed rgba(201,150,42,0.3);
  border-radius: 4px;
  padding: 10px 24px;
  color: var(--parchment);
  opacity: 0.5;
  font-family: 'Crimson Pro', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.drop-zone-sm:hover { opacity: 1; border-color: var(--gold); }

/* ── READER VIEW ── */
#reader-view {
  display: none;
  background: var(--page-bg);
  min-height: calc(100vh - 83px);
  flex-direction: column;
}

#reader-view.active { display: flex; }

.reader-toolbar {
  background: linear-gradient(180deg, var(--cream-dark) 0%, var(--cream) 100%);
  border-bottom: 2px solid var(--parchment);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.btn-back {
  background: none;
  border: 1px solid var(--parchment);
  color: var(--deep-brown);
  padding: 6px 14px;
  border-radius: 2px;
  font-family: 'Crimson Pro', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-back:hover { background: var(--deep-brown); color: var(--cream); border-color: var(--deep-brown); }

.reader-book-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 400;
  font-style: italic;
  color: var(--deep-brown);
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.control-btn {
  background: none;
  border: 1px solid var(--parchment);
  color: var(--deep-brown);
  width: 34px;
  height: 34px;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.15s ease;
}

.control-btn:hover { background: var(--deep-brown); color: var(--cream); }

.font-size-display {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--deep-brown);
  opacity: 0.6;
  min-width: 24px;
  text-align: center;
}

/* ── READER LAYOUT ── */
.reader-body { display: flex; flex: 1; overflow: hidden; }

/* ── TOC SIDEBAR ── */
.toc-sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--cream-dark) 0%, var(--cream) 100%);
  border-right: 1px solid var(--parchment);
  overflow-y: auto;
  flex-shrink: 0;
  display: none;
}

.toc-sidebar.visible { display: block; }

.toc-header {
  padding: 20px 20px 12px;
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  color: var(--deep-brown);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--parchment);
}

.toc-list { padding: 8px 0; }

.toc-item {
  display: block;
  padding: 8px 20px;
  font-family: 'Crimson Pro', serif;
  font-size: 0.9rem;
  color: var(--deep-brown);
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
  line-height: 1.4;
}

.toc-item:hover { background: rgba(0,0,0,0.04); }

.toc-item.active {
  border-left-color: var(--warm-brown);
  background: rgba(139,105,20,0.08);
  color: var(--warm-brown);
  font-weight: 600;
}

/* ── READER CONTENT ── */
.reader-content-wrapper {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  background: var(--page-bg);
  background-image: radial-gradient(ellipse at top, rgba(212,197,169,0.1) 0%, transparent 60%);
}

.reader-page {
  max-width: 700px;
  width: 100%;
  padding: 60px 60px 100px;
  position: relative;
}

.reader-page::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent 0%, var(--parchment) 20%, var(--parchment) 80%, transparent 100%);
  opacity: 0.3;
}

#reader-content {
  font-family: 'Crimson Pro', serif;
  font-size: 1.15rem;
  line-height: 1.85;
  color: #2A1E0E;
}

#reader-content h1, #reader-content h2, #reader-content h3 {
  font-family: 'Playfair Display', serif;
  color: var(--deep-brown);
  margin: 2em 0 0.7em;
  line-height: 1.2;
}

#reader-content h1 { font-size: 2rem; font-weight: 900; }
#reader-content h2 { font-size: 1.5rem; }
#reader-content h3 { font-size: 1.2rem; font-style: italic; }

#reader-content p { margin-bottom: 1.2em; text-align: justify; hyphens: auto; }

#reader-content p:first-of-type::first-letter {
  font-family: 'Playfair Display', serif;
  font-size: 3.2em;
  font-weight: 900;
  float: left;
  line-height: 0.8;
  margin-right: 8px;
  margin-top: 4px;
  color: var(--warm-brown);
}

#reader-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2em auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  border-radius: 2px;
}

#reader-content blockquote {
  border-left: 3px solid var(--gold);
  margin: 1.5em 0;
  padding: 8px 0 8px 20px;
  color: var(--deep-brown);
  font-style: italic;
  background: rgba(201,150,42,0.05);
}

#reader-content a { color: var(--warm-brown); text-decoration: underline; }

/* ── PROGRESS BAR ── */
.reading-progress { position: fixed; bottom: 0; left: 0; right: 0; height: 4px; background: rgba(0,0,0,0.1); z-index: 100; }
.reading-progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold) 0%, var(--red-accent) 100%); transition: width 0.2s ease; }

/* ── CHAPTER NAV ── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  border-top: 1px solid var(--parchment);
  margin-top: 40px;
}

.btn-chapter {
  background: none;
  border: 1px solid var(--parchment);
  color: var(--deep-brown);
  padding: 10px 20px;
  border-radius: 2px;
  font-family: 'Crimson Pro', serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-chapter:hover { background: var(--deep-brown); color: var(--cream); }
.btn-chapter:disabled { opacity: 0.3; cursor: not-allowed; }

.chapter-indicator {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--deep-brown);
  opacity: 0.4;
  letter-spacing: 0.1em;
}

/* ── DARK MODE ── */
body.dark-mode { --page-bg: #1A1208; }

body.dark-mode #reader-view { background: #1A1208; }

body.dark-mode .reader-toolbar { background: #2A1E10; border-color: #3A2E1A; }

body.dark-mode .reader-book-title,
body.dark-mode .btn-back,
body.dark-mode .control-btn,
body.dark-mode .font-size-display,
body.dark-mode .toc-header,
body.dark-mode .toc-item { color: var(--cream-dark); }

body.dark-mode .toc-sidebar { background: #201508; border-color: #3A2E1A; }
body.dark-mode .reader-content-wrapper { background: #1A1208; }
body.dark-mode #reader-content { color: #D4C5A9; }
body.dark-mode #reader-content h1, body.dark-mode #reader-content h2, body.dark-mode #reader-content h3 { color: var(--gold-light); }
body.dark-mode .btn-chapter { color: var(--cream-dark); border-color: #3A2E1A; }
body.dark-mode .btn-chapter:hover { background: var(--cream-dark); color: var(--ink); }
body.dark-mode .chapter-indicator { color: var(--cream-dark); }

/* ── LOADING OVERLAY ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,18,8,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.loading-overlay.visible { display: flex; }

.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid rgba(201,150,42,0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  color: var(--parchment);
  font-size: 1.1rem;
}

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

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--deep-brown);
  color: var(--parchment);
  padding: 12px 20px;
  border-radius: 2px;
  font-family: 'Crimson Pro', serif;
  font-size: 0.95rem;
  border-left: 3px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
  z-index: 2000;
  max-width: 320px;
}

.toast.show { transform: translateX(0); }

/* ── TTS HIGHLIGHT ── */
.word-span {
  display: inline;
  border-radius: 3px;
  transition: background 0.08s ease, color 0.08s ease;
  cursor: pointer;
  padding: 0 1px;
}

.word-span:hover { background: rgba(201,150,42,0.18); }

.word-span.tts-active {
  background: #F5C842;
  color: #1C1208 !important;
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(245,200,66,0.4);
}

body.dark-mode .word-span.tts-active { background: #C9962A; color: #1C1208 !important; }

.word-span.tts-sentence { background: rgba(201,150,42,0.12); border-radius: 2px; }

/* ── TTS PANEL ── */
.tts-panel {
  position: fixed;
  bottom: 8px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: linear-gradient(145deg, var(--deep-brown) 0%, #2A1A0A 100%);
  border: 1px solid rgba(201,150,42,0.3);
  border-radius: 16px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  z-index: 500;
  transition: transform 0.4s cubic-bezier(.34,1.56,.64,1);
  min-width: 360px;
  max-width: 90vw;
}

.tts-panel.visible { transform: translateX(-50%) translateY(0); }

.tts-btn {
  background: none; border: none;
  color: var(--parchment); cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.tts-btn:hover { background: rgba(255,255,255,0.1); }
.tts-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.tts-play-btn {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--warm-brown) 100%);
  color: var(--ink);
  font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.tts-play-btn:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--gold) 0%, var(--warm-brown) 100%); }

.tts-close { font-size: 0.8rem; opacity: 0.5; }
.tts-close:hover { opacity: 1; }

.tts-divider { width: 1px; height: 32px; background: rgba(255,255,255,0.1); flex-shrink: 0; }

.tts-word-preview {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  color: var(--gold-light);
  font-size: 0.95rem;
  min-width: 80px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.tts-speed-wrap { display: flex; flex-direction: column; gap: 2px; min-width: 80px; }

.tts-speed-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.55rem;
  color: var(--parchment);
  opacity: 0.5;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tts-speed-val {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--gold-light);
}

.tts-slider {
  -webkit-appearance: none;
  height: 3px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  outline: none;
  width: 80px;
  cursor: pointer;
}

.tts-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
}

.tts-voice-select {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--parchment);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  max-width: 100px;
  cursor: pointer;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,105,20,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139,105,20,0.6); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  header { padding: 16px 20px; }
  .logo-title { font-size: 1.5rem; }
  #library-view { padding: 24px 20px; }
  .reader-toolbar { padding: 10px 16px; gap: 8px; }
  .reader-page { padding: 32px 24px 80px; }
  .tts-panel { min-width: auto; padding: 10px 14px; gap: 8px; }
  .tts-speed-wrap, .tts-voice-select { display: none; }
}
