/* ── The History Notebook — Site Stylesheet ──────────────── */

/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1a1e;
  --bg-raised: #222226;
  --bg-inset:  #2a2a2f;
  --border:    #3a3a40;
  --text:      #d4d4d8;
  --text-dim:  #8a8a92;
  --text-bright: #f0f0f3;
  --accent:    #7c9ddb;
  --accent-dim:#5a7ab8;
  --red:       #c97070;
  --green:     #70a070;
  --amber:     #c9a050;
  --tag-bg:    #2e3340;
  --tag-border:#3e4350;
  --quote-border: #4a4a55;
  --link:      #8ab4f8;
  --hero-grad-start: #1e2028;
  --hero-grad-end:   #252830;
  --leaflet-attrib-bg: rgba(26,26,30,0.8);
}

[data-theme="light"] {
  --bg:        #f4f4f2;
  --bg-raised: #ffffff;
  --bg-inset:  #ecece8;
  --border:    #d5d5ce;
  --text:      #222228;
  --text-dim:  #60606a;
  --text-bright: #111118;
  --accent:    #355f9a;
  --accent-dim:#2b4f82;
  --red:       #9f3e3e;
  --green:     #3f6f3f;
  --amber:     #9b732c;
  --tag-bg:    #e6e9ef;
  --tag-border:#d0d4dd;
  --quote-border: #b8bec9;
  --link:      #2f5ea0;
  --hero-grad-start: #e7e8e3;
  --hero-grad-end:   #dfe2dc;
  --leaflet-attrib-bg: rgba(255,255,255,0.88);
}

html { font-size: 18px; scroll-behavior: smooth; }

body {
  font-family: "Libre Baskerville", "Source Serif Pro", Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────── */
.page-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

@media (max-width: 900px) {
  .page-grid { grid-template-columns: 1fr; }
  .sidebar   { display: none; }
}

/* ── Sidebar / outline ────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  padding: 2rem 1.25rem;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.83rem;
  line-height: 1.55;
}

.sidebar-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 1.2rem;
}

.sidebar a {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.2rem 0;
  transition: color 0.15s;
}
.sidebar a:hover,
.sidebar a.active { color: var(--accent); }

.sidebar .depth-2 { padding-left: 0; font-weight: 600; margin-top: 0.6rem; color: var(--text); }
.sidebar .depth-3 { padding-left: 1rem; }

.sidebar .chapter-link {
  font-size: 0.79rem;
  padding: 0.15rem 0;
  margin-top: 0;
}
.sidebar .chapter-link.active {
  color: var(--accent);
  font-weight: 600;
}
.sidebar hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* ── Main content ─────────────────────────────────────── */
.content {
  max-width: 52rem;
  margin: 0 auto;
  padding: 3rem 2.5rem 6rem;
}

/* ── Typography ───────────────────────────────────────── */
h1 {
  font-size: 2.35rem;
  font-weight: 700;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  color: var(--text-bright);
  margin-bottom: 0.25rem;
  letter-spacing: -0.01em;
}

h2, h3, h4, h5, h6 {
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
}

.subtitle {
  font-style: italic;
  color: var(--text-dim);
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-bright);
  margin: 2.8rem 0 1rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-bright);
  margin: 2rem 0 0.8rem;
}

p { margin-bottom: 1.1rem; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

em { font-style: italic; }
strong { font-weight: 700; color: var(--text-bright); }

/* ── Preamble ─────────────────────────────────────────── */
.preamble {
  font-style: italic;
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.78;
  padding: 1.5rem 0;
  margin: 0.5rem 0 1.5rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.preamble .no-citation {
  display: inline-block;
  font-style: normal;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--amber);
  background: rgba(201, 160, 80, 0.12);
  border: 1px solid rgba(201, 160, 80, 0.25);
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 0.3rem;
}

/* ── Cast list (formations) ───────────────────────────── */
.cast-block {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}

.cast-block .cast-heading {
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-bright);
  display: block;
  margin-bottom: 0.7rem;
  white-space: normal;
}

.cast-section-label {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.55rem;
  display: block;
}

.cast-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.2rem;
}

.cast-side {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-raised);
  padding: 0.75rem 0.9rem;
}

.cast-list,
.cast-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cast-list > li {
  margin-bottom: 0.45rem;
}

.cast-list > li:last-child {
  margin-bottom: 0;
}

.cast-list ul {
  margin-top: 0.35rem;
  margin-left: 0.9rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}

.cast-list ul li {
  margin-bottom: 0.32rem;
}

.cast-list ul li:last-child {
  margin-bottom: 0;
}

.cast-unit {
  color: var(--text);
}

.cast-commander {
  color: var(--text-dim);
  font-size: 0.84rem;
  margin-left: 0.35rem;
}


/* ── Historiographical boxes ──────────────────────────── */
.box {
  border-left: 3px solid var(--quote-border);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  background: var(--bg-raised);
  border-radius: 0 6px 6px 0;
  font-size: 0.94rem;
}

.box.sources-diverge  { border-left-color: var(--amber); }
.box.gap-in-record    { border-left-color: var(--red); }
.box.primary-source   { border-left-color: var(--green); }
.box.killed-in-action { border-left-color: #888; }

.box-label {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.6rem;
  display: block;
}
.box.sources-diverge .box-label  { color: var(--amber); }
.box.gap-in-record .box-label    { color: var(--red); }
.box.primary-source .box-label   { color: var(--green); }
.box.killed-in-action .box-label { color: #aaa; }

.box p { margin-bottom: 0.8rem; }
.box p:last-child { margin-bottom: 0; }

/* ── Tables ───────────────────────────────────────────── */
.box table,
table.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.8rem 0;
}

.box table th,
.box table td,
table.ref-table th,
table.ref-table td {
  text-align: left;
  padding: 0.35rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.box table th,
table.ref-table th {
  font-weight: 600;
  color: var(--text-bright);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Inline citations ─────────────────────────────────── */
.cite {
  color: var(--text-dim);
  font-size: 0.88rem;
}

/* ── Testimony blockquotes ────────────────────────────── */
blockquote.testimony {
  border-left: 3px solid var(--quote-border);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  background: var(--bg-raised);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  font-size: 0.94rem;
}
blockquote.testimony p { margin-bottom: 0.8rem; }
blockquote.testimony p:last-child { margin-bottom: 0; }

/* ── Map ──────────────────────────────────────────────── */
.map-container {
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 1.5rem 0;
}

.map-container #map {
  height: 420px;
  width: 100%;
  background: var(--bg-inset);
}

.map-title {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.map-title strong { color: var(--text); }

/* Leaflet dark theme overrides */
.leaflet-container { background: var(--bg-inset); }
.leaflet-popup-content-wrapper {
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 6px;
  box-shadow: 0 3px 14px rgba(0,0,0,0.5);
}
.leaflet-popup-content { font-family: "Work Sans", system-ui, sans-serif; font-size: 0.82rem; line-height: 1.5; margin: 10px 14px; }
.leaflet-popup-tip { background: var(--bg-raised); }
.leaflet-control-zoom a { background: var(--bg-raised) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--bg-inset) !important; }
.leaflet-control-attribution { background: var(--leaflet-attrib-bg) !important; color: var(--text-dim) !important; font-size: 0.65rem !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }

.map-caption {
  font-style: italic;
  font-size: 0.88rem;
  color: var(--text-dim);
  margin: 0.5rem 0 1.5rem;
  line-height: 1.55;
}

/* ── Bibliography ─────────────────────────────────────── */
.bibliography {
  font-size: 0.9rem;
  line-height: 1.6;
}
.bibliography li {
  margin-bottom: 0.5rem;
  padding-left: 2rem;
  text-indent: -2rem;
  list-style: none;
}

/* ── Provenance banner ────────────────────────────────── */
.provenance {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.8rem;
  margin-bottom: 2rem;
  display: inline-block;
}

/* ── Tags ─────────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: middle;
}
.tag-origin   { background: rgba(122, 157, 219, 0.15); border: 1px solid rgba(122, 157, 219, 0.3); color: var(--accent); }
.tag-status   { background: rgba(201, 160, 80, 0.12); border: 1px solid rgba(201, 160, 80, 0.25); color: var(--amber); }

/* ── Chapter footer (narrative link) ──────────────────── */
.chapter-footer {
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.92rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.chapter-footer a {
  color: var(--accent);
}

/* ── Chapter navigation (prev/next) ───────────────────── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
}
.chapter-nav a {
  text-decoration: none;
  color: var(--text-dim);
  transition: color 0.15s;
}
.chapter-nav a:hover { color: var(--accent); }
.chapter-nav-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}
.chapter-nav-title {
  display: block;
  font-size: 0.88rem;
  color: var(--text);
}
.chapter-nav a:hover .chapter-nav-title { color: var(--accent); }
.chapter-nav-next { text-align: right; }

/* ── Hero banner ──────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--hero-grad-start), var(--hero-grad-end));
  border-bottom: 1px solid var(--border);
  padding: 2rem 0;
  margin-bottom: 0;
}

.hero-inner {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 2.5rem;
}

.hero-badge {
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.hero h1 { font-size: 1.6rem; margin-bottom: 0.3rem; }

.hero .subtitle { margin-bottom: 0.8rem; }

.hero-description {
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.55;
  max-width: 38rem;
}

.hero-tags { margin-top: 0.8rem; }

/* ── Top bar ──────────────────────────────────────────── */
.topbar {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 2rem;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.topbar-title {
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.topbar-sep { color: var(--border); }

.topbar a { color: var(--text-dim); text-decoration: none; }
.topbar a:hover { color: var(--accent); }

.theme-toggle {
  margin-left: 0.1rem;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: "Work Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.75rem;
}

.lang-switch a {
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
}

.lang-switch a:hover {
  color: var(--accent);
}

.lang-switch a.active {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Figures & captions ──────────────────────────────── */
figure.plate {
  margin: 2rem 0;
  padding: 0;
}

figure.plate img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

figure.plate.portrait {
  max-width: 200px;
  float: right;
  margin: 0 0 1.2rem 1.5rem;
}

figure.plate.portrait img {
  width: 100%;
}

figure.plate figcaption {
  font-style: italic;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 0.5rem;
}

figure.plate.portrait figcaption {
  font-size: 0.8rem;
}
