/* ── Every Byte Tells a Story — Web Edition ────────────── */
:root {
  --midnight: #191970;
  --midnight-90: rgba(25,25,112,0.9);
  --midnight-50: rgba(25,25,112,0.5);
  --midnight-10: rgba(25,25,112,0.08);
  --bitcoin: #f7931a;
  --bitcoin-light: rgba(247,147,26,0.08);
  --version-blue: #2962ff;
  --input-red: #dc3232;
  --output-green: #009646;
  --witness-violet: #8000c8;
  --scriptsig-orange: #e68214;
  --locktime-gray: #787878;
  --varint-teal: #008064;
  --value-gold: #c8a500;
  --spk-lime: #50a000;
  --field-bg: #fafaf5;
  --warm-gray: #807669;
  --deep-green: #006400;
  --brick-red: #cb4154;
  --goldenrod: #daa520;
  --bg: #fefdfb;
  --text: #1a1a2e;
  --border: #e0ddd6;
  --code-bg: #f5f3ee;
  --success: #28a745;
  --danger: #dc3545;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'EB Garamond', 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  font-size: 18px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ─────────────────────────────────────────────── */
.site-header {
  background: var(--midnight);
  color: white;
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.site-header .logo { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.site-header .logo .accent { color: var(--bitcoin); }
.site-header nav { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.site-header nav a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  transition: all 0.2s;
  font-family: 'Inter', system-ui, sans-serif;
}
.site-header nav a:hover, .site-header nav a.active {
  color: white;
  background: rgba(255,255,255,0.12);
}

.content-wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Typography ─────────────────────────────────────────── */
h1 {
  font-size: 2.2rem;
  color: var(--midnight);
  margin: 2rem 0 0.5rem;
  line-height: 1.2;
  border-bottom: 2px solid var(--midnight-50);
  padding-bottom: 0.4rem;
}
h2 {
  font-size: 1.5rem;
  color: var(--midnight-90);
  margin: 2.5rem 0 0.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
h3 {
  font-size: 1.2rem;
  color: var(--midnight-90);
  margin: 1.8rem 0 0.5rem;
}
h4 {
  font-size: 1.05rem;
  color: var(--midnight-90);
  margin: 1.5rem 0 0.4rem;
}
.chapter-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--midnight-50);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
  display: block;
}
.chapter-number {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--bitcoin);
  letter-spacing: 0.04em;
  display: block;
  margin-bottom: -0.3rem;
}

p { margin: 0.8rem 0; }
strong { color: var(--midnight); }

.epigraph {
  margin: 1.5rem 0 2rem;
  padding: 0 2rem;
  border-left: 3px solid var(--border);
  font-style: italic;
  color: var(--warm-gray);
}
.epigraph .source {
  display: block;
  text-align: right;
  font-style: normal;
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

.lettrine::first-letter {
  float: left;
  font-size: 3.4em;
  line-height: 0.8;
  padding-right: 0.08em;
  color: var(--midnight);
  font-weight: 700;
}

a { color: var(--midnight); }
a:hover { color: var(--bitcoin); }

/* ── Code & Hex ─────────────────────────────────────────── */
code {
  font-family: 'BeraMono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre {
  font-family: 'BeraMono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.hex-inline { color: var(--scriptsig-orange); font-family: 'BeraMono', monospace; font-size: 0.85em; }

/* ── Boxes (matching PDF tcolorbox environments) ────────── */
.box {
  border-radius: 6px;
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
}
.box-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  font-variant: small-caps;
}
.box p { margin: 0.4rem 0; }
.box ul, .box ol { margin: 0.4rem 0 0.4rem 1.5rem; }

.box.insight  { background: var(--bitcoin-light); border-color: var(--bitcoin); }
.box.insight .box-title { color: var(--bitcoin); }

.box.warning  { background: rgba(220,53,69,0.06); border-color: var(--brick-red); }
.box.warning .box-title { color: var(--brick-red); }

.box.history  { background: var(--midnight-10); border-color: var(--midnight); }
.box.history .box-title { color: var(--midnight); }

.box.hexbox   { background: var(--field-bg); border-color: var(--warm-gray); font-family: monospace; }
.box.hexbox .box-title { color: var(--warm-gray); font-family: 'Inter', sans-serif; }

.box.parsebox { background: white; border-color: var(--midnight-50); }
.box.parsebox .box-title { color: var(--midnight); font-family: 'Inter', sans-serif; }

/* ── Interactive Demo Container ─────────────────────────── */
.demo-container {
  margin: 2rem -1.5rem;
  border: 2px solid var(--bitcoin);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(247,147,26,0.12);
}
.demo-container iframe {
  width: 100%;
  border: none;
  min-height: 900px;
}
.demo-label {
  background: var(--bitcoin);
  color: white;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.demo-label .icon { font-size: 1.1rem; }

/* ── Tables ─────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
}
th {
  background: var(--field-bg);
  font-weight: 700;
  text-align: left;
  padding: 0.5rem 0.8rem;
  border-bottom: 2px solid var(--border);
  color: var(--midnight);
}
td {
  padding: 0.4rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
tr:hover { background: rgba(25,25,112,0.02); }

/* ── Footnotes ──────────────────────────────────────────── */
.footnote-ref { font-size: 0.75em; vertical-align: super; color: var(--midnight); }
.footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--warm-gray);
}
.footnotes p { margin: 0.3rem 0; }

/* ── Chapter Nav ────────────────────────────────────────── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin: 3rem 0 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.85rem;
}
.chapter-nav a {
  color: var(--midnight);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: all 0.2s;
}
.chapter-nav a:hover {
  background: var(--midnight);
  color: white;
  border-color: var(--midnight);
}

/* ── Math (KaTeX will handle this) ──────────────────────── */
.math-block {
  text-align: center;
  margin: 1rem 0;
  font-size: 1.1em;
}

/* ── Footnotes ──────────────────────────────────────────── */
.footnote-ref {
  cursor: help;
  color: var(--bitcoin);
  font-size: 0.7em;
  vertical-align: super;
  text-decoration: none;
  border-bottom: 1px dotted var(--bitcoin);
}
.footnote-ref:hover {
  color: var(--midnight);
}

/* ── Math ───────────────────────────────────────────────── */
.math {
  font-family: 'EB Garamond', Georgia, serif;
  font-style: italic;
  color: var(--midnight);
  white-space: nowrap;
}

/* ── Description Lists ──────────────────────────────────── */
dl {
  margin: 0.8rem 0;
}
dt {
  font-weight: 700;
  color: var(--midnight);
  margin-top: 0.8rem;
}
dd {
  margin-left: 0;
  padding-left: 1.2rem;
  margin-bottom: 0.4rem;
}

/* ── Inline Specimen Hex ────────────────────────────────── */
.sh-wrapper {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 1.5rem 0;
}
.sh-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--field-bg);
  border-bottom: 1px solid var(--border);
}
.sh-title {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--midnight);
  font-family: 'Inter', system-ui, sans-serif;
}
.sh-link {
  font-size: 0.72rem;
  font-family: 'Inter', sans-serif;
  color: var(--bitcoin);
  text-decoration: none;
}
.sh-link:hover { text-decoration: underline; }
.sh-explain {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--warm-gray);
  background: var(--field-bg);
  border-bottom: 1px solid var(--border);
  min-height: 2rem;
  transition: all 0.15s;
}
.sh-explain.sh-active {
  background: var(--midnight);
  color: white;
}
.sh-explain strong { font-weight: 700; }
.sh-explain .sh-meta {
  opacity: 0.6;
  font-size: 0.72rem;
  font-family: 'Courier New', monospace;
}
.sh-hex {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.78rem;
  line-height: 2;
  padding: 1rem;
  background: white;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
}
.sh-byte {
  cursor: pointer;
  padding: 1px 0;
  border-radius: 1px;
  transition: background 0.1s;
}
.sh-byte:hover { opacity: 0.8; }
.sh-byte.sh-hl { border-radius: 2px; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .content-wrap { padding: 1rem; }

  /* Header */
  .site-header {
    padding: 0.6rem 0.8rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .site-header .logo { font-size: 0.9rem; }
  .site-header nav { gap: 0.2rem; flex-wrap: wrap; }
  .site-header nav a { padding: 0.3rem 0.5rem; min-height: 44px; display: inline-flex; align-items: center; }

  /* Typography */
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .epigraph { padding: 0 1rem; }

  /* Specimen hex */
  .sh-wrapper { font-size: 0.65rem; }
  .sh-hex { padding: 0.5rem; font-size: 0.65rem; }
  .sh-header { flex-wrap: wrap; gap: 0.3rem; padding: 0.4rem 0.6rem; }

  /* Demo containers */
  .demo-container { margin: 1rem -1rem; }
  .demo-container iframe { min-height: 500px; }

  /* Tables */
  table { font-size: 0.78rem; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 0.35rem 0.5rem; white-space: nowrap; }

  /* Boxes */
  .box { padding: 0.8rem; }

  /* Home page hero */
  .hero h1 { font-size: 1.8rem; }
  .hero { padding: 2.5rem 1rem 2rem; }
  .hero .subtitle { font-size: 1rem; }

  /* Touch-friendly tap targets */
  button, a.tool-card, .chapter-nav a, .sh-link, .toc-chapter {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .toc-chapter { padding: 0.5rem 0; }
  .chapter-nav a { padding: 0.6rem 1rem; }
}
