/* =========================================================
   Scripture — KJV Bible App
   ========================================================= */

/* --- Design Tokens (Dark Theme Default) --- */
:root {
  --bg-app: #12100e;
  --bg-topbar: #1a1713;
  --bg-sidebar-book: #161310;
  --bg-sidebar-chapter: #1c1916;
  --bg-content: #13110f;
  --bg-sidebar-hover: rgba(212, 175, 95, 0.08);
  --bg-sidebar-active: rgba(212, 175, 95, 0.15);

  --text-primary: #e8dcc8;
  --text-secondary: #a09070;
  --text-muted: #5a5040;
  --text-verse: #d4c4a0;
  --text-heading: #f0e4c8;

  --accent: #c9a84c;
  --accent-glow: rgba(201, 168, 76, 0.25);
  --accent-dim: #8a6f33;

  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(255, 255, 255, 0.1);

  --scrollbar-track: rgba(255, 255, 255, 0.03);
  --scrollbar-thumb: rgba(255, 255, 255, 0.12);

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-serif: 'Lora', Georgia, serif;

  --sidebar-book-w: 175px;
  --sidebar-chapter-w: 80px;
  --topbar-h: 52px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition-fast: 130ms ease;
  --transition-med: 220ms ease;

  --font-size-base: 18px;
}

/* --- Light Theme --- */
[data-theme="light"] {
  --bg-app: #fdf8f0;
  --bg-topbar: #f5efe3;
  --bg-sidebar-book: #f0e8d8;
  --bg-sidebar-chapter: #f8f2e5;
  --bg-content: #fdf8f0;
  --bg-sidebar-hover: rgba(150, 110, 40, 0.07);
  --bg-sidebar-active: rgba(150, 110, 40, 0.13);

  --text-primary: #2a2010;
  --text-secondary: #7a6040;
  --text-muted: #b09068;
  --text-verse: #2e2312;
  --text-heading: #1a1208;

  --accent: #8b6914;
  --accent-glow: rgba(139, 105, 20, 0.18);
  --accent-dim: #b08830;

  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.12);

  --scrollbar-track: rgba(0, 0, 0, 0.04);
  --scrollbar-thumb: rgba(0, 0, 0, 0.15);
}

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

html {
  font-size: 16px; /* stable base — component sizes use rem off this */
}

body {
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100dvh;
  overflow: hidden;
  transition: background var(--transition-med), color var(--transition-med);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* =========================================================
   TOP BAR
   ========================================================= */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 200;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--transition-med);
}

/* Mobile menu toggle — hidden on desktop */
#btn-menu {
  display: none;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  padding: 0;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

#btn-menu:hover {
  background: var(--bg-sidebar-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

#topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#brand-icon {
  color: var(--accent);
  font-size: 1rem;
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 8px var(--accent-glow);
  }
  50% {
    opacity: 0.7;
    text-shadow: 0 0 16px var(--accent-glow);
  }
}

#brand-name {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-heading);
  letter-spacing: 0.02em;
}

#brand-version {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(201, 168, 76, 0.25);
  padding: 2px 7px;
  border-radius: 99px;
  text-transform: uppercase;
}

#topbar-location {
  flex: 1;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

#location-book {
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#location-sep {
  color: var(--text-muted);
  flex-shrink: 0;
}

#location-chapter {
  white-space: nowrap;
  flex-shrink: 0;
}

#topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  height: 32px;
  padding: 0 10px;
  transition: all var(--transition-fast);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--bg-sidebar-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* =========================================================
   MAIN LAYOUT
   ========================================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#main-layout {
  display: flex;
  flex-direction: row;
  height: calc(100dvh - var(--topbar-h));
  margin-top: var(--topbar-h);
  overflow: hidden;
  position: relative;
}

/* =========================================================
   SIDEBAR OVERLAY (mobile)
   ========================================================= */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: overlayFadeIn 200ms ease forwards;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#sidebar-overlay.visible {
  display: block;
}

/* =========================================================
   BOOK SIDEBAR
   ========================================================= */
#book-sidebar {
  width: var(--sidebar-book-w);
  flex-shrink: 0;
  background: var(--bg-sidebar-book);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 24px;
  transition: background var(--transition-med), transform 300ms cubic-bezier(0.25, 0.8, 0.25, 1);
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-section-header {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 16px 14px 6px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar-book);
  z-index: 1;
}

.book-list {
  list-style: none;
}

.book-item {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-secondary);
  border-radius: 0;
  transition: all var(--transition-fast);
  border-left: 2px solid transparent;
  line-height: 1.35;
  user-select: none;
}

.book-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.book-item.active {
  background: var(--bg-sidebar-active);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

/* =========================================================
   CHAPTER SIDEBAR
   ========================================================= */
#chapter-sidebar {
  width: var(--sidebar-chapter-w);
  flex-shrink: 0;
  background: var(--bg-sidebar-chapter);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: background var(--transition-med), transform 300ms cubic-bezier(0.25, 0.8, 0.25, 1);
}

#chapter-sidebar-title {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 16px 0 6px;
  text-align: center;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar-chapter);
  z-index: 1;
}

#chapter-list {
  list-style: none;
  padding: 4px 6px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  user-select: none;
}

.chapter-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.chapter-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(201, 168, 76, 0.2);
}

/* =========================================================
   CONTENT AREA
   ========================================================= */
#content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-content);
  transition: background var(--transition-med);
  scroll-behavior: smooth;
  min-width: 0;
}

#chapter-header {
  padding: 48px 60px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

#chapter-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  color: var(--text-heading);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

#chapter-title span {
  color: var(--accent);
  font-weight: 600;
}

#chapter-text {
  padding: 36px 60px 100px;
  max-width: 820px;
}

/* --- Verse font scaling using CSS custom property --- */
.verse-paragraph {
  margin-bottom: 1.4em;
  line-height: 1.9;
  font-family: var(--font-serif);
  font-size: clamp(0.9rem, 1vw + 0.5rem, 1.15rem);
  color: var(--text-verse);
}

/* Apply user font-size override only to verse text */
body[data-font-size] .verse-paragraph {
  font-size: calc(var(--user-font-size, 18px) * 0.0556rem);
}

/* --- Verse Number (superscript) --- */
.verse-num {
  font-family: var(--font-sans);
  font-size: 0.6em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
  margin-right: 2px;
  letter-spacing: 0.02em;
  user-select: none;
  opacity: 0.85;
}

/* --- Loading --- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 80px 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- Error --- */
.error-state {
  padding: 60px 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.7;
}

.error-state a {
  color: var(--accent);
  text-decoration: none;
}

/* --- Fade In Content --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.content-fade {
  animation: fadeInUp 280ms ease forwards;
}

/* =========================================================
   VERSE SELECTION
   ========================================================= */
.verse-span {
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  margin: 0 -2px;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.verse-span:hover {
  background: rgba(201, 168, 76, 0.06);
}

.verse-span.selected {
  background: rgba(201, 168, 76, 0.14);
  box-shadow: inset 0 0 0 1px rgba(201, 168, 76, 0.2);
}

[data-theme="light"] .verse-span.selected {
  background: rgba(139, 105, 20, 0.1);
  box-shadow: inset 0 0 0 1px rgba(139, 105, 20, 0.18);
}

/* =========================================================
   AI TOPBAR BUTTON
   ========================================================= */
.icon-btn--ai {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.12), rgba(201, 168, 76, 0.05));
  border-color: rgba(201, 168, 76, 0.3);
  color: var(--accent);
  letter-spacing: 0.06em;
}

.icon-btn--ai:hover {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.25), rgba(201, 168, 76, 0.1));
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.15);
}

.icon-btn--ai.active {
  background: var(--accent);
  color: var(--bg-app);
  border-color: var(--accent);
  font-weight: 700;
}

/* =========================================================
   AI SIDEBAR
   ========================================================= */
.ai-sidebar {
  width: 0;
  min-width: 0;
  flex-shrink: 0;
  background: var(--bg-sidebar-book);
  border-left: 1px solid var(--border-subtle);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width 280ms cubic-bezier(0.25, 0.8, 0.25, 1),
    min-width 280ms cubic-bezier(0.25, 0.8, 0.25, 1);
  opacity: 0;
}

.ai-sidebar.open {
  width: 360px;
  min-width: 360px;
  opacity: 1;
  transition: width 280ms cubic-bezier(0.25, 0.8, 0.25, 1),
    min-width 280ms cubic-bezier(0.25, 0.8, 0.25, 1),
    opacity 200ms ease 80ms;
}

#ai-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

#ai-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-heading);
}

.ai-icon-glow {
  color: var(--accent);
  font-size: 1.1rem;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  animation: pulse-glow 3s ease-in-out infinite;
}

#ai-sidebar-actions {
  display: flex;
  gap: 6px;
}

.icon-btn--sm {
  height: 28px;
  padding: 0 10px;
  font-size: 0.65rem;
}

/* --- Chat Messages --- */
#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeInUp 280ms ease forwards;
}

.ai-msg-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-left: 2px;
}

.ai-msg-bubble {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.7;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  word-wrap: break-word;
}

.ai-msg--user .ai-msg-bubble {
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid rgba(201, 168, 76, 0.15);
  color: var(--text-verse);
  white-space: pre-wrap;
}

.ai-msg--ai .ai-msg-bubble {
  background: var(--bg-sidebar-chapter);
  border: 1px solid var(--border-subtle);
  white-space: normal;
}

.ai-msg--ai .ai-msg-label {
  color: var(--accent);
}

/* --- Markdown Elements inside AI bubble --- */
.ai-msg-bubble p {
  margin: 0 0 0.65em;
  line-height: 1.7;
}

.ai-msg-bubble p:last-child {
  margin-bottom: 0;
}

.ai-msg-bubble strong {
  font-weight: 700;
  color: var(--text-heading);
}

.ai-msg-bubble em {
  font-style: italic;
  color: var(--text-primary);
}

.ai-msg-bubble del {
  opacity: 0.55;
  text-decoration: line-through;
}

.ai-msg-bubble .ai-h2 {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-heading);
  margin: 0.9em 0 0.35em;
  letter-spacing: 0.01em;
}

.ai-msg-bubble .ai-h3 {
  font-family: var(--font-serif);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0.75em 0 0.3em;
  letter-spacing: 0.02em;
}

.ai-msg-bubble .ai-h4 {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0.75em 0 0.25em;
}

.ai-msg-bubble .ai-hr {
  border: none;
  border-top: 1px solid var(--border-strong);
  margin: 0.75em 0;
}

.ai-msg-bubble .ai-code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.78em;
  background: rgba(201, 168, 76, 0.08);
  border: 1px solid rgba(201, 168, 76, 0.15);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--accent);
}

/* --- Typing Indicator --- */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 14px 14px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* --- Chat Input --- */
#ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

#ai-chat-input {
  flex: 1;
  background: var(--bg-content);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  padding: 10px 12px;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color var(--transition-fast);
}

#ai-chat-input:focus {
  border-color: var(--accent-dim);
}

#ai-chat-input::placeholder {
  color: var(--text-muted);
}

.icon-btn--send {
  height: 42px;
  width: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--bg-app);
  border-color: var(--accent);
  flex-shrink: 0;
}

.icon-btn--send:hover {
  background: var(--accent-dim);
  color: var(--text-heading);
}

/* =========================================================
   FLOATING EXPLAIN BUTTON
   ========================================================= */
.explain-fab {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: 210;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: auto;
}

.explain-fab.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(14px);
}

.explain-fab button {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0f0d0a;
  border: none;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 13px 28px;
  border-radius: 99px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 4px 24px rgba(201, 168, 76, 0.35),
    0 0 0 1px rgba(201, 168, 76, 0.15);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.explain-fab button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(201, 168, 76, 0.45),
    0 0 0 1px rgba(201, 168, 76, 0.25);
}

.explain-fab button:active {
  transform: translateY(0);
}

/* --- Welcome State --- */
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  gap: 12px;
  color: var(--text-muted);
  flex: 1;
  justify-content: center;
}

.ai-welcome-icon {
  font-size: 2rem;
  color: var(--accent);
  opacity: 0.5;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.ai-welcome-title {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.ai-welcome-desc {
  font-size: 0.72rem;
  line-height: 1.6;
  max-width: 260px;
}

/* =========================================================
   CHAPTER NAV ARROWS (prev/next) — content footer
   ========================================================= */
#chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 60px 48px;
  gap: 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 8px;
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 10px 18px;
  transition: all var(--transition-fast);
  user-select: none;
}

.chapter-nav-btn:hover {
  background: var(--bg-sidebar-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.chapter-nav-btn:active {
  transform: scale(0.97);
}

.chapter-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.chapter-nav-btn .nav-arrow {
  font-size: 1rem;
  line-height: 1;
}

/* =========================================================
   TABLET BREAKPOINT (≤ 900px)
   ========================================================= */
@media (max-width: 900px) {
  :root {
    --sidebar-book-w: 150px;
    --sidebar-chapter-w: 60px;
  }

  #chapter-header {
    padding: 32px 32px 20px;
  }

  #chapter-text {
    padding: 24px 32px 80px;
  }

  #chapter-nav {
    padding: 20px 32px 40px;
  }

  #chapter-title {
    font-size: 1.7rem;
  }

  .ai-sidebar.open {
    width: 320px;
    min-width: 320px;
  }
}

/* =========================================================
   MOBILE BREAKPOINT (≤ 680px)
   — sidebars become slide-in drawers
   ========================================================= */
@media (max-width: 680px) {
  :root {
    --topbar-h: 50px;
  }

  /* Show hamburger */
  #btn-menu {
    display: flex;
  }

  /* Hide font-size buttons on tiny screens to save space */
  #btn-font-decrease,
  #btn-font-increase {
    display: none;
  }

  /* Shrink brand text */
  #brand-name {
    font-size: 0.92rem;
  }

  #topbar-location {
    font-size: 0.75rem;
    gap: 5px;
  }

  /* Book sidebar: fixed drawer, slides in from left */
  #book-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: min(280px, 80vw);
    z-index: 160;
    transform: translateX(-100%);
    border-right: 1px solid var(--border-strong);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  #book-sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Chapter sidebar: fixed drawer, slides in from left (overlapping book) */
  #chapter-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: min(160px, 50vw);
    z-index: 155;
    transform: translateX(-100%);
    border-right: 1px solid var(--border-strong);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  #chapter-sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Content area takes full width */
  #content-area {
    width: 100%;
  }

  #chapter-header {
    padding: 24px 20px 16px;
  }

  #chapter-title {
    font-size: 1.5rem;
  }

  #chapter-text {
    padding: 20px 20px 80px;
  }

  #chapter-nav {
    padding: 16px 20px 32px;
  }

  .chapter-nav-btn {
    padding: 10px 14px;
    font-size: 0.74rem;
  }

  /* AI sidebar goes full-screen on mobile */
  .ai-sidebar.open {
    position: fixed;
    right: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: 100% !important;
    min-width: 100% !important;
    z-index: 160;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
  }

  /* Topbar location shrinks */
  #topbar-location {
    max-width: 130px;
  }

  /* Explain FAB lifted above bottom edge */
  .explain-fab {
    bottom: 20px;
  }
}

/* =========================================================
   VERY SMALL (≤ 380px)
   ========================================================= */
@media (max-width: 380px) {
  #brand-version {
    display: none;
  }

  #topbar-location {
    display: none;
  }

  #chapter-header {
    padding: 20px 16px 14px;
  }

  #chapter-text {
    padding: 16px 16px 80px;
  }

  #chapter-nav {
    padding: 14px 16px 28px;
  }
}