/* ============================================================
   AuraReader Pro — app.css
   Aesthetic: Minimalist Bento Grid, Apple Books–inspired
   Fonts: Lora (serif display) + DM Sans (body)
   ============================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  /* Typography */
  --font-display: 'Lora', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  /* Light theme (default) */
  --bg:           #F8F7F4;
  --bg-card:      #FFFFFF;
  --bg-overlay:   rgba(248,247,244,0.92);
  --surface:      #F0EDE8;
  --border:       #E5E1DA;
  --text-primary: #1A1815;
  --text-secondary:#6B6560;
  --text-muted:   #A09890;
  --accent:       #C07A4A;       /* warm amber-copper */
  --accent-light: #EDD9C5;
  --accent-dim:   #8F5A35;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --shadow-lg:    0 12px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06);
  --shadow-xl:    0 24px 64px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.10);
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    20px;
  --radius-xl:    28px;
  --transition:   0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg:            #0F0E0C;
  --bg-card:       #1A1917;
  --bg-overlay:    rgba(15,14,12,0.94);
  --surface:       #252320;
  --border:        #2E2C28;
  --text-primary:  #F0EDE8;
  --text-secondary:#9A9590;
  --text-muted:    #5A5550;
  --accent:        #D4935E;
  --accent-light:  #3A2515;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.3);
  --shadow-md:     0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:     0 12px 40px rgba(0,0,0,.5);
}

[data-theme="sepia"] {
  --bg:            #F5EDD6;
  --bg-card:       #FAF3E0;
  --bg-overlay:    rgba(245,237,214,0.93);
  --surface:       #EDE0C4;
  --border:        #D9CDB0;
  --text-primary:  #2C2016;
  --text-secondary:#7A6A54;
  --text-muted:    #9A8A70;
  --accent:        #A0602A;
  --accent-light:  #E8D5B0;
  --accent-dim:    #7A4518;
  --shadow-sm:     0 1px 3px rgba(44,32,22,.08), 0 1px 2px rgba(44,32,22,.05);
  --shadow-md:     0 4px 16px rgba(44,32,22,.1),  0 2px 6px rgba(44,32,22,.06);
  --shadow-lg:     0 12px 40px rgba(44,32,22,.14), 0 4px 12px rgba(44,32,22,.08);
  --shadow-xl:     0 24px 64px rgba(44,32,22,.18), 0 8px 24px rgba(44,32,22,.10);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

/* ── Library Layout ─────────────────────────────────────────── */
.ar-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.ar-logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  flex-shrink: 0;
}
.ar-logo span { color: var(--accent); }

.ar-search-wrap {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.ar-search {
  width: 100%;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 16px 0 40px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ar-search::placeholder { color: var(--text-muted); }
.ar-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.ar-search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.ar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ── Pill filter tabs ───────────────────────────────────────── */
.ar-filters {
  display: flex;
  gap: 6px;
  padding: 12px 24px;
  overflow-x: auto;
  scrollbar-width: none;
}
.ar-filters::-webkit-scrollbar { display: none; }

.ar-filter-btn {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.ar-filter-btn:hover,
.ar-filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Bento Book Grid ────────────────────────────────────────── */
.ar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  padding: 20px 24px 48px;
}

@media (min-width: 640px)  { .ar-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
@media (min-width: 1024px) { .ar-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
@media (min-width: 1400px) { .ar-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); } }

/* ── Book Card ──────────────────────────────────────────────── */
.ar-book-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: inherit;
  display: block;
}
.ar-book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.ar-book-cover-wrap {
  position: relative;
  width: 100%;
  padding-top: 150%;   /* 2:3 aspect */
  overflow: hidden;
  background: var(--surface);
}
.ar-book-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.ar-book-card:hover .ar-book-cover { transform: scale(1.04); }

/* Format badge */
.ar-format-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
  background: rgba(0,0,0,0.42);
  color: #fff;
}

/* Progress ring overlay */
.ar-progress-ring-wrap {
  position: absolute;
  bottom: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
}
.ar-progress-ring { transform: rotate(-90deg); }
.ar-progress-ring-bg { fill: none; stroke: rgba(255,255,255,0.25); stroke-width: 3; }
.ar-progress-ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 88;  /* 2π×14 ≈ 88 */
  stroke-dashoffset: 88;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.ar-book-info {
  padding: 12px 14px 14px;
}
.ar-book-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ar-book-author {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty state */
.ar-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 24px;
  color: var(--text-muted);
}
.ar-empty svg { opacity: 0.3; }
.ar-empty p { font-size: 0.9375rem; }

/* ── Buttons ─────────────────────────────────────────────────── */
.ar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}
.ar-btn-primary {
  background: var(--accent);
  color: #fff;
}
.ar-btn-primary:hover { background: var(--accent-dim); }
.ar-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.ar-btn-ghost:hover { background: var(--surface); color: var(--text-primary); }
.ar-btn-icon {
  width: 38px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

/* ── Reader Page ────────────────────────────────────────────── */
#ar-reader-page {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Reader top bar */
.ar-reader-bar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  z-index: 40;
}

.ar-reader-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

/* Progress bar */
.ar-reader-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  transition: width 0.5s ease;
  border-radius: 0 1px 1px 0;
}

/* Reader body */
#ar-reader {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Settings drawer */
.ar-settings-drawer {
  position: fixed;
  right: 0;
  top: 52px;
  bottom: 0;
  width: 300px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 50;
  padding: 24px 20px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}
.ar-settings-drawer.open { transform: translateX(0); }
#ar-reader-page:has(.ar-view-controls) .ar-settings-drawer { top: 88px; }

.ar-drawer-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  margin-top: 20px;
}
.ar-drawer-label:first-child { margin-top: 0; }

/* Theme swatches */
.ar-theme-row { display: flex; gap: 8px; }
.ar-theme-swatch {
  flex: 1;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font-body);
  font-weight: 500;
  transition: border-color var(--transition);
}
.ar-theme-swatch[data-theme-val="light"] { background: #FFF8F2; color: #1A1815; }
.ar-theme-swatch[data-theme-val="sepia"] { background: #F5EDD6; color: #2C2016; }
.ar-theme-swatch[data-theme-val="dark"]  { background: #1A1917; color: #F0EDE8; }
.ar-theme-swatch.selected { border-color: var(--accent); }

/* Font size control */
.ar-font-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ar-font-row span { flex: 1; text-align: center; font-size: 0.875rem; color: var(--text-primary); }
.ar-font-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.ar-font-btn:hover { background: var(--accent-light); }

/* Slider */
.ar-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Bookmarks panel */
.ar-bookmarks-list { display: flex; flex-direction: column; gap: 8px; }
.ar-bookmark-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.ar-bookmark-item:hover { background: var(--accent-light); }
.ar-bookmark-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ar-bookmark-label { flex: 1; font-size: 0.8125rem; color: var(--text-primary); }
.ar-bookmark-pct { font-size: 0.75rem; color: var(--text-muted); }

/* ── Zen Mode ───────────────────────────────────────────────── */
body.zen-active.chrome-hidden .ar-reader-bar,
body.zen-active.chrome-hidden .ar-view-controls {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}
body.zen-active.chrome-hidden .ar-nav {
  opacity: 0;
  pointer-events: none;
}
body.zen-active:not(.chrome-hidden) .ar-reader-bar,
body.zen-active:not(.chrome-hidden) .ar-view-controls,
body.zen-active:not(.chrome-hidden) .ar-nav {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ── Nav bar (PDF/Image paging) ─────────────────────────────── */
.ar-nav {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-overlay);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 20px;
  box-shadow: var(--shadow-md);
  transition: opacity 0.4s ease;
  z-index: 30;
}
.ar-nav button {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-primary);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background var(--transition);
}
.ar-nav button:hover { background: var(--surface); }
.ar-nav button:disabled { color: var(--text-muted); cursor: not-allowed; }
#ar-page-indicator, #ar-loc-indicator {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  min-width: 80px;
  text-align: center;
}

/* ── Loading & Error states ─────────────────────────────────── */
.ar-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.ar-spinner {
  display: block;
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ar-spin 0.8s linear infinite;
}
@keyframes ar-spin { to { transform: rotate(360deg); } }

.ar-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
}
.ar-error pre {
  font-size: 0.75rem;
  background: var(--surface);
  padding: 12px;
  border-radius: var(--radius-sm);
  max-width: 500px;
  word-break: break-all;
  color: var(--text-muted);
}

/* ── Admin Panel ────────────────────────────────────────────── */
.ar-admin-layout {
  display: flex;
  min-height: 100vh;
}
.ar-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ar-sidebar-logo {
  padding: 0 20px 20px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.ar-sidebar-logo span { color: var(--accent); }
.ar-sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 0;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.ar-sidebar-link:hover,
.ar-sidebar-link.active {
  color: var(--accent);
  background: var(--accent-light);
  border-left-color: var(--accent);
}
.ar-admin-main {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}
.ar-admin-main h1 {
  font-size: 1.75rem;
  margin-bottom: 24px;
  color: var(--text-primary);
}

/* Stat cards */
.ar-stats-row { display: flex; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
.ar-stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.ar-stat-num {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.ar-stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Upload drop zone */
.ar-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
  margin-bottom: 24px;
}
.ar-drop-zone:hover,
.ar-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.ar-drop-zone svg { color: var(--text-muted); margin: 0 auto 12px; display: block; }
.ar-drop-zone p { color: var(--text-secondary); font-size: 0.9375rem; }
.ar-drop-zone small { color: var(--text-muted); font-size: 0.8125rem; }

/* Admin book table */
.ar-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ar-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  font-size: 0.875rem;
}
.ar-table th {
  background: var(--surface);
  padding: 12px 16px;
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.ar-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.ar-table tr:last-child td { border-bottom: none; }
.ar-table tr:hover td { background: var(--surface); }
.ar-table-cover {
  width: 36px; height: 54px;
  object-fit: cover;
  border-radius: 4px;
}

/* Upload progress bar */
.ar-upload-bar-wrap {
  background: var(--surface);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin-top: 12px;
}
.ar-upload-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

/* Input/select styles */
.ar-input, .ar-select, .ar-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ar-input:focus, .ar-select:focus, .ar-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.ar-textarea { resize: vertical; min-height: 80px; }
.ar-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.ar-form-row { margin-bottom: 16px; }

/* Toast notification */
.ar-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--text-primary);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  animation: ar-toast-in 0.3s ease forwards;
  max-width: 320px;
}
@keyframes ar-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ar-toast.error { background: #C0392B; }
.ar-toast.success { background: #27AE60; }

/* ── Swiper overrides ───────────────────────────────────────── */
.ar-swiper .swiper-button-next,
.ar-swiper .swiper-button-prev {
  color: #fff;
  background: rgba(0,0,0,.4);
  width: 40px; height: 40px;
  border-radius: 50%;
  backdrop-filter: blur(8px);
}
.ar-swiper .swiper-button-next::after,
.ar-swiper .swiper-button-prev::after { font-size: 14px; }
.ar-swiper .swiper-pagination-fraction { color: rgba(255,255,255,.8); font-size: 0.8rem; }

/* ── Fade-in animation for grid cards ──────────────────────── */
.ar-book-card {
  animation: ar-card-in 0.4s ease backwards;
}
@keyframes ar-card-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ar-admin-layout { flex-direction: column; }
  .ar-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; padding: 0; overflow-x: auto; }
  .ar-sidebar-logo { display: none; }
  .ar-sidebar-link { padding: 14px 16px; border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .ar-sidebar-link.active { border-left: none; border-bottom-color: var(--accent); }
  .ar-admin-main { padding: 20px; }
  .ar-grid { padding: 16px; gap: 14px; }
  .ar-settings-drawer { width: 100%; top: auto; bottom: 0; height: 70vh; border-left: none; border-top: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; transform: translateY(100%); }
  .ar-settings-drawer.open { transform: translateY(0); }
}

/* ── Login page ─────────────────────────────────────────────── */
.ar-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.ar-login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.ar-login-card h1 {
  font-size: 1.75rem;
  margin-bottom: 6px;
}
.ar-login-card p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ── Categories (filter bar + card pills) ───────────────────── */
.ar-filter-divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
  margin: 4px 6px;
  align-self: stretch;
}

.ar-cat-btn:hover,
.ar-cat-btn.active {
  background: var(--cat-color, var(--accent));
  border-color: var(--cat-color, var(--accent));
  color: #fff;
}

.ar-card-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.ar-card-cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── Layout buttons (page spread / scroll direction) ────────── */
.ar-layout-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}
.ar-layout-btn:hover,
.ar-layout-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}



/* ── Bookmark panel fixes ───────────────────────────────────── */
.ar-bookmark-item {
  cursor: pointer;
  user-select: none;
}
.ar-bookmark-item:hover {
  background: var(--accent-light);
}

.ar-bm-delete {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
}
.ar-bm-delete:hover {
  background: #FEE2E2;
  border-color: #FCA5A5;
  color: #B91C1C;
}

.ar-bm-empty {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
  font-style: italic;
}

/* ── Active icon highlight for toggle buttons ───────────────── */
.ar-btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Admin categories page ──────────────────────────────────── */
.ar-cat-manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}
.ar-cat-manage-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ar-cat-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ar-cat-manage-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.9375rem;
}

/* ═══════════════════════════════════════════════════════════════
   AUTH SYSTEM — login · register · modals · user menu · visibility
   ═══════════════════════════════════════════════════════════════ */

/* ── Auth page split layout ──────────────────────────────────── */
.ar-auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 768px) {
  .ar-auth-page { grid-template-columns: 1fr; }
}

/* Left decorative panel */
.ar-auth-panel {
  background: linear-gradient(145deg, #1A1815 0%, #2D2520 50%, #3D3028 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  position: relative;
  overflow: hidden;
}
@media (max-width: 768px) { .ar-auth-panel { display: none; } }

.ar-auth-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(192,122,74,.18) 0%, transparent 60%);
}

.ar-auth-panel-inner { position: relative; z-index: 1; text-align: center; }

.ar-auth-panel-logo {
  font-family: 'Lora', Georgia, serif;
  font-size: 2.5rem;
  color: #F5F0EB;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}
.ar-auth-panel-logo span { color: #C07A4A; }

.ar-auth-panel-tagline {
  color: #9A9590;
  font-size: 1rem;
  margin-bottom: 48px;
}

/* Animated book spines */
.ar-auth-panel-books {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  justify-content: center;
  height: 140px;
}
.ar-panel-book {
  width: 32px;
  border-radius: 3px 6px 6px 3px;
  background: var(--color, #C07A4A);
  opacity: .85;
  animation: bookRise 1.4s ease-out var(--delay, 0s) both;
}
@keyframes bookRise {
  from { height: 0; opacity: 0; }
  to   { height: calc(60px + var(--delay, 0s) * 60px); opacity: .85; }
}

/* Right form panel */
.ar-auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg);
}

.ar-auth-card {
  width: 100%;
  max-width: 420px;
}

.ar-auth-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 32px;
  transition: color var(--transition);
}
.ar-auth-back:hover { color: var(--accent); }

.ar-auth-title {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.ar-auth-sub {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.5;
}

.ar-auth-alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.875rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
.ar-auth-alert-error   { background: #FEE2E2; border: 1px solid #FCA5A5; color: #B91C1C; }
.ar-auth-alert-success { background: #D1FAE5; border: 1px solid #6EE7B7; color: #065F46; }

.ar-auth-switch {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 24px;
}
.ar-auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }
.ar-auth-switch a:hover { text-decoration: underline; }

/* Password show/hide */
.ar-input-pw-wrap {
  position: relative;
}
.ar-input-pw-wrap .ar-input { padding-right: 44px; }
.ar-pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
}
.ar-pw-toggle:hover { color: var(--accent); }

/* Password strength */
.ar-pw-strength-wrap {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.ar-pw-strength-bar {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width .3s, background .3s;
}

/* Full-width button */
.ar-btn-full {
  width: 100%;
  justify-content: center;
}

/* ── User menu / dropdown ─────────────────────────────────────── */
.ar-user-menu {
  position: relative;
}

.ar-user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: all var(--transition);
}
.ar-user-trigger:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.ar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.ar-user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .ar-user-name { display: none; }
  .ar-search-wrap { max-width: none; }
}
@media (max-width: 480px) {
  .ar-search-wrap { display: none; }
  .ar-header { padding: 0 12px; gap: 8px; }
}

.ar-user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  padding: 8px;
  display: none;
  animation: dropIn .15s ease;
}
.ar-user-dropdown.open { display: block; }

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

.ar-user-info {
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ar-user-info strong { font-size: 0.9rem; color: var(--text-primary); }
.ar-user-info span   { font-size: 0.8rem; color: var(--text-muted); }

.ar-storage-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.ar-storage-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .4s;
}
.ar-storage-label { font-size: 0.72rem !important; color: var(--text-muted) !important; }

.ar-dropdown-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}
.ar-dropdown-link:hover { background: var(--surface); color: var(--text-primary); }
.ar-dropdown-link-danger:hover { background: #FEE2E2; color: #B91C1C; }

/* ── Welcome banner ───────────────────────────────────────────── */
.ar-welcome-banner {
  background: linear-gradient(90deg, var(--accent-light) 0%, transparent 100%);
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* ── Modal system ─────────────────────────────────────────────── */
.ar-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(3px);
  z-index: 300;
}

.ar-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 301;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: min(560px, 95vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  animation: modalIn .2s ease;
}
.ar-modal-sm { width: min(440px, 95vw); }

@keyframes modalIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% - 12px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

.ar-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-shrink: 0;
}
.ar-modal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.ar-modal-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  line-height: 1;
  padding: 0;
}
.ar-modal-close:hover { background: #FEE2E2; border-color: #FCA5A5; color: #B91C1C; }


/* ── Visibility picker ────────────────────────────────────────── */
.ar-vis-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ar-vis-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  user-select: none;
}
.ar-vis-option:hover { border-color: var(--accent); background: var(--accent-light); }
.ar-vis-option.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(192,122,74,.15);
}

.ar-vis-icon  { font-size: 1.4rem; }
.ar-vis-label { font-size: 0.8125rem; font-weight: 600; color: var(--text-primary); }
.ar-vis-desc  { font-size: 0.7rem; color: var(--text-muted); line-height: 1.3; }

/* Visibility badges on book cards */
.ar-vis-badge-card {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.85rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  backdrop-filter: blur(4px);
  background: rgba(0,0,0,.35);
}

/* ── Category checkboxes in forms ────────────────────────────── */
.ar-cat-check-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  user-select: none;
}
.ar-cat-check-label:hover, .ar-cat-check-label.active {
  border-color: var(--cat-color, var(--accent));
  background: var(--accent-light);
  color: var(--cat-color, var(--accent));
  border-color: var(--cat-color, var(--accent));
}

/* ── Card action buttons (edit / share) ──────────────────────── */
.ar-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
@media (hover: none) {
  .ar-book-card:not([style*="display: none"]) .ar-card-actions { opacity: 1; }
  .ar-book-card:not([style*="display: none"]) .ar-card-action-btn { opacity: 1; }
}
.ar-card-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0;
}
.ar-card-action-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }


/* ── Admin user list ──────────────────────────────────────────── */
.ar-user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.ar-user-table th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ar-user-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ar-user-table tr:last-child td { border-bottom: none; }
.ar-user-table tr:hover td { background: var(--surface); }

.ar-role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ar-role-admin { background: #FEF3C7; color: #92400E; }
.ar-role-user  { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Vis label badges (list view) ────────────────────────────── */
.ar-vis-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.ar-vis-public  { background: #D1FAE5; color: #065F46; }
.ar-vis-private { background: #FEE2E2; color: #991B1B; }
.ar-vis-link    { background: #EDE9FE; color: #5B21B6; }

/* ── Profile page ─────────────────────────────────────────────── */
.ar-profile-avatar-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  cursor: pointer;
}
.ar-profile-avatar-wrap img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
}
.ar-profile-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity var(--transition);
  text-align: center;
  line-height: 1.3;
}
.ar-profile-avatar-wrap:hover .ar-profile-avatar-overlay { opacity: 1; }

/* ── Hero banner (guest homepage) ────────────────────────────── */
.ar-hero-banner {
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
  padding: 48px 32px;
}
.ar-hero-inner {
  max-width: 680px;
  margin: 0 auto;
}
.ar-hero-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  color: var(--text-primary);
  letter-spacing: -0.04em;
  margin-bottom: 16px;
}
.ar-hero-sub {
  font-size: 1.0625rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 28px;
  max-width: 520px;
}

/* ── Guest CTA footer strip ───────────────────────────────────── */
.ar-guest-cta {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.9375rem;
  flex-wrap: wrap;
}

/* ============================================================
   AuraReader Pro — Reader v3 additions
   Tap zones, view controls, bookmark toast, fullscreen, flip
   ============================================================ */

/* ── Tap zones ──────────────────────────────────────────────── */
.ar-tap-zone {
  position: fixed;
  top: 52px; /* below topbar */
  bottom: 0;
  z-index: 20;
  pointer-events: auto;
}
.ar-tap-zone-left  { left: 0;   width: 18%; }
.ar-tap-zone-mid   { left: 18%; width: 64%; }
.ar-tap-zone-right { right: 0;  width: 18%; }

/* Only show visual tap hints on touch devices */
@media (hover: none) {
  .ar-tap-zone-left::after,
  .ar-tap-zone-right::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: var(--accent);
    opacity: 0;
    border-radius: 50%;
    transition: opacity 0.15s;
  }
  .ar-tap-zone-left::after  { right: 8px; }
  .ar-tap-zone-right::after { left: 8px; }
  .ar-tap-zone-left:active::after,
  .ar-tap-zone-right:active::after { opacity: 0.18; }
}

/* Adjust tap zones when view controls bar is visible */
.ar-view-controls ~ #ar-reader ~ .ar-tap-zone,
body:has(.ar-view-controls) .ar-tap-zone { top: 88px; }

/* ── View controls bar (PDF / image_series) ─────────────────── */
.ar-view-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  height: 36px;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  transition: opacity 0.3s, transform 0.3s;
}
.ar-view-controls::-webkit-scrollbar { display: none; }
.ar-view-controls.zen-hidden { opacity: 0; pointer-events: none; transform: translateY(-4px); }

.ar-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.ar-view-btn:hover { background: var(--surface); color: var(--text-primary); }
.ar-view-btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}
.ar-view-icon-only { padding: 0 7px; }
.ar-view-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}
.ar-zoom-val {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: center;
}

/* Reader body: shift down when view controls are present */
#ar-reader-page:has(.ar-view-controls) #ar-reader {
  /* top is handled by flex column layout — just ensure flex works */
}

/* ── Progress text in topbar ────────────────────────────────── */
.ar-reader-progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: -4px;
  margin-right: 4px;
}

/* ── Bookmark inline toast ──────────────────────────────────── */
.ar-bookmark-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: min(420px, calc(100vw - 32px));
  animation: ar-toast-drop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ar-toast-drop {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.ar-bookmark-toast-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  box-shadow: var(--shadow-lg);
}
.ar-bookmark-toast-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  min-width: 0;
}
.ar-bookmark-toast-input::placeholder { color: var(--text-muted); }

/* ── Page flip animation ────────────────────────────────────── */
#ar-reader.flip-mode .epub-view iframe {
  transform-origin: left center;
  transition: transform 0.45s cubic-bezier(0.645, 0.045, 0.355, 1),
              opacity   0.25s ease;
}
#ar-reader.flip-mode.flip-out .epub-view iframe {
  transform: perspective(1200px) rotateY(-22deg) scaleX(0.96);
  opacity: 0.55;
}
#ar-reader.flip-mode.flip-in .epub-view iframe {
  transform: perspective(1200px) rotateY(0deg) scaleX(1);
  opacity: 1;
}

/* ── Auto-hide chrome on mobile ─────────────────────────────── */
body.chrome-hidden .ar-reader-bar,
body.chrome-hidden .ar-view-controls {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}
body.chrome-hidden .ar-nav {
  opacity: 0;
  pointer-events: none;
}

/* ── Fullscreen tweaks ──────────────────────────────────────── */
:fullscreen #ar-reader-page,
:-webkit-full-screen #ar-reader-page {
  background: #000;
}
:fullscreen .ar-reader-bar,
:-webkit-full-screen .ar-reader-bar {
  background: rgba(0,0,0,0.85);
  border-color: rgba(255,255,255,0.08);
}

/* ── View controls responsive (hide labels on small screens) ── */
@media (max-width: 480px) {
  .ar-view-btn:not(.ar-view-icon-only) { padding: 0 8px; font-size: 0; gap: 0; }
  .ar-view-btn:not(.ar-view-icon-only) svg { display: block; }
  .ar-zoom-val { min-width: 28px; font-size: 0.7rem; }
}

/* ── Zen mode: also hide view controls ──────────────────────── */
body.zen-active .ar-view-controls { opacity: 0; pointer-events: none; }
body.zen-active:hover .ar-view-controls { opacity: 1; pointer-events: auto; }

/* ═══════════════════════════════════════════════════════
   Reader v10 — Left panel, selection toolbar, layout
   ═══════════════════════════════════════════════════════ */

/* ── Reader body: flex row containing left panel + main area ── */
.ar-reader-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Left panel ─────────────────────────────────────────────── */
.ar-left-panel {
  width: 0;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width 0.28s cubic-bezier(0.4,0,0.2,1);
  z-index: 30;
}
.ar-left-panel.open { width: 260px; }

.ar-left-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.ar-left-panel-body {
  flex: 1;
  overflow-y: auto;
}

.ar-panel-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
}

/* TOC items */
.ar-toc-item {
  padding: 8px 12px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 6px;
  transition: background var(--transition), color var(--transition);
  line-height: 1.4;
}
.ar-toc-item:hover { background: var(--surface); color: var(--text-primary); }
.ar-toc-item.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }

/* Thumbnails */
.ar-thumb-item {
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color var(--transition);
}
.ar-thumb-item:hover { border-color: var(--accent-light); }
.ar-thumb-item.active { border-color: var(--accent); }
.ar-thumb-canvas-wrap { background: var(--surface); aspect-ratio: 3/4; overflow: hidden; }
.ar-thumb-label {
  display: block;
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  padding: 3px 0;
}

/* ── Main reader area fills remaining space ─────────────────── */
#ar-reader {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

/* ── Text selection toolbar ─────────────────────────────────── */
.ar-selection-toolbar {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--text-primary);
  border-radius: 8px;
  padding: 4px 6px;
  box-shadow: var(--shadow-lg);
  animation: ar-toast-in 0.15s ease;
}
.ar-sel-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--bg);
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  border-radius: 5px;
  white-space: nowrap;
  transition: background 0.15s;
}
.ar-sel-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Settings drawer shifts for left panel on desktop ───────── */
@media (min-width: 641px) {
  .ar-settings-drawer { top: 52px; }
  #ar-reader-page:has(.ar-left-panel.open) .ar-settings-drawer { right: 0; }
}

/* ── Mobile: left panel full width overlay ──────────────────── */
@media (max-width: 640px) {
  .ar-left-panel.open {
    position: fixed;
    top: 52px; left: 0; bottom: 0;
    width: 85vw !important;
    box-shadow: var(--shadow-lg);
    z-index: 60;
  }
}
