:root {
  color-scheme: light;
  --bg: #f7ecd7;
  --paper: #fff9ed;
  --paper-strong: #f0dcc0;
  --ink: #241912;
  --muted: #7b685a;
  --line: rgba(88, 49, 30, 0.18);
  --brand: #7d2f1c;
  --brand-strong: #581c13;
  --gold: #b98231;
  --ok: #2e6a4d;
  --shadow: 0 16px 40px rgba(79, 38, 16, 0.16);
  --radius: 16px;
  --topbar-height: calc(61px + env(safe-area-inset-top));
  --section-nav-height: 54px;
  --reading-toolbar-height: 52px;
  --reading-font-size: 20px;
  --reading-line-height: 1.65;
  --reading-font-family: "KaiTi", "STKaiti", "楷体", "LXGW WenKai", "Noto Serif SC", "Source Han Serif SC", "STSong", "Songti SC", serif;
  font-family: "LXGW WenKai", "Noto Serif SC", "Source Han Serif SC", "STSong", "Songti SC", "Iowan Old Style", "Palatino Linotype", serif;
}

:root.dark {
  color-scheme: dark;
  --bg: #160f0b;
  --paper: #231712;
  --paper-strong: #331f17;
  --ink: #f7ead5;
  --muted: #c8ad91;
  --line: rgba(255, 232, 198, 0.14);
  --brand: #d46a45;
  --brand-strong: #f1b071;
  --gold: #d0a15b;
  --ok: #7fc19d;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(185, 130, 49, 0.2), transparent 34rem),
    linear-gradient(180deg, var(--bg), var(--paper-strong));
  color: var(--ink);
  letter-spacing: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button,
input {
  font: inherit;
}

input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--brand);
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(185, 130, 49, 0.5);
  outline-offset: 2px;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 44px;
  align-items: center;
  gap: 6px;
  min-height: var(--topbar-height);
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(18px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  justify-content: center;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-controls::-webkit-scrollbar {
  display: none;
}

.topbar-chip-slot {
  display: flex;
  align-items: center;
  min-width: 0;
}

.icon-button,
.info-button,
.immersive-button,
.article-picker-button {
  position: relative;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-color: transparent;
}

.icon-button {
  background: var(--brand);
  color: #fff8e8;
}

.info-button {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: var(--paper);
  box-shadow:
    0 2px 8px rgba(79, 38, 16, 0.12),
    inset 0 0 0 1px color-mix(in srgb, #ffffff 42%, transparent);
}

.info-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.immersive-button {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--gold) 24%, transparent), transparent 46%),
    var(--brand);
  color: #fff5dc;
  border-color: color-mix(in srgb, var(--gold) 34%, transparent);
  box-shadow:
    0 2px 10px rgba(79, 38, 16, 0.18),
    inset 0 0 0 2px color-mix(in srgb, #fff1cf 18%, transparent);
}

.immersive-button span {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid color-mix(in srgb, #fff4d6 62%, transparent);
  border-radius: 8px;
  color: #fff5dc;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.article-picker-button {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  color: var(--brand-strong);
  box-shadow:
    0 2px 8px rgba(79, 38, 16, 0.1),
    inset 0 0 0 1px color-mix(in srgb, #ffffff 38%, transparent);
}

.article-picker-button > span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.article-picker-button::before {
  content: "";
  width: 18px;
  height: 20px;
  border: 2px solid currentColor;
  border-left-width: 5px;
  border-radius: 3px 5px 5px 3px;
  background: color-mix(in srgb, var(--gold) 14%, transparent);
  box-shadow: inset -4px 0 0 color-mix(in srgb, currentColor 10%, transparent);
}

.article-picker-button::after {
  content: "";
  position: absolute;
  top: 13px;
  right: 13px;
  width: 5px;
  height: 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 78%, var(--gold));
  opacity: 0.86;
}

.article-picker-button.loading::before {
  opacity: 0;
}

.article-picker-button.loading::after {
  top: 15px;
  right: 15px;
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in srgb, var(--brand) 28%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  background: transparent;
  animation: spin 700ms linear infinite;
}

.icon-button::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}

.icon-button::after {
  content: "";
  position: absolute;
  top: 9px;
  left: 16px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand);
  transition: transform 160ms ease;
}

.icon-button.dark-active::before {
  inset: 9px;
  box-shadow:
    0 -7px 0 -5px currentColor,
    0 7px 0 -5px currentColor,
    7px 0 0 -5px currentColor,
    -7px 0 0 -5px currentColor,
    5px 5px 0 -5px currentColor,
    -5px -5px 0 -5px currentColor,
    5px -5px 0 -5px currentColor,
    -5px 5px 0 -5px currentColor;
}

.icon-button.dark-active::after {
  transform: translateX(20px);
}

/* ── Segmented control (in topbar) ── */

.segmented {
  display: flex;
  padding: 4px;
  border-radius: 999px;
  border: 2px solid var(--brand);
  background: color-mix(in srgb, var(--paper-strong) 50%, transparent);
  overflow: hidden;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 15%, transparent),
    0 3px 8px rgba(88, 29, 18, 0.1);
  flex-shrink: 0;
}

.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 70%, var(--muted));
  font-size: 14px;
  font-weight: 500;
  transition:
    background 200ms ease,
    color 200ms ease,
    box-shadow 200ms ease,
    transform 160ms ease;
}

.segmented button.active {
  background: var(--brand);
  color: #fff8e8;
  box-shadow: 0 4px 12px rgba(125, 47, 28, 0.3);
}

.segmented button:active {
  transform: scale(0.96);
}

/* ── Chip stack: overlays both groups in the same grid cell ── */

.chip-stack {
  display: grid;
  grid-template-columns: 1fr;
}

.topbar-toggles,
.recite-chips {
  grid-area: 1 / 1;
  display: flex;
  gap: 3px;
  align-items: center;
  transition: opacity 200ms ease;
}

/* Hidden group: invisible but contributes to sizing */
.topbar-toggles[hidden] {
  opacity: 0;
  pointer-events: none;
}

.recite-chips[hidden] {
  opacity: 0;
  pointer-events: none;
}

/* Shared chip styles */
.chip-stack input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.chip-stack label,
.chip-stack button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 28px;
  min-width: 0;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 999px;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 55%, var(--muted));
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.chip-stack label:has(input:checked) {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff8e8;
}

.chip-stack label.unavailable {
  border-color: color-mix(in srgb, var(--line) 54%, transparent);
  color: color-mix(in srgb, var(--muted) 72%, transparent);
  cursor: not-allowed;
  opacity: 0.58;
}

.chip-stack label.unavailable:has(input:checked) {
  background: transparent;
  border-color: color-mix(in srgb, var(--line) 54%, transparent);
  color: color-mix(in srgb, var(--muted) 72%, transparent);
}

.chip-stack button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff8e8;
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: calc(var(--topbar-height) + var(--section-nav-height) + 14px) 14px 96px;
}

body.sheet-open {
  overflow: hidden;
}

.section,
.line-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  box-shadow: var(--shadow);
}

.section-nav {
  position: fixed;
  top: var(--topbar-height);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  gap: 6px;
  justify-content: flex-start;
  width: min(760px, 100%);
  min-height: var(--section-nav-height);
  margin: 0;
  padding: 8px 18px;
  border-block: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--paper) 90%, transparent),
      color-mix(in srgb, var(--bg) 80%, transparent)
    );
  backdrop-filter: blur(12px);
  max-width: 100vw;
  overflow-x: auto;
  scroll-padding-inline: 18px;
  scrollbar-width: none;
  contain: layout paint;
  transition:
    transform 240ms ease,
    opacity 180ms ease;
  will-change: transform;
}

.section-nav.nav-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 2px));
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.section-nav::-webkit-scrollbar {
  display: none;
}

.section-nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 62px;
  min-height: 36px;
  padding: 4px 9px 4px 6px;
  border: 1.5px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  color: color-mix(in srgb, var(--ink) 72%, var(--muted));
  box-shadow: none;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  transition:
    background 200ms ease,
    color 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease;
}

.section-number,
.section-summary-number {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid color-mix(in srgb, var(--gold) 64%, var(--line));
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--gold) 18%, transparent), transparent 56%),
    color-mix(in srgb, var(--paper-strong) 44%, var(--paper));
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--paper) 55%, transparent);
}

.section-label {
  line-height: 1;
  white-space: nowrap;
}

.section-nav button.active {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 92%, var(--paper));
  color: #fff8e8;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 30%, transparent);
  font-weight: 600;
}

.section-nav button.active .section-number {
  border-color: color-mix(in srgb, var(--gold) 78%, #fff8e8);
  background: color-mix(in srgb, #fff8e8 92%, var(--gold));
  color: var(--brand);
}

.section-nav button:active,
.segmented button:active,
.bottom-actions button:active {
  transform: translateY(1px);
}

.section {
  margin-top: 14px;
  padding: 14px;
}

.section-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-radius: 12px;
  background:
    linear-gradient(
      90deg,
      color-mix(in srgb, var(--gold) 10%, transparent),
      color-mix(in srgb, var(--paper) 72%, transparent)
    );
  color: color-mix(in srgb, var(--ink) 86%, var(--muted));
}

.section-summary-main {
  flex: 1 1 140px;
  min-width: 0;
}

.section-summary-title {
  display: block;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-card {
  position: relative;
  margin-top: 10px;
  padding: 18px 14px 14px;
  box-shadow: none;
  transition:
    border-color 200ms ease,
    background 200ms ease,
    transform 200ms ease,
    box-shadow 200ms ease;
}

.line-card.recite-card {
  cursor: pointer;
}

.line-card.recite-card:focus-visible {
  outline: 3px solid rgba(185, 130, 49, 0.5);
  outline-offset: 2px;
}

.line-card.recite-card:active {
  transform: scale(0.985);
}

.line-card.recite-revealed {
  border-color: color-mix(in srgb, var(--gold) 50%, var(--line));
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--gold) 9%, var(--paper)),
      color-mix(in srgb, var(--paper) 94%, transparent)
    );
  box-shadow: 0 2px 12px color-mix(in srgb, var(--gold) 12%, transparent);
}

.line-card.recite-card .original {
  border: 1px solid transparent;
  border-radius: 12px;
}

.line-index {
  position: absolute;
  top: 12px;
  left: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  opacity: 0.68;
}

.original {
  margin: 12px 0 0;
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
  font-family: var(--reading-font-family);
  font-weight: 700;
  letter-spacing: 0;
  overflow-wrap: normal;
  word-break: normal;
}

.original-line {
  display: block;
  --row-scale: 1;
  font-size: calc(1em * var(--row-scale));
  overflow-wrap: normal;
  word-break: normal;
}

.original-chunk {
  display: inline-block;
  white-space: nowrap;
  vertical-align: baseline;
}

.original.covered {
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--paper) 94%, transparent),
      color-mix(in srgb, var(--paper-strong) 18%, var(--paper))
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 20px,
      color-mix(in srgb, var(--line) 30%, transparent) 21px
    );
  color: transparent;
  user-select: none;
  border-radius: 12px;
  padding: 8px 4px;
  min-height: 1.65em;
}

/* ── First-character hint: mask individual chars ── */

.original.hint-first-char {
  border: 1px dashed color-mix(in srgb, var(--line) 65%, transparent);
  background: color-mix(in srgb, var(--paper) 60%, transparent);
  color: var(--ink);
  user-select: none;
  border-radius: 12px;
  padding: 8px 4px;
}

.original.hint-first-char .first-char-hint {
  display: block;
}

.char-masked {
  color: transparent;
  background: color-mix(in srgb, var(--line) 65%, transparent);
  border-radius: 2px;
  padding: 2px 3px;
  margin: 0 1px;
  user-select: none;
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--line) 40%, transparent);
  text-decoration-thickness: 2px;
}

/* ── Memory hint mode ── */

.original.hint-hint {
  border: 1px dashed color-mix(in srgb, var(--line) 55%, transparent);
  background: color-mix(in srgb, var(--paper) 50%, transparent);
  color: transparent;
  user-select: none;
  border-radius: 12px;
  padding: 8px 4px;
}

.hint-line {
  display: block;
  font-style: normal;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.7;
  color: color-mix(in srgb, var(--muted) 85%, transparent);
  letter-spacing: 0.3px;
  padding: 2px 0;
  position: relative;
}

.hint-line::before {
  content: "「";
  color: color-mix(in srgb, var(--gold) 50%, transparent);
  font-size: 14px;
  margin-right: 2px;
}

.hint-line::after {
  content: "」";
  color: color-mix(in srgb, var(--gold) 50%, transparent);
  font-size: 14px;
  margin-left: 2px;
}

/* ── Pinyin ruby annotations ── */

.original.has-pinyin {
  font-size: calc(var(--reading-font-size) - 1px);
  line-height: 2.8;
}

ruby {
  ruby-align: center;
  ruby-overhang: none;
  margin-inline: 1px;
}

ruby rt {
  font-size: 11px;
  font-weight: 400;
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  letter-spacing: 0;
  line-height: 1.2;
  font-style: normal;
}

ruby rp {
  display: none;
}

.original.covered.has-pinyin {
  line-height: 2.8;
}

.original.hint-first-char.has-pinyin {
  line-height: 2.8;
}

.aid-note {
  position: relative;
  margin: 10px 0 0;
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-left: 4px solid color-mix(in srgb, var(--gold) 70%, var(--brand));
  border-radius: 10px;
  background:
    linear-gradient(
      90deg,
      color-mix(in srgb, var(--gold) 11%, transparent),
      color-mix(in srgb, var(--paper) 72%, transparent)
    );
  padding: 10px 12px;
  line-height: 1.75;
  color: color-mix(in srgb, var(--ink) 88%, var(--muted));
}

.annotation {
  border-left-color: color-mix(in srgb, var(--brand) 66%, var(--gold));
  background:
    linear-gradient(
      90deg,
      color-mix(in srgb, var(--brand) 8%, transparent),
      color-mix(in srgb, var(--paper) 76%, transparent)
    );
  color: color-mix(in srgb, var(--ink) 76%, var(--muted));
  font-size: 14px;
}

.aid-label {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 90%, var(--gold));
  color: #fff8e8;
  font-size: 12px;
  line-height: 1;
}

.aid-label.meaning-label {
  background: color-mix(in srgb, var(--gold) 82%, var(--brand));
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.info-sheet[hidden] {
  display: none;
}

.info-sheet,
.article-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
}

.article-sheet[hidden] {
  display: none;
}

.immersive-sheet[hidden] {
  display: none;
}

.immersive-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: block;
  background:
    radial-gradient(circle at 22% 8%, rgba(185, 130, 49, 0.16), transparent 28rem),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 86%, #1c120b), var(--paper-strong));
}

.info-backdrop,
.article-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: rgba(36, 25, 18, 0.34);
}

.immersive-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(77, 41, 21, 0.2), transparent 18%, transparent 82%, rgba(77, 41, 21, 0.2)),
    rgba(36, 25, 18, 0.2);
}

.immersive-panel {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: calc(18px + env(safe-area-inset-top)) 14px calc(30px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
}

.immersive-panel:focus {
  outline: none;
}

.immersive-close {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  z-index: 2;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-color: color-mix(in srgb, var(--line) 82%, transparent);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  box-shadow: 0 8px 22px rgba(62, 34, 16, 0.16);
}

.immersive-close span::before,
.immersive-close span::after {
  content: "";
  position: absolute;
  top: 20px;
  left: 12px;
  width: 17px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.immersive-close span::before {
  transform: rotate(45deg);
}

.immersive-close span::after {
  transform: rotate(-45deg);
}

.immersive-body {
  position: relative;
  width: min(720px, 100%);
  min-height: calc(100vh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: calc(100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: 0 auto;
  padding: 34px 54px 60px;
  border-inline: 1px solid color-mix(in srgb, var(--gold) 30%, var(--line));
  background:
    linear-gradient(90deg, rgba(126, 74, 32, 0.1), transparent 20px, transparent calc(100% - 20px), rgba(126, 74, 32, 0.1)),
    linear-gradient(180deg, color-mix(in srgb, var(--paper) 96%, transparent), color-mix(in srgb, var(--paper-strong) 20%, var(--paper)));
  box-shadow:
    0 24px 60px rgba(53, 29, 14, 0.2),
    inset 20px 0 26px rgba(126, 74, 32, 0.05),
    inset -20px 0 26px rgba(126, 74, 32, 0.05);
}

.immersive-body::before,
.immersive-body::after {
  content: "";
  position: absolute;
  right: 20px;
  left: 20px;
  height: 1px;
  background: color-mix(in srgb, var(--gold) 24%, transparent);
}

.immersive-body::before {
  top: 18px;
}

.immersive-body::after {
  bottom: 18px;
}

.immersive-article-head {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin-bottom: 30px;
  text-align: center;
}

.immersive-byline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.immersive-article-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: 0;
}

.immersive-scroll {
  display: grid;
  gap: 22px;
}

.immersive-section {
  display: grid;
  gap: 0;
}

.immersive-text {
  display: grid;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.85;
}

.immersive-line {
  display: block;
  overflow-wrap: anywhere;
}

.info-panel,
.article-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(760px, calc(100% - 18px));
  height: min(72vh, 560px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--paper) 98%, transparent),
      color-mix(in srgb, var(--paper-strong) 24%, var(--paper))
    );
  box-shadow: 0 -18px 44px rgba(43, 24, 12, 0.24);
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
}

.info-panel:focus {
  outline: none;
}

.article-panel {
  height: min(78vh, 620px);
}

.article-panel:focus {
  outline: none;
}

.info-head,
.article-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.info-head h2,
.article-panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.sheet-close {
  position: relative;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--paper) 84%, transparent);
}

.sheet-close::before,
.sheet-close::after {
  content: "";
  position: absolute;
  top: 19px;
  left: 12px;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.sheet-close::before {
  transform: rotate(45deg);
}

.sheet-close::after {
  transform: rotate(-45deg);
}

.article-search {
  display: block;
  margin-top: 14px;
}

.article-search input {
  width: 100%;
  min-height: 42px;
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-radius: 12px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--gold) 8%, transparent), transparent),
    color-mix(in srgb, var(--paper) 84%, transparent);
  color: var(--ink);
  padding: 0 13px;
  font: inherit;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-width: thin;
}

.article-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  min-height: 64px;
  border-radius: 12px;
  border-color: color-mix(in srgb, var(--line) 80%, transparent);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--gold) 8%, transparent), transparent 58%),
    color-mix(in srgb, var(--paper) 86%, transparent);
  padding: 12px;
  text-align: left;
  box-shadow: none;
}

.article-option.active {
  border-color: color-mix(in srgb, var(--brand) 72%, var(--line));
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand) 13%, transparent), transparent 58%),
    color-mix(in srgb, var(--paper) 90%, transparent);
}

.article-option-main {
  display: grid;
  gap: 7px;
}

.article-option-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.article-option-title {
  min-width: 0;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.article-option-byline {
  flex: 0 0 auto;
  color: color-mix(in srgb, var(--muted) 86%, var(--ink));
  font-size: 12px;
  line-height: 1.2;
}

.article-option-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.article-option-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 999px;
  padding: 0 8px;
  background: color-mix(in srgb, var(--paper-strong) 44%, transparent);
  color: color-mix(in srgb, var(--ink) 70%, var(--muted));
  font-size: 12px;
  line-height: 1;
}

.article-option.active .article-option-byline {
  color: var(--brand-strong);
}

.article-option.active .article-option-tags span {
  border-color: color-mix(in srgb, var(--brand) 38%, var(--line));
  background: color-mix(in srgb, var(--brand) 10%, var(--paper));
  color: var(--brand-strong);
}

.article-option-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.article-option.active .article-option-meta {
  color: var(--brand-strong);
  font-weight: 700;
}

.article-option-meta:empty {
  display: none;
}

.article-empty,
.article-error {
  margin: 0;
  border: 1px dashed color-mix(in srgb, var(--line) 90%, transparent);
  border-radius: 12px;
  color: var(--muted);
  padding: 18px 14px;
  text-align: center;
}

.article-error {
  display: grid;
  gap: 5px;
  color: color-mix(in srgb, var(--brand-strong) 82%, var(--muted));
  text-align: left;
}

.info-tabs {
  display: grid;
  grid-template-columns: repeat(var(--info-tab-count, 4), minmax(0, 1fr));
  gap: 6px;
  margin-top: 14px;
  padding: 4px;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper-strong) 42%, transparent);
  flex-shrink: 0;
}

.info-tabs button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 80%, var(--muted));
  font-size: 14px;
}

.info-tabs button.active {
  background: var(--brand);
  color: #fff8e8;
  box-shadow: 0 5px 12px rgba(88, 29, 18, 0.14);
}

.info-body {
  margin-top: 14px;
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  padding: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.info-kicker {
  margin: 0;
  color: var(--brand-strong);
  font-size: 12px;
}

.info-body h3 {
  margin: 4px 0 8px;
  font-size: 22px;
  letter-spacing: 0;
}

.info-body p:last-child {
  margin: 0;
  color: color-mix(in srgb, var(--ink) 84%, var(--muted));
  font-size: 15px;
  white-space: pre-line;
  line-height: 1.8;
}

.bottom-actions {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: 0 -2px 12px rgba(79, 38, 16, 0.06);
  transition: transform 260ms ease;
  will-change: transform;
}

.bottom-actions.bar-hidden {
  transform: translateY(100%);
}

.bottom-actions.recite-active {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bottom-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  padding: 0 10px;
  white-space: nowrap;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--paper) 96%, transparent),
      color-mix(in srgb, var(--paper-strong) 22%, var(--paper))
    );
  box-shadow: 0 5px 14px rgba(79, 38, 16, 0.08);
}

.bottom-actions button[hidden] {
  display: none;
}

.bottom-actions button:disabled {
  cursor: default;
  opacity: 0.55;
  box-shadow: none;
}

.bottom-action-title {
  max-width: 100%;
  overflow: hidden;
  color: color-mix(in srgb, var(--ink) 88%, var(--brand));
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  text-overflow: ellipsis;
}

#resetReveals {
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 700;
}

.floating-actions {
  display: none;
}

/* ── Section transition animations ── */

.section.exiting {
  animation: sectionExit 180ms ease forwards;
}

.section.exiting-reverse {
  animation: sectionExitReverse 180ms ease forwards;
}

.section.entering {
  animation: sectionEnter 220ms ease forwards;
}

.section.entering-reverse {
  animation: sectionEnterReverse 220ms ease forwards;
}

@keyframes sectionExit {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(-16px); }
}

@keyframes sectionExitReverse {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(16px); }
}

@keyframes sectionEnter {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes sectionEnterReverse {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (max-width: 480px) {
  main {
    padding-bottom: calc(112px + env(safe-area-inset-bottom));
  }

  .bottom-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bottom-actions.recite-active {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar-left .info-button {
    display: none;
  }

  .immersive-panel {
    padding: calc(12px + env(safe-area-inset-top)) 10px calc(18px + env(safe-area-inset-bottom));
  }

  .immersive-close {
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    width: 40px;
    min-height: 40px;
  }

  .immersive-body {
    min-height: calc(100vh - 30px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: calc(100dvh - 30px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 30px 24px 46px;
  }

  .immersive-article-head {
    margin-bottom: 24px;
  }

  .immersive-article-head h2 {
    font-size: 25px;
  }

  .immersive-scroll {
    gap: 20px;
  }

  .immersive-text {
    gap: 7px;
    font-size: 19px;
    line-height: 1.78;
  }

  .floating-actions {
    position: fixed;
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 14;
    display: grid;
    justify-items: end;
    gap: 8px;
    pointer-events: none;
  }

  .floating-action-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
  }

  .floating-action-button {
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
    border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--paper) 96%, transparent),
        color-mix(in srgb, var(--paper-strong) 24%, var(--paper))
      );
    color: var(--brand-strong);
    box-shadow: 0 8px 22px rgba(79, 38, 16, 0.18);
    font-size: 17px;
    font-weight: 800;
    overflow: hidden;
  }

  .floating-action-button.primary {
    background: var(--paper);
    border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
    color: var(--brand-strong);
  }

  .floating-info-button,
  .floating-tools-button {
    display: inline-grid;
    place-items: center;
    background: var(--paper);
  }

  .floating-info-button img,
  .floating-tools-button img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
  }

  .floating-tools-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    width: 102px;
    padding: 8px;
    border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
    border-radius: 18px;
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(18px);
    box-shadow: 0 12px 32px rgba(79, 38, 16, 0.18);
    pointer-events: auto;
  }

  .floating-tools-panel[hidden] {
    display: none;
  }

  .floating-tools-panel .chip-stack,
  .floating-tools-panel .topbar-toggles:not([hidden]),
  .floating-tools-panel .recite-chips:not([hidden]) {
    display: contents;
  }

  .floating-tools-panel .topbar-toggles[hidden],
  .floating-tools-panel .recite-chips[hidden] {
    display: none;
  }

  .floating-tools-panel .chip-stack label,
  .floating-tools-panel .chip-stack button {
    width: 100%;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 14px;
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--paper) 96%, transparent),
        color-mix(in srgb, var(--paper-strong) 20%, var(--paper))
      );
    box-shadow: 0 5px 14px rgba(79, 38, 16, 0.08);
    color: color-mix(in srgb, var(--ink) 82%, var(--brand));
    font-size: 0;
    font-weight: 700;
  }

  .floating-tools-panel .chip-stack label::after,
  .floating-tools-panel .chip-stack button::after {
    content: attr(data-mobile-label);
    font-size: 15px;
    line-height: 1;
  }

  .floating-tools-panel .chip-stack label:has(input:checked),
  .floating-tools-panel .chip-stack button.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff8e8;
  }

  .floating-tools-panel .chip-stack label.unavailable {
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--paper) 92%, transparent),
        color-mix(in srgb, var(--paper-strong) 14%, var(--paper))
      );
    border-color: color-mix(in srgb, var(--line) 54%, transparent);
    box-shadow: none;
    color: color-mix(in srgb, var(--muted) 72%, transparent);
    opacity: 0.62;
  }
}

/* ── Allusion tab styles ── */

.allusion-intro {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.allusion-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.allusion-card {
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 60%, transparent);
  overflow: hidden;
}

.allusion-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 15px;
  list-style: none;
}

.allusion-header::-webkit-details-marker {
  display: none;
}

.allusion-header::before {
  content: "▶";
  float: left;
  margin-right: 8px;
  font-size: 10px;
  color: var(--brand);
  transition: transform 200ms ease;
}

.allusion-card[open] .allusion-header::before {
  transform: rotate(90deg);
}

.allusion-quote {
  font-weight: 700;
  color: var(--ink);
  font-size: 16px;
}

.allusion-name {
  font-size: 13px;
  color: var(--muted);
}

.allusion-detail {
  padding: 0 12px 12px;
}

.allusion-source {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--brand-strong);
  font-style: italic;
}

.allusion-story {
  margin: 0;
  font-size: 14px;
  line-height: 1.8;
  color: color-mix(in srgb, var(--ink) 84%, var(--muted));
}

/* ── Inline allusion links ── */

.allusion-link {
  text-decoration: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--brand);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  cursor: pointer;
  border-radius: 2px;
  transition: background 160ms ease;
}

.allusion-link:active {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}

/* ── Allusion popover ── */

.allusion-popover {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--paper) 98%, transparent);
  box-shadow: 0 8px 24px rgba(43, 24, 12, 0.2);
  padding: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.allusion-popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 15px;
}

.allusion-popover-close {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  border-radius: 50%;
}

.allusion-popover-source {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--brand-strong);
  font-style: italic;
}

.allusion-popover-story {
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
  color: color-mix(in srgb, var(--ink) 84%, var(--muted));
}

@media (max-width: 380px) {
  .topbar {
    gap: 4px;
    padding-inline: 6px;
  }

  .topbar-left {
    gap: 4px;
  }

  .icon-button,
  .info-button,
  .immersive-button,
  .article-picker-button {
    width: 38px;
    height: 38px;
    min-height: 38px;
  }

  .immersive-button span {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    font-size: 16px;
  }

  .topbar-controls {
    gap: 4px;
    justify-content: flex-start;
  }

  .segmented button {
    flex: 0 0 35px;
    min-height: 28px;
    padding-inline: 0;
    font-size: 13px;
  }

  .info-tabs {
    grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  }

  .article-option-title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

@media (max-width: 360px) {
  main {
    padding-inline: 10px;
  }

  .section {
    padding-inline: 10px;
  }

  .line-card {
    padding-inline: 8px;
  }
}

@media (min-width: 720px) {
  :root {
    --reading-font-size: 22px;
  }

  main {
    padding-top: calc(var(--topbar-height) + var(--section-nav-height) + 24px);
  }

  ruby rt {
    font-size: 12px;
  }

  .hint-line {
    font-size: 20px;
  }
}

@media (max-width: 430px) {
  .aid-note,
  .meaning,
  .annotation {
    overflow-wrap: anywhere;
  }
}

/* ── Desktop / wide-screen layout (≥ 860px) ──
   CSS-first responsive layer: a fixed reading toolbar (full-word toggles +
   settings popover) replaces the mobile chip row, and the bottom sheets
   become centered modals. Wider desktop widths also use side arrows.
   Mobile styles above are intentionally left untouched. */

@media (min-width: 860px) {
  main {
    width: min(880px, 100%);
    padding-top: calc(var(--topbar-height) + var(--section-nav-height) + var(--reading-toolbar-height) + 18px);
    padding-bottom: 96px;
  }

  .section-nav {
    width: min(880px, 100%);
  }

  .topbar-chip-slot:empty {
    display: none;
  }

  /* ── Reading toolbar (fixed, always available) ── */

  .reading-toolbar {
    position: fixed;
    top: calc(var(--topbar-height) + var(--section-nav-height));
    left: 50%;
    transform: translateX(-50%);
    z-index: 8;
    width: min(880px, 100%);
    min-height: var(--reading-toolbar-height);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(14px);
    box-shadow: 0 6px 16px rgba(79, 38, 16, 0.06);
  }

  .reading-toolbar[hidden] {
    display: none;
  }

  .reading-chip-slot {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    padding: 3px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--paper-strong) 42%, transparent);
    border: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  }

  .reading-toolbar-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 12px;
    border-left: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  }

  /* Full-word chip labels inside the reading toolbar (joined segmented group). */
  .reading-toolbar .chip-stack label,
  .reading-toolbar .chip-stack button {
    min-height: 28px;
    padding: 0 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: color-mix(in srgb, var(--ink) 60%, var(--muted));
    font-size: 0;
  }

  .reading-toolbar .chip-stack label::after,
  .reading-toolbar .chip-stack button::after {
    content: attr(data-mobile-label);
    font-size: 13px;
    line-height: 1;
    font-weight: 600;
  }

  .reading-toolbar .chip-stack label:has(input:checked),
  .reading-toolbar .chip-stack button.active {
    background: var(--brand);
    color: #fff8e8;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 30%, transparent);
  }

  .reading-toolbar .chip-stack label.unavailable {
    opacity: 0.45;
  }

  /* Font size quick control (joined stepper). */
  .font-size-control {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
    background: var(--paper);
    overflow: hidden;
  }

  .font-size-control button {
    min-height: 28px;
    padding: 0 10px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--brand-strong);
    font-size: 13px;
    font-weight: 700;
  }

  .font-size-label {
    min-width: 30px;
    padding: 0 4px;
    text-align: center;
    color: color-mix(in srgb, var(--ink) 60%, var(--muted));
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    border-inline: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  }

  /* Settings button + popover. */
  .settings-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--gold) 60%, transparent);
    background: linear-gradient(180deg, var(--paper), color-mix(in srgb, var(--paper-strong) 38%, var(--paper)));
    color: var(--brand-strong);
    font-size: 13px;
    font-weight: 700;
  }

  .desktop-reset-button {
    display: none;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--brand) 48%, var(--line));
    background: color-mix(in srgb, var(--brand) 10%, var(--paper));
    color: var(--brand-strong);
    font-size: 13px;
    font-weight: 700;
  }

  .desktop-reset-button[hidden] {
    display: none;
  }

  .settings-icon {
    font-size: 15px;
    line-height: 1;
  }

  .settings-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 16;
    width: 248px;
    display: grid;
    gap: 13px;
    padding: 14px;
    border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
    border-radius: 14px;
    background: color-mix(in srgb, var(--paper) 97%, transparent);
    backdrop-filter: blur(14px);
    box-shadow: 0 14px 34px rgba(43, 24, 12, 0.2);
  }

  .settings-popover[hidden] {
    display: none;
  }

  .settings-row {
    display: grid;
    gap: 6px;
  }

  .settings-row-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12px;
    color: color-mix(in srgb, var(--ink) 68%, var(--muted));
  }

  .settings-value {
    color: var(--brand-strong);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
  }

  .settings-range {
    width: 100%;
    accent-color: var(--brand);
  }

  .font-family-control {
    display: flex;
    gap: 6px;
  }

  .font-family-option {
    flex: 1 1 0;
    min-height: 34px;
    padding: 0;
    border-radius: 9px;
    border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
    background: var(--paper);
    color: color-mix(in srgb, var(--ink) 68%, var(--muted));
    font-size: 16px;
    font-weight: 700;
  }

  .font-family-option.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff8e8;
  }

  .settings-reset {
    min-height: 32px;
    border-radius: 9px;
    border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
    background: transparent;
    color: color-mix(in srgb, var(--ink) 62%, var(--muted));
    font-size: 12px;
  }

  /* ── Side prev/next arrows ── */

  .side-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 11;
    width: 46px;
    height: 58px;
    min-height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 22px rgba(79, 38, 16, 0.16);
    color: var(--brand-strong);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    transition: opacity 200ms ease, transform 160ms ease;
  }

  .side-nav[hidden] {
    display: none;
  }

  .side-nav:disabled {
    opacity: 0.32;
    cursor: default;
    box-shadow: none;
  }

  .side-nav:not(:disabled):hover {
    transform: translateY(-50%) scale(1.06);
  }

  .side-nav-prev {
    left: 18px;
  }

  .side-nav-next {
    right: 18px;
  }

  /* ── Bottom sheets become centered modals ── */

  .info-sheet,
  .article-sheet {
    align-items: center;
    padding-block: 40px;
  }

  .info-panel,
  .article-panel {
    width: min(720px, calc(100% - 40px));
    height: min(78vh, 660px);
    border-radius: 18px;
    border-bottom: 1px solid var(--line);
  }

  /* ── Immersive full-text: a touch wider on desktop ── */

  .immersive-body {
    width: min(820px, 100%);
    padding-inline: 64px;
  }

  .immersive-text {
    font-size: 23px;
  }
}

@media (min-width: 1024px) {
  main {
    padding-bottom: 64px;
  }

  .bottom-actions {
    display: none;
  }

  .desktop-reset-button:not([hidden]) {
    display: inline-flex;
  }
}
