/* The Theater Papers: reading settings (theme, type, layout, focus).
   Shared by every volume page and the library page. reader.js reads the
   reader's saved choices and sets the data-* attributes on <html> that the
   rules below key off; it also builds the settings panel styled here.
   Rules and the reasoning behind them: assets/DESIGN.md. */

/* ---- Self-hosted typefaces (SIL OFL 1.1, see fonts/OFL-*.txt) ----
   Declared here, downloaded only when something on the page uses them:
   picking the face, or opening the settings panel (its tiles preview each
   face in itself). Latin only; other scripts fall through to Georgia and
   the system fonts, as they always have. */
@font-face {
  font-family: "Literata"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/assets/fonts/literata-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Literata"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url("/assets/fonts/literata-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/assets/fonts/atkinson-regular-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap;
  src: url("/assets/fonts/atkinson-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/assets/fonts/atkinson-bold-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 700; font-display: swap;
  src: url("/assets/fonts/atkinson-bolditalic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---- Themes ----
   Light and Dark (and Auto, which is no data-theme at all) are defined by
   each page's own stylesheet; these add Sepia, Dim and Black with the same
   token set. Every token a page uses must be set in every block. */
:root[data-theme="light"], :root[data-theme="sepia"] { color-scheme: light; }
:root[data-theme="dark"], :root[data-theme="dim"], :root[data-theme="black"] { color-scheme: dark; }
:root[data-theme="sepia"] {
  --bg: #f4ecdc; --bg-elevated: #fbf6ea; --text: #3a2c1f; --text-muted: #6f5c47;
  --accent: #8a3b2b; --rule: #e3d5bb; --link: #7a3324; --progress: #8a3b2b;
  --shadow: 0 2px 12px rgba(74,52,20,0.1);
  --img-filter: grayscale(0.5) sepia(0.5) contrast(1.03) brightness(0.98);
}
:root[data-theme="dim"] {
  --bg: #2f2b26; --bg-elevated: #3a352f; --text: #ddd4c6; --text-muted: #a99f90;
  --accent: #e5b391; --rule: #4b443b; --link: #ebc0a0; --progress: #dea27c;
  --shadow: 0 2px 14px rgba(0,0,0,0.3);
  --img-filter: grayscale(0.55) sepia(0.3) contrast(1.05) brightness(0.88);
}
:root[data-theme="black"] {
  --bg: #000000; --bg-elevated: #141210; --text: #c9c1b4; --text-muted: #8f877b;
  --accent: #dba07c; --rule: #2a2622; --link: #e3b08e; --progress: #cf9470;
  --shadow: 0 0 0 1px #221f1b;
  --img-filter: grayscale(0.55) sepia(0.3) contrast(1.1) brightness(0.72);
}

/* ---- Type and layout (volume pages only: reader.js sets data-tp-reader) ----
   The page's own sizes are in rem, so each reading element is restated here
   as its original size times the reader's scale. Headings scale more
   gently (--tp-hs) so a large text size doesn't produce a poster-sized h1.
   The column widens with the text so the line length, in characters, stays
   where the default puts it. */
:root[data-tp-reader] {
  --tp-scale: 1;
  --tp-leading: 1.7;
  --tp-hs: calc(1 + (var(--tp-scale) - 1) * 0.6);
  --tp-measure: var(--measure, 40rem);
  --tp-gutter: 1.5rem;
  --tp-font: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
}
:root[data-tp-reader][data-tp-font="literata"] { --tp-font: "Literata", Georgia, "Times New Roman", serif; }
:root[data-tp-reader][data-tp-font="sans"] { --tp-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
:root[data-tp-reader][data-tp-font="atkinson"] { --tp-font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
:root[data-tp-reader][data-tp-width="narrow"] { --tp-measure: 35rem; --tp-gutter: 2rem; }
:root[data-tp-reader][data-tp-width="wide"] { --tp-measure: 48rem; --tp-gutter: 1rem; }

:root[data-tp-reader] body { font-family: var(--tp-font); font-size: calc(var(--fs-body) * var(--tp-scale)); line-height: var(--tp-leading); }
:root[data-tp-reader] h1 { font-size: calc(var(--fs-h1) * var(--tp-hs)); }
:root[data-tp-reader] .subtitle { font-size: calc(var(--fs-lead) * var(--tp-hs)); }
:root[data-tp-reader] .byline { font-size: calc(var(--fs-body) * var(--tp-scale)); }
:root[data-tp-reader] .readtime { font-size: calc(var(--fs-small) * var(--tp-scale)); }
:root[data-tp-reader] .frontmatter,
:root[data-tp-reader] .chapter-nav,
:root[data-tp-reader] footer.colophon { font-size: calc(var(--fs-small) * var(--tp-scale)); }
:root[data-tp-reader] blockquote.epigraph { font-size: calc(var(--fs-lead) * var(--tp-scale)); }
:root[data-tp-reader] section.chapter > h2 { font-size: calc(var(--fs-h2) * var(--tp-hs)); }
:root[data-tp-reader] figcaption { font-size: calc(var(--fs-small) * var(--tp-scale)); }
:root[data-tp-reader] .wrap { max-width: calc(var(--tp-measure) * var(--tp-scale)); }
:root[data-tp-reader] section.chapter p { text-wrap: pretty; }

/* Below 700px the column is already full-width, so "width" means margins. */
@media (max-width: 700px) {
  :root[data-tp-reader] .wrap { padding-left: var(--tp-gutter); padding-right: var(--tp-gutter); }
}

:root[data-tp-reader][data-tp-align="justify"] section.chapter :is(p, li) {
  text-align: justify; -webkit-hyphens: auto; hyphens: auto;
}

/* Book-style paragraphs: no gap, first-line indent. The paragraph before a
   figure, list or the chapter nav keeps its gap so those don't crowd it. */
:root[data-tp-reader][data-tp-para="indent"] section.chapter > p { margin-bottom: 0; }
:root[data-tp-reader][data-tp-para="indent"] section.chapter > p + p { text-indent: 1.5em; }
:root[data-tp-reader][data-tp-para="indent"] section.chapter > p:has(+ :not(p)) { margin-bottom: 1.1em; }

:root[data-tp-reader][data-tp-images="color"] figure img { filter: none; }
:root[data-tp-reader][data-tp-images="hidden"] section.chapter > figure { display: none; }

/* ---- Focus mode ----
   reader.js marks the paragraph crossing the reading line (about 40% down
   the viewport) with .tp-current; the rest of the chapter text recedes.
   Headings and the chapter nav stay at full strength as landmarks. While
   scrolling down, the floating controls step aside (.tp-chrome-away) and
   come back on any upward scroll, pointer near the top, or keyboard focus. */
:root[data-tp-focus="on"] section.chapter > :is(p, figure),
:root[data-tp-focus="on"] section.chapter > ol > li { opacity: 0.3; transition: opacity 0.35s ease; }
:root[data-tp-focus="on"] section.chapter > .tp-current,
:root[data-tp-focus="on"] section.chapter > ol > li.tp-current { opacity: 1; }
:root[data-tp-focus="on"] :is(.top-controls, .hamburger-btn, .bottom-controls) { transition: opacity 0.25s ease, transform 0.25s ease; }
:root[data-tp-focus="on"].tp-chrome-away .controls.top-controls:not(:focus-within):not(:has(#langSelect:disabled)),
:root[data-tp-focus="on"].tp-chrome-away .hamburger-btn:not(:focus-visible),
:root[data-tp-focus="on"].tp-chrome-away .controls.bottom-controls:not(:focus-within) {
  opacity: 0; transform: translateY(-0.4rem); pointer-events: none;
}

/* ---- Settings trigger ("Aa") ---- */
.tp-settings-btn {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1rem; letter-spacing: 0.01em; line-height: 1;
}
.tp-settings-btn[aria-expanded="true"] { opacity: 1; border-color: var(--accent); color: var(--accent); }
.ctrl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Settings panel ----
   A popover under the top-right controls; on phones the full panel becomes
   a bottom sheet. No backdrop on either: the page behind is the preview,
   so it stays visible and scrollable while the reader adjusts it. */
.tp-panel {
  position: fixed; top: 4.4rem; right: 1.1rem; z-index: 130;
  width: min(22.5rem, calc(100vw - 2.2rem));
  max-height: calc(100vh - 5.6rem); max-height: calc(100dvh - 5.6rem);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--rule); border-radius: var(--r-lg, 12px);
  box-shadow: 0 18px 48px rgba(0,0,0,0.16), var(--shadow);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  font-size: 0.875rem; line-height: 1.4; text-align: left;
  padding: 0 1.2rem 1rem;
  -webkit-user-select: none; user-select: none;
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(0.985); transform-origin: top right;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
}
.tp-panel.is-open {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s;
}
.tp-panel-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 0 -1.2rem; padding: 0.95rem 1.2rem 0.55rem;
  background: var(--bg-elevated);
}
/* Volume pages style every bare h2 as a chapter heading; reset all of it. */
.tp-panel-title { margin: 0; padding: 0; border: none; font-size: 1rem; font-weight: 400; letter-spacing: 0.01em; line-height: 1.3; color: var(--text); }
.tp-close {
  flex: none; width: 2rem; height: 2rem; border: none; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; color: var(--text-muted); font-size: 1.25rem; line-height: 1; cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.tp-close:hover { background: var(--bg); color: var(--text); }
.tp-section { border-top: 1px solid var(--rule); padding-top: 0.2rem; }
.tp-section:first-of-type { border-top: none; }
.tp-section-label {
  margin: 0.75rem 0 0.75rem; font-size: 0.75rem; font-weight: 400; font-variant-ligatures: none;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-muted);
}
.tp-row { display: grid; grid-template-columns: 5.4rem minmax(0, 1fr); align-items: center; gap: 0.75rem; margin-bottom: 0.65rem; }
.tp-row-label { color: var(--text-muted); font-size: 0.875rem; }
.tp-row-label .tp-narrow-only { display: none; }
@media (max-width: 700px) {
  .tp-row-label .tp-wide-only { display: none; }
  .tp-row-label .tp-narrow-only { display: inline; }
}
.tp-hint { margin: -0.25rem 0 0.75rem; font-size: 0.75rem; color: var(--text-muted); line-height: 1.45; }

.tp-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Every option is a real radio (keyboard arrows, screen readers and form
   semantics for free) visually replaced by its label's .tp-opt box. */
.tp-choice { position: relative; display: block; cursor: pointer; min-width: 0; }
.tp-choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tp-choice input:focus-visible + .tp-opt { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Theme tiles: each previews its own paper and ink. */
.tp-themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.55rem; margin-bottom: 0.4rem; }
.tp-theme { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.tp-swatch {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 3rem; border-radius: var(--r-md, 8px);
  border: 1px solid rgba(0,0,0,0.12); font-size: 1.15rem; letter-spacing: 0.01em;
  box-shadow: inset 0 0 0 0 transparent; transition: box-shadow 0.15s;
}
.tp-theme-name { font-size: 0.75rem; color: var(--text-muted); }
.tp-choice input:checked + .tp-theme .tp-swatch { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--accent); }
.tp-choice input:checked + .tp-theme .tp-theme-name { color: var(--text); }
.tp-swatch[data-v="auto"] { background: linear-gradient(90deg, #faf8f4 50%, #1b1815 50%); }
.tp-swatch[data-v="auto"] .tp-ink-l { color: #241f1a; }
.tp-swatch[data-v="auto"] .tp-ink-d { color: #cdc5b8; }
.tp-swatch[data-v="light"] { background: #faf8f4; color: #241f1a; }
.tp-swatch[data-v="sepia"] { background: #f4ecdc; color: #3a2c1f; }
.tp-swatch[data-v="dim"]   { background: #2f2b26; color: #ddd4c6; border-color: rgba(255,255,255,0.08); }
.tp-swatch[data-v="dark"]  { background: #1b1815; color: #cdc5b8; border-color: rgba(255,255,255,0.08); }
.tp-swatch[data-v="black"] { background: #000000; color: #c9c1b4; border-color: rgba(255,255,255,0.12); }

/* Typeface tiles: each name is set in its own face. */
.tp-fonts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin-bottom: 0.75rem; }
.tp-font {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 0.75rem; border: 1px solid var(--rule); border-radius: var(--r-md, 8px);
  background: var(--bg); transition: border-color 0.15s, background-color 0.15s;
}
.tp-font-ag { flex: none; width: 1.9rem; text-align: center; font-size: 1.35rem; line-height: 1; color: var(--text); }
.tp-font-text { display: flex; flex-direction: column; min-width: 0; }
.tp-font-name { font-size: 0.875rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-font-note { font-family: Georgia, "Times New Roman", serif; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-choice:hover .tp-font { border-color: var(--text-muted); }
.tp-choice input:checked + .tp-font { border-color: var(--accent); background: var(--bg-elevated); box-shadow: 0 0 0 1px var(--accent); }
.tp-face-georgia { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; }
.tp-face-literata { font-family: "Literata", Georgia, serif; }
.tp-face-sans { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.tp-face-atkinson { font-family: "Atkinson Hyperlegible", system-ui, sans-serif; }

/* Segmented controls */
.tp-seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--bg); border: 1px solid var(--rule); border-radius: 999px;
}
.tp-seg .tp-choice { flex: 1 1 0; }
.tp-seg .tp-opt {
  display: flex; align-items: center; justify-content: center; gap: 0.35rem;
  height: 2rem; padding: 0 0.5rem; border-radius: 999px;
  font-size: 0.875rem; color: var(--text-muted); white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.tp-seg .tp-choice:hover .tp-opt { color: var(--text); }
.tp-seg input:checked + .tp-opt {
  background: var(--bg-elevated); color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 1px var(--rule);
}
.tp-opt svg { display: block; flex: none; }

/* Text size slider */
.tp-size { display: flex; align-items: center; gap: 0.6rem; }
.tp-size-a { flex: none; color: var(--text-muted); line-height: 1; font-family: Georgia, "Times New Roman", serif; }
.tp-size-a.small { font-size: 0.75rem; }
.tp-size-a.large { font-size: 1.25rem; }
.tp-range {
  flex: 1; min-width: 0; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 999px; outline: none; cursor: pointer; margin: 0;
  background: linear-gradient(to right, var(--accent) 0 var(--tp-fill, 33%), var(--rule) var(--tp-fill, 33%) 100%);
}
.tp-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--accent); box-shadow: var(--shadow); cursor: pointer;
}
.tp-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--accent); box-shadow: var(--shadow); cursor: pointer;
}
.tp-range::-moz-range-track { height: 4px; border-radius: 999px; background: transparent; }
.tp-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
.tp-size-value { flex: none; min-width: 3rem; text-align: right; font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Switch */
.tp-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.35rem; cursor: pointer; }
.tp-switch-row .tp-row-label { color: var(--text); font-size: 0.875rem; }
.tp-switch { position: relative; flex: none; width: 2.6rem; height: 1.5rem; }
.tp-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.tp-switch-track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--rule);
  transition: background-color 0.18s; pointer-events: none;
}
.tp-switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: calc(1.5rem - 6px); height: calc(1.5rem - 6px);
  border-radius: 50%; background: var(--bg-elevated); box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.18s ease;
}
.tp-switch input:checked + .tp-switch-track { background: var(--accent); }
.tp-switch input:checked + .tp-switch-track::after { transform: translateX(1.1rem); }
.tp-switch input:focus-visible + .tp-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.tp-panel-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1px solid var(--rule);
  font-size: 0.75rem; color: var(--text-muted);
}
.tp-reset {
  border: none; background: none; padding: 0.25rem 0; cursor: pointer;
  font: inherit; font-size: 0.875rem; color: var(--link);
  text-decoration: underline; text-underline-offset: 2px;
}
.tp-reset:disabled { color: var(--text-muted); text-decoration: none; cursor: default; }
.tp-reset:focus-visible, .tp-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Phones: the full panel is a bottom sheet with a grab bar. */
@media (max-width: 600px) {
  .tp-panel.tp-sheet {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 64vh; max-height: 64dvh;
    border-radius: 18px 18px 0 0; border-bottom: none;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%); transform-origin: bottom center;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
    transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.26s;
  }
  .tp-panel.tp-sheet.is-open { transform: none; transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
  .tp-panel.tp-sheet .tp-panel-head { padding-top: 1.35rem; }
  .tp-panel.tp-sheet .tp-panel-head::before {
    content: ""; position: absolute; top: 0.5rem; left: 50%; width: 2.4rem; height: 4px;
    margin-left: -1.2rem; border-radius: 999px; background: var(--rule);
  }
}

/* ---- Language menu ----
   reader.js swaps each language <select> for this pill button and a pop-up
   list, styled like the sidebar-control menu. The select stays in the page,
   hidden, as the source of truth (see reader.js). The pill sizes to the
   chosen language in every browser, so its chevron always sits just after
   the text. Fallbacks after each token: the library page has no page.css. */
.tp-lang-btn {
  display: inline-flex; align-items: center; gap: 0.5rem; flex: none;
  height: var(--ctrl, 2.5rem); padding: 0 0.75rem 0 0.875rem;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow);
  font-family: inherit; font-size: 0.875rem; line-height: 1; white-space: nowrap; cursor: pointer;
  -webkit-user-select: none; user-select: none;
  transition: border-color 0.15s;
}
.tp-lang-btn svg { flex: none; display: block; color: var(--text-muted); transition: transform 0.15s; }
.tp-lang-btn:hover { border-color: var(--text-muted); }
.tp-lang-btn[aria-expanded="true"] { border-color: var(--accent); }
.tp-lang-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.tp-lang-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tp-lang-btn:disabled { opacity: 0.6; cursor: wait; }
.drawer-footer .tp-lang-btn { flex: 1; min-width: 0; justify-content: space-between; }
/* Toolbar size (the library page's sort): the pager's 2rem height, 6px
   corners and no shadow, so it reads as part of the list, not the page chrome. */
.tp-lang-btn.tp-menu-compact { height: 2rem; padding: 0 0.625rem 0 0.75rem; border-radius: 6px; box-shadow: none; }
@media (max-width: 480px) { .tp-lang-btn { height: var(--ctrl, 2.25rem); } }
/* Dimmed top controls come back to full while their menu is open. */
:root.tp-lang-open .controls.top-controls { opacity: 1; }

.tp-lang-menu {
  position: fixed; z-index: 131; min-width: 11rem;
  max-height: min(22rem, calc(100vh - 2rem)); overflow-y: auto; overscroll-behavior: contain;
  padding: 0.25rem 0; border: 1px solid var(--rule); border-radius: var(--r-lg, 12px);
  background: var(--bg-elevated); color: var(--text);
  box-shadow: 0 12px 36px rgba(0,0,0,0.18), var(--shadow);
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: 0.875rem; line-height: 1.3;
  -webkit-user-select: none; user-select: none;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0.14s;
}
.tp-lang-menu.is-up { transform: translateY(4px); }
.tp-lang-menu.is-open { opacity: 1; visibility: visible; transform: none; transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s; }
.tp-lang-option {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.875rem 0.5rem 0.5rem; white-space: nowrap; cursor: pointer;
}
.tp-lang-option:hover, .tp-lang-option:focus { background: var(--bg); outline: none; }
.tp-lang-option:focus-visible { box-shadow: inset 2px 0 0 var(--accent); }
.tp-lang-dot { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 1rem; height: 1rem; }
.tp-lang-option[aria-selected="true"] .tp-lang-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .tp-lang-btn, .tp-lang-btn svg, .tp-lang-menu, .tp-lang-menu.is-open,
  .tp-panel, .tp-panel.is-open, .tp-panel.tp-sheet, .tp-panel.tp-sheet.is-open,
  .tp-swatch, .tp-font, .tp-seg .tp-opt, .tp-switch-track, .tp-switch-track::after,
  :root[data-tp-focus="on"] section.chapter > :is(p, figure),
  :root[data-tp-focus="on"] section.chapter > ol > li,
  :root[data-tp-focus="on"] :is(.top-controls, .hamburger-btn, .bottom-controls) { transition: none; }
}
