:root {
  --paper: #f1e6d0;
  --paper-2: #e8d7bc;
  --paper-3: #dcc7a4;
  --soot: #1c1410;
  --ink: #2a1c14;
  --muted: #6b5344;
  --dim: #8a7260;
  --oxblood: #8f2d22;
  --oxblood-deep: #5c1c18;
  --brass: #b0893e;
  --brass-dim: #8a6a32;
  --venous: #5a3144;
  --arterial: #c44536;
  --rule: #cbb99a;
  --card: #f7efe2;
  --shadow: rgba(28, 20, 16, 0.14);
  --font-display: Palatino, "Palatino Linotype", "Book Antiqua", "Iowan Old Style", Georgia, serif;
  --font-ui: "Avenir Next", "Century Gothic", Futura, "Segoe UI", sans-serif;
  --max: 40rem;
  --wide: 58rem;
  --radius: 14px;
  --gap: 1.25rem;
}

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

html {
  font-size: 18px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 400px at 50% -80px, rgba(176, 137, 62, 0.18), transparent 70%),
    var(--paper);
}

a { color: var(--oxblood); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--oxblood-deep); }

button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 88%, var(--paper-3));
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--ink);
  text-decoration: none;
}

.langsw {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--muted);
}
.langsw a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.45rem;
  border-radius: 999px;
}
.langsw a[aria-current="page"] {
  color: var(--paper);
  background: var(--soot);
}

.container {
  width: min(var(--wide), calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 4rem;
}

.hero { margin-bottom: 2.5rem; }

.hero-badge {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-dim);
  margin-bottom: 0.8rem;
}

h1 {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}

.hero-lead {
  font-size: 1.08rem;
  max-width: var(--max);
  color: var(--ink);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin-top: 1.8rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.05rem 1.1rem;
  box-shadow: 0 10px 30px var(--shadow);
}

.stat-card.ember { border-top: 3px solid var(--oxblood); }
.stat-card.venous { border-top: 3px solid var(--venous); }
.stat-card.brass { border-top: 3px solid var(--brass); }

.stat-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat-val {
  font-size: 2rem;
  line-height: 1;
  color: var(--oxblood-deep);
  font-variant-numeric: lining-nums;
}
.stat-unit { font-size: 0.95rem; color: var(--muted); margin-left: 0.15rem; }
.stat-desc { margin-top: 0.45rem; font-size: 0.88rem; color: var(--muted); }

section { margin: 2.6rem 0; }
h2 {
  font-size: 1.55rem;
  line-height: 1.2;
  margin-bottom: 0.6rem;
}
h3 {
  font-size: 1.15rem;
  margin: 1.4rem 0 0.45rem;
}
.section-kicker {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass-dim);
  margin-bottom: 0.3rem;
}

p { margin: 0.7rem 0 0; max-width: var(--max); }
.lede-wide p, .prose p { max-width: var(--max); }

.instrument {
  background: var(--soot);
  color: #f4efe4;
  border-radius: 18px;
  padding: 1.1rem 1.1rem 1.25rem;
  box-shadow: 0 18px 50px rgba(28, 20, 16, 0.28);
  margin-top: 1rem;
}

.instrument h2, .instrument p { color: #f4efe4; }
.instrument p { color: #d9cbb6; max-width: none; }

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0.8rem 0;
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.preset {
  appearance: none;
  border: 1px solid #4a3b32;
  background: #2a211c;
  color: #f4efe4;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font: inherit;
  min-height: 44px;
}
.preset[aria-pressed="true"], .preset.active {
  background: var(--oxblood);
  border-color: var(--oxblood);
}

.kymo-wrap {
  position: relative;
  margin-top: 0.6rem;
  border-radius: 12px;
  overflow: hidden;
  background: #140f0c;
  border: 1px solid #3a2e26;
}
#kymo {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin-top: 0.85rem;
}
.hud-card {
  background: #2a211c;
  border: 1px solid #4a3b32;
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
}
.hud-title {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b89f88;
}
.hud-val {
  font-size: 1.25rem;
  margin-top: 0.15rem;
  font-variant-numeric: lining-nums tabular-nums;
}

.sliders {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.8rem;
  margin-top: 0.9rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
}
.sliders label { display: flex; flex-direction: column; gap: 0.35rem; color: #d9cbb6; }
.sliders input[type="range"] {
  accent-color: var(--oxblood);
  width: 100%;
  min-height: 32px;
}

.tetramer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin-top: 0.9rem;
  padding-bottom: 1.7rem;
}
.pocket {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--brass);
  background:
    radial-gradient(circle at 40% 35%, #3a2a22, #1c1410 70%);
  position: relative;
  display: grid;
  place-items: center;
}
.pocket .fill {
  width: 62%;
  height: 62%;
  border-radius: 50%;
  background: var(--oxblood);
  transform: scale(0);
  opacity: 0.2;
  transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease;
}
.pocket.bound .fill { transform: scale(1); background: var(--arterial); opacity: 1; }
.pocket span {
  position: absolute;
  bottom: -1.35rem;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: #b89f88;
}

.cargo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1rem;
}
.barrel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
}
.barrel h3 { margin-top: 0; }
.stack {
  height: 9rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  background: #efe4d0;
  margin: 0.6rem 0;
}
.stack i {
  display: block;
  width: 100%;
  transition: height 200ms ease;
}
.stack .bound { background: var(--oxblood); }
.stack .dissolved { background: var(--brass); }

.measure {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 1.1rem;
  box-shadow: 0 10px 30px var(--shadow);
}
.fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin: 0.9rem 0;
  font-family: var(--font-ui);
}
.fields label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }
.fields input, .fields select {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: #fffaf2;
  color: var(--ink);
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 1rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--oxblood);
  color: #f8eee4;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
}
.btn-primary:hover { background: var(--oxblood-deep); }
.btn-ghost {
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
}

.note {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: #fffaf2;
  border-left: 3px solid var(--brass);
  border-radius: 0 12px 12px 0;
  font-size: 0.95rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 1rem 0 0;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
th { font-family: var(--font-ui); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.mono { font-variant-numeric: tabular-nums lining-nums; }

.method {
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.92rem;
}
.method p { max-width: none; }
.method ul { margin: 0.6rem 0 0 1.1rem; }
.method li { margin: 0.25rem 0; }

footer.site-foot {
  margin-top: auto;
  padding: 1.2rem 1.25rem 2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
footer.site-foot a { color: var(--muted); }

.page-404 { min-height: 100vh; }
.error-card {
  max-width: 28rem;
  margin: 12vh auto;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 1.6rem;
  text-align: center;
}
.badge {
  font-family: var(--font-ui);
  letter-spacing: 0.14em;
  color: var(--oxblood);
}

@media (max-width: 800px) {
  html { font-size: 17px; }
  .stat-grid, .hud, .sliders, .cargo, .fields, .tetramer { grid-template-columns: 1fr 1fr; }
  .hud { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .container { width: min(var(--wide), calc(100% - 1.25rem)); }
  .stat-grid, .sliders, .cargo, .fields { grid-template-columns: 1fr; }
  .tetramer { grid-template-columns: repeat(4, 1fr); }
  h1 { font-size: 2rem; }
  .instrument { padding: 0.9rem; }
}

@media (min-width: 900px) {
  .hero-lead { font-size: 1.12rem; }
}
