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

/* ─── Dark theme (default) ───────────────────────────────── */
:root {
  --bg:           #0d0d10;
  --bg-panel:     #111116;
  --bg-card:      #17171e;
  --bg-hover:     #1e1e28;
  --border:       #252530;
  --border-light: #2e2e3e;
  --text:         #dddde8;
  --text-dim:     #a0a0b8;
  --text-faint:   #77778e;
  --accent:       #8b7df8;
  --accent-dim:   #2a2450;
  --accent-glow:  rgba(139,125,248,0.15);
  --accent-hover: #a89eff;
  --danger:       #e05a6a;
  --gold:         #d4a84b;
  --teal:         #4ec9b0;
  --nav-h:        52px;
  --right-w:      380px;
  --radius-sm:    4px;
  --radius:       8px;
  --radius-lg:    12px;
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;
  --font-text:    'Georgia', 'Palatino Linotype', 'Times New Roman', serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
  --font-size-text: 1.05rem;
  --text-align:   left;
}

/* ─── Light theme ────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f8f7f3;
  --bg-panel:     #f0eeea;
  --bg-card:      #ffffff;
  --bg-hover:     #e8e6e0;
  --border:       #d8d5cc;
  --border-light: #c4c0b4;
  --text:         #1a1a1f;
  --text-dim:     #3e3c4e;
  --text-faint:   #6e6e80;
  --accent:       #5b4fd8;
  --accent-dim:   #ede9ff;
  --accent-glow:  rgba(91,79,216,0.08);
  --accent-hover: #4840c0;
  --danger:       #c03040;
  --gold:         #a07020;
}

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button { font-family: inherit; cursor: pointer; }

/* ── App shell ─────────────────────────────── */
#app { height: 100%; display: flex; flex-direction: column; }

/* ── Loading ─────────────────────────────── */
.loading-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; color: var(--text-dim); font-size: 1rem; letter-spacing: 0.05em;
}

/* ─────────────────────────────────────────────
   TOP NAV
───────────────────────────────────────────── */
.topnav {
  height: var(--nav-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 50;
}

.topnav .brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-decoration: none;
  white-space: nowrap;
}

.topnav .nav-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-faint);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topnav .nav-breadcrumb span { color: var(--text-dim); }

.topnav .nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.topnav .user-label {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Buttons */
.btn {
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: var(--font-ui);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-light); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ─────────────────────────────────────────────
   READER  (main layout)
───────────────────────────────────────────── */
.page-reader {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.reader-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left: text panel ───────────────────── */
.panel-text {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 3rem 4rem;
  background: var(--bg);
  border-right: 1px solid var(--border);
  /* Wider left for text focus */
  min-width: 0;
}

.panel-text::-webkit-scrollbar { width: 6px; }
.panel-text::-webkit-scrollbar-track { background: transparent; }
.panel-text::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* ── Right: analysis panel ────────────── */
.panel-analysis {
  width: var(--right-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
}

/* Right top: arc — distinct background to separate from analysis */
.analysis-arc {
  flex-shrink: 0;
  padding: 0;
  border-bottom: 2px solid var(--accent-dim);
  overflow-y: auto;
  max-height: 42%;
  background: var(--bg);
}
.analysis-arc::-webkit-scrollbar { width: 4px; }
.analysis-arc::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* Arc header — colored band */
.arc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1.25rem;
  background: var(--accent-dim);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  position: sticky;
  top: 0;
  z-index: 1;
}
.arc-header-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.arc-body {
  padding: 0.9rem 1.25rem 1rem;
}

.analysis-arc .arc-text {
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--text-dim);
}

.resolution-targets { margin-top: 1rem; }

.resolution-targets .rt-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.rt-item {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-dim);
}

.rt-item .rt-num {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

/* Theme toggle button */
.btn-theme {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.btn-theme:hover { background: var(--bg-hover); color: var(--text); }

/* Settings gear button */
.btn-settings {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  cursor: pointer;
}
.btn-settings:hover { background: var(--bg-hover); color: var(--text); }

/* Panel collapse icon button */
.panel-toggle {
  width: 20px; height: 20px; padding: 0;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-faint);
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.panel-toggle:hover { background: var(--bg-hover); color: var(--text-dim); }

/* Collapsed panels */
.analysis-arc.is-collapsed .arc-body,
.analysis-arc.is-collapsed .resolution-targets { display: none; }
.analysis-section.is-collapsed #as-content { display: none; }

/* Right bottom: current section detail */
.analysis-section {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  position: relative;
  background: var(--bg-panel);
}
.analysis-section::-webkit-scrollbar { width: 4px; }
.analysis-section::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* Analysis header — teal/gold band to clearly differ from arc */
.as-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1.25rem;
  background: color-mix(in srgb, var(--teal) 15%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--teal) 30%, transparent);
  position: sticky;
  top: 0;
  z-index: 1;
}
.as-header-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--teal);
}

#as-content {
  padding: 1rem 1.25rem 1.25rem;
}

.as-label, .as-page-label {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-style: italic;
  margin-bottom: 0.3rem;
}

.as-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  line-height: 1.35;
}

.as-summary {
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.as-quote {
  border-left: 2px solid var(--accent);
  padding: 0.5rem 0.8rem;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--accent-hover);
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.as-connection-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
}

.as-connection {
  font-size: 0.8rem;
  line-height: 1.65;
  color: var(--text-dim);
  border-left: 2px solid var(--border-light);
  padding-left: 0.7rem;
  margin-bottom: 1rem;
}

.as-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.75rem;
}

.as-badge {
  background: var(--accent-dim);
  color: var(--accent-hover);
  border-radius: 10px;
  padding: 0.1rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.as-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
  padding: 1rem;
}

/* ─────────────────────────────────────────────
   TEXT PANEL  — section typography
───────────────────────────────────────────── */
.text-block {
  margin-bottom: 3.5rem;
  cursor: default;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.text-block:hover { background: color-mix(in srgb, var(--accent) 3%, transparent); }

.text-block-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.text-block-num {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  padding-right: 1.1em;
  user-select: none;
}

/* Star icon uses ::before so we can swap the glyph via CSS */
.text-block-num .star-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0;           /* hide the HTML text node */
  line-height: 1;
  pointer-events: none;   /* clicks hit the parent num span */
}

.text-block-num .star-btn::before {
  content: '\2605';       /* ★ filled star */
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.text-block-num:hover .star-btn::before {
  opacity: 0.45;
}

/* When starred: always show filled star in dark red */
.text-block.is-starred .text-block-num .star-btn::before {
  opacity: 1;
  color: #8b1a1a;
}

/* On hover of a starred num: switch to outlined star to hint "click to unstar" */
.text-block.is-starred .text-block-num:hover .star-btn::before {
  content: '\2606';       /* ☆ outlined star */
  color: #8b1a1a;
  opacity: 0.8;
}

/* Starred: number turns dark red */
.text-block.is-starred .text-block-num {
  color: #8b1a1a;
}

/* Starred active state: keep dark red (override .is-active tint) */
.text-block.is-starred.is-active .text-block-num {
  color: #a02020;
}

.text-block-title {
  font-size: 0.8rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-block-page {
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-left: auto;
  flex-shrink: 0;
}

.text-section {
  font-family: var(--font-text);
  font-size: var(--font-size-text);
  line-height: 2;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: 0.01em;
  text-align: var(--text-align);
  /* Suppress iOS long-press callout ("Copy / Look Up / Share…") */
  -webkit-touch-callout: none;
}
.text-section strong { font-weight: 700; }
.text-section em { font-style: italic; }
.md-marker { display: none; }

/* Highlight when section is "active" (visible in viewport) */
.text-block.is-active .text-block-num {
  color: var(--accent-hover);
}

/* ─────────────────────────────────────────────
   THEME LIST PAGE
───────────────────────────────────────────── */
.page-themes {
  max-width: 860px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.page-themes h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
  letter-spacing: -0.02em;
}

.page-themes .subtitle {
  color: var(--text-dim);
  margin-bottom: 0;
  font-size: 0.88rem;
}

/* ── Theme card ── */
.theme-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  display: block;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
}
.theme-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  color: inherit;
}
.theme-card .tc-title {
  font-weight: 600;
  font-size: 0.93rem;
  margin-bottom: 0.3rem;
  color: var(--text);
  position: relative; /* sit above the wave layer */
  z-index: 1;
}
.tc-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.3rem;
}
.tc-title-row .tc-title {
  margin-bottom: 0;
}
.theme-card .tc-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

/* ── Reading-progress: grid canvas wave (managed by wave-progress.js) ── */
.tc-progress-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  border-radius: var(--radius);
}

/* Percentage badge (bottom-right, grid only) */
.tc-progress-pct {
  position: absolute;
  bottom: 0.4rem; right: 0.5rem;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-hover);
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 1px 4px var(--bg);
}

/* ── Reading-progress: list left-to-right bar ── */
.tc-progress-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: linear-gradient(to right, var(--accent), var(--accent-hover));
  border-radius: 0 1px 0 var(--radius-sm);
  pointer-events: none;
  transition: width 0.9s cubic-bezier(0.34, 1.4, 0.64, 1);
}


/* ─────────────────────────────────────────────
   AUTH PAGE
───────────────────────────────────────────── */
.page-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg);
}

.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 360px;
}

.auth-box h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 1.5rem; }

.form-group { margin-bottom: 0.9rem; }
.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  transition: border-color 0.12s;
}
.form-group input:focus { outline: none; border-color: var(--accent); }
.form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  transition: border-color 0.12s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23888' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
}
.form-group select:focus { outline: none; border-color: var(--accent); }
.form-group input[readonly] {
  opacity: 0.5;
  cursor: default;
  user-select: text;
}

.form-error { color: var(--danger); font-size: 0.78rem; min-height: 1.2em; margin-top: 0.4rem; }
.form-link { font-size: 0.78rem; margin-top: 1rem; color: var(--text-faint); }

/* ─────────────────────────────────────────────
   THEMES HEADER + ACTIONS
───────────────────────────────────────────── */
.themes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

/* Actions row */
.themes-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-btn {
  width: 32px; height: 30px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.95rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.view-btn:hover { background: var(--bg-hover); color: var(--text); }
.view-btn.active { background: var(--accent-dim); color: var(--accent); }
.view-btn + .view-btn { border-left: 1px solid var(--border); }

/* New folder button */
.btn-new-folder {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-new-folder:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-light); }

/* Import button */
.btn-import {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.78rem;
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-import:hover { background: var(--accent-dim); }
.btn-import:disabled { opacity: 0.5; cursor: wait; }

/* ── Library navigation (inside a folder) ── */
.lib-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.lib-back-btn {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 0.82rem;
  font-family: var(--font-ui);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.12s, background 0.12s;
}
.lib-back-btn:hover { color: var(--text); background: var(--bg-hover); }
.lib-folder-label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.lib-folder-icon { font-size: 1.1rem; }

/* ── Sections ── */
.lib-section { margin-bottom: 2.5rem; }
.lib-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

/* ── Grid / List layouts ── */
.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.list-view {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
/* List-view theme card overrides */
.list-view .theme-entry .theme-card {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
}
.list-view .tc-title { font-size: 0.88rem; white-space: nowrap; overflow: hidden; /* no ellipsis — marquee handles it */ }
.list-view .tc-meta  { font-size: 0.73rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; flex: 1; min-width: 0; }

/* tc-title-row is the actual flex child in list view — give it 50% */
.list-view .theme-entry .theme-card .tc-title-row {
  display: block;
  width: 50%;
  flex-shrink: 0;
  min-width: 0;
  overflow: hidden;
  margin-bottom: 0;
}

/* Marquee scroll for title or meta text that overflows in list view */
@keyframes marquee-ltr {
  0%   { transform: translateX(0); }
  45%  { transform: translateX(var(--marquee-shift)); }
  55%  { transform: translateX(var(--marquee-shift)); }
  100% { transform: translateX(0); }
}
.list-view .tc-title.is-overflowing span,
.list-view .tc-meta.is-overflowing span {
  display: inline-block;
  animation: marquee-ltr 8s ease-in-out infinite;
}

/* ── Theme entry (card wrapper) ── */
.theme-entry { position: relative; }

/* Admin edit overlay — hidden, revealed on hover */
.card-admin-overlay {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-entry:hover .card-admin-overlay {
  opacity: 1;
  pointer-events: auto;
}
.list-view .theme-entry .card-admin-overlay {
  top: 50%; bottom: auto; right: 0.5rem;
  transform: translateY(-50%);
  display: flex;
  flex-direction: row;
  gap: 4px;
}
/* On hover reveal buttons — smoothly shrink tc-meta to make room */
.list-view .theme-entry .theme-card { padding-right: 1rem; transition: padding-right 0.15s; }
.list-view .theme-entry:hover .theme-card { padding-right: 4.5rem; }

.card-edit-btn {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.card-edit-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ── Folder cards (grid) ── */
.folder-grid-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1rem 0.9rem;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
  text-align: center;
}
.folder-grid-card:hover { border-color: var(--accent); background: var(--bg-hover); }
.folder-grid-icon { font-size: 2.2rem; line-height: 1; margin-bottom: 0.5rem; }
.folder-grid-name {
  font-size: 0.88rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.folder-grid-count { font-size: 0.72rem; color: var(--text-faint); margin-top: 0.2rem; }

/* ── Folder rows (list) ── */
.folder-list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
  position: relative;
}
.folder-list-row:hover { border-color: var(--accent); background: var(--bg-hover); }
.folder-list-icon { font-size: 1.1rem; flex-shrink: 0; }
.folder-list-name { font-size: 0.88rem; font-weight: 600; color: var(--text); flex: 1; }
.folder-list-count { font-size: 0.73rem; color: var(--text-faint); }
.folder-list-arrow { color: var(--text-faint); font-size: 1rem; }

/* Folder admin action buttons (shared grid/list) */
.folder-card-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.folder-grid-card:hover .folder-card-actions,
.folder-list-row:hover .folder-card-actions { opacity: 1; }
.folder-grid-card .folder-card-actions {
  position: absolute;
  top: 0.4rem; right: 0.4rem;
}
.folder-list-row .folder-card-actions { margin-left: auto; }

.folder-card-btn {
  width: 22px; height: 22px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: var(--bg-hover);
  color: var(--text-faint);
  font-size: 0.78rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.folder-card-btn:hover { background: var(--bg-panel); color: var(--text); }
.folder-delete-btn:hover { background: rgba(224,90,106,0.12); color: var(--danger); }

/* Empty folder page */
.folder-empty-page {
  color: var(--text-faint); font-size: 0.88rem;
  padding: 3rem 0; text-align: center;
}
.no-themes { color: var(--text-faint); font-size: 0.9rem; margin-top: 2rem; }

/* ── Library tabs (My Library / Community) ── */
.lib-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 0 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.lib-tab {
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  background: none;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.lib-tab:hover { color: var(--text); background: var(--bg-hover); }
.lib-tab.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* ── Card badges (public / yours / in-library) ── */
.badge-public,
.badge-yours,
.badge-in-library {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.4;
  margin-left: 0.4rem;
}
.badge-public     { background: rgba(78,201,176,0.15); color: var(--teal); border: 1px solid rgba(78,201,176,0.3); }
.badge-yours      { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(139,125,248,0.3); }
.badge-in-library { background: rgba(100,100,120,0.15); color: var(--text-dim); border: 1px solid var(--border-light); }

/* ── Theme card publish/unpublish button ── */
.card-publish-btn {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  line-height: 1;
}
.card-publish-btn:hover { background: rgba(78,201,176,0.12); color: var(--teal); border-color: var(--teal); }
.card-publish-btn.btn-unpublish:hover { background: rgba(224,90,106,0.12); color: var(--danger); border-color: var(--danger); }

/* ── Community card overlay (fork button) ── */
.card-comm-overlay {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.theme-entry:hover .card-comm-overlay {
  opacity: 1;
  pointer-events: auto;
}
.list-view .theme-entry .card-comm-overlay {
  top: 50%; bottom: auto; right: 0.5rem;
  transform: translateY(-50%);
}
/* Prevent fork button from overlapping card text in list view */
.list-view .theme-entry:has(.btn-fork) .theme-card {
  padding-right: 5.5rem;
}

/* ── Fork button (community card + reader) ── */
.btn-fork {
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.btn-fork:hover { background: var(--accent); color: #fff; }
.btn-fork:disabled { opacity: 0.5; cursor: default; }

/* ── Community search ── */
.community-search {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  width: 220px;
  transition: border-color 0.15s;
}
.community-search:focus { outline: none; border-color: var(--accent); }

/* ── Read-only badge (theme reader) ── */
.badge-readonly {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.4;
  margin-left: 0.4rem;
  background: rgba(212,168,75,0.15);
  color: var(--gold);
  border: 1px solid rgba(212,168,75,0.3);
  vertical-align: middle;
}

/* ── Reader read-only banner ── */
.reader-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--accent-dim), transparent);
}
.reader-banner-readonly {
  color: var(--text);
}
.reader-banner .btn-fork {
  flex-shrink: 0;
}



/* ── Drag-and-drop ── */
.theme-entry[draggable="true"] { cursor: grab; }
.theme-entry[draggable="true"]:active { cursor: grabbing; }
.theme-entry.dragging { opacity: 0.4; pointer-events: none; }
.drag-over {
  outline: 2px solid var(--accent) !important;
  outline-offset: -2px;
  background: var(--bg-hover) !important;
}
.lib-back-btn.drag-over {
  outline-offset: 2px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  width: 100%; max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem; color: var(--text); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ─────────────────────────────────────────────
   TOAST NOTIFICATIONS
───────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 12px);
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: #fff;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  cursor: pointer;
  max-width: 360px;
}
.toast.toast-visible { opacity: 1; transform: translateX(0); }
.toast-success { border-left: 3px solid var(--teal); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent); }

/* ─────────────────────────────────────────────
   FOCUS STATES
───────────────────────────────────────────── */
.btn:focus-visible,
.btn-primary:focus-visible,
.btn-theme:focus-visible,
.btn-import:focus-visible,
.panel-toggle:focus-visible,
.tool-btn:focus-visible,
.theme-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.form-group input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* ─────────────────────────────────────────────
   SECTION VIEW STATES
───────────────────────────────────────────── */

/* State indicator arrow in header */
.text-block-header { cursor: pointer; user-select: none; position: relative; }
.state-arrow {
  font-size: 0.6rem;
  color: var(--text-faint);
  margin-left: auto;
  flex-shrink: 0;
  transition: color 0.15s, opacity 0.2s;
}
.text-block-header:hover .state-arrow { color: var(--text-dim); }

/* Collapsed: hide content + book logo */
.text-block.is-collapsed .book-logo-wrap,
.text-block.is-collapsed .summary-input-panel { display: none; }
/* Exception: custom summary overlay is showing in collapsed state — keep book logo visible */
.text-block.is-collapsed.overlay-shown .book-logo-wrap { display: flex; }

/* Content crossfade: text + excerpt overlap in the same grid cell */
.content-crossfade {
  display: grid;
  overflow: hidden;
  transition: height 0.38s ease-out;
}
/* Suppress all transitions during initial page render */
.notransition .content-crossfade,
.notransition .text-section-wrap,
.notransition .excerpt-section {
  transition: none !important;
}
.content-crossfade > .text-section-wrap,
.content-crossfade > .excerpt-section {
  grid-area: 1/1;
  align-self: start;
  min-width: 0;
}

.text-section-wrap {
  position: relative;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.25s ease;
}
.text-block.is-excerpt .text-section-wrap,
.text-block.is-collapsed .text-section-wrap {
  opacity: 0;
  pointer-events: none;
}
/* Exception: overlay lives inside text-section-wrap; keep it visible so the overlay shows */
.text-block.is-collapsed.overlay-shown .text-section-wrap {
  opacity: 1;
}

/* Excerpt section */
.excerpt-section {
  font-family: var(--font-text);
  font-size: var(--font-size-text);
  line-height: 2;
  color: var(--text);
  letter-spacing: 0.01em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.text-block.is-excerpt .excerpt-section {
  opacity: 1;
  pointer-events: auto;
}
.excerpt-ellipsis {
  color: var(--text-faint);
  font-style: italic;
}

/* ── Book logo + pen drawer ────────────── */
.book-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 5;
}
.text-block:hover .book-logo-wrap { opacity: 1; }
/* Hide book logo when input panel is visible */
.text-block.input-open .book-logo-wrap { display: none; }
.pen-logo {
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px 0 0 4px;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text-dim);
  transform: translateX(100%);
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
  white-space: nowrap;
}
.book-logo-wrap.has-summary:hover .pen-logo {
  transform: translateX(0);
  opacity: 1;
}
.book-logo-wrap.has-summary:hover .book-logo {
  border-radius: 0 4px 4px 0;
}
.book-logo {
  font-size: 15px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text-faint);
  transition: color 0.15s, border-color 0.15s;
  z-index: 1;
}
.book-logo:hover { color: var(--accent); border-color: var(--accent); }

/* Overlay active indicator on book logo */
.book-logo.overlay-active { color: var(--accent); border-color: var(--accent); }

/* ── Custom summary input panel ────────── */
.summary-input-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 10px;
}
.summary-input-panel textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-text);
  font-size: 0.88rem;
  line-height: 1.7;
  resize: vertical;
  min-height: 80px;
}
.summary-input-panel textarea:focus { outline: none; border-color: var(--accent); }
.summary-input-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
}
.summary-input-actions .btn-save {
  padding: 4px 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
}
.summary-input-actions .btn-save:hover { background: var(--accent-hover); }
.summary-input-actions .btn-cancel {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: var(--font-ui);
  cursor: pointer;
}
.summary-input-actions .btn-cancel:hover { background: var(--bg-hover); }

/* ── Custom summary overlay ────────────── */
.text-section-wrap {
  position: relative;
  overflow: hidden;
}
.custom-summary-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  padding: 12px 16px;
  z-index: 2;
  transition: opacity 0.25s ease;
}
.custom-summary-overlay .overlay-text {
  font-family: var(--font-text);
  font-size: 1.05rem;
  line-height: 2;
  color: var(--text);
  width: 100%;
}
/* Gradient fade at bottom when original text is clipped */
.text-section-wrap .clip-fade {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  background: linear-gradient(to bottom, transparent, var(--bg) 90%);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 4px 16px 6px;
  pointer-events: none;
  z-index: 1;
  font-family: var(--font-text);
  font-size: 0.9rem;
  color: var(--text-faint);
}

/* ─────────────────────────────────────────────
   RESPONSIVE — tablet & mobile
───────────────────────────────────────────── */
@media (max-width: 768px) {
  .reader-body {
    flex-direction: column;
  }
  .panel-text {
    padding: 1.5rem 1.25rem 2rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 55vh;
  }
  .panel-analysis {
    width: 100%;
    max-height: 45vh;
  }
  .analysis-arc { max-height: 35%; }
  .page-themes { padding: 2rem 1rem; }
  .grid-view { grid-template-columns: 1fr; }
  .topnav {
    padding: 0 0.75rem;
    gap: 0.5rem;
  }
  .topnav .nav-breadcrumb {
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  .panel-text { padding: 1rem; }
  .text-section { font-size: 0.95rem; line-height: 1.8; }
  .page-themes h1 { font-size: 1.4rem; }
  .themes-header { flex-wrap: wrap; }
  .auth-box { padding: 1.5rem; }
}

/* ─────────────────────────────────────────────
   SETTINGS MODAL
───────────────────────────────────────────── */
/* Animations */
@keyframes settingsBackdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes settingsBackdropOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes settingsModalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes settingsModalOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(12px) scale(0.97); }
}
.settings-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  animation: settingsBackdropIn 0.2s ease-out;
}
.settings-backdrop.closing {
  animation: settingsBackdropOut 0.18s ease-in forwards;
}
.settings-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 380px; max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  /* overflow: visible so tooltips inside aren't clipped */
  overflow: visible;
  animation: settingsModalIn 0.25s cubic-bezier(0.16,1,0.3,1);
}
.settings-backdrop.closing .settings-modal {
  animation: settingsModalOut 0.18s ease-in forwards;
}
.settings-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden; /* clip child bg to top rounded corners */
  background: var(--bg-panel);
}
.settings-modal-header h3 {
  font-size: 0.95rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 0.5rem;
}
.settings-modal-close {
  width: 28px; height: 28px; padding: 0;
  border: none; background: transparent;
  color: var(--text-dim); font-size: 1.2rem;
  cursor: pointer; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.settings-modal-close:hover { background: var(--bg-hover); color: var(--text); }
.settings-modal-body {
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1.25rem;
  background: var(--bg-panel);
}
.settings-group label {
  display: block; font-size: 0.8rem; font-weight: 600;
  color: var(--text-dim); margin-bottom: 0.5rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* Custom font dropdown */
.font-dropdown {
  position: relative; width: 100%;
}
.font-dropdown-trigger {
  width: 100%; padding: 0.55rem 0.75rem;
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 0.95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.font-dropdown-trigger:hover { border-color: var(--accent); }
.font-dropdown-trigger .dd-arrow { font-size: 0.7rem; color: var(--text-faint); }
.font-dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  display: none;
}
.font-dropdown-menu.open { display: block; }
.font-dropdown-item {
  padding: 0.5rem 0.75rem; cursor: pointer;
  font-size: 1rem; color: var(--text);
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.font-dropdown-item:hover { background: var(--bg-hover); }
.font-dropdown-item.selected {
  border-left-color: var(--accent); color: var(--accent);
}
.font-dropdown-item + .font-dropdown-item {
  border-top: 1px solid var(--border);
}

/* Segmented control */
.seg-control {
  display: flex; border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); overflow: hidden;
}
.seg-btn {
  flex: 1; padding: 0.5rem 0.25rem; border: none;
  background: var(--bg-card); color: var(--text-dim);
  font-size: 0.85rem; cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border-light); }
.seg-btn:hover { background: var(--bg-hover); color: var(--text); }
.seg-btn.active {
  background: var(--accent-dim); color: var(--accent);
  font-weight: 600;
}
.seg-btn .seg-preview {
  font-size: 1rem; line-height: 1;
}

/* ── Apple-style toggle switch ─────────────────────────────────────── */
.settings-toggle-row {
  display: flex; align-items: center; justify-content: space-between;
}
.settings-toggle-row .toggle-label {
  display: flex; flex-direction: column; gap: 0.15rem;
}
.settings-toggle-row .toggle-label strong {
  font-size: 0.9rem; font-weight: 500; color: var(--text);
  display: flex; align-items: center; gap: 0.35rem;
}
/* Tooltip question-mark badge */
.settings-tooltip-anchor {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px;
  background: var(--border-light);
  color: var(--text-dim);
  border-radius: 50%;
  font-size: 0.65rem; font-weight: 700;
  cursor: default;
  position: relative;
  flex-shrink: 0;
}
.settings-tooltip-anchor::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: 210px;
  white-space: normal;
  text-align: left;
  background: rgba(50, 50, 55, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #f0f0f0;
  font-size: 0.75rem; font-weight: 400;
  line-height: 1.45;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.settings-tooltip-anchor:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* Caret */
.settings-tooltip-anchor::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%; transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(50, 50, 55, 0.88);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.settings-tooltip-anchor:hover::before { opacity: 1; }
.settings-toggle-row .toggle-label span {
  font-size: 0.75rem; color: var(--text-dim);
}
/* The invisible checkbox */
.ios-toggle { position: absolute; opacity: 0; width: 0; height: 0; }
/* The pill track */
.ios-toggle-track {
  display: inline-block; position: relative;
  width: 51px; height: 31px; flex-shrink: 0;
  background: var(--border-light);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.ios-toggle:checked + .ios-toggle-track {
  background: #34C759;   /* Apple green */
}
/* The thumb */
.ios-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.28), 0 0 0 0.5px rgba(0,0,0,0.06);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s;
}
.ios-toggle:checked + .ios-toggle-track::after {
  transform: translateX(20px);
}
/* Pressed state */
.ios-toggle-track:active::after {
  width: 31px;  /* stretch toward direction of travel */
}
.ios-toggle:checked + .ios-toggle-track:active::after {
  transform: translateX(16px);
}

/* Modal footer */
.settings-modal-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
  background: var(--bg-panel);
}
.settings-modal-footer .btn { min-width: 80px; }
.settings-modal-footer .btn-save {
  background: var(--accent); color: #fff; border: none;
  padding: 0.45rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.85rem; cursor: pointer; font-weight: 600;
}
.settings-modal-footer .btn-save:hover { background: var(--accent-hover); }
.settings-modal-footer .btn-cancel {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border-light);
  padding: 0.45rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.85rem; cursor: pointer;
}
.settings-modal-footer .btn-cancel:hover { background: var(--bg-hover); color: var(--text); }
