/* ============================================================
   Illumine Lingao — "The Transmigrator's Archive"
   Foundation: tokens, fonts, chrome. Ming-paper serif prose,
   engineering-document mono chrome. Depth = 1px rules only.
   ============================================================ */

/* Tokens */
:root {
  --paper: #f2efe8; --panel: #faf8f3; --ink: #23211c; --muted: #6e6a60;
  --rule: #d8d4cc; --blue: #345d7e; --vermilion: #9e3122;
  --serif: 'Source Serif 4', 'Noto Serif SC', 'Songti SC', 'SimSun', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --overlay-shadow: 0 2px 10px rgba(35, 33, 28, 0.18);
}

/* Lamplight: aged paper by lamplight — warm browns, two distinct inks (Task 5) */
[data-theme="lamplight"] {
  --paper: #201c17; --panel: #262119; --ink: #e8e2d4; --muted: #a89f8d;
  --rule: #453e33; --blue: #8fb4d4; --vermilion: #d98a75;
  --overlay-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Fonts (self-hosted latin subsets) */
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('fonts/source-serif-4-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/source-serif-4-400i.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/plex-mono-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/plex-mono-500.woff2') format('woff2');
}

/* Base */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.75;
}

.container {
  max-width: 68ch;
  margin: 0 auto;
  padding: 0 20px;
}

/* .content is always nested inside .container on chapter pages, so it
   inherits the column width and gutters — no own max-width/padding, or the
   prose would be inset an extra 20px past .chapter-head and .chapter-nav. */
.content {
  margin: 0 auto;
}

a {
  color: var(--blue);
}

/* Header chrome */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--rule);
}

.site-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
  text-decoration: none;
}

.site-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.theme-toggle {
  font-family: var(--mono);
  font-size: 12px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
}

/* Chapter head */
.chapter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--ink);
  margin: 36px 0 28px;
  padding-bottom: 8px;
}

.chapter-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 24px;
  margin: 0;
}

.chapter-pos {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

/* Prose */
.content p {
  margin: 0 0 1em;
}

.content h2 { font-family: var(--serif); font-weight: 600; font-size: 21px; }
.content h3 { font-family: var(--serif); font-weight: 600; font-size: 19px; }
.content h4 { font-family: var(--serif); font-weight: 600; font-size: 17px; }

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 28px 15%;
}

/* Chapter navigation */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  margin: 28px 0;
}

.chapter-nav a {
  color: var(--muted);
  text-decoration: none;
}

.chapter-nav a:hover {
  color: var(--ink);
}

/* Index / volume page title — bare h1 (direct child of .container);
   .chapter-head h1 is nested one level deeper, so it is not matched. */
.container > h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  margin: 36px 0 28px;
}

/* File register (index pages) */
.file-register {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-register li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--rule);
  padding: 10px 2px;
}

.file-register .file-no {
  flex: 0 0 3.5em;
  width: 3.5em;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.file-register a {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--blue);
  text-decoration: none;
}

.file-register a:hover {
  text-decoration: underline;
}

/* entity refs — Task 2 */
.entity-ref { cursor: pointer; text-decoration: underline; text-decoration-thickness: 1px;
  text-underline-offset: 4px; color: inherit; }
.entity-ref[data-world="modern"] { text-decoration-color: var(--blue); }
.entity-ref[data-world="ming"] { text-decoration-color: var(--vermilion); }
.entity-ref:not([data-first]) { text-decoration-color: var(--rule); }
.entity-ref:not([data-first])[data-world="modern"]:hover { text-decoration-color: var(--blue); }
.entity-ref:not([data-first])[data-world="ming"]:hover { text-decoration-color: var(--vermilion); }

/* slip — Task 3 */
.illumine-slip { position: absolute; width: 280px; background: var(--panel);
  border: 1px solid var(--ink); border-radius: 2px; box-shadow: var(--overlay-shadow);
  font-size: 13.5px; line-height: 1.55; z-index: 40; }
.slip-tab { font-family: var(--mono); font-size: 11px; display: flex;
  justify-content: space-between; align-items: center;
  padding: 4px 10px; border-bottom: 1px solid var(--ink); color: var(--muted); }
.illumine-slip[data-world="modern"] .slip-tab { color: var(--blue); }
.illumine-slip[data-world="ming"] .slip-tab { color: var(--vermilion); }
.slip-close { font: inherit; background: none; border: 0; cursor: pointer; color: inherit; }
.slip-body { padding: 10px 12px; }
.slip-body b { font-size: 15px; }
.slip-zh { font-family: var(--serif); color: var(--muted); margin-left: 6px; }
.slip-body p { margin: 6px 0 8px; }
.slip-open-file { font-family: var(--mono); font-size: 11px; color: var(--blue);
  background: none; border: 0; padding: 0; cursor: pointer; }
@media (max-width: 768px) {
  .illumine-slip { position: fixed; top: auto !important; left: 16px !important;
    right: 16px; bottom: 16px; width: auto; }
}

/* drawer — Task 4 */
.illumine-drawer { position: fixed; top: 0; right: 0; width: 360px; max-width: 92vw;
  height: 100vh; background: var(--panel); border-left: 1px solid var(--ink);
  box-shadow: var(--overlay-shadow); z-index: 50; overflow-y: auto;
  font-size: 14px; line-height: 1.6; }
.drawer-tab { font-family: var(--mono); font-size: 11px; display: flex;
  justify-content: space-between; align-items: center; padding: 8px 14px;
  border-bottom: 1px solid var(--ink); position: sticky; top: 0; background: var(--panel); }
.illumine-drawer[data-world="modern"] .drawer-tab { color: var(--blue); }
.illumine-drawer[data-world="ming"] .drawer-tab { color: var(--vermilion); }
.drawer-close { font: inherit; background: none; border: 0; cursor: pointer; color: inherit; }
.drawer-body { padding: 16px; }
.drawer-portrait { border: 1px solid var(--rule); aspect-ratio: 3 / 4; max-width: 180px;
  margin: 0 auto 14px; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px; color: var(--muted); }
.drawer-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.drawer-name { font-size: 19px; margin: 0 0 10px; }
.modal-section { margin: 0 0 14px; }
.modal-section h4 { font-family: var(--mono); font-size: 11px; font-weight: 500;
  color: var(--muted); margin: 0 0 6px; border-bottom: 1px solid var(--rule); padding-bottom: 3px; }
.modal-section ul { padding-left: 18px; margin: 0; }
.modal-section li { margin-bottom: 6px; }
.modal-rel-link { color: var(--blue); text-decoration: none; border-bottom: 1px dotted var(--blue); }
.rel-type { color: var(--muted); font-size: 12px; }
.modal-map-container { height: 180px; border: 1px solid var(--rule); margin-top: 8px; }
@media (max-width: 768px) {
  .illumine-drawer { top: auto; bottom: 0; width: 100%; max-width: none;
    height: 75vh; border-left: 0; border-top: 1px solid var(--ink); }
}

/* Mobile */
@media (max-width: 768px) {
  body { font-size: 17px; }
  .site-header { padding: 12px 16px; }
}
