/* ==========================================================================
   Shared design system: library, map and reader.
   One warm "dark wood and brass" palette, one type pair (Source Serif 4 for
   reading, Inter for interface, Cinzel only for small display headings),
   three themes for the reader and a per-volume accent driven by --hue.
   ========================================================================== */

:root {
  --hue: 38;
  --accent-l: 62%;

  /* Night (default) */
  --bg: #0f0c09;
  --surface: #18120d;
  --surface-2: #241a13;
  --surface-3: #31231a;
  --line: #3d2c20;
  --line-strong: #5a4330;
  --text: #f0e6d2;
  --text-dim: #b8a98f;
  --gold: #d4af37;
  --on-gold: #1a1208;
  --backdrop: rgba(8, 6, 4, 0.72);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 22px 50px rgba(0, 0, 0, 0.58);
  color-scheme: dark;

  /* Names used by the reader stylesheet */
  --bg-elevated: var(--surface-2);
  --bg-hover: var(--surface-3);
  --bg-glass: rgba(15, 12, 9, 0.92);
  --fg: var(--text);
  --fg-heading: #fbf3e2;
  --muted: #a99b84;
  --on-accent: #1a1208;
  --tint: rgba(255, 244, 224, 0.05);

  /* Type */
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-serif:
    "Source Serif 4", Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-ui:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-sans: var(--font-ui);
  --font-mono: var(--font-ui);
  --font-reader: var(--font-serif);

  --gutter: 16px;
}

/* Accent is derived from --hue, so any element can re-tint its subtree
   with class="accent" style="--hue: 120". */
:root,
.accent {
  --accent: hsl(var(--hue) 55% var(--accent-l));
  --accent-hover: hsl(var(--hue) 60% calc(var(--accent-l) + 8%));
  --accent-soft: hsl(var(--hue) 55% var(--accent-l) / 0.16);
  --accent-faint: hsl(var(--hue) 55% var(--accent-l) / 0.08);
  --accent-border: hsl(var(--hue) 40% 38%);
  --accent-glow: hsl(var(--hue) 55% var(--accent-l) / 0.26);
}

/* Paper: warm sepia for daylight reading */
html[data-theme="paper"] {
  --accent-l: 34%;
  --bg: #f1e8d6;
  --surface: #faf3e4;
  --surface-2: #ece1c9;
  --surface-3: #e2d5b8;
  --line: #d8caae;
  --line-strong: #bfae8c;
  --text: #2d2319;
  --text-dim: #6f5f4b;
  --gold: #8a6a12;
  --on-gold: #fffaf0;
  --backdrop: rgba(60, 44, 24, 0.45);
  --shadow-sm: 0 4px 14px rgba(70, 50, 20, 0.12);
  --shadow-md: 0 8px 24px rgba(70, 50, 20, 0.16);
  --shadow-lg: 0 16px 40px rgba(70, 50, 20, 0.2);
  --shadow-xl: 0 22px 50px rgba(70, 50, 20, 0.24);
  --bg-glass: rgba(241, 232, 214, 0.92);
  --fg-heading: #17110a;
  --muted: #7a6a57;
  --on-accent: #fffaf0;
  --tint: rgba(70, 50, 20, 0.06);
  color-scheme: light;
}

/* Black: true black for OLED phones in a dark room */
html[data-theme="black"] {
  --bg: #000;
  --surface: #0b0907;
  --surface-2: #141110;
  --surface-3: #1d1916;
  --line: #231f1a;
  --line-strong: #3a3028;
  --bg-glass: rgba(0, 0, 0, 0.92);
  --text: #d6cfc2;
  --fg-heading: #f1ebdf;
  --muted: #8d857a;
}

/* Reader font choices */
html[data-font="serif"] {
  --font-reader: "Source Serif 4", Georgia, "Iowan Old Style", serif;
}
html[data-font="literata"] {
  --font-reader: "Literata", Georgia, "Iowan Old Style", serif;
}
html[data-font="sans"] {
  --font-reader: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.6 var(--font-serif);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Page frame ---------- */
.lamp {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    ellipse 60rem 34rem at 50% -8%,
    rgba(212, 175, 55, 0.09),
    transparent 70%
  );
}

html[data-theme="paper"] .lamp {
  display: none;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 var(--gutter) 56px;
}

.site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font: 600 1.05rem var(--font-display);
  letter-spacing: 0.06em;
  color: var(--text);
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: 4px;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  font: 500 0.9rem var(--font-ui);
  color: var(--text-dim);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
}

.site-nav .long {
  display: none;
}

@media (min-width: 640px) {
  .site-nav .short {
    display: none;
  }
  .site-nav .long {
    display: inline;
  }
}

.site-foot {
  margin-top: 44px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: center;
  font: 400 0.8125rem var(--font-ui);
  color: var(--text-dim);
}

/* ---------- Small components ---------- */
.eyebrow {
  font: 600 0.75rem var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: 600 0.9375rem var(--font-ui);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.btn:hover {
  border-color: var(--accent);
  background: var(--surface-3);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

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

/* Progress bar: set --p (0..1) on the bar or on an ancestor */
.bar {
  display: block;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: calc(var(--p, 0) * 100%);
  background: var(--accent);
  border-radius: inherit;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 36px 0 12px;
}

.section-head h2 {
  font: 600 0.9375rem var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--gold);
}

.section-head a {
  font: 500 0.875rem var(--font-ui);
  color: var(--text-dim);
  text-decoration: none;
}

.section-head a:hover {
  color: var(--text);
}
