/* ============================================
   BookReader Design System
   Aesthetic: Apple Books meets Notion
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-body: Georgia, "Times New Roman", "Noto Serif", serif;
  --font-mono: "SF Mono", Monaco, Consolas, monospace;

  /* Reading measure */
  --reading-width: 840px;
  --sidebar-width: 280px;
  --topbar-height: 56px;

  /* Light Mode (Paper) */
  --bg-body: #faf9f7;
  --bg-surface: #ffffff;
  --bg-sidebar: #f5f4f2;
  --bg-elevated: #ffffff;
  --bg-hover: #f0eeeb;
  --bg-code: #f3f2f0;

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --text-inverse: #ffffff;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-rgb: 0, 113, 227;
  --highlight-strong: #9a3412;
  --highlight-strong-bg: rgba(254, 243, 199, 0.55);

  --border: #e5e5e7;
  --border-subtle: #f0f0f2;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.12);

  /* Component tokens */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Font override classes */
body.font-tajawal { --font-body: "Tajawal", "Noto Naskh Arabic", serif; }
body.font-amiri   { --font-body: "Amiri", "Noto Naskh Arabic", serif; }
body.font-cairo   { --font-body: "Cairo", "Noto Naskh Arabic", sans-serif; }
body.font-eb-garamond { --font-body: "EB Garamond", Georgia, serif; }
body.font-literata    { --font-body: "Literata", Georgia, serif; }

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #0F1117;
    --bg-surface: #171A21;
    --bg-sidebar: #13151A;
    --bg-elevated: #1E2128;
    --bg-hover: #24272E;
    --bg-code: #1E2128;

    --text-primary: #FFFFFF;
    --text-secondary: #B0B0B0;
    --text-tertiary: #8C8C8C;
    --text-inverse: #0F1117;

    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-rgb: 10, 132, 255;
    --highlight-strong: #f59e0b;
    --highlight-strong-bg: rgba(245, 158, 11, 0.12);

    --border: #38383a;
    --border-subtle: #2c2c2e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.6);
  }
}

/* Manual dark mode override */
[data-theme="dark"] {
  --bg-body: #0F1117;
  --bg-surface: #171A21;
  --bg-sidebar: #13151A;
  --bg-elevated: #1E2128;
  --bg-hover: #24272E;
  --bg-code: #1E2128;

  --text-primary: #FFFFFF;
  --text-secondary: #B0B0B0;
  --text-tertiary: #8C8C8C;
  --text-inverse: #0F1117;

  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-rgb: 10, 132, 255;
  --highlight-strong: #fbbf24;
  --highlight-strong-bg: rgba(251, 191, 36, 0.18);

  --border: #38383a;
  --border-subtle: #2c2c2e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
  --bg-body: #faf9f7;
  --bg-surface: #ffffff;
  --bg-sidebar: #f5f4f2;
  --bg-elevated: #ffffff;
  --bg-hover: #f0eeeb;
  --bg-code: #f3f2f0;

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --text-inverse: #ffffff;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-rgb: 0, 113, 227;
  --highlight-strong: #9a3412;
  --highlight-strong-bg: rgba(254, 243, 199, 0.55);

  --border: #e5e5e7;
  --border-subtle: #f0f0f2;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}


/* ---------- Native App Feel ---------- */
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body {
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection {
  background: rgba(var(--accent-rgb), 0.25);
  color: var(--text-primary);
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
button, a, input[type="range"] { min-height: 44px; min-width: 44px; }
a, button { -webkit-touch-callout: none; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-body);
  min-height: 100vh;
  overflow-x: hidden;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ---------- Top Bar ---------- */
.top-bar {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: var(--topbar-height);
  background: rgba(250, 249, 247, 0.88);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="dark"] .top-bar {
  background: rgba(15, 17, 23, 0.88);
}
.top-bar.hidden { transform: translateY(-100%); }
@supports (padding-top: env(safe-area-inset-top)) {
  .top-bar {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
  }
}

.top-bar-left,
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.top-bar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.site-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-logo:hover {
  text-decoration: none;
  color: var(--accent);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.breadcrumb a {
  color: var(--text-secondary);
  font-weight: 500;
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb-sep {
  opacity: 0.5;
}

/* ---------- Progress Bar ---------- */
.reading-progress {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: 2px;
  background: transparent;
  z-index: 1001;
}

.reading-progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease-out;
}

/* ---------- Buttons & Controls ---------- */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.lang-toggle {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.lang-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--topbar-height);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-height));
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), margin-left 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  position: fixed;
  inset-block-start: var(--topbar-height);
  inset-inline-start: 0;
  z-index: 900;
}

/* Desktop collapsed state */
@media (min-width: 901px) {
  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .main-content.expanded {
    margin-inline-start: 0;
  }
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  margin-inline-start: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-height));
  transition: margin-inline-start 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  min-width: 0;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chapter-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.chapter-nav::-webkit-scrollbar {
  width: 5px;
}

/* Chapter search */
.chapter-search {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: 0.5rem 0.75rem 0.25rem;
  width: calc(100% - 1.5rem);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font-ui);
}

.chapter-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

.chapter-search::placeholder {
  color: var(--text-tertiary);
}

/* Chapter status dots */
.chapter-status {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  margin-inline-end: 0.4rem;
  opacity: 0.35;
  flex-shrink: 0;
  transition: background var(--transition), opacity var(--transition), box-shadow var(--transition);
}

.chapter-link.active .chapter-status {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.25);
}

.chapter-link.read .chapter-status {
  background: #34c759;
  opacity: 0.9;
}

.chapter-link.read:hover .chapter-status {
  opacity: 1;
}

.chapter-nav::-webkit-scrollbar-track {
  background: transparent;
}

.chapter-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.chapter-link {
  display: block;
  padding: 0.6rem 0.75rem;
  border-inline-start: 3px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: start;
  cursor: pointer;
  font-family: inherit;
}

.chapter-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chapter-link.active {
  background: rgba(var(--accent-rgb), 0.12);
  border-inline-start: 3px solid var(--accent);
  padding-inline-start: calc(0.6rem - 3px);
  color: var(--text-primary);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.08), 0 0 12px rgba(var(--accent-rgb), 0.06);
}

.chapter-link .chapter-number {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: block;
  margin-bottom: 0.15rem;
}

.chapter-link.active .chapter-number {
  color: var(--accent);
  opacity: 0.8;
}

/* ---------- Content Wrapper ---------- */
.content-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  width: 100%;
}

/* ---------- Reading Canvas ---------- */
.reading-canvas {
  max-width: var(--reading-width);
  width: 100%;
  margin: 0 auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 3.5rem 4rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  border: 1px solid var(--border-subtle);
}

/* Wider canvas when sidebar is collapsed on desktop */
.sidebar.collapsed ~ .main-content .reading-canvas {
  max-width: min(calc(100vw - 6rem), 1100px);
}

/* ---------- Typography (Reader) ---------- */
.reading-canvas h1 {
  font-family: var(--font-ui);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.reading-canvas h2 {
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.reading-canvas h3 {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.reading-canvas p {
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1.75;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
}

.reading-canvas p strong,
.reading-canvas li strong {
  font-weight: 700;
  color: var(--text-primary);
}

.reading-canvas ul,
.reading-canvas ol {
  margin: 1.25rem 0;
  padding-inline-start: 1.75rem;
}

.reading-canvas li {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.7;
  margin-bottom: 0.6rem;
  color: var(--text-primary);
}

/* ---------- Special Components ---------- */
/* Action Steps */
.action-steps {
  list-style: none;
  padding: 0;
}

.action-steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 0.85rem;
  font-family: var(--font-body);
}

.action-steps .checkbox {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid var(--accent);
  border-radius: 5px;
  margin-top: 0.15rem;
  cursor: pointer;
  transition: background var(--transition);
}

.action-steps .checkbox:hover {
  background: rgba(var(--accent-rgb), 0.1);
}

.action-steps .checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
}

/* Reflective Questions */
.reflective-questions {
  list-style: none;
  padding: 0;
  counter-reset: question;
}

.reflective-questions li {
  counter-increment: question;
  padding: 1rem 1.25rem 1rem 3.25rem;
  background: var(--bg-body);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  position: relative;
  font-family: var(--font-body);
  border: 1px solid var(--border-subtle);
}

.reflective-questions li::before {
  content: counter(question);
  position: absolute;
  inset-inline-start: 1rem;
  top: 1rem;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--font-ui);
}

/* Journaling Prompts */
.journaling-prompts {
  list-style: none;
  padding: 0;
}

.journaling-prompts li {
  background: rgba(255, 159, 10, 0.06);
  border-inline-start: 3px solid #ff9f0a;
  padding: 1rem 1.25rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: 0.75rem;
  font-family: var(--font-body);
  border: 1px solid rgba(255, 159, 10, 0.15);
}

/* ---------- Chapter Footer Nav ---------- */
.chapter-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.chapter-nav-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chapter-nav-btn {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.chapter-nav-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
  color: var(--text-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.chapter-nav-btn.next {
  text-align: end;
  align-items: flex-end;
}

.chapter-nav-btn .label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 0.35rem;
}

.chapter-nav-btn .title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.chapter-nav-btn:hover .title {
  color: var(--accent);
}

body.no-sidebar .main-content {
  margin-inline-start: 0;
}

body.no-sidebar .content-wrapper {
  padding-top: 1rem;
}

/* ---------- Library / Cards ---------- */
.library-container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  overflow-x: hidden;
  box-sizing: border-box;
}

.library-hero {
  text-align: center;
  padding: 3rem 0 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.library-hero h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.library-hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
  padding: 0 0 4rem;
}

.book-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}

.book-card:hover {
  text-decoration: none;
  color: inherit;
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

/* ---------- Book Cover Art ---------- */
.book-card-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #1e293b 0%, #334155 60%, #475569 100%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.book-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-md);
}

.book-card-cover h3 {
  position: relative;
  z-index: 1;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
  margin: 0;
  text-shadow: 0 2px 6px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.3);
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: balance;
}

.book-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* Category badges */
.book-card-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.book-category-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg-hover);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

/* Category filter bar */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 0 1.5rem;
}

.category-chip {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-ui);
}

.category-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.category-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Book Landing ---------- */
.book-hero {
  text-align: center;
  padding: 3rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

.reading-canvas.book-hero {
  text-align: center;
  padding: 5rem 3rem;
}

.book-hero-cover {
  width: 160px;
  aspect-ratio: 2 / 3;
  margin: 0 auto 1.5rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.book-hero-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-hero h1,
.book-hero-title {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.book-hero-subtitle {
  margin: 1.5rem 0;
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1.6;
}

.book-hero .chapter-count {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-xl);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.book-hero .cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: var(--text-inverse);
  padding: 14px 28px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), 0.35), 0 0 0 1px rgba(var(--accent-rgb), 0.1);
}

.book-hero .cta:hover {
  background: var(--accent-hover);
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.45), 0 0 0 1px rgba(var(--accent-rgb), 0.15);
}

.book-hero .cta:active {
  transform: translateY(0);
}

.toc-section {
  max-width: var(--reading-width);
  margin: 2rem auto 3rem;
  padding: 0 2rem;
}

.toc-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.toc-list {
  list-style: none;
  padding: 0;
}

.toc-list li {
  margin-bottom: 0.5rem;
}

.toc-list a {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-weight: 500;
  transition: background var(--transition);
}

.toc-list a:hover {
  background: var(--bg-hover);
  text-decoration: none;
}

.toc-list .toc-number {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  font-weight: 600;
  min-width: 2rem;
}

/* ---------- Mobile Sidebar Drawer ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 899;
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar-overlay.open {
  display: block;
  opacity: 1;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    width: min(80vw, 300px);
    min-width: min(80vw, 300px);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    padding: 0.75rem 1rem;
    position: relative;
  }

  .sidebar-title {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-inline-end: 1.5rem;
  }

  .sidebar-subtitle {
    font-size: 0.65rem;
    letter-spacing: 0.04em;
  }

  .sidebar-close {
    display: flex !important;
    position: absolute;
    top: 0.5rem;
    inset-inline-end: 0.5rem;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    cursor: pointer;
  }

  .sidebar-close:hover,
  .sidebar-close:active {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  .chapter-nav {
    padding: 0.25rem 0.5rem 0.5rem;
  }

  .chapter-link {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    line-height: 1.35;
    border-radius: 6px;
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chapter-link .chapter-number {
    display: inline;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 0;
    margin-inline-end: 0.35rem;
  }

  .chapter-link.active {
    background: rgba(var(--accent-rgb), 0.1);
    border-inline-start: 3px solid var(--accent);
    padding-inline-start: calc(0.5rem - 3px);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.06), 0 0 8px rgba(var(--accent-rgb), 0.04);
  }

  .chapter-link.active .chapter-number {
    color: var(--accent);
    opacity: 0.85;
  }

  .main-content {
    margin-inline-start: 0;
  }

  .reading-canvas,
  .reading-canvas.book-hero {
    padding: 2rem;
    border-radius: var(--radius-md);
  }

  .reading-canvas h1 {
    font-size: 1.6rem;
  }

  .reading-canvas p {
    font-size: 1.05rem;
  }

  .chapter-nav-buttons {
    grid-template-columns: 1fr;
  }

  .chapter-nav-btn.next {
    text-align: start;
    align-items: flex-start;
  }

  .content-wrapper {
    padding: 1.5rem 1rem;
  }

  .book-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 0 0 2rem;
  }

  .category-filter {
    padding: 0 0 1rem;
  }

  .continue-reading-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}

/* Large screens — wider reading canvas when sidebar is open */
@media (min-width: 1400px) {
  :root {
    --reading-width: 960px;
  }
}

/* XL screens — even wider when sidebar is collapsed */
@media (min-width: 1600px) {
  .sidebar.collapsed ~ .main-content .reading-canvas {
    max-width: min(calc(100vw - 8rem), 1200px);
  }
}

@media (max-width: 600px) {
  .top-bar {
    padding: 0 0.75rem;
  }

  .site-logo-text {
    display: none;
  }

  .top-bar-center {
    display: block;
    position: static;
    transform: none;
    max-width: none;
    flex: 1;
    text-align: center;
    padding: 0 0.5rem;
    font-size: 0.8rem;
  }

  .top-bar-right .breadcrumb,
  .top-bar-right .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: flex !important;
  }

  .library-hero h1 {
    font-size: 1.8rem;
  }

  .book-hero h1 {
    font-size: 1.6rem;
  }

  .lang-toggle {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }

  .book-card {
    padding: 0.875rem;
  }

  .book-card-cover {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .book-card-cover h3 {
    font-size: 0.75rem;
  }

  .book-card-title {
    font-size: 0.85rem;
  }

  .book-category-badge {
    font-size: 0.6rem;
    padding: 0.15rem 0.4rem;
  }

  .category-chip {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }
}

/* ---------- RTL Support ---------- */
[dir="rtl"] .reading-canvas ul,
[dir="rtl"] .reading-canvas ol {
  padding-inline-start: 1.75rem;
  padding-inline-end: 0;
}

[dir="rtl"] .action-steps li {
  flex-direction: row-reverse;
}

[dir="rtl"] .reflective-questions li {
  padding: 1rem 3.25rem 1rem 1.25rem;
}

[dir="rtl"] .reflective-questions li::before {
  inset-inline-start: auto;
  inset-inline-end: 1rem;
}

[dir="rtl"] .journaling-prompts li {
  border-inline-start: none;
  border-inline-end: 3px solid #ff9f0a;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

[dir="rtl"] .breadcrumb {
  direction: rtl;
}

[dir="rtl"] .chapter-nav-btn.next {
  text-align: start;
  align-items: flex-start;
}

@media (max-width: 900px) {
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
    inset-inline-start: auto;
    inset-inline-end: 0;
  }

  [dir="rtl"] .sidebar.open {
    transform: translateX(0);
  }
}

/* ---------- Accessibility ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Font Menu ---------- */
.font-menu {
  position: fixed;
  top: calc(var(--topbar-height) + 8px);
  right: 16px;
  width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem 0;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity var(--transition), transform var(--transition);
}

.font-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.font-menu-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.5rem;
}

.font-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--transition);
  text-align: left;
  font-family: var(--font-ui);
}

.font-option:hover {
  background: var(--bg-hover);
}

.font-option.active {
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  font-weight: 600;
}

.font-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-body);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-primary);
}

[dir="rtl"] .font-menu {
  right: auto;
  left: 16px;
}

[dir="rtl"] .font-option {
  text-align: right;
  flex-direction: row-reverse;
}

@media (max-width: 600px) {
  .font-menu {
    right: 8px;
    width: calc(100vw - 16px);
    max-width: 280px;
  }
  [dir="rtl"] .font-menu {
    left: 8px;
  }
}

/* ---------- Strong / Bold Highlight ---------- */
.reading-canvas strong,
.reading-canvas b {
  color: var(--highlight-strong);
  background: var(--highlight-strong-bg);
  padding: 0.05em 0.2em;
  border-radius: 3px;
  font-weight: 700;
}

/* ---------- Font Size Scaling (EPUB-style) ---------- */
:root {
  --reader-scale: 1;
}

.reading-canvas h1 {
  font-size: calc(2rem * var(--reader-scale));
}

.reading-canvas h2 {
  font-size: calc(1.15rem * var(--reader-scale));
}

.reading-canvas h3 {
  font-size: calc(1rem * var(--reader-scale));
}

.reading-canvas p {
  font-size: calc(1.1rem * var(--reader-scale));
}

.reading-canvas li {
  font-size: calc(1.05rem * var(--reader-scale));
}

/* Size classes */
.reader-scale-95  { --reader-scale: 0.95; }
.reader-scale-100 { --reader-scale: 1; }
.reader-scale-105 { --reader-scale: 1.05; }
.reader-scale-110 { --reader-scale: 1.1; }
.reader-scale-115 { --reader-scale: 1.15; }
.reader-scale-120 { --reader-scale: 1.2; }
.reader-scale-125 { --reader-scale: 1.25; }

/* ---------- Font Size Slider Menu ---------- */
.font-size-menu {
  position: fixed;
  top: calc(var(--topbar-height) + 8px);
  right: 62px;
  width: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1rem;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity var(--transition), transform var(--transition);
}

.font-size-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.font-size-menu-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.font-size-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.font-size-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-body);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  font-family: var(--font-ui);
}

.font-size-btn:hover {
  background: var(--bg-hover);
}

.font-size-value {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-family: var(--font-ui);
}

.font-size-slider {
  width: 100%;
  margin-top: 0.75rem;
  cursor: pointer;
  accent-color: var(--accent);
}

[dir="rtl"] .font-size-menu {
  right: auto;
  left: 62px;
}

@media (max-width: 600px) {
  .font-size-menu {
    right: 8px;
    left: auto;
    width: calc(100vw - 16px);
    max-width: 240px;
  }
  [dir="rtl"] .font-size-menu {
    left: 8px;
    right: auto;
  }
}

/* ---------- Mobile Settings Panel ---------- */
.mobile-only {
  display: none;
}

.mobile-settings-panel {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.mobile-settings-panel.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-settings-panel .mobile-settings-sheet {
  background: var(--bg-surface);
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.mobile-settings-panel.open .mobile-settings-sheet {
  transform: translateY(0);
}

.mobile-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}

.mobile-settings-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-settings-body {
  padding: 1rem 1.25rem 2rem;
}

.mobile-settings-section {
  margin-bottom: 1.5rem;
}

.mobile-settings-section:last-child {
  margin-bottom: 0;
}

.mobile-settings-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.mobile-font-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ---------- Active / Touch Feedback ---------- */
.icon-btn:active { transform: scale(0.92); }
.chapter-link:active { background: var(--bg-hover); }
.font-option:active { background: var(--bg-hover); }
.chapter-nav-btn:active { transform: scale(0.98); }
.top-bar, .sidebar, .sidebar-overlay, .font-menu, .font-size-menu {
  user-select: none; -webkit-user-select: none;
}

/* ---------- Progress System ---------- */

/* Book card progress ring */
.book-card-cover {
  position: relative;
}

.book-progress-overlay {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 2;
}

.book-progress-ring {
  position: relative;
  width: 44px;
  height: 44px;
}

.book-progress-ring svg {
  transform: rotate(-90deg);
}

.book-progress-ring .ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 3;
}

.book-progress-ring .ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.32, 0.72, 0, 1);
}

.book-progress-ring .ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.book-progress-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* Continue Reading section */
.continue-reading {
  max-width: 1200px;
  margin: 0 auto 2rem;
  padding: 0;
}

.continue-reading h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.continue-reading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

/* Book landing progress panel */
.book-progress-panel {
  max-width: 420px;
  margin: 2rem auto 0;
  padding: 1.25rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.book-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.book-progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.32, 0.72, 0, 1);
}

.book-progress-panel.completed .book-progress-bar-fill {
  background: #34c759;
}

.book-progress-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.book-progress-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.book-reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.book-reset-btn:hover {
  color: #ff3b30;
  background: rgba(255, 59, 48, 0.08);
}

.book-reset-btn svg {
  width: 14px;
  height: 14px;
}

/* Sidebar read indicators */
.chapter-link {
  position: relative;
}

.chapter-link .read-check {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  color: var(--accent);
  opacity: 0.85;
}

.chapter-link.read .read-check {
  display: flex;
}

.chapter-link.read {
  color: var(--text-tertiary);
}

.chapter-link.read .chapter-number {
  color: var(--text-tertiary);
}

.chapter-link.read:hover {
  color: var(--text-primary);
}

/* Progress panel completed state */
.book-progress-panel.completed .book-progress-text {
  color: #34c759;
  font-weight: 700;
}

[dir="rtl"] .book-progress-overlay {
  right: auto;
  left: 10px;
}

[dir="rtl"] .chapter-link .read-check {
  right: auto;
  left: 0.5rem;
}

[dir="rtl"] .chapter-status {
  margin-inline-end: 0;
  margin-inline-start: 0.4rem;
}

/* ── Auth System ── */

/* Auth trigger button in top bar */
.auth-bar {
  position: relative;
}

.auth-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform 0.15s ease;
}

.auth-trigger:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.auth-icon svg {
  display: block;
}

.auth-label {
  display: none;
}

@media (min-width: 600px) {
  .auth-label {
    display: inline;
  }
}

/* Auth dropdown */
.auth-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem 0;
  z-index: 1100;
}

.auth-dropdown.open {
  display: block;
}

.auth-dropdown-user {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.25rem;
}

.auth-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.auth-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

[dir="rtl"] .auth-dropdown {
  right: auto;
  left: 0;
}

[dir="rtl"] .auth-dropdown-item {
  text-align: right;
  flex-direction: row-reverse;
}

/* Auth modal */
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.auth-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.auth-sheet {
  background: var(--bg-surface);
  width: 100%;
  max-width: 420px;
  margin: 1rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform: scale(0.96);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.auth-modal.open .auth-sheet {
  transform: scale(1);
}

.auth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.auth-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.auth-field input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

.auth-submit {
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
}

.auth-submit:hover {
  background: var(--accent-hover);
}

.auth-submit:active {
  transform: scale(0.97);
}

.auth-error {
  font-size: 0.85rem;
  color: #ff3b30;
  min-height: 1.2rem;
  text-align: center;
}

.admin-success {
  color: #34c759;
}

/* Admin panel */
.admin-sheet {
  max-width: 480px;
}

.admin-body {
  padding: 1.25rem 1.5rem 1.5rem;
}

.auth-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.admin-add-btn {
  margin-top: 0.25rem;
}

.admin-list-wrap {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.admin-list-wrap h4 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.admin-cat-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.admin-cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-md);
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
}

.admin-cat-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
}

.admin-cat-chip button:hover {
  background: rgba(var(--accent-rgb), 0.15);
}

.auth-field-select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font-ui);
  cursor: pointer;
}

.auth-field-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

.admin-user-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 200px;
  overflow-y: auto;
}

.admin-user-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-body);
  border-radius: var(--radius-sm);
}

.admin-user-list .role-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
}

/* Unauthenticated state — blur content */
body:not(.authenticated) .book-grid,
body:not(.authenticated) .reading-canvas,
body:not(.authenticated) .chapter-link,
body:not(.authenticated) .toc-list {
  filter: blur(6px);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
  transition: filter 0.4s ease, opacity 0.4s ease;
}

body:not(.authenticated) .top-bar,
body:not(.authenticated) .sidebar,
body:not(.authenticated) .sidebar-overlay,
body:not(.authenticated) #loginModal,
body:not(.authenticated) .auth-bar,
body:not(.authenticated) .library-hero,
body:not(.authenticated) .font-menu,
body:not(.authenticated) .font-size-menu {
  filter: none;
  opacity: 1;
  pointer-events: auto;
  user-select: auto;
}

body.authenticated .book-grid,
body.authenticated .reading-canvas,
body.authenticated .chapter-link,
body.authenticated .toc-list {
  filter: none;
  opacity: 1;
  pointer-events: auto;
  user-select: auto;
  transition: filter 0.4s ease, opacity 0.4s ease;
}

/* Hide progress and admin features when not logged in */
body:not(.authenticated) .book-progress-overlay,
body:not(.authenticated) .book-progress-panel,
body:not(.authenticated) .chapter-link .read-check {
  display: none !important;
}

body:not(.authenticated) .continue-reading {
  display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
  .auth-field-row {
    grid-template-columns: 1fr;
  }

  .auth-sheet {
    margin: 0.75rem;
    border-radius: var(--radius-lg);
  }
}

/* ---------- Micro-interactions ---------- */

/* Card lift on hover */
.book-card {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

/* Smooth progress bar */
.book-progress-bar-fill {
  transition: width 0.6s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Chapter link hover lift */
.chapter-link {
  transition: background var(--transition), color var(--transition), border-color var(--transition), padding-inline-start var(--transition);
}

/* TOC item hover */
.toc-list a {
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.toc-list a:hover {
  transform: translateX(2px);
}

/* Button/switch haptic feedback */
.icon-btn, .auth-trigger, .lang-toggle {
  transition: background var(--transition), color var(--transition), transform 0.15s ease;
}

.icon-btn:active, .auth-trigger:active, .lang-toggle:active {
  transform: scale(0.95);
}

/* Reading canvas smooth scroll padding for anchors */
.reading-canvas [id] {
  scroll-margin-top: calc(var(--topbar-height) + 1rem);
}

/* Focus ring for accessibility */
input:focus, button:focus, a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Upload Modal Styles ---------- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 1rem;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.04);
}

.upload-prompt svg {
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.upload-prompt p {
  margin: 0;
  color: var(--text-secondary);
  font-weight: 500;
}

.upload-hint {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

.upload-progress {
  margin: 1rem 0;
}

.upload-progress-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.upload-progress-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-align: center;
}

.upload-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.upload-results {
  margin-top: 1rem;
}

.upload-result-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
}

.upload-result-item.success {
  color: #16a34a;
}

.upload-result-item.error {
  color: #dc2626;
}

/* Library loading state */
.library-loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-tertiary);
  font-size: 1rem;
}
