/* ── Design tokens ─────────────────────────────────────────────────── */
:root {
  --font-tamil: 'Noto Sans Tamil', 'Noto Serif Tamil', 'Latha', 'Vijaya', sans-serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-scale: 1;

  --bg:           #fdfcf7;
  --surface:      #ffffff;
  --border:       #e5dfd0;
  --text:         #1a1208;
  --text-muted:   #7a6e5a;
  --text-faint:   #b0a898;
  --accent:       #8b3a00;
  --accent-hover: #6a2c00;
  --accent-light: #faf0e6;
  --highlight:    #fde68a;
  --highlight-fg: #78350f;
  --fuzzy-bg:     #f0f9ff;
  --kbd-bg:       #f0ece0;
  --kbd-btn:      #e8e2d0;
  --kbd-btn-hover:#d4c9a8;
  --kbd-pending:  #8b3a00;
  --kbd-pending-fg: #ffffff;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10);
  --radius:       8px;
  --radius-sm:    4px;
}

/* Dark mode — system preference (unless user forced light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #18130e;
    --surface:      #231e16;
    --border:       #3a322a;
    --text:         #f0e8d8;
    --text-muted:   #9a8e7a;
    --text-faint:   #5a5248;
    --accent:       #e8a050;
    --accent-hover: #f0b870;
    --accent-light: #2a1e10;
    --highlight:    #5a3a08;
    --highlight-fg: #fde68a;
    --fuzzy-bg:     #0f1e2a;
    --kbd-bg:       #231e16;
    --kbd-btn:      #2e2820;
    --kbd-btn-hover:#3a3228;
    --kbd-pending:  #e8a050;
    --kbd-pending-fg: #18130e;
  }
}

/* Dark mode — user explicitly chose dark */
:root[data-theme="dark"] {
  --bg:           #18130e;
  --surface:      #231e16;
  --border:       #3a322a;
  --text:         #f0e8d8;
  --text-muted:   #9a8e7a;
  --text-faint:   #5a5248;
  --accent:       #e8a050;
  --accent-hover: #f0b870;
  --accent-light: #2a1e10;
  --highlight:    #5a3a08;
  --highlight-fg: #fde68a;
  --fuzzy-bg:     #0f1e2a;
  --kbd-bg:       #231e16;
  --kbd-btn:      #2e2820;
  --kbd-btn-hover:#3a3228;
  --kbd-pending:  #e8a050;
  --kbd-pending-fg: #18130e;
}

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

html { scroll-behavior: smooth; overflow-x: clip; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

#site-header button,
#search-bar button,
#tamil-keyboard button,
#content button,
#community-drawer button,
#toc-panel button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
}

/* ── Loading overlay ────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 1000;
  transition: opacity 0.3s;
}
#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
#loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Header ─────────────────────────────────────────────────────────── */
#site-header {
  position: sticky;
  top: 0;
  z-index: 210;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
#header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
#header-text { flex: 1; min-width: 0; }
#site-title {
  font-family: var(--font-tamil);
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.01em;
}
#invocation {
  font-family: var(--font-tamil);
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ── Header TOC button ───────────────────────────────────────────────── */
#toc-btn {
  flex-shrink: 0;
  height: 2.1rem;
  min-width: 2.1rem;
  padding: 0 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--accent-light);
  border: 1.5px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#toc-btn:hover { background: var(--kbd-btn-hover); }

/* ── TOC footer settings ─────────────────────────────────────────────── */
.toc-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.toc-footer-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.toc-footer-label {
  flex: 1;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-tamil);
}
.toc-footer-btns {
  display: flex;
  gap: 0.3rem;
}
.toc-footer button {
  height: 2rem;
  min-width: 2rem;
  padding: 0 0.45rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: var(--font-ui);
  font-weight: 600;
  background: var(--accent-light);
  border: 1.5px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  white-space: nowrap;
}
.toc-footer button:hover { background: var(--kbd-btn-hover); }
.toc-footer button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.toc-footer button:disabled { opacity: 0.35; pointer-events: none; }
#theme-toggle { font-size: 1.1rem; border-radius: 50%; width: 2rem; }
#theme-toggle:hover { transform: rotate(20deg); }

/* ── Search bar ─────────────────────────────────────────────────────── */
#search-bar {
  position: sticky;
  top: var(--header-height, 64px);
  z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 0.6rem 1.25rem;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* full-bleed sticky background behind search bar */
#search-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--surface);
  z-index: -1;
  left: -100vw;
  right: -100vw;
  border-bottom: 1px solid var(--border);
}

#search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  transition: border-color 0.15s;
}
#search-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

#search-icon {
  color: var(--text-faint);
  font-size: 1rem;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-tamil);
  font-size: 1.05rem;
  color: var(--text);
  outline: none;
  min-width: 0;
}
#search-input::placeholder {
  color: var(--text-faint);
  font-size: 0.9rem;
}
#search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

#keyboard-toggle {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
#keyboard-toggle:hover, #keyboard-toggle.active {
  background: var(--accent-light);
  color: var(--accent);
}

#search-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  min-height: 1em;
}

/* ── Tamil keyboard ─────────────────────────────────────────────────── */
#tamil-keyboard {
  position: sticky;
  top: calc(var(--header-height, 64px) + var(--search-bar-h, 70px));
  z-index: 190;
  background: var(--kbd-bg);
  border-bottom: 2px solid var(--border);
  max-height: 420px;
  overflow: hidden;
  transition: max-height 0.25s ease, border-width 0.25s;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.kbd-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem 0.6rem;
}
#tamil-keyboard.keyboard-hidden {
  max-height: 0;
  border-bottom-width: 0;
}

.kbd-section-label {
  font-size: 0.65rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-ui);
  margin-top: 0.4rem;
  margin-bottom: 0.2rem;
  text-align: center;
}
.kbd-row-inline-label {
  font-size: 0.6rem;
  color: var(--text-faint);
  font-family: var(--font-tamil);
  white-space: nowrap;
  align-self: center;
  margin-right: 0.2rem;
  opacity: 0.75;
}
.kbd-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
  justify-content: center;
}
.kbd-row.vowel-row { justify-content: space-between; }
.kbd-row.control-row { justify-content: center; margin-top: 0.25rem; }

.kbd-key {
  font-family: var(--font-tamil);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  min-width: 2.6rem;
  height: 2.6rem;
  padding: 0 0.3rem;
  background: var(--kbd-btn);
  border: 1px solid var(--border);
  border-bottom: 3px solid color-mix(in srgb, var(--border) 70%, #000);
  border-radius: var(--radius-sm);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, transform 0.08s;
  flex-shrink: 0;
}
.kbd-key:hover { background: var(--kbd-btn-hover); }
.kbd-key:active { transform: translateY(1px); border-bottom-width: 2px; }
.kbd-key.pending {
  background: var(--kbd-pending);
  color: var(--kbd-pending-fg);
  border-color: var(--kbd-pending);
}

.kbd-key.wide {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  min-width: 4.5rem;
  color: var(--text-muted);
}
.kbd-key.spacebar {
  flex: 1;
  max-width: 200px;
}

/* ── Keyboard mode selector ──────────────────────────────────────────── */
.kbd-mode-bar {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}
.kbd-mode-btn {
  font-family: var(--font-tamil);
  font-size: 0.78rem;
  padding: 0.2rem 0.7rem;
  border-radius: 99px;
  background: var(--kbd-btn);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  touch-action: manipulation;
}
.kbd-mode-btn:hover  { background: var(--kbd-btn-hover); }
.kbd-mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Suggest strip ────────────────────────────────────────────────────── */
.kbd-suggest-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.3rem;
  margin-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
  min-height: 2rem;
}
.kbd-suggest-strip:empty { display: none; }
.kbd-suggest-strip[hidden] { display: none; }
.kbd-suggest-btn {
  font-family: var(--font-tamil);
  font-size: 0.9rem;
  padding: 0.15rem 0.6rem;
  border-radius: 99px;
  background: var(--kbd-btn);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.1s;
}
.kbd-suggest-btn:hover { background: var(--kbd-btn-hover); }

/* ── Phonetic QWERTY keys ─────────────────────────────────────────────── */
.kbd-row.phonetic-row { justify-content: center; }
.kbd-row.phonetic-row .kbd-key {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  min-width: 0;
  width: calc((100% - 9 * 0.3rem) / 10);
  max-width: 2.8rem;
}

/* ── Tamil99 OSK key sizing & dual-label layout ─────────────────────── */
.kbd-row.t99-row { justify-content: center; }
.kbd-row.t99-row .kbd-key {
  flex: 1;
  min-width: 0;
  max-width: 2.6rem;
  padding: 0.15rem 0.1rem 0.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1;
}
/* Main Tamil character — larger */
.t99-key .t99-char {
  font-family: var(--font-tamil);
  font-size: 1rem;
  line-height: 1.15;
  display: block;
}
.t99-key .t99-char.t99-char-shifted {
  color: var(--accent);
}
/* QWERTY sublabel — small, muted */
.t99-key .t99-eng {
  font-size: 0.55rem;
  color: var(--text-muted);
  font-family: sans-serif;
  line-height: 1.2;
  display: block;
  opacity: 0.75;
}
/* Shift active state */
.t99-shift-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Keyman Web status area ──────────────────────────────────────────── */
.kbd-kmw-area {
  padding: 0.5rem 0.25rem;
  font-family: var(--font-tamil);
  font-size: 0.88rem;
  color: var(--text-muted);
}
.kbd-kmw-ready { color: var(--text); }
.kbd-kmw-error { color: #c0392b; }

/* Keyman injects elements — restore UA defaults our reset wiped */
[class*="kmw"], [class*="kmw"] *,
[id*="kmw"],    [id*="kmw"] * {
  box-sizing: revert;
  margin: revert;
  padding: revert;
  border: revert;
  font-family: revert;
  font-size: revert;
  line-height: revert;
  color: revert;
  background: revert;
  cursor: revert;
}

/* Force KMW OSK to always appear in the viewport, not at document origin.
   Keyman sets position:absolute + inline top/left via JS — !important wins.
   margin:auto doesn't center fixed elements; use left:50%+translateX instead. */
.kmw-osk-frame {
  position: fixed !important;
  bottom: 0 !important;
  top: auto !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  width: min(100vw, 860px) !important;
  margin: 0 !important;
  z-index: 10002 !important;
  overflow: hidden !important;  /* clip keys that Keyman sized to full viewport width */
}
/* Force key layers to fill the (now-constrained) frame, not the viewport */
.kmw-osk-frame .kmw-key-layer-group,
.kmw-osk-frame .kmw-key-layer,
.kmw-osk-frame .kmw-osk-inner-frame {
  width: 100% !important;
  max-width: 100% !important;
  left: 0 !important;
  box-sizing: border-box !important;
}

/* hidden areas */
.kbd-area[hidden] { display: none; }

/* ── Content area ───────────────────────────────────────────────────── */
#content {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

/* ── Browse view ────────────────────────────────────────────────────── */
.invocation-block, .closing-block {
  text-align: center;
  padding: 1.5rem 0 1rem;
  font-family: var(--font-tamil);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.closing-block { padding: 1rem 0 2rem; border-top: 1px solid var(--border); }

.section-block {
  margin-top: 1.25rem;
}
.section-header-label {
  font-family: var(--font-tamil);
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  padding: 0.5rem 0.5rem 0.4rem;
  margin-bottom: 0.5rem;
  border-top: 2px solid var(--accent-light);
  border-bottom: 1px solid var(--border);
  background: var(--accent-light);
  border-radius: var(--radius-sm);
}

.couplet {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  transition: background 0.12s, border-color 0.12s;
  cursor: pointer;
}
.couplet:hover { background: var(--accent-light); }
.couplet.focused {
  background: var(--accent-light);
  border-left-color: var(--accent);
  border-left-width: 4px;
  padding-left: 0.625rem; /* keep text position stable (0.75 - 4px + 3px) */
  box-shadow: inset 3px 0 0 var(--accent), var(--shadow-sm);
  scroll-margin-top: 150px;
}

.verse-nums {
  min-width: 4rem;
  text-align: right;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-family: var(--font-ui);
  padding-top: 0.35rem;
  flex-shrink: 0;
  user-select: none;
}

.verse-lines {
  font-family: var(--font-tamil);
  font-size: calc(clamp(1rem, 2.5vw, 1.15rem) * var(--font-scale));
  line-height: 1.95;
  flex: 1;
  min-width: 0;
}
.verse-line {
  word-break: break-word;
}

/* ── Search results ─────────────────────────────────────────────────── */
#search-view {
  padding-top: 0.75rem;
}

.results-section-tag {
  display: inline-block;
  font-family: var(--font-tamil);
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  margin-top: 0.25rem;
}

.results-separator {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-faint);
  padding: 0.6rem 0.5rem 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 1px dashed var(--border);
  margin-top: 0.5rem;
}

.couplet.matched {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  padding-left: 0.35rem;
}
.couplet.fuzzy-match {
  background: var(--fuzzy-bg);
  border-left-color: #7090b0;
}

mark {
  background: var(--highlight);
  color: var(--highlight-fg);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}

.no-results {
  font-family: var(--font-tamil);
  color: var(--text-muted);
  padding: 2rem 0.5rem;
  font-size: 1rem;
}

/* ── Lazy load placeholder ──────────────────────────────────────────── */
.lazy-section-placeholder {
  height: 60px;
  background: var(--border);
  opacity: 0.3;
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.2; }
  50%       { opacity: 0.4; }
}

/* ── Tamil text utility ─────────────────────────────────────────────── */
.tamil-text { font-family: var(--font-tamil); }

/* ── TOC overlay (mobile backdrop) ──────────────────────────────────── */
#toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 509;
  -webkit-tap-highlight-color: transparent;
}
#toc-overlay.visible { display: block; }
/* Only show on screens where the TOC covers most of the content */
@media (min-width: 680px) {
  #toc-overlay { display: none !important; }
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #header-inner { padding: 0.75rem 1rem 0.5rem; }
  #search-bar { padding: 0.5rem 1rem; }
  /* Reserve right-side space for 3 always-visible action buttons on touch */
  .couplet { padding-right: 6rem; }
  #content { padding: 0 1rem 3rem; }
  .verse-nums { min-width: 2.8rem; }
  .kbd-key { min-width: 2.2rem; height: 2.4rem; font-size: 0.9rem; }
  /* Hide font label text on small screens, keep icon */
  #font-dec, #font-inc { font-size: 0.7rem; min-width: 1.8rem; padding: 0 0.2rem; }
  #translit-btn { font-size: 0.7rem; padding: 0 0.2rem; }
  /* Pin makes no sense on mobile — TOC would cover the content */
  #toc-pin-btn { display: none; }
}

@media (max-width: 400px) {
  .kbd-key { min-width: 1.9rem; height: 2.2rem; font-size: 0.82rem; gap: 0.2rem; }
  #tamil-keyboard { padding: 0.4rem 0.5rem 0.5rem; }
}

/* ── Safe area insets (Android home bar / iOS home indicator) ────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #content {
    padding-bottom: max(3rem, calc(env(safe-area-inset-bottom) + 1.5rem));
  }
  #scroll-top-btn {
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  }
  .toc-footer {
    padding-bottom: max(1rem, calc(env(safe-area-inset-bottom) + 0.75rem));
  }
}

/* ── TOC panel (feature 4) ───────────────────────────────────────────── */
#toc-panel {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(280px, 85vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0,0,0,.15);
  z-index: 510;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
#toc-panel.toc-open { transform: translateX(0); }
.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toc-header-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.toc-close,
.toc-pin {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.35rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.toc-close:hover,
.toc-pin:hover { background: var(--accent-light); color: var(--accent); }
.toc-pin[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

/* When pinned: drop shadow removed (it's now a permanent sidebar) */
#toc-panel.toc-pinned { box-shadow: none; }
.toc-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0;
  overscroll-behavior: contain;
}
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 1rem;
  font-family: var(--font-tamil);
  font-size: 0.9rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-left: 3px solid transparent;
}
.toc-item:hover { background: var(--accent-light); color: var(--accent); }
.toc-item.toc-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-light);
  font-weight: 600;
}

/* ── Related verses panel (feature 13) ──────────────────────────────── */
#related-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 860px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 2px solid var(--accent-light);
  box-shadow: 0 -4px 20px rgba(0,0,0,.12);
  z-index: 180;
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  overflow-x: auto;
}
#related-panel[hidden] { display: none; }
.related-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-family: var(--font-tamil);
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  writing-mode: vertical-lr;
  text-orientation: mixed;
}
.related-close {
  cursor: pointer;
  color: var(--text-faint);
  font-size: 0.75rem;
  writing-mode: horizontal-tb;
}
.related-item {
  flex: 1;
  min-width: 180px;
  max-width: 260px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: background 0.12s;
}
.related-item:hover { background: var(--accent-light); }
.related-nums {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-ui);
  margin-bottom: 0.15rem;
}
.related-text {
  display: block;
  font-family: var(--font-tamil);
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.related-sec-tag {
  display: block;
  font-family: var(--font-tamil);
  font-size: 0.65rem;
  color: var(--accent);
  margin-top: 0.2rem;
}

/* ── Heatmap (feature 9) ─────────────────────────────────────────────── */
.couplet[data-popularity="cool"] { border-left: 3px solid color-mix(in srgb, var(--accent) 20%, transparent); }
.couplet[data-popularity="warm"] { border-left: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.couplet[data-popularity="hot"]  { border-left: 3px solid var(--accent); }

/* ── Copy feedback ───────────────────────────────────────────────────── */
.couplet-action.copied {
  background: #22c55e;
  border-color: #22c55e;
  color: #fff;
}

/* ── Reading progress bar ────────────────────────────────────────────── */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 1001;          /* above everything */
  width: 0%;
  transition: width 0.3s ease;
  pointer-events: none;
}

/* ── Scroll-to-top button ────────────────────────────────────────────── */
#scroll-top-btn {
  position: fixed;
  bottom: 5rem; right: 1.25rem;
  width: 2.6rem; height: 2.6rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--accent);
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
}
#scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
#scroll-top-btn:hover { background: var(--accent-light); }
