/* ==== DFH-1 blog post stylesheet ==== */

:root {
  --bg: #0e1116;
  --bg-alt: #161b22;
  --bg-elev: #1e242b;
  --fg: #e8e8e8;
  --fg-dim: #9aa4ad;
  --fg-mute: #6b7580;
  --accent: #e53935;        /* red flag flavor */
  --accent-soft: #ff6b68;
  --accent2: #4fc3f7;        /* cyan for data */
  --accent3: #ffd54f;        /* amber for highlights */
  --accent4: #81c784;        /* green for positive findings */
  --border: #2a323d;
  --code-bg: #0a0d12;
  --hairline: #1f252d;
  --font-body: 'Inter', 'Source Han Sans SC', 'Noto Sans SC', 'PingFang SC',
               'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  --font-serif: 'Source Han Serif SC', 'Noto Serif SC', 'Songti SC', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(14, 17, 22, 0.18), rgba(14, 17, 22, 0.76) 70%),
    radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.28) 100%),
    url("bg-dfh-doodle-monotone.png"),
    radial-gradient(circle at 18% 12%, rgba(229, 57, 53, 0.06), transparent 28rem),
    radial-gradient(circle at 82% 18%, rgba(79, 195, 247, 0.045), transparent 26rem),
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.01) 1px, transparent 1px);
  background-size:
    100% 100%,
    100% 100%,
    820px auto,
    100% 100%,
    100% 100%,
    48px 48px,
    48px 48px;
  background-position:
    0 0,
    0 0,
    center top,
    0 0,
    0 0,
    0 0,
    0 0;
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.75;
  margin: 0;
  padding: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.86),
    0 0 14px rgba(0, 0, 0, 0.38);
}

.container-wide {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.86),
    0 0 14px rgba(0, 0, 0, 0.38);
}

.container code,
.container pre,
.container table,
.container-wide code,
.container-wide pre,
.container-wide table {
  text-shadow: none;
}

.hero {
  min-height: 70vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 1.5rem 2rem;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.hero-inner {
  max-width: 880px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
  width: 100%;
}

.hero h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 3.8rem);
  margin: 0 0 0.5rem;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.hero-subtitle {
  font-size: 1.25rem;
  color: var(--fg-dim);
  margin: 0 0 2rem;
  line-height: 1.5;
  max-width: 46em;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  color: var(--fg-mute);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}

.hero-meta span { display: flex; align-items: center; gap: 0.4em; }
.hero-meta .key { color: var(--fg-mute); }
.hero-meta .val { color: var(--accent2); font-family: var(--font-mono); }

/* ---- Hero background animation ---- */
.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.3;
  pointer-events: none;
}

/* ---- Navigation ---- */

.top-nav {
  position: sticky;
  top: 0;
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.top-nav a { color: var(--fg-dim); text-decoration: none; }
.top-nav a:hover { color: var(--fg); }
.top-nav-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 0.95rem;
}
.top-nav-chapter {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--fg-mute);
}

/* ---- Typography ---- */

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
  margin-top: 2.4em;
  margin-bottom: 0.8em;
}

h2 {
  font-size: 1.9rem;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.35rem;
  color: var(--accent2);
}

h4 {
  font-size: 1.1rem;
  color: var(--accent3);
}

p {
  margin: 0.8em 0;
}

a {
  color: var(--accent2);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent2);
  transition: color 0.15s, border-color 0.15s;
}
a:hover {
  color: var(--accent-soft);
  border-bottom-color: var(--accent-soft);
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--accent3);
  padding: 0.15em 0.35em;
  border-radius: 3px;
  border: 1px solid var(--hairline);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1em;
  overflow-x: auto;
  line-height: 1.5;
}
pre code {
  background: none;
  padding: 0;
  border: none;
  color: var(--fg);
}

blockquote {
  margin: 1.4em 0;
  padding: 0.6em 1.2em;
  border-left: 3px solid var(--accent);
  background: rgba(229, 57, 53, 0.05);
  color: var(--fg-dim);
  font-style: italic;
}

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

/* ---- Tables ---- */

table {
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.92rem;
  background: var(--bg-alt);
  border-radius: 6px;
  overflow: hidden;
  width: 100%;
}
th, td {
  padding: 0.6em 0.9em;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--bg-elev);
  color: var(--accent2);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  font-size: 0.88rem;
  letter-spacing: 0.03em;
}
td.num { font-family: var(--font-mono); text-align: right; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(79, 195, 247, 0.04); }

/* ---- Figures ---- */

figure {
  margin: 2em 0;
  padding: 0;
}
figure img, figure svg {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  border-radius: 4px;
  background: var(--bg-alt);
}
figcaption {
  margin-top: 0.5em;
  font-size: 0.86rem;
  color: var(--fg-mute);
  line-height: 1.5;
  text-align: center;
  font-style: italic;
}
figcaption strong {
  color: var(--fg-dim);
  font-style: normal;
}

.generated-figure {
  margin: 2.2em 0;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}
.generated-figure img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}
.hero-illustration {
  max-width: 780px;
  margin: 2.4rem auto 2rem;
}
.hero-illustration img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.32);
}

/* ---- Chapter layout ---- */

.chapter-header {
  padding: 4rem 1.25rem 2rem;
  max-width: 880px;
  margin: 0 auto;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.86),
    0 0 14px rgba(0, 0, 0, 0.38);
}
.chapter-num {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  margin-bottom: 0.4em;
}
.chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  margin: 0 0 0.4em;
}
.chapter-lede {
  font-size: 1.15rem;
  color: var(--fg-dim);
  line-height: 1.6;
  border-left: 3px solid var(--accent);
  padding-left: 1em;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin: 4em 0 2em;
  padding: 1em 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.chapter-nav a {
  display: flex;
  flex-direction: column;
  padding: 0.5em 0.8em;
  background: var(--bg-alt);
  border-radius: 4px;
  border: none;
  max-width: 45%;
}
.chapter-nav a .dir {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--fg-mute);
  margin-bottom: 0.1em;
}
.chapter-nav a .title {
  color: var(--accent2);
}
.chapter-nav .prev { text-align: left; }
.chapter-nav .next { text-align: right; margin-left: auto; }

/* ---- TOC on landing page ---- */

.toc {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}
.toc-item {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  display: block;
}
.toc-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent2);
  background: rgba(79, 195, 247, 0.05);
}
.toc-item .num {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  margin-bottom: 0.3em;
}
.toc-item .title {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--fg);
  font-size: 1.1rem;
  margin-bottom: 0.4em;
  line-height: 1.3;
}
.toc-item .brief {
  color: var(--fg-dim);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
}

/* ---- Telegram-style chat bubbles ---- */

.chat {
  max-width: 720px;
  margin: 2em auto;
  font-family: var(--font-body);
}
.msg {
  display: flex;
  margin-bottom: 0.4em;
  max-width: 100%;
}
.msg-content {
  max-width: 80%;
  background: var(--bg-alt);
  border-radius: 14px;
  padding: 0.5em 0.9em;
  font-size: 0.96rem;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}
.msg-content .who {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 0.15em;
  display: block;
}
.msg-content .time {
  font-size: 0.72rem;
  color: var(--fg-mute);
  margin-left: 0.5em;
  font-family: var(--font-mono);
}
.msg.difan .msg-content {
  background: #0b4573;
  color: #e0f2fe;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.msg.difan .msg-content .who { color: #7dd3fc; }
.msg.scateu .msg-content {
  background: var(--bg-alt);
  color: var(--fg);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.msg.scateu .msg-content .who { color: var(--accent3); }

.msg-attachment {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent3);
  background: rgba(255, 213, 79, 0.08);
  padding: 0.35em 0.6em;
  border-radius: 4px;
  display: inline-block;
  border: 1px solid rgba(255, 213, 79, 0.25);
}

/* ---- Callout boxes ---- */

.callout {
  margin: 2em 0;
  padding: 1em 1.4em;
  border-radius: 6px;
  background: var(--bg-alt);
  border-left: 4px solid var(--accent2);
}
.callout.warn { border-left-color: var(--accent3); }
.callout.danger { border-left-color: var(--accent); }
.callout.success { border-left-color: var(--accent4); }
.callout-title {
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 0.4em;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.callout.warn .callout-title { color: var(--accent3); }
.callout.danger .callout-title { color: var(--accent); }
.callout.success .callout-title { color: var(--accent4); }

/* ---- Stat blocks ---- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  margin: 2em 0;
}
.stat {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1em;
  text-align: center;
}
.stat .num {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  color: var(--accent2);
  font-weight: 700;
  display: block;
  line-height: 1.2;
}
.stat .label {
  font-size: 0.82rem;
  color: var(--fg-mute);
  margin-top: 0.3em;
  letter-spacing: 0.04em;
}

/* ---- Pill badges ---- */

.pill {
  display: inline-block;
  padding: 0.12em 0.55em;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  border-radius: 10px;
  margin: 0 0.2em;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.pill.star3 { background: rgba(129, 199, 132, 0.15); color: #81c784; border-color: rgba(129, 199, 132, 0.3); }
.pill.star2 { background: rgba(255, 213, 79, 0.15); color: #ffd54f; border-color: rgba(255, 213, 79, 0.3); }
.pill.star1 { background: rgba(229, 57, 53, 0.15); color: #e57373; border-color: rgba(229, 57, 53, 0.3); }

/* ---- Footnote / aside ---- */

.aside {
  margin: 2em 0;
  padding: 1em 1.3em;
  background: var(--bg-alt);
  border-radius: 6px;
  color: var(--fg-dim);
  font-size: 0.92rem;
  border-left: 3px solid var(--fg-mute);
}

/* ---- Interactive viz container ---- */

.viz-container {
  background: #04080d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1em;
  margin: 2em 0;
}
.viz-container .viz-title {
  font-family: var(--font-serif);
  color: var(--fg-dim);
  font-size: 0.95rem;
  margin-bottom: 0.5em;
}
.viz-container svg {
  width: 100%;
  height: auto;
  display: block;
}
.viz-container .axis text {
  fill: var(--fg-dim);
  font-size: 11px;
  font-family: var(--font-mono);
}
.viz-container .axis line,
.viz-container .axis path {
  stroke: var(--border);
}

/* ---- Quote with attribution ---- */

.quote-box {
  margin: 2em 0;
  padding: 1.5em;
  background: linear-gradient(135deg,
    rgba(229, 57, 53, 0.06),
    rgba(79, 195, 247, 0.03));
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--fg);
  font-size: 1.08rem;
  line-height: 1.7;
}
.quote-box .attribution {
  margin-top: 0.8em;
  font-size: 0.88rem;
  color: var(--fg-mute);
  font-style: normal;
  text-align: right;
}

/* ---- Inline small-caps ---- */

.sc { font-variant: small-caps; letter-spacing: 0.05em; }

/* ---- Scroll behaviour ---- */

@media (max-width: 700px) {
  .container, .container-wide, .chapter-header { padding: 1.5rem 1rem 3rem; }
  .hero { padding: 2rem 1rem 1.5rem; min-height: 50vh; }
  .hero h1 { font-size: 2rem; }
  .toc { grid-template-columns: 1fr; }
  .msg-content { max-width: 92%; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce), (max-width: 700px) {
  body { background-attachment: scroll; }
}

/* ---- Print styles ---- */

@media print {
  body { background: white; color: black; }
  .hero, .top-nav { display: none; }
  a { color: #0066cc; border-bottom: none; }
}

/* ---- MathJax sizing ---- */
mjx-container {
  font-size: inherit !important;
}
mjx-container[jax="SVG"][display="true"] {
  margin: 0.6em 0;
  text-align: left;
}
/* Inline math: align baseline, never grow taller than surrounding line-height */
mjx-container[jax="SVG"]:not([display="true"]) {
  display: inline-block;
  vertical-align: -0.18em;
  line-height: 0;
}
mjx-container[jax="SVG"]:not([display="true"]) svg {
  display: inline-block;
  max-height: 1.25em;
  vertical-align: -0.15em;
}
/* Table cells: match cell font, no extra height */
table mjx-container[jax="SVG"]:not([display="true"]) svg {
  max-height: 1.1em;
}
/* Headings: scale math down so it doesn't tower over heading glyphs */
h1 mjx-container svg, h2 mjx-container svg, h3 mjx-container svg {
  max-height: 1em;
}
/* Tooltip-style anchors that mjax wraps */
mjx-container a { color: inherit; }
