/* Neuroglyph Reader — literary, restrained */

:root {
  --paper: #e8ecf0;
  --paper-elevated: #f2f5f8;
  --ink: #14181f;
  --ink-muted: #5a6570;
  --ink-faint: #8a959e;
  --accent: #2f6f68;
  --accent-soft: rgba(47, 111, 104, 0.14);
  --rule: rgba(20, 24, 31, 0.1);
  --shadow: rgba(20, 24, 31, 0.08);
  --serif-zh: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --serif-en: "Cormorant Garamond", "Palatino Linotype", Georgia, serif;
  --measure: 38rem;
  --toc-w: 17.5rem;
  --topbar-h: 3.25rem;
  --bottombar-h: 3.4rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sm: 1.12rem;
  --font-md: 1.32rem;
  --font-lg: 1.65rem;
  --body-size: var(--font-md);
}

[data-theme="night"] {
  --paper: #0e1116;
  --paper-elevated: #161b22;
  --ink: #e8ecef;
  --ink-muted: #9aa5b0;
  --ink-faint: #6b7680;
  --accent: #5fa89f;
  --accent-soft: rgba(95, 168, 159, 0.16);
  --rule: rgba(232, 236, 239, 0.1);
  --shadow: rgba(0, 0, 0, 0.35);
}

body[data-fontsize="sm"] {
  --body-size: var(--font-sm);
}
body[data-fontsize="md"] {
  --body-size: var(--font-md);
}
body[data-fontsize="lg"] {
  --body-size: var(--font-lg);
}

body[data-fontsize="sm"] .prose {
  font-size: 1.12rem;
}
body[data-fontsize="md"] .prose {
  font-size: 1.32rem;
}
body[data-fontsize="lg"] .prose {
  font-size: 1.65rem;
}
body[data-fontsize="sm"] .article__title {
  font-size: 1.55rem;
}
body[data-fontsize="md"] .article__title {
  font-size: 1.85rem;
}
body[data-fontsize="lg"] .article__title {
  font-size: 2.2rem;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--serif-zh);
  background: var(--paper);
  color: var(--ink);
  transition: background 0.35s var(--ease), color 0.35s var(--ease);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

[hidden] {
  display: none !important;
}

/* ——— Library shelf (Apple Books–like) ——— */

.shelf {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 90% 70% at 50% 0%, #f7f4ef 0%, transparent 55%),
    linear-gradient(180deg, #ece7df 0%, #e3ddd3 48%, #d9d2c6 100%);
  color: #1a1c1e;
  overflow-x: hidden;
}

.shelf__header {
  padding: clamp(2.5rem, 8vh, 4.5rem) 1.5rem 1.25rem;
  text-align: center;
  animation: rise 0.8s var(--ease) both;
}

.shelf__title {
  margin: 0;
  font-family: var(--serif-en);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(26, 28, 30, 0.45);
  line-height: 1.4;
}

.shelf__name {
  color: #1a1c1e;
  font-weight: 400;
}

.shelf__row {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 0.5rem 0 12vh;
  animation: rise 0.9s var(--ease) 0.08s both;
}

.shelf__rail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.35rem 1rem;
  justify-items: center;
  align-items: end;
  width: min(100%, 42rem);
  margin: 0 auto;
  padding: 0 1.25rem 0.5rem;
  perspective: 1200px;
}

.shelf__ledge {
  height: 0.85rem;
  margin: 0 auto;
  width: min(92%, 42rem);
  border-radius: 2px;
  background: linear-gradient(
    180deg,
    #cfc6b8 0%,
    #b9ae9d 55%,
    #a89c8a 100%
  );
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 10px 28px rgba(40, 32, 20, 0.18),
    0 2px 0 rgba(70, 55, 35, 0.2);
}

.shelf-book {
  width: 100%;
  max-width: 10.5rem;
  border: 0;
  background: none;
  padding: 0;
  text-align: center;
  cursor: pointer;
  transform-origin: center bottom;
  transition: transform 0.35s var(--ease);
  /* Prevent flex/grid shrink from crushing covers on narrow screens */
  min-width: 0;
}

.shelf-book:hover,
.shelf-book:focus-visible {
  transform: translateY(-0.55rem) scale(1.03);
  outline: none;
}

.shelf-book:active {
  transform: translateY(-0.2rem) scale(1.01);
}

.shelf-book__cover {
  position: relative;
  aspect-ratio: 2 / 3.15;
  width: 100%;
  border-radius: 3px 5px 5px 3px;
  overflow: hidden;
  background: #2a2f36;
  box-shadow:
    0 14px 28px rgba(30, 24, 16, 0.28),
    0 2px 4px rgba(30, 24, 16, 0.18),
    inset -1px 0 0 rgba(255, 255, 255, 0.12),
    inset 3px 0 8px rgba(0, 0, 0, 0.25);
  transform: rotateY(-6deg) rotateX(2deg);
  transform-style: preserve-3d;
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

.shelf-book:hover .shelf-book__cover,
.shelf-book:focus-visible .shelf-book__cover {
  transform: rotateY(-2deg) rotateX(0deg);
  box-shadow:
    0 22px 40px rgba(30, 24, 16, 0.32),
    0 4px 8px rgba(30, 24, 16, 0.16),
    inset -1px 0 0 rgba(255, 255, 255, 0.14),
    inset 3px 0 8px rgba(0, 0, 0, 0.22);
}

.shelf-book__cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 0.35rem;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.35),
    rgba(255, 255, 255, 0.08)
  );
  z-index: 2;
  pointer-events: none;
}

.shelf-book__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.shelf-book__face {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.1rem 0.75rem 1rem;
  color: #f4efe6;
  background:
    radial-gradient(ellipse 80% 50% at 50% 20%, rgba(244, 239, 230, 0.12), transparent 60%),
    linear-gradient(165deg, #1c2420 0%, #2a3530 45%, #3d4a40 100%);
  text-align: center;
}

.shelf-book__face-brand {
  margin: 0;
  font-family: var(--serif-en);
  font-size: clamp(0.95rem, 3.2vw, 1.2rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.shelf-book__face-sub {
  margin: 0.45rem 0 0;
  font-family: var(--serif-zh);
  font-size: 0.78rem;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  opacity: 0.78;
}

.shelf-book__face-tag {
  margin: auto 0 0;
  font-family: var(--serif-zh);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  opacity: 0.55;
}

.shelf-book__caption {
  margin: 0.85rem 0 0;
  font-family: var(--serif-en);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: rgba(26, 28, 30, 0.72);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shelf-book__progress {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--serif-zh);
  font-size: 0.68rem;
  color: rgba(26, 28, 30, 0.42);
}

/* Phone: 2 covers per row (readable size) */
@media (max-width: 520px) {
  .shelf__header {
    padding: 2rem 1.25rem 1rem;
  }

  .shelf__rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem 0.85rem;
    padding: 0 1rem 0.5rem;
  }

  .shelf-book {
    max-width: none;
  }

  .shelf-book__cover {
    transform: none;
    border-radius: 4px;
  }

  .shelf-book:hover .shelf-book__cover,
  .shelf-book:focus-visible .shelf-book__cover {
    transform: none;
  }

  .shelf-book:hover,
  .shelf-book:focus-visible {
    transform: translateY(-0.25rem);
  }

  .shelf-book__caption {
    font-size: 0.75rem;
    margin-top: 0.65rem;
  }

  .shelf__ledge {
    width: calc(100% - 2rem);
  }
}

/* Tablet: 3 columns */
@media (min-width: 521px) and (max-width: 860px) {
  .shelf__rail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(100%, 36rem);
    gap: 1.5rem 1.15rem;
  }

  .shelf-book {
    max-width: 9.5rem;
  }
}

/* Desktop: up to 4, larger covers, centered shelf feel */
@media (min-width: 861px) {
  .shelf__row {
    justify-content: center;
    padding-bottom: 16vh;
  }

  .shelf__rail {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(100%, 52rem);
    gap: 1.75rem 1.5rem;
    padding: 0 2rem 0.35rem;
  }

  .shelf-book {
    max-width: 11.5rem;
  }

  .shelf__ledge {
    width: min(92%, 52rem);
  }
}

/* ——— Cover ——— */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cover {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: end center;
  padding: 0;
  overflow: hidden;
  background: #ebe6dc;
}

.cover__art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  animation: cover-fade 1.1s var(--ease) both;
}

@keyframes cover-fade {
  from {
    opacity: 0;
    transform: scale(1.03);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cover__scrim {
  position: absolute;
  inset: auto 0 0;
  height: min(42vh, 22rem);
  background: linear-gradient(
    to top,
    rgba(235, 230, 220, 0.96) 0%,
    rgba(235, 230, 220, 0.72) 45%,
    rgba(235, 230, 220, 0) 100%
  );
  pointer-events: none;
}

.cover__back {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 2;
  min-height: 2rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(20, 24, 31, 0.12);
  background: color-mix(in srgb, #ebe6dc 82%, transparent);
  backdrop-filter: blur(8px);
  font-family: var(--serif-en);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.cover__back:hover {
  color: var(--ink);
}

.cover__lang {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 2;
}

.lang-switch,
.cover__lang,
.lang-switch--compact {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.2rem;
  border-radius: 999px;
  border: 1px solid rgba(20, 24, 31, 0.12);
  background: color-mix(in srgb, #ebe6dc 82%, transparent);
  backdrop-filter: blur(8px);
}

.lang-btn {
  min-width: 2.4rem;
  height: 1.85rem;
  padding: 0 0.55rem;
  border-radius: 999px;
  font-family: var(--serif-en);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.lang-btn:hover {
  color: var(--ink);
}

.lang-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.cover--typo {
  background:
    radial-gradient(ellipse 80% 60% at 50% 35%, #f4efe6 0%, transparent 70%),
    linear-gradient(165deg, #1c2420 0%, #2a3530 42%, #3d4a40 100%);
  place-items: center;
}

.cover--typo .cover__scrim {
  display: none;
}

.cover--typo .cover__inner {
  place-self: end center;
}

.cover--typo .cover__meta,
.cover--typo .btn--ghost,
.cover--typo .cover__back {
  color: rgba(244, 239, 230, 0.78);
}

.cover--typo .cover__back {
  border-color: rgba(244, 239, 230, 0.22);
  background: color-mix(in srgb, #1c2420 55%, transparent);
}

.cover--typo .btn--primary {
  background: #f4efe6;
  color: #1c2420;
}

.cover--typo .cover__lang {
  border-color: rgba(244, 239, 230, 0.22);
  background: color-mix(in srgb, #1c2420 55%, transparent);
}

.cover--typo .lang-btn {
  color: rgba(244, 239, 230, 0.7);
}

.cover--typo .lang-btn.is-active {
  background: rgba(244, 239, 230, 0.16);
  color: #f4efe6;
}

.cover__typo {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 2rem 1.5rem 8rem;
  color: #f4efe6;
  animation: cover-fade 1.1s var(--ease) both;
}

.cover__typo-brand {
  margin: 0;
  font-family: var(--serif-en);
  font-size: clamp(2.8rem, 10vw, 5.2rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
}

.cover__typo-sub {
  margin: 1rem 0 0;
  font-family: var(--serif-zh, "Noto Serif SC", serif);
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  font-weight: 500;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
}

.cover__typo-tag {
  margin: 1.75rem 0 0;
  font-family: var(--serif-zh, "Noto Serif SC", serif);
  font-size: 0.95rem;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  opacity: 0.72;
}

.cover__typo-author {
  margin: 2.5rem 0 0;
  font-family: var(--serif-en);
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.55;
}

.topbar__tools {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.cover__inner {
  position: relative;
  z-index: 1;
  width: min(100%, 28rem);
  padding: 0 1.5rem max(2.5rem, env(safe-area-inset-bottom));
  text-align: center;
  animation: rise 0.9s var(--ease) 0.15s both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(1.25rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cover__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0 1.5rem;
  border-radius: 999px;
  font-size: 0.92rem;
  letter-spacing: 0.06em;
  transition: background 0.25s var(--ease), color 0.25s var(--ease),
    transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 10px 28px rgba(20, 24, 31, 0.16);
}

.btn--primary:hover {
  background: var(--accent);
  color: #fff;
}

.btn--ghost {
  border: 1px solid rgba(20, 24, 31, 0.18);
  color: var(--ink);
  background: color-mix(in srgb, #ebe6dc 70%, transparent);
  backdrop-filter: blur(6px);
}

.btn--ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.cover__meta {
  margin: 1.1rem 0 0;
  font-size: 0.78rem;
  color: rgba(20, 24, 31, 0.45);
  letter-spacing: 0.04em;
}

@media (max-width: 640px) {
  .cover__art {
    object-position: center 12%;
  }
}

/* ——— Reader shell ——— */

.reader {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--bottombar-h);
  grid-template-columns: var(--toc-w) minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "toc stage"
    "bottom bottom";
}

.reader.toc-collapsed {
  grid-template-columns: 0 1fr;
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.topbar__titles {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  overflow: hidden;
}

.topbar__brand {
  font-family: var(--serif-en);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  flex-shrink: 0;
}

.topbar__sep {
  color: var(--ink-faint);
  flex-shrink: 0;
}

.topbar__chapter {
  font-size: 0.85rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-btn {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  padding: 0.35rem 0.5rem;
}

.text-btn:hover {
  color: var(--accent);
}

.text-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 0.35rem;
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border-radius: 0.4rem;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-btn__bars {
  display: block;
  width: 1rem;
  height: 1px;
  background: currentColor;
  box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.toc__close {
  font-size: 1.4rem;
  line-height: 1;
}

/* ——— TOC ——— */

.toc {
  grid-area: toc;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h) - var(--bottombar-h));
  height: calc(100dvh - var(--topbar-h) - var(--bottombar-h));
  overflow: auto;
  background: var(--paper-elevated);
  border-right: 1px solid var(--rule);
  transition: transform 0.4s var(--ease), opacity 0.35s var(--ease);
}

.reader.toc-collapsed .toc {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

.toc__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.15rem 0.75rem;
  position: sticky;
  top: 0;
  background: var(--paper-elevated);
  z-index: 1;
}

.toc__title {
  margin: 0;
  font-family: var(--serif-en);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.toc__close {
  display: none;
}

.toc__nav {
  padding: 0.25rem 0.75rem 2rem;
}

.toc__part {
  margin: 1.15rem 0 0.35rem;
  padding: 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.toc__link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-radius: 0.35rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-muted);
  transition: background 0.2s, color 0.2s;
}

.toc__link:hover {
  color: var(--ink);
  background: var(--accent-soft);
}

.toc__link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}

.toc-backdrop {
  display: none;
}

/* ——— Stage / article ——— */

.stage {
  grid-area: stage;
  overflow: auto;
  scroll-behavior: smooth;
  min-height: 0;
  min-width: 0;
}

.article {
  max-width: calc(var(--measure) + 4rem);
  margin: 0 auto;
  padding: 2.75rem 1.75rem 4rem;
  animation: fadeChapter 0.45s var(--ease) both;
}

.article.is-switching {
  animation: none;
  opacity: 0;
}

@keyframes fadeChapter {
  from {
    opacity: 0;
    transform: translateY(0.6rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.article__part {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: none;
  color: var(--accent);
  font-weight: 600;
}

.article__title {
  margin: 0 0 2rem;
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.02em;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--rule);
  transition: font-size 0.2s var(--ease);
}

[data-lang="en"] .prose,
[data-lang="fr"] .prose {
  font-family: "Cormorant Garamond", "Palatino Linotype", Georgia, serif;
  letter-spacing: 0.01em;
  line-height: 1.75;
}

[data-lang="en"] .article__title,
[data-lang="fr"] .article__title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
}

.prose {
  font-size: var(--body-size, 1.32rem);
  line-height: 1.85;
  transition: font-size 0.2s var(--ease);
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-weight: 600;
  line-height: 1.4;
  margin: 2.2em 0 0.75em;
  letter-spacing: 0.03em;
}

.prose h2 {
  font-size: 1.2em;
}

.prose h3 {
  font-size: 1.08em;
}

.prose p {
  margin: 0 0 1.15em;
}

.prose ul,
.prose ol {
  margin: 0 0 1.15em;
  padding-left: 1.4em;
}

.prose li {
  margin: 0.35em 0;
}

.prose li::marker {
  color: var(--accent);
}

.prose blockquote {
  margin: 1.5em 0;
  padding: 0.15em 0 0.15em 1.15em;
  border-left: 2px solid var(--accent);
  color: var(--ink-muted);
  font-style: normal;
}

.prose blockquote p {
  margin-bottom: 0.5em;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  border-radius: 0.25em;
  background: var(--accent-soft);
}

.prose pre {
  margin: 1.4em 0;
  padding: 1rem 1.15rem;
  overflow: auto;
  border-radius: 0.5rem;
  background: var(--paper-elevated);
  border: 1px solid var(--rule);
  font-size: 0.82em;
  line-height: 1.55;
}

.prose pre code {
  padding: 0;
  background: none;
}

.prose hr {
  border: none;
  height: 1px;
  background: var(--rule);
  margin: 2.5em 0;
}

.prose strong {
  font-weight: 600;
}

.prose a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.92em;
}

.prose th,
.prose td {
  border: 1px solid var(--rule);
  padding: 0.45em 0.65em;
  text-align: left;
  vertical-align: top;
}

.prose th {
  background: var(--accent-soft);
  font-weight: 600;
}

.article__nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.nav-link {
  font-size: 0.88rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  padding: 0.5rem 0;
}

.nav-link:hover:not(:disabled) {
  color: var(--accent);
}

.nav-link:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ——— Bottom bar ——— */

.bottombar {
  grid-area: bottom;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.15rem;
  height: var(--bottombar-h);
  border-top: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  z-index: 40;
}

.bottombar__progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.progress-track {
  flex: 1;
  height: 2px;
  background: var(--rule);
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s linear;
}

.progress-label {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  min-width: 2.5rem;
}

.bottombar__fonts {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  z-index: 2;
}

.font-btn {
  min-width: 2.25rem;
  min-height: 2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border-radius: 0.4rem;
  color: var(--ink-faint);
  font-family: var(--serif-en);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.font-btn:nth-child(1) {
  font-size: 0.85rem;
}
.font-btn:nth-child(2) {
  font-size: 1.05rem;
}
.font-btn:nth-child(3) {
  font-size: 1.3rem;
}

.font-btn.is-active,
.font-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.font-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ——— Mobile ——— */

@media (max-width: 900px) {
  .reader {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "stage"
      "bottom";
  }

  .toc {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(20rem, 88vw);
    height: 100%;
    height: 100dvh;
    z-index: 60;
    transform: translateX(-105%);
    opacity: 1;
    pointer-events: auto;
    box-shadow: 8px 0 32px var(--shadow);
  }

  .reader.toc-open .toc {
    transform: translateX(0);
  }

  .reader.toc-collapsed .toc {
    transform: translateX(-105%);
    opacity: 1;
  }

  .toc__close {
    display: grid;
  }

  .toc-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(10, 12, 16, 0.4);
    backdrop-filter: blur(2px);
  }

  .article {
    padding: 2rem 1.25rem 3.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
