:root {
  --font-sans: "Pretendard Variable", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Gowun Batang", "Noto Serif KR", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --outer-bg: #0d0e10;
  --bg: #050607;
  --bar-bg: rgba(5, 6, 7, 0.9);
  --nav-bg: rgba(8, 9, 11, 0.94);
  --surface: rgba(255, 255, 255, 0.035);
  --border: rgba(216, 224, 218, 0.11);
  --ink: #e8ece6;
  --body: #c4cac3;
  --muted: #6f7671;
  --accent: #e8ece6;
  --plate-bg: #111316;
  --plate-border: rgba(255, 255, 255, 0.14);
  --body-size: 0.96rem;
  --body-lh: 1.92;
}

html[data-fontsize="sm"] { --body-size: 0.89rem; --body-lh: 1.88; }
html[data-fontsize="md"] { --body-size: 0.96rem; --body-lh: 1.92; }
html[data-fontsize="lg"] { --body-size: 1.06rem; --body-lh: 1.98; }

html[data-pill="blue"][data-theme="light"] {
  --outer-bg: #e3ddd0;
  --bg: #f6f2e9;
  --bar-bg: rgba(246, 242, 233, 0.93);
  --nav-bg: rgba(246, 242, 233, 0.96);
  --surface: rgba(255, 255, 255, 0.58);
  --border: #ddd5c5;
  --ink: #1c1917;
  --body: #3a342c;
  --muted: #726a5d;
  --accent: #1d4ed8;
  --plate-bg: #fbf8f1;
  --plate-border: #cfc5b2;
}

html[data-pill="blue"][data-theme="dark"] {
  --outer-bg: #080c15;
  --bg: #0d1321;
  --bar-bg: rgba(13, 19, 33, 0.93);
  --nav-bg: rgba(11, 16, 29, 0.95);
  --surface: rgba(255, 255, 255, 0.035);
  --border: #202e47;
  --ink: #f1f5f9;
  --body: #cbd5e1;
  --muted: #8ea0bc;
  --accent: #60a5fa;
  --plate-bg: #141d30;
  --plate-border: #263654;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--outer-bg);
  color: var(--ink);
  transition: background-color 0.28s ease;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.ui-icon { width: 18px; height: 18px; display: block; }
.hidden { display: none !important; }

.app-shell {
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background-color 0.28s ease, color 0.28s ease;
}

@media (min-width: 520px) {
  body { padding: 20px 16px 32px; }
  .app-shell {
    min-height: 820px;
    border-radius: 28px;
    border: 1px solid var(--border);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  }
}

/* Film grain only in Red Pill */
.grain-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  opacity: 0;
  background-image: radial-gradient(rgba(220, 230, 224, 0.045) 1px, transparent 0);
  background-size: 3px 3px;
  transition: opacity 0.28s ease;
}
html[data-pill="red"] .grain-overlay { opacity: 0.45; }

/* Restrained VHS tracking transition */
#vhs-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 95;
  display: none;
  overflow: hidden;
}
#vhs-overlay.active {
  display: block;
  animation: vhsFade 0.24s ease-out forwards;
}
#vhs-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.28) 0 1px, transparent 1px 3px);
}
#vhs-overlay::after {
  content: "";
  position: absolute;
  left: 0; right: 0; height: 18px;
  background: linear-gradient(180deg, transparent, rgba(225,232,228,0.18) 42%, rgba(255,255,255,0.28) 52%, transparent);
  animation: vhsBand 0.24s linear forwards;
}
.vhs-jitter { animation: vhsMicro 0.22s steps(3, end) forwards; }

@keyframes vhsFade {
  0% { opacity: 0.85; background: rgba(5,6,7,0.42); }
  55% { opacity: 0.45; background: rgba(5,6,7,0.16); }
  100% { opacity: 0; background: transparent; }
}
@keyframes vhsBand {
  0% { top: 18%; transform: translateX(-2px); }
  50% { top: 54%; transform: translateX(2px); }
  100% { top: 82%; transform: translateX(0); }
}
@keyframes vhsMicro {
  0% { transform: translateX(-1.5px); filter: contrast(1.08); }
  50% { transform: translateX(1.5px); filter: contrast(1.04) saturate(0.88); }
  100% { transform: translateX(0); filter: none; }
}

/* Sticky Slim Header */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 50px;
  padding: 0 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.top-left { display: flex; align-items: center; }
.top-center { display: flex; justify-content: center; }
.top-right { display: flex; justify-content: flex-end; gap: 4px; }

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  opacity: 0.95;
}
.brand-wordmark {
  font-family: "Pretendard Variable", "Noto Sans KR", "Arial Black", "Helvetica Neue", sans-serif;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
}
.brand-btn .ui-icon { width: 16px; height: 16px; }

.mode-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.mode-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
  transition:
    transform 0.24s cubic-bezier(0.32, 0.72, 0, 1),
    background-color 0.24s ease,
    border-color 0.24s ease,
    box-shadow 0.24s ease;
}
html[data-pill="blue"] .mode-switch-thumb {
  transform: translateX(100%);
}
html[data-pill="blue"][data-theme="light"] .mode-switch-thumb {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.09);
}
html[data-pill="blue"][data-theme="dark"] .mode-switch-thumb {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(96, 165, 250, 0.38);
}
.mode-switch-btn {
  position: relative;
  z-index: 1;
  width: 32px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
}
.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
  opacity: 0.34;
  transform: scale(0.84);
  transition:
    opacity 0.22s ease,
    transform 0.24s cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow 0.22s ease;
}
.mode-switch-btn:not(.active):hover .mode-dot {
  opacity: 0.65;
}
.mode-switch-btn.active .mode-dot {
  opacity: 1;
  transform: scale(1);
}
.mode-dot-red {
  background: #dc2626;
}
.mode-switch-btn.active .mode-dot-red {
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.45);
}
.mode-dot-blue {
  background: #3b82f6;
}
html[data-pill="blue"][data-theme="light"] .mode-dot-blue {
  background: #2563eb;
}
.mode-switch-btn.active .mode-dot-blue {
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.35);
}
html[data-animations="off"] .mode-switch-thumb,
html[data-animations="off"] .mode-dot {
  transition: none;
}

.icon-btn {
  padding: 6px;
  border-radius: 999px;
  opacity: 0.45;
  transition: opacity 0.2s ease, color 0.2s ease;
}
.icon-btn:hover { opacity: 0.9; }
.icon-btn.is-read { opacity: 1; color: #34d399; }
.icon-btn.is-bookmarked { opacity: 1; color: #fbbf24; }

/* Main Content */
.main-content { flex: 1; padding-bottom: 84px; }

/* Red Pill Detail */
.red-hero-wrap { position: relative; background: #000; overflow: hidden; }
.red-hero-btn { display: block; width: 100%; position: relative; }
.red-hero-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  filter: contrast(1.07) saturate(0.82) brightness(0.95);
}
.vhs-scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.22) 0 1px, transparent 1px 3px);
}
.red-hero-fade {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.2) 0%, transparent 45%, rgba(5,6,7,0.88) 84%, #050607 100%);
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.72);
}
.red-hero-meta {
  position: absolute;
  left: 22px; right: 18px; bottom: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}
.tape-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  color: #a6aea7;
  margin: 0;
  text-transform: uppercase;
}
.prev-next-btn .pn-tape {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.red-body-wrap { padding: 20px 22px 44px; }
.red-epigraph {
  margin: 0 0 28px;
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 0.9rem;
  line-height: 1.85;
  color: #a6aea7;
}
.prose-stack p {
  margin: 0 0 20px;
  font-size: var(--body-size);
  line-height: var(--body-lh);
  color: var(--body);
}
.prose-stack p:last-child { margin-bottom: 0; }

/* Blue Pill Detail */
.blue-wrap { padding: 20px 22px 44px; }
.blue-header { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.blue-code {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 6px;
}
.blue-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}
.blue-orig {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 6px;
}
.blue-tags { margin: 8px 0 0; font-size: 11px; color: var(--muted); }

.blue-figure { margin: 22px 0; }
.archival-plate {
  display: block;
  width: 100%;
  padding: 5px;
  background: var(--plate-bg);
  border: 1px solid var(--plate-border);
}
.archival-plate img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.blue-caption { margin: 8px 0 0; font-size: 11px; color: var(--muted); }

.blue-section { padding-top: 22px; margin-top: 22px; border-top: 1px solid var(--border); }
.blue-section:first-child { padding-top: 0; margin-top: 0; border-top: 0; }
.blue-section h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.ref-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: 12px; }
.related-row { display: flex; flex-wrap: wrap; gap: 8px; }
.related-chip {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink);
  background: var(--surface);
}

/* Sub Pages (Index, Gallery, Library, Settings) */
.page-pad { padding: 16px 20px 40px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.search-box .ui-icon { width: 15px; height: 15px; color: var(--muted); }
.search-box input {
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  font-size: 0.82rem;
}
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0 8px;
}
.filter-chips { display: flex; gap: 6px; overflow-x: auto; }
.chip-btn {
  flex-shrink: 0;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--muted);
}
.chip-btn.active { border-color: var(--border); color: var(--ink); font-weight: 600; }
.count-label { font-size: 11px; color: var(--muted); flex-shrink: 0; }

.hairline-list { border-top: 1px solid var(--border); }
.entry-row {
  width: 100%;
  text-align: left;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.entry-row-title { font-weight: 600; font-size: 0.96rem; color: var(--ink); }
.entry-row-orig { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-left: 6px; }
.entry-row-read { font-size: 10px; color: var(--accent); margin-left: 6px; }
.entry-row-summary { margin: 6px 0 0; font-size: 0.78rem; line-height: 1.6; color: var(--body); }
.entry-row-arrow { font-size: 11px; color: var(--muted); padding-top: 3px; flex-shrink: 0; }

.gallery-card { padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.gallery-card:last-child { border-bottom: 0; margin-bottom: 0; }
.gallery-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.gallery-head h2 { margin: 0; font-size: 0.88rem; font-weight: 600; }
.gallery-open { font-size: 11px; color: var(--muted); }
.gallery-img-btn { display: block; width: 100%; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.gallery-img-btn img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.gallery-img-btn img.is-red { filter: contrast(1.07) saturate(0.82) brightness(0.95); }

.stats-row { display: flex; gap: 36px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.stat-label { margin: 0; font-size: 11px; color: var(--muted); }
.stat-val { margin: 4px 0 0; font-family: var(--font-mono); font-size: 1.25rem; font-weight: 600; }
.empty-msg { padding: 40px 0; text-align: center; font-size: 0.8rem; color: var(--muted); }

.setting-row { padding: 18px 0; border-bottom: 1px solid var(--border); }
.setting-row.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-title { margin: 0 0 10px; font-size: 0.82rem; font-weight: 600; }
.setting-row.inline .setting-title { margin-bottom: 0; }
.seg-group { display: flex; gap: 8px; }
.seg-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}
.seg-btn.active { background: #2563eb; border-color: #2563eb; color: #fff; font-weight: 600; }
.pill-toggle {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.pill-toggle.on { background: var(--surface); color: var(--ink); border-color: var(--ink); }
.outline-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: 64px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  position: relative;
}
.nav-tab .ui-icon { width: 17px; height: 17px; }
.nav-tab.active { color: var(--accent); font-weight: 600; }
.nav-dot {
  position: absolute;
  top: 10px;
  right: 22%;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}

/* Lightbox & Toast */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.lightbox img { max-width: 100%; max-height: 76vh; border-radius: 8px; object-fit: contain; }
.lightbox p { margin: 12px 0 0; font-size: 12px; color: #cbd5e1; text-align: center; }
.lightbox-close {
  position: absolute;
  top: 16px; right: 16px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.toast {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translate(-50%, -6px);
  z-index: 90;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  background: #141519;
  color: #f4f4f5;
  border: 1px solid rgba(255, 255, 255, 0.14);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.read-sentinel { height: 12px; margin-top: 20px; }

/* === Dictionnaire Infernal-inspired Gallery, Library & Settings === */
html[data-fontsize="normal"] { --body-size: 0.96rem; --body-lh: 1.92; }
html[data-fontsize="large"] { --body-size: 1.07rem; --body-lh: 2.0; }

.di-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.di-panel h2 {
  margin: 0 0 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
}

/* Gallery 2-row filter & 2-col plate grid */
.gallery-toolbar {
  display: grid;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.pill-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.pill-row::-webkit-scrollbar { display: none; }
.g-pill {
  flex-shrink: 0;
  font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: transparent;
  transition: all 0.18s ease;
}
.g-pill.active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  font-weight: 600;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.plate-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.plate-tile-img-btn {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 4.4;
  overflow: hidden;
  background: #000;
}
.plate-tile-img-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.plate-tile-img-btn img.is-red {
  filter: contrast(1.07) saturate(0.82) brightness(0.95);
}
.plate-tile-foot {
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: left;
}
.plate-tile-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.plate-tile-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin: 2px 0 0;
}

/* Library status panel */
.library-status-title {
  margin: 0 0 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
}
.library-status-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.library-status-stats strong {
  color: var(--ink);
  font-family: var(--font-mono);
}

/* Settings Rows, Segmented & Switches */
.di-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.di-setting-row:first-child { padding-top: 2px; }
.di-setting-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.di-setting-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}
/* Smooth theme crossfade (from Dictionnaire Infernal) */
html.is-theme-switching,
html.is-theme-switching body,
html.is-theme-switching .app-shell,
html.is-theme-switching .top-bar,
html.is-theme-switching .bottom-nav,
html.is-theme-switching .di-panel,
html.is-theme-switching .di-segmented,
html.is-theme-switching .setting-switch-track,
html.is-theme-switching .di-action-btn {
  transition: background-color 240ms ease, color 240ms ease, border-color 240ms ease !important;
}

/* FLIP-sliding segmented control (from Dictionnaire Infernal) */
.di-segmented {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  height: 36px;
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  gap: 2px;
}
.di-segmented button {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 28px;
  padding: 0 11px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  transition: color 200ms ease, transform 120ms ease;
}
.di-segmented[data-segmented="theme"] button {
  width: 36px;
  padding: 0;
}
.di-segmented button:active {
  transform: scale(0.95);
}
.di-segmented button .ui-icon { width: 16px; height: 16px; }
.di-segmented button.active {
  background: transparent;
  color: var(--bg);
  font-weight: 600;
}
.di-segmented button.active::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: var(--ink);
  z-index: -1;
  transform-origin: 0 50%;
  will-change: transform;
}
.di-segmented button.active.is-sliding::before {
  animation: segmentedPillSlide 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes segmentedPillSlide {
  0% { transform: translate3d(var(--seg-dx, 0px), 0, 0) scaleX(var(--seg-sx, 1)); }
  100% { transform: translate3d(0, 0, 0) scaleX(1); }
}

/* Smooth glide toggle switch (from Dictionnaire Infernal) */
.setting-switch {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.setting-switch-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 48px;
  height: 26px;
  padding: 2px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: background-color 200ms ease, border-color 200ms ease, filter 160ms ease;
}
.setting-switch.is-on .setting-switch-track {
  background: var(--ink);
  border-color: var(--ink);
}
.setting-switch-thumb {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--muted);
  transform: translateX(0);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), background-color 200ms ease, width 140ms ease;
  will-change: transform;
}
.setting-switch.is-on .setting-switch-thumb {
  background: var(--bg);
  transform: translateX(22px);
}
.setting-switch:active .setting-switch-thumb {
  width: 23px;
}
.setting-switch.is-on:active .setting-switch-thumb {
  transform: translateX(19px);
}
html[data-animations="off"] .di-segmented button.active.is-sliding::before {
  animation: none !important;
}
html[data-animations="off"] .setting-switch-track,
html[data-animations="off"] .setting-switch-thumb {
  transition: none !important;
}

.di-action-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--bg);
}
.di-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.di-colophon {
  margin: 0;
  font-size: 0.77rem;
  line-height: 1.72;
  color: var(--muted);
}
.backup-modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.backup-card {
  width: 100%;
  max-width: 340px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 18px;
}
.backup-card h3 { margin: 0 0 8px; font-size: 0.92rem; }
.backup-card p { margin: 0 0 14px; font-size: 0.78rem; line-height: 1.6; color: var(--muted); }
.backup-actions { display: grid; gap: 8px; }
.backup-actions button { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.8rem; font-weight: 600; }
.backup-actions button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }


/* Dictionnaire Infernal-style Prev / Next Footer */
.detail-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  width: 100%;
}
.detail-prev-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.prev-next-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition: border-color 160ms ease, background-color 160ms ease, transform 120ms ease;
}
.prev-next-btn:active { transform: scale(0.98); }
.prev-next-btn.next { text-align: right; align-items: flex-end; }
.pn-dir {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.prev-next-btn strong {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
}
.prev-next-spacer { min-height: 1px; }

/* Dictionnaire Infernal-style 3-Button Floating Stack (140ms in, 1.2s hold, 850ms linear fade-out) */
.detail-fab-stack {
  position: fixed;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  right: max(14px, calc(50% - 201px));
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.85s linear;
}
.detail-fab-stack.is-scroll-visible {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.14s linear;
}
.detail-list-fab {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bar-bg);
  backdrop-filter: blur(10px);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.24);
  transition: opacity 180ms ease, transform 120ms ease, border-color 160ms ease;
}
.detail-list-fab .ui-icon { width: 17px; height: 17px; }
.detail-list-fab:active { transform: scale(0.93); }
.detail-scroll-btn.is-edge {
  opacity: 0.3;
  pointer-events: none;
}
