/* The Theater Papers: reading page base styles.
   Every volume page links this first (then reader.css and sidebar.css);
   until 2026-10-06 each page carried its own copy, and No.1 to No.3 had
   drifted from the rest. Built on the tokens below; the rules, and why
   each value is what it is, are in assets/DESIGN.md ("Page system"). */

/* ---- Tokens ---- */
:root {
  /* Color: Light. Dark below; Sepia, Dim and Black in reader.css. */
  --bg: #faf8f4;
  --bg-elevated: #ffffff;
  --text: #241f1a;
  --text-muted: #6b6259;
  --accent: #8a3b2b;
  --rule: #e4ddd2;
  --link: #7a3324;
  --progress: #8a3b2b;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --img-filter: grayscale(0.55) sepia(0.35) contrast(1.05) brightness(1);

  /* Type: seven sizes, each with one job. */
  --fs-label: 0.75rem;   /* 12px  uppercase eyebrows */
  --fs-small: 0.875rem;  /* 14px  meta, captions, navigation, notes */
  --fs-ui: 1rem;         /* 16px  phone drawer rows, overlays */
  --fs-body: 1.125rem;   /* 18px  reading text */
  --fs-lead: 1.25rem;    /* 20px  subtitle, epigraph */
  --fs-h2: 1.5rem;       /* 24px  chapter titles */
  --fs-h1: 2.5rem;       /* 40px  volume title */
  --lh-body: 1.7;
  --lh-heading: 1.25;
  --lh-ui: 1.4;
  --track-label: 0.2em;  /* every uppercase label, one value */

  /* Shape and layout. Spacing is rem on a 4px grid (multiples of 0.25rem);
     only paragraph spacing is in em, so it follows the text size. */
  --r-sm: 6px;           /* images, tooltips */
  --r-md: 8px;           /* rows, tiles, small buttons */
  --r-lg: 12px;          /* cards, panels, toasts, menus */
  --ctrl: 2.5rem;        /* round floating buttons and the language pill */
  --inset: 1rem;         /* floating controls' distance from the window edge */
  --measure: 40rem;      /* reading column, about 66 characters a line */
  --fig-max: 26rem;      /* tallest an illustration may be */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --bg-elevated: #242019;
    --text: #cdc5b8;
    --text-muted: #948b7d;
    --accent: #e0a985;
    --rule: #3a3229;
    --link: #e6b593;
    --progress: #d99a72;
    --shadow: 0 2px 16px rgba(0,0,0,0.4);
    --img-filter: grayscale(0.55) sepia(0.3) contrast(1.1) brightness(0.82);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815; --bg-elevated: #242019; --text: #cdc5b8; --text-muted: #948b7d;
  --accent: #e0a985; --rule: #3a3229; --link: #e6b593; --progress: #d99a72;
  --shadow: 0 2px 16px rgba(0,0,0,0.4);
  --img-filter: grayscale(0.55) sepia(0.3) contrast(1.1) brightness(0.82);
}
:root[data-theme="light"] {
  --bg: #faf8f4; --bg-elevated: #ffffff; --text: #241f1a; --text-muted: #6b6259;
  --accent: #8a3b2b; --rule: #e4ddd2; --link: #7a3324; --progress: #8a3b2b;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --img-filter: grayscale(0.55) sepia(0.35) contrast(1.05) brightness(1);
}
@media (max-width: 480px) {
  :root { --fs-body: 1.0625rem; --fs-h1: 2rem; --ctrl: 2.25rem; --inset: 0.75rem; }
}

/* ---- Base ---- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  /* Kerning and common ligatures on at every size (the browser default,
     "auto", can drop kerning on small text). */
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
}
/* Browsers don't let form controls inherit the page font; buttons and selects
   would otherwise drop into the system sans-serif mid-page. */
button, select { font-family: inherit; }
p { margin: 0 0 1.1em; text-align: left; }
a { color: var(--link); }

/* Uppercase eyebrow labels: one size, one tracking, no ligatures. */
.kicker, nav.toc h2, h2 .chnum, footer.colophon h2 {
  font-size: var(--fs-label); font-weight: 400; line-height: var(--lh-ui);
  letter-spacing: var(--track-label); text-transform: uppercase;
  font-variant-ligatures: none; color: var(--text-muted);
}

#progress { position: fixed; top: 0; left: 0; height: 3px; width: 0%; background: var(--progress); z-index: 100; transition: width 0.1s linear; }
.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 1.5rem 6rem; }

/* ---- Hero ---- */
header.hero { text-align: center; padding: 4.5rem 1.5rem 0.5rem; }
header.hero p { text-align: center; }
.kicker { margin-bottom: 1rem; }
h1 { font-size: var(--fs-h1); font-weight: 400; line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 0.5rem; }
.subtitle { font-size: var(--fs-lead); font-style: italic; color: var(--text-muted); font-weight: 400; line-height: 1.35; margin: 0 0 1.5rem; }
.byline { font-size: var(--fs-body); letter-spacing: 0.02em; margin-bottom: 0.25rem; }
.readtime { font-size: var(--fs-small); color: var(--text-muted); font-style: italic; margin: 0; }
.hero-rule { width: 3.5rem; height: 2px; background: var(--accent); margin: 2rem auto 0; border: none; opacity: 0.6; }

/* ---- Front matter, epigraph, contents ----
   Top-level blocks share one 3.5rem rhythm. */
.frontmatter { font-size: var(--fs-small); line-height: 1.6; color: var(--text-muted); margin: 3.5rem 0; padding: 1.5rem 1.75rem; background: var(--bg-elevated); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.frontmatter p { margin: 0 0 0.75em; }
.frontmatter p:last-child { margin-bottom: 0; }
blockquote.epigraph { margin: 3.5rem 0; padding: 0 0 0 1.5rem; border-left: 3px solid var(--accent); font-style: italic; font-size: var(--fs-lead); color: var(--text); line-height: 1.6; }
blockquote.epigraph p { margin: 0; }
blockquote.epigraph cite { display: block; margin-top: 1rem; font-style: normal; font-size: var(--fs-small); color: var(--text-muted); }
nav.toc { margin: 3.5rem 0; }
nav.toc h2 { border: none; margin: 0 0 1rem; padding: 0; text-align: left; }
nav.toc ol { list-style: none; margin: 0; padding: 0; columns: 1; }
nav.toc li { margin-bottom: 0.5rem; }
nav.toc a { display: flex; gap: 0.75rem; text-decoration: none; color: var(--text); line-height: 1.45; padding: 0.125rem 0; border-bottom: 1px dotted transparent; transition: border-color 0.15s, color 0.15s; }
nav.toc a:hover { color: var(--link); border-bottom-color: var(--link); }
.toc-num { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 1.4em; }

/* ---- Chapters ---- */
section.chapter { margin: 3.5rem 0; scroll-margin-top: 1.5rem; }
h2 { font-size: var(--fs-h2); font-weight: 400; line-height: var(--lh-heading); margin: 0 0 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); color: var(--accent); }
/* The chapter number reads as a label ("Chapter 3"), not a stray digit.
   ::before keeps "Chapter" out of textContent, which the resume prompt
   reads to build its own "Chapter 3: ..." line. */
h2 .chnum { display: block; margin-bottom: 0.5rem; }
h2 .chnum::before { content: "Chapter "; }
h2.section-head { border-bottom: 1px solid var(--rule); text-align: left; }

/* Figures. Each <figure> carries its image's natural size,
   style="--w:1400;--h:1028" (written by manuscript_to_web.py), and --fig-w
   turns that into the box the loaded image will fill: the column width at
   most, never past its natural width, never taller than --fig-max. Two
   things follow from knowing that width up front:
   - the box is reserved before the lazy image loads, so a chapter link
     lands on its heading instead of short of it while images load;
   - the caption is held to the image's width, so their left and right
     edges line up. Under a narrow image the caption keeps a readable
     22rem minimum and is centred with it instead. */
figure { margin: 2rem 0; }
figure img { width: auto; height: auto; max-width: 100%; max-height: var(--fig-max); border-radius: var(--r-sm); display: block; margin: 0 auto; box-shadow: var(--shadow); filter: var(--img-filter); transition: filter 0.2s; }
figure[style*="--w"] { --fig-w: min(100%, calc(var(--w) * 1px), calc(var(--fig-max) * var(--w) / var(--h))); }
figure[style*="--w"] img { width: var(--fig-w); aspect-ratio: var(--w) / var(--h); height: auto; }
figure[style*="--w"] figcaption { width: max(var(--fig-w), min(100%, 22rem)); margin-inline: auto; }
figcaption { font-size: var(--fs-small); color: var(--text-muted); margin-top: 0.75rem; line-height: 1.5; font-style: italic; }
figcaption .credit { display: block; margin-top: 0.25em; font-style: normal; }

.chapter-nav { display: flex; justify-content: space-between; gap: 1.5rem; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); font-size: var(--fs-small); }
.chapter-nav a { color: var(--text-muted); text-decoration: none; line-height: var(--lh-ui); border-bottom: 1px dotted transparent; transition: color 0.15s, border-color 0.15s; }
.chapter-nav a:hover { color: var(--link); border-bottom-color: var(--link); }
.chapter-nav-prev { text-align: left; }
.chapter-nav-next { text-align: right; margin-left: auto; }

#ledger ol { margin: 0 0 1.1em; padding-left: 1.5rem; }
#ledger li { margin-bottom: 1rem; }

footer.colophon { margin-top: 5rem; padding-top: 2.5rem; border-top: 1px solid var(--rule); font-size: var(--fs-small); line-height: 1.6; color: var(--text-muted); }
footer.colophon h2 { border: none; padding: 0; margin: 2.5rem 0 0.75rem; }
footer.colophon h2:first-child { margin-top: 0; }

/* ---- Floating controls ----
   Top and bottom controls share one inset, so the language pill, Aa and
   back-to-top sit on the same right-hand line, and the language pill is as
   tall as the round buttons beside it. */
.controls { position: fixed; display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; z-index: 90; }
.controls.top-controls { top: var(--inset); right: var(--inset); flex-direction: row; align-items: center; transition: opacity 0.2s; }
.controls.top-controls.dimmed { opacity: 0.32; }
.controls.top-controls.dimmed:hover, .controls.top-controls.dimmed:focus-within { opacity: 1; }
.controls.top-controls.dimmed:has(#langSelect:disabled) { opacity: 1; }
.controls.bottom-controls { bottom: var(--inset); right: var(--inset); }
.ctrl-btn { width: var(--ctrl); height: var(--ctrl); padding: 0; border-radius: 50%; border: 1px solid var(--rule); background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow); cursor: pointer; font-size: 1.125rem; display: flex; align-items: center; justify-content: center; opacity: 0.9; transition: opacity 0.15s, transform 0.15s; }
.ctrl-btn:hover { opacity: 1; transform: translateY(-1px); }
/* The language pill draws its own chevron (two currentColor triangles, so it
   follows the theme) instead of the browser's, which sat at the far edge of a
   box sized for the longest language name. field-sizing sizes the pill to the
   chosen language, so the chevron sits just after the text, inset as far from
   the right edge as the text is from the left (Chromium; other browsers keep
   the widest option's width, chevron still in place). */
#langSelect, #langSelectDrawer { -webkit-appearance: none; appearance: none; field-sizing: content; height: var(--ctrl); font-family: inherit; font-size: var(--fs-small); padding: 0 2.25rem 0 0.875rem; border-radius: 999px; border: 1px solid var(--rule); background-color: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow); cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
#langSelect:disabled, #langSelectDrawer:disabled { opacity: 0.6; cursor: wait; }
#langStatus { font-size: var(--fs-label); color: var(--text-muted); background: var(--bg-elevated); padding: 0.25rem 0.75rem; border-radius: 999px; box-shadow: var(--shadow); display: none; }
#langStatus.visible { display: block; }
#langOverlay { display: none; }
html.lang-pending #langOverlay { display: flex; position: fixed; inset: 0; z-index: 999; align-items: center; justify-content: center; background: var(--bg); color: var(--text-muted); font-family: Georgia, 'Times New Roman', serif; font-size: var(--fs-ui); letter-spacing: 0.02em; }
html.lang-pending body > *:not(#langOverlay) { visibility: hidden; }
#toTop { opacity: 0; pointer-events: none; }
#toTop.visible { opacity: 0.55; pointer-events: auto; }

/* ---- Resume prompt ---- */
#resumeToast {
  position: fixed; left: var(--inset); right: var(--inset); bottom: 5rem; z-index: 96;
  display: flex; align-items: center; gap: 0.75rem;
  max-width: 26rem; margin: 0 auto;
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 0.5rem 0.5rem 0.5rem 1rem;
  font-size: var(--fs-small); line-height: 1.35;
  opacity: 0; transform: translateY(0.5rem); pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#resumeToast.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
#resumeToast .resume-text strong { color: var(--accent); font-weight: 400; }
#resumeToast .resume-go {
  flex: none; color: var(--link); text-decoration: none; font-size: var(--fs-small); font-weight: 600;
  border: 1px solid var(--rule); border-radius: 999px; padding: 0.375rem 0.875rem;
  white-space: nowrap; transition: background-color 0.15s;
}
#resumeToast .resume-go:hover { background: var(--bg); }
#resumeToast .resume-dismiss {
  flex: none; width: 1.75rem; height: 1.75rem; border: none; background: none; color: var(--text-muted);
  font-size: 1.125rem; line-height: 1; cursor: pointer; border-radius: 50%; padding: 0;
}
#resumeToast .resume-dismiss:hover { color: var(--text); background: var(--bg); }

/* ---- Hamburger + chapter drawer (phones; sidebar.css turns it into the
   desktop sidebar) ---- */
.hamburger-btn { position: fixed; top: var(--inset); left: var(--inset); z-index: 95; }
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
}
html.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.chapter-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 120;
  width: min(20rem, 84vw);
  background: var(--bg-elevated); box-shadow: var(--shadow);
  transform: translateX(-100%); transition: transform 0.25s ease;
  display: flex; flex-direction: column; overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
}
html.drawer-open .chapter-drawer { transform: translateX(0); }
/* The volume's title is ink, not accent: in the drawer and sidebar the
   accent means "you are here" (the current chapter). */
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.drawer-header-title { font-size: var(--fs-small); line-height: 1.35; color: var(--text); }
.drawer-home-link { margin: 0 0 1rem; }
.drawer-home-link a { font-size: var(--fs-small); color: var(--text-muted); text-decoration: none; }
.drawer-home-link a:hover { color: var(--link); }
.drawer-close { width: 2.25rem; height: 2.25rem; font-size: 1.25rem; flex: none; }
.drawer-toc h2 { font-size: var(--fs-label); letter-spacing: var(--track-label); text-transform: uppercase; font-variant-ligatures: none; font-weight: 400; line-height: var(--lh-ui); color: var(--text-muted); border: none; margin: 0 0 0.75rem; padding: 0; }
.drawer-toc ol { list-style: none; margin: 0; padding: 0; }
.drawer-toc li { margin-bottom: 0.25rem; }
.drawer-toc a { display: flex; gap: 0.75rem; align-items: baseline; text-decoration: none; color: var(--text); padding: 0.5rem; border-radius: var(--r-md); font-size: var(--fs-ui); line-height: var(--lh-ui); transition: background-color 0.15s, color 0.15s; }
.drawer-toc a:hover, .drawer-toc a:focus-visible { background: var(--bg); color: var(--link); }
.drawer-toc .toc-num { color: var(--text-muted); min-width: 1.5em; font-variant-numeric: tabular-nums; }
.drawer-footer { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); display: flex; align-items: center; gap: 0.5rem; }
.drawer-footer #langSelectDrawer { flex: 1; min-width: 0; }

@media (max-width: 480px) {
  header.hero { padding: 5.5rem 1.25rem 0.5rem; }
  .frontmatter { padding: 1.25rem; }
  .ctrl-btn { font-size: 1rem; }
  #resumeToast { bottom: 4.5rem; padding: 0.5rem 0.5rem 0.5rem 1rem; }
  .chapter-nav { flex-direction: column; gap: 0.5rem; }
  .chapter-nav-next { text-align: left; margin-left: 0; }
  .chapter-drawer { width: min(18rem, 88vw); padding: 1rem 1.25rem 1.25rem; }
}

/* ---- Content protection ----
   Raises real friction against casual copy-paste and right-click saving.
   Not a real barrier: anyone who disables CSS, opens dev tools, or points a
   camera at the screen still gets the text. The watermark is the part that
   still works even then: it's baked into any screenshot, so a leaked copy
   stays traceable back to this edition. */
body {
  -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
#langSelect, #langSelectDrawer, .ctrl-btn { -webkit-user-select: auto; user-select: auto; }
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
.watermark {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='260'%3E%3Ctext x='10' y='150' font-family='Georgia,serif' font-size='21' fill='%23888' transform='rotate(-28 210 130)'%3E%C2%A9 Akshay Shrestha%3C/text%3E%3C/svg%3E");
  background-repeat: repeat;
}
@media print {
  body * { visibility: hidden !important; }
  body::after {
    content: "This page is not available for printing or saving as PDF. Read it online at the original link, or find the print/ebook edition through the author.";
    visibility: visible !important;
    position: fixed; top: 42%; left: 50%; transform: translate(-50%, -50%);
    width: 70%; text-align: center; font-family: Georgia, serif; font-size: 1.2rem;
  }
}
