/* ============================================================
   CINNABAR BUREAU — the Ministry of Schemes
   design system for The Thirty-Six Stratagems (三十六計)
   ------------------------------------------------------------
   An ancient Chinese war manual redrawn by a contemporary
   studio: big 汉字 slabs, red seal-stamps (印章), a deceptively
   adorable panda "general". Poster-bold, modern China — not
   antique scroll. See specs/design.md for the full argument.
   House rules that survive any redesign:
   - tokens on :root, dark variant ("Ink Night") re-declares
     under html.dark; reading surface never pure white, ink
     never pure black; every accent carries meaning.
   ============================================================ */

:root {
  /* surfaces & ink — warm rice paper, warm ink */
  --c-bg: #F5EDDD;          /* warm rice paper, never white */
  --paper-2: #EFE5D0;       /* recessed panel */
  --c-surface: #FBF6EA;     /* raised card */
  --c-ink: #241E1A;         /* warm ink, never pure black */
  --c-muted: #5C5347;       /* muted labels */
  --c-rule: #DCCFB4;        /* hairlines */
  /* accents — each with semantic weight */
  --c-accent: #CE3B2B;      /* --seal: cinnabar — identity, seal-stamps, links, mascot */
  --c-accent-soft: #A72A20; /* seal-deep — hover/press */
  --seal: #CE3B2B;
  --gold: #B0831F;          /* the classic verse / calligraphy plaque */
  --jade: #3E7A63;          /* 今 Today — the modern-life example device */
  --rust: #9C4A2E;          /* 反 Backfire — the caution device */
  /* type — display grotesk / reading serif / mono data / CJK */
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-ui: "Bricolage Grotesque", system-ui, sans-serif;
  --font-hanzi: "Noto Serif SC", serif;
  /* layout & surface craft */
  --measure: 34rem;
  --page: 72rem;
  --radius: 14px;
  --grain: 0.05;
  --shadow: 0 1px 0 rgba(36,30,26,.04), 0 18px 40px -28px rgba(36,30,26,.45);
}

html.dark {                 /* "Ink Night" — the same world re-lit, accents brighten */
  --c-bg: #14110C;          /* ink-stone, not inverted */
  --paper-2: #1B1710;
  --c-surface: #1E1911;
  --c-ink: #EDE4D2;
  --c-muted: #A99C84;
  --c-rule: #332B1E;
  --c-accent: #E75E4A;
  --c-accent-soft: #C4402F;
  --seal: #E75E4A;
  --gold: #D9AE4E;
  --jade: #5FA083;
  --rust: #C97A54;
  --grain: 0.07;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 22px 50px -30px rgba(0,0,0,.8);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  transition: background .4s ease, color .4s ease;
}

/* paper grain — feTurbulence overlay, the Cinnabar Bureau surface texture */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  opacity: var(--grain); mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
html.dark body::before { mix-blend-mode: screen; opacity: .06; }

/* Chinese characters always get the dedicated CJK face */
.hanzi, [lang="zh"] { font-family: var(--font-hanzi); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

a { color: var(--c-accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--c-accent-soft); }

code, pre, .data { font-family: var(--font-mono); font-size: 0.9em; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--c-accent); color: var(--c-bg); padding: 0.5rem 1rem;
}
.skip-link:focus { left: 0; z-index: 10; }

/* ---------- masthead ---------- */

.masthead { border-bottom: 1px solid var(--c-rule); }

.masthead__inner {
  max-width: var(--page); margin: 0 auto; padding: 0.9rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

.brand { text-decoration: none; color: var(--c-ink); }
.brand__title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }

.masthead__links { display: flex; align-items: center; gap: 1.1rem; }

.navlink {
  font-family: var(--font-ui); font-size: 0.95rem;
  color: var(--c-ink); text-decoration: none;
}
.navlink:hover { color: var(--c-accent); }

.masthead__burger { display: none; }

.theme-toggle {
  background: none; border: 1px solid var(--c-rule); border-radius: 999px;
  width: 2.1rem; height: 2.1rem; padding: 0.35rem; cursor: pointer; color: var(--c-ink);
}
.theme-toggle svg { width: 100%; height: 100%; }
.theme-toggle__moon { display: none; }
html.dark .theme-toggle__sun { display: none; }
html.dark .theme-toggle__moon { display: block; }

@media (max-width: 40rem) {
  .masthead__burger {
    display: flex; flex-direction: column; gap: 4px;
    background: none; border: none; padding: 0.4rem; cursor: pointer;
  }
  .masthead__burger span { width: 20px; height: 2px; background: var(--c-ink); }
  .masthead__links {
    display: none; position: absolute; right: 1rem; top: 3.4rem;
    flex-direction: column; align-items: flex-end; gap: 0.8rem;
    background: var(--c-surface); border: 1px solid var(--c-rule);
    border-radius: 6px; padding: 1rem 1.25rem; z-index: 20;
  }
  .masthead__links.is-open { display: flex; }
}

/* ---------- content ---------- */

.hero { max-width: var(--measure); margin: 3.5rem auto 1rem; padding: 0 1.25rem; }
.hero__title { font-size: clamp(2rem, 6vw, 3.2rem); margin: 0 0 0.5rem; }
.hero__dek { color: var(--c-muted); font-size: 1.15rem; margin: 0; }

.prose { max-width: var(--measure); margin: 2rem auto 4rem; padding: 0 1.25rem; }
.prose h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); }
.prose img { max-width: 100%; height: auto; }
.prose blockquote {
  margin: 1.5rem 0; padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--c-accent); color: var(--c-muted); font-style: italic;
}
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--c-rule); padding: 0.4rem 0.6rem; text-align: left; }
.prose th { font-family: var(--font-ui); font-size: 0.85rem; }

/* ---------- colophon ---------- */

.colophon { border-top: 1px solid var(--c-rule); margin-top: 2rem; }
.colophon__inner {
  max-width: var(--page); margin: 0 auto; padding: 2rem 1.25rem 2.5rem;
  font-family: var(--font-ui); font-size: 0.9rem; color: var(--c-muted);
}
.colophon__title { font-family: var(--font-display); color: var(--c-ink); margin: 0 0 0.5rem; }
.colophon__creed { max-width: 60ch; margin: 0 0 1rem; font-family: var(--font-body); font-size: 0.95rem; line-height: 1.55; color: var(--c-muted); }
.colophon__creed a { color: var(--seal); white-space: nowrap; }
.colophon__links { display: flex; flex-wrap: wrap; gap: 1rem; }
.colophon__links a { color: var(--c-muted); }
.colophon__foot { margin-top: 1.25rem; }

/* ---------- motion & print floor (non-negotiable) ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .masthead, .colophon, .theme-toggle, .skip-link { display: none; }
  body { background: #fff; color: #000; }
}

/* ============================================================
   CINNABAR BUREAU — components
   ============================================================ */

.kicker {
  font-family: var(--font-mono); font-weight: 700; font-size: 0.72rem;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--seal);
}

/* ---------- the recurring mascot ---------- */
.panda { display: block; width: 100%; height: auto; }
.panda__fur { fill: #fff; }
html.dark .panda__fur { fill: #F1E8D6; }
.panda__blk { fill: #2A241E; }
.panda__cap { fill: var(--seal); }
.panda__gold { fill: var(--gold); }
.panda__lid, .panda__smirk { fill: none; stroke: #2A241E; stroke-width: 2.2; stroke-linecap: round; }
.panda__smirk { stroke-width: 2.6; }
.panda__limb { fill: none; stroke: #2A241E; stroke-width: 8.5; stroke-linecap: round; stroke-linejoin: round; }
.panda__paw { fill: #2A241E; }
.panda__prop { paint-order: stroke; }

/* ---------- home hero ---------- */
.hero--home { position: relative; max-width: var(--page); margin: 0 auto;
  padding: clamp(3rem, 7vw, 5rem) 1.25rem 1.5rem; overflow: hidden; }
.hero__ghost { position: absolute; right: -2%; top: -14%; z-index: 0; pointer-events: none;
  user-select: none; font-weight: 900; color: var(--seal); opacity: 0.07;
  font-size: min(46vw, 460px); line-height: 0.8; }
.hero--home > * { position: relative; z-index: 1; }
.hero__lead { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; margin: 0 0 1rem; }
.hero__hz { font-family: var(--font-hanzi); font-weight: 900; font-size: 2.3rem; color: var(--gold); line-height: 1; }
.hero--home .hero__title { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(2.4rem, 6.5vw, 4.6rem); line-height: 1.02; margin: 0; max-width: 18ch; }
.hero__dek { color: var(--c-muted); font-size: 1.2rem; max-width: 48ch; margin: 1rem 0 0; }
.hero__note { max-width: 52ch; margin: 1.5rem 0 0; font-size: 1.02rem; }

/* ---------- the index ---------- */
.index { max-width: var(--page); margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.chapter-block { margin: 3rem 0 0; }
.chapter-banner { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  border-bottom: 2px solid var(--c-ink); padding-bottom: 0.6rem; }
.chapter-banner__link { display: flex; align-items: baseline; gap: 0.9rem; flex-wrap: wrap;
  text-decoration: none; color: var(--c-ink); }
.chapter-banner__link:hover .chapter-banner__title { color: var(--seal); }
.chapter-banner__no { font-family: var(--font-mono); font-weight: 700; font-size: 0.78rem;
  letter-spacing: 0.14em; color: var(--seal); text-transform: uppercase; }
.chapter-banner__hz { font-family: var(--font-hanzi); font-weight: 900; font-size: 1.5rem; }
.chapter-banner__title { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; letter-spacing: -0.01em; }
.chapter-banner__meta { margin-left: auto; font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.08em; color: var(--c-muted); }
.chapter-block__blurb { color: var(--c-muted); max-width: 60ch; margin: 0.8rem 0 1.4rem; }

/* ---------- card grid ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
@media (max-width: 60rem) { .grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 34rem) { .grid { grid-template-columns: 1fr; } }

.card { position: relative; display: flex; flex-direction: column; gap: 0.85rem;
  background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--radius);
  padding: 1.15rem; text-decoration: none; color: var(--c-ink); box-shadow: var(--shadow);
  transition: transform 0.18s ease, border-color 0.18s ease; }
.card:hover { transform: translateY(-3px); border-color: var(--seal); }
.stamp { position: absolute; top: 0.9rem; right: 0.9rem; z-index: 2; width: 2.6rem; height: 2.6rem;
  border-radius: 0.6rem; background: var(--seal); color: #fff; font-family: var(--font-mono);
  font-weight: 700; font-size: 1.1rem; display: grid; place-items: center; transform: rotate(5deg);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.28); }
.card__art { position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: 0.6rem; border: 1px solid var(--c-rule);
  background: radial-gradient(130% 120% at 28% 0%, color-mix(in srgb, var(--gold) 20%, var(--c-surface)), var(--paper-2)); }
.card__hz { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: center;
  padding-top: 0.5rem; font-family: var(--font-hanzi); font-weight: 900; font-size: 2.4rem;
  line-height: 1; color: var(--c-ink); opacity: 0.9; }
.card__panda { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); height: 72%; width: auto;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.16)); }
.card__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  object-position: left center; display: block; }
/* On scene cards the 汉字 label overlays the illustration, whose background is
   ALWAYS light (the raster doesn't theme) — so the label stays dark ink with a
   cream halo in BOTH themes, never tied to --ink. */
.card__art--scene .card__hz { color: #241E1A; opacity: 0.95;
  text-shadow: 0 1px 12px rgba(245,237,221,0.9), 0 0 3px rgba(245,237,221,0.8); }
.card__body { display: flex; flex-direction: column; gap: 0.25rem; }
.card__py { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--seal); }
.card__en { font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; line-height: 1.15; }
.card__gl { color: var(--c-muted); font-size: 0.95rem; line-height: 1.5; }

/* ---------- breadcrumb ---------- */
.crumb { max-width: var(--page); margin: 1.5rem auto 0; padding: 0 1.25rem;
  font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.06em; color: var(--c-muted); }
.crumb a { color: var(--c-muted); } .crumb a:hover { color: var(--seal); }

/* ---------- chapter page ---------- */
.chapter { max-width: var(--page); margin: 0 auto; padding: 0.5rem 1.25rem 3rem; }
.chapter__head { position: relative; overflow: hidden; padding: 1.5rem 0 1rem; }
.chapter__ghost { position: absolute; right: -1%; top: -30%; z-index: 0; pointer-events: none; user-select: none;
  font-family: var(--font-hanzi); font-weight: 900; color: var(--seal); opacity: 0.07; font-size: min(34vw, 320px); line-height: 0.8; }
.chapter__head > * { position: relative; z-index: 1; }
.chapter__title { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(2rem, 5vw, 3.4rem); margin: 0; }
.chapter__blurb { color: var(--c-muted); font-size: 1.15rem; max-width: 54ch; margin: 0.8rem 0 1.8rem; }
.chapter .grid { margin-top: 0.5rem; }

.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2.5rem; }
.chapter-nav__link { display: flex; flex-direction: column; gap: 0.15rem; text-decoration: none; color: var(--c-ink);
  border: 1px solid var(--c-rule); border-radius: var(--radius); padding: 0.85rem 1.1rem; background: var(--c-surface); }
.chapter-nav__link:hover { border-color: var(--seal); }
.chapter-nav__link--next { text-align: right; }
.chapter-nav .l { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--c-muted); }
.chapter-nav .t { font-family: var(--font-display); font-weight: 700; }

/* ---------- dossier (stratagem detail) ---------- */
.dossier { max-width: 48rem; margin: 0 auto; padding: 0.5rem 1.25rem 3rem; }
.masthead-card { display: grid; grid-template-columns: auto 1fr; gap: 1.4rem; align-items: center;
  background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow); margin-top: 1rem; }
.bigstamp { width: 5rem; height: 5rem; border-radius: 1rem; background: var(--seal); color: #fff;
  display: grid; place-items: center; font-family: var(--font-mono); font-weight: 700; font-size: 2.3rem;
  transform: rotate(-5deg); box-shadow: inset 0 0 0 3px rgba(255,255,255,0.28); }
.dossier__hz { font-family: var(--font-hanzi); font-weight: 900; font-size: clamp(2.4rem, 7vw, 3.2rem); line-height: 1; margin: 0.3rem 0 0.2rem; }
.dossier__py { font-family: var(--font-mono); color: var(--seal); font-size: 0.92rem; letter-spacing: 0.05em; margin: 0; }
.dossier__en { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.4rem, 3.5vw, 2rem); line-height: 1.1; margin: 0.35rem 0 0; }

.hero-art { position: relative; margin: 1.5rem 0 0; aspect-ratio: 16 / 9; overflow: hidden;
  border: 1px solid var(--c-rule); border-radius: var(--radius);
  background: radial-gradient(120% 150% at 78% 0%, color-mix(in srgb, var(--gold) 22%, var(--c-surface)), var(--paper-2)); }
.hero-art--scene { background: var(--paper-2); }
.hero-art__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-art--scene .hero-art__hz { display: none; }
.hero-art__hz { position: absolute; right: 3%; top: 50%; transform: translateY(-50%); font-family: var(--font-hanzi);
  font-weight: 900; font-size: min(30vw, 190px); line-height: 0.8; color: var(--c-ink); opacity: 0.1; }
.hero-art__panda { position: absolute; left: 5%; bottom: 3%; height: 90%; width: auto;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.18)); }
.hero-art__cap { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 0.5rem 0.9rem;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--c-muted);
  background: color-mix(in srgb, var(--c-surface) 78%, transparent); }
.hero-art__cap .hanzi { color: var(--c-ink); }

.plaque { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.6rem 0;
  border-left: 4px solid var(--gold); background: color-mix(in srgb, var(--gold) 9%, transparent);
  padding: 0.9rem 1.2rem; border-radius: 0 0.6rem 0.6rem 0; }
.plaque__hz { font-family: var(--font-hanzi); font-weight: 900; font-size: 1.9rem; color: var(--gold); }
.plaque__lit { font-family: var(--font-mono); font-size: 0.82rem; letter-spacing: 0.02em; color: var(--c-muted); }

.dossier__body { max-width: var(--measure); }
.dossier__gloss { font-size: 1.2rem; line-height: 1.55; margin: 0 0 1.4rem; }

.device { border: 1px solid var(--c-rule); border-radius: 0.8rem; padding: 1.1rem 1.25rem; margin: 1.1rem 0;
  background: var(--c-surface); box-shadow: var(--shadow); }
.device__lbl { display: flex; align-items: center; gap: 0.5rem; font-family: var(--font-mono); font-weight: 700;
  font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; margin: 0 0 0.5rem; }
.device__g { font-family: var(--font-hanzi); font-weight: 900; font-size: 1.15rem; }
.device__text { margin: 0; line-height: 1.6; }
.device--today { border-left: 4px solid var(--jade); } .device--today .device__lbl { color: var(--jade); }
.device--back { border-left: 4px solid var(--rust); } .device--back .device__lbl { color: var(--rust); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2.2rem;
  border-top: 1px solid var(--c-rule); padding-top: 1.3rem; }
.pager__link { display: flex; flex-direction: column; gap: 0.1rem; text-decoration: none; color: var(--c-ink);
  border: 1px solid var(--c-rule); border-radius: var(--radius); padding: 0.85rem 1.1rem; background: var(--c-surface); }
.pager__link:hover { border-color: var(--seal); }
.pager__link--empty { border: none; background: none; }
.pager__link--next { text-align: right; }
.pager__l { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.13em; text-transform: uppercase; color: var(--c-muted); }
.pager__t { font-family: var(--font-hanzi); font-weight: 700; font-size: 1.25rem; }
.pager__en { font-family: var(--font-display); font-weight: 600; font-size: 0.9rem; color: var(--c-muted); }

/* ---------- buttons ---------- */
.button { display: inline-flex; align-items: center; gap: 0.5rem; background: var(--seal); color: #fff;
  font-family: var(--font-display); font-weight: 700; text-decoration: none; padding: 0.75rem 1.3rem;
  border-radius: 0.7rem; box-shadow: var(--shadow); }
.button:hover { background: var(--c-accent-soft); color: #fff; }

/* ---------- 404 ---------- */
.notfound { max-width: 40rem; margin: 3rem auto; padding: 0 1.25rem; text-align: center; }
.notfound__art { position: relative; width: 170px; margin: 0 auto 1rem; }
.notfound__prop { position: absolute; right: -6px; top: -6px; font-size: 2rem; }
.notfound__code { font-family: var(--font-mono); font-weight: 700; letter-spacing: 0.3em; color: var(--seal); margin: 0.5rem 0 0; }
.notfound__title { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.6rem, 4.5vw, 2.4rem); margin: 0.3rem 0 0.6rem; }
.notfound__dek { color: var(--c-muted); max-width: 42ch; margin: 0 auto 1.5rem; }

/* ---------- responsive dossier ---------- */
@media (max-width: 34rem) {
  .masthead-card { grid-template-columns: 1fr; gap: 0.9rem; }
  .bigstamp { width: 3.6rem; height: 3.6rem; font-size: 1.6rem; }
  .chapter-nav, .pager { grid-template-columns: 1fr; }
  .pager__link--next, .chapter-nav__link--next { text-align: left; }
}
