/* reader/classic.css — THE CLASSIC template: the ARC reading experience as a
   hosted page. Serif column at --rd-measure, drop caps, fleuron rules, TOC left
   rail with the razor-thin scrollbar + cracked-open fold. The right (margin-notes)
   rail is deliberately OMITTED on hosted pages. Consumes ONLY themes.css tokens. */

:root { --rdt-rail: 304px; --rdt-topbar: 56px; }

/* ---------- top bar ---------- */
.rd-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--rdt-topbar); z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0 0.8rem; padding-left: calc(0.8rem + env(safe-area-inset-left));
  padding-right: calc(0.8rem + env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-bottom: 1px solid var(--rd-rule);
}
.rd-topbar-left, .rd-topbar-right { display: flex; align-items: center; gap: 0.25rem; min-width: 0; }
.rd-book { display: flex; flex-direction: column; min-width: 0; padding: 0 0.3rem; }
.rd-book-title {
  font-family: var(--rd-serif); font-style: italic; font-weight: 600; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink);
}
.rd-book-author { font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-iconbtn {
  display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 0.45rem;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink);
  cursor: pointer; font-family: inherit; font-size: 0.95rem;
}
.rd-iconbtn:hover { background: var(--rd-surface); }
.rd-iconbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rd-iconbtn .rd-a-small { font-size: 0.78em; }

/* ---------- reading progress ---------- */
.rd-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60; pointer-events: none; }
.rd-progress span { display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 70%, var(--bg)), var(--accent)); }

/* ---------- left rail (TOC) — razor-thin scrollbar + cracked-open fold ---------- */
.rd-rail {
  --rd-rail-mode: fixed;
  position: fixed; top: var(--rdt-topbar); bottom: 0; left: 0; width: var(--rdt-rail); z-index: 40;
  background: color-mix(in srgb, var(--ink) 3%, var(--bg));
  border-right: 1px solid var(--rd-rule);
  box-shadow: inset -13px 0 16px -15px color-mix(in srgb, var(--rd-dim) 45%, transparent);
  padding: 0.6rem 0.5rem 3rem;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: transparent transparent;
}
.rd-rail:hover, .rd-rail:focus-within { scrollbar-color: color-mix(in srgb, var(--rd-dim) 60%, transparent) transparent; }
.rd-rail::-webkit-scrollbar { width: 12px; background: transparent; }
.rd-rail::-webkit-scrollbar-track, .rd-rail::-webkit-scrollbar-corner { background: transparent; border: 0; }
.rd-rail::-webkit-scrollbar-button { width: 0; height: 0; display: none; }
.rd-rail::-webkit-scrollbar-thumb {
  background-color: transparent; background-clip: padding-box;
  border: 3px solid transparent; border-radius: 999px; min-height: 40px;
}
.rd-rail:hover::-webkit-scrollbar-thumb, .rd-rail:focus-within::-webkit-scrollbar-thumb {
  background-color: color-mix(in srgb, var(--rd-dim) 60%, transparent);
}
@media (hover: none) {
  .rd-rail { scrollbar-width: auto; scrollbar-color: auto; scrollbar-gutter: auto; }
  .rd-rail::-webkit-scrollbar { width: 0; height: 0; }
}
.rd-rail-head {
  padding: 0.4rem 0.6rem 0.6rem; font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); border-bottom: 1px solid var(--rd-rule); margin-bottom: 0.4rem;
}
.rd-toc-item {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  padding: 0.42rem 0.6rem; border: none; border-radius: 9px; background: transparent;
  color: var(--ink); cursor: pointer; font-family: inherit; font-size: 0.9rem; line-height: 1.25;
}
.rd-toc-item:hover { background: var(--rd-surface); }
.rd-toc-item.active { background: var(--rd-surface); box-shadow: inset 2px 0 0 var(--accent); }
.rd-toc-num {
  flex: none; width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--rd-rule);
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; color: var(--muted);
}
.rd-toc-item.active .rd-toc-num { border-color: var(--accent); color: var(--accent); }
.rd-toc-kind-frontmatter .rd-toc-num, .rd-toc-kind-backmatter .rd-toc-num { border: none; }
.rd-toc-label { flex: 1; min-width: 0; }

/* ---------- reading column ---------- */
.rd-reading { padding-top: var(--rdt-topbar); margin-left: var(--rdt-rail); min-height: 100vh; }
.rd-article {
  max-width: var(--rd-measure); margin: 0 auto;
  padding: clamp(1.4rem, 4vw, 4rem) clamp(1.1rem, 4vw, 2rem) 6rem;
  padding-bottom: calc(6rem + env(safe-area-inset-bottom));
}
.rd-sec { margin: 0 0 4.5rem; }

/* chapter head — centered, italic kicker + clamp()-sized serif title (ARC signature) */
.rd-chapter-head { margin: 0 0 2.2rem; text-align: center; }
.rd-chapter-eyebrow { text-transform: uppercase; letter-spacing: 0.26em; font-size: 0.7rem; color: var(--accent); }
.rd-chapter-title {
  font-family: var(--rd-serif); font-weight: 600; font-size: clamp(2rem, 6vw, 2.9rem);
  line-height: 1.08; margin: 0.35rem 0 0.5rem; letter-spacing: -0.01em; text-wrap: balance;
}
.rd-chapter-rule { width: 64px; height: 2px; background: var(--accent); margin: 1.5rem auto 0; opacity: 0.8; border: none; }
.rd-chapter-rule::before { content: none; }

/* drop cap on each section's first paragraph — float fallback, initial-letter when
   supported; Comfort preset turns caps off entirely */
:root:not([data-reader-font='comfort']) .rd-sec .rd-prose > p:first-of-type::first-letter {
  font-family: var(--rd-serif); float: left; font-size: 3.1em; line-height: 0.82;
  padding: 0.04em 0.08em 0 0; color: var(--accent); font-weight: 600;
}
@supports (initial-letter: 3) or (-webkit-initial-letter: 3) {
  :root:not([data-reader-font='comfort']) .rd-sec .rd-prose > p:first-of-type::first-letter {
    float: none; padding: 0 0.08em 0 0; font-size: inherit; line-height: inherit;
    -webkit-initial-letter: 3; initial-letter: 3;
  }
}

/* ---------- settings popover ---------- */
.rd-pop {
  position: fixed; top: calc(var(--rdt-topbar) + 8px); right: 12px; z-index: 70;
  width: min(340px, calc(100vw - 24px));
  background: var(--bg); border: 1px solid var(--rd-rule); border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  box-shadow: 0 14px 40px -16px color-mix(in srgb, var(--rd-dim) 80%, transparent);
}
.rd-pop[hidden] { display: none; }

/* ---------- empty book ---------- */
.rd-empty { text-align: center; color: var(--muted); padding: 18vh 1rem; font-family: var(--rd-serif); font-style: italic; }

/* ---------- responsive — mobile-first collapse; landscape phone = FULL desktop ---------- */
@media (max-width: 899px) and (orientation: portrait), (max-width: 639px) {
  .rd-reading { margin-left: 0; }
  .rd-rail {
    --rd-rail-mode: drawer;
    transform: translateX(-104%); transition: transform 0.22s ease; width: min(320px, 86vw);
    box-shadow: 0 14px 40px -16px color-mix(in srgb, var(--rd-dim) 80%, transparent);
  }
  :root[data-rd-rail='open'] .rd-rail { transform: none; }
}
