/* ═══════════════════════════════════════════════════════════════
   KELLY — the geometry of growth
   a bohemian-minimalist system: warm paper, ink, hairlines,
   terracotta / sage / ochre, Fraunces + Karla, film grain.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --paper: #F4EEE2;
  --paper-2: #FAF6ED;
  --card: #FCF9F2;
  --ink: #322A20;
  --ink-soft: #5C5040;
  --muted: #8B7D68;
  --line: #E6DDCB;
  --line-strong: #D5C8B0;
  --terra: #C06B45;
  --sage: #7D8B6A;
  --ochre: #C99A3F;
  --blue: #7B93A4;
  --plum: #8D5F72;
  --sand: #C8B18E;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Karla', 'Helvetica Neue', Arial, sans-serif;
  --radius: 22px;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* film grain — a whisper of turbulence over the whole page */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2000;
  opacity: 0.045;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wrap { max-width: 1220px; margin: 0 auto; padding: 0 34px; }

/* ── masthead ─────────────────────────────────────────────────── */
.masthead {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, white);
}
.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding-top: 26px;
  padding-bottom: 0;
  flex-wrap: wrap;
}
.wordmark {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 30px;
  letter-spacing: 0.01em;
}
.wordmark .dot { color: var(--terra); margin: 0 10px; font-weight: 400; }
.wordmark em {
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.tabs { display: flex; gap: 30px; }
.tabs button {
  appearance: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 2px 16px;
  border-bottom: 2px solid transparent;
  transition: color .25s ease, border-color .25s ease;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--terra); }

/* ── layout ───────────────────────────────────────────────────── */
main { padding: 38px 0 20px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .45s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.lab-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 26px;
  align-items: start;
}
.stack { display: flex; flex-direction: column; gap: 26px; min-width: 0; }
.duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px;
  min-width: 0;
}
.duo-uneven { grid-template-columns: 1.15fr 1fr; }

/* ── cards ────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  min-width: 0;
}
.card h3 {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.caption {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: 13.5px;
  color: var(--muted);
  margin: -6px 0 14px;
  max-width: 62ch;
}

/* ── controls ─────────────────────────────────────────────────── */
.controls .card h3, aside.controls h3 {
  margin: 20px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
aside.controls > h3:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.ctl { display: block; margin: 13px 0; }
.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.ctl-head output {
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--terra);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}
.ctl.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ctl.inline .ctl-head { margin: 0; }
.ctl input[type="number"] {
  width: 130px;
  padding: 8px 10px;
  font: 500 14px var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
}
.ctl input[type="number"]:focus { border-color: var(--terra); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line-strong);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--terra);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1.5px var(--terra);
  margin-top: -6.5px;
  transition: transform .15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-track {
  height: 2px;
  background: var(--line-strong);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--terra);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1.5px var(--terra);
}

/* segmented control */
.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 10px;
}
.seg button {
  appearance: none;
  border: none;
  background: transparent;
  padding: 7px 16px;
  font: 600 11px var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s ease;
}
.seg button.active { background: var(--ink); color: var(--paper); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 4px; }
.chips button {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 13px;
  font: 500 11.5px var(--sans);
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .18s ease;
}
.chips button:hover { border-color: var(--terra); color: var(--terra); }

.note {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 16px;
}
.note b { color: var(--ink); }
.note.dim { color: var(--muted); }
.note.center { text-align: center; margin: 4px auto 22px; max-width: 88ch; }
.note em { font-family: var(--serif); }

/* wide market controls */
.controls-wide {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr;
  gap: 34px;
}
.controls-wide fieldset { border: none; min-width: 0; }
.controls-wide legend {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  margin-bottom: 4px;
}
.btn-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 18px;
  font: 600 11.5px var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .2s ease;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.run-id { font-family: var(--serif); font-style: italic; font-size: 12.5px; color: var(--muted); }
.toggle-line { margin-top: 10px; }

.toggle { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.toggle input { accent-color: var(--terra); width: 13px; height: 13px; cursor: pointer; }
.toggle label { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); cursor: pointer; }

/* ── charts ───────────────────────────────────────────────────── */
.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; width: 100%; height: 290px; }
#cv-growth { height: 320px; }
#cv-hist { height: 230px; }
.tip {
  display: none;
  position: absolute;
  z-index: 30;
  pointer-events: none;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 9px 12px;
  min-width: 150px;
  box-shadow: 0 8px 22px rgba(50, 42, 32, 0.10);
  font-size: 11.5px;
}
.tip-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 1.5px 0;
  color: var(--muted);
}
.tip-row b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: -6px 0 10px; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: 0.05em; color: var(--muted); }
.lg i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ── stats tiles ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px 22px;
}
.tile { border-top: 1px solid var(--line); padding-top: 10px; }
.t-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.t-value {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 23px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.005em;
}
.t-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.warn { margin-top: 16px; font-size: 12.5px; color: var(--terra); line-height: 1.7; }
.warn:empty { display: none; }

/* ── the tape ─────────────────────────────────────────────────── */
.tape {
  max-height: 264px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.tape-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.tape-table th {
  position: sticky; top: 0;
  background: var(--card);
  text-align: left;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 6px 8px;
  border-bottom: 1px solid var(--line);
}
.tape-table td { padding: 5px 6px; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); color: var(--ink-soft); }
.tape-table tr:last-child td { border-bottom: none; }
.tape-table .buy { color: var(--terra); font-weight: 600; }
.tape-table .sell { color: var(--blue); font-weight: 600; }
.tape-table .win { color: var(--sage); font-weight: 600; }
.tape-table .loss { color: var(--terra); font-weight: 600; }
.tape-table .pass { color: var(--muted); font-style: italic; }
.tape-table tr.noedge td { opacity: 0.5; }

/* ── field notes ──────────────────────────────────────────────── */
.prose {
  max-width: 720px;
  margin: 0 auto;
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--ink-soft);
  padding: 10px 0 40px;
}
.prose p { margin-bottom: 1.1em; }
.prose .first {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 21px;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 1.4em;
}
.prose .first::first-letter {
  font-family: var(--serif);
  font-size: 64px;
  float: left;
  line-height: 0.85;
  padding: 6px 12px 0 0;
  color: var(--terra);
  font-weight: 400;
}
.prose h2 {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2.2em 0 0.8em;
  padding-top: 1.6em;
  border-top: 1px solid var(--line);
}
.prose em { font-family: var(--serif); }
.prose .formula {
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  text-align: center;
  color: var(--ink);
  padding: 14px 0;
  margin: 0.4em 0 1em;
}
.prose ul { margin: 0 0 1.2em 1.2em; }
.prose li { margin-bottom: 0.5em; }
.prose .terra { color: var(--terra); }
.prose .refs { font-size: 13px; font-style: italic; color: var(--muted); }

/* ── colophon ─────────────────────────────────────────────────── */
.colophon {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--muted);
  padding-top: 26px;
  padding-bottom: 40px;
  border-top: 1px solid var(--line);
  margin-top: 34px;
}
.colophon .hublink { color: var(--terra); }
.colophon .hublink:hover { color: var(--ink); }
.colophon .sep { margin: 0 10px; }

/* ── the duel ─────────────────────────────────────────────────── */
.stage-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.stage-bank .stage-money {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 40px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.005em;
  line-height: 1.1;
}
.stage-bank .stage-money.bust { color: var(--terra); }
.stage-mid { text-align: right; min-width: 220px; }
.stage-next { font-size: 13px; color: var(--ink-soft); }
.stage-next b { color: var(--ink); }
.stage-next em { color: var(--muted); font-family: var(--serif); }
.stage-last { font-size: 13px; margin-top: 4px; color: var(--ink-soft); }
.stage-last .win { color: var(--sage); font-weight: 600; }
.stage-last .loss { color: var(--terra); font-weight: 600; }
.stage-last .dim { color: var(--muted); font-style: italic; }
.stage-last b { font-variant-numeric: tabular-nums; }

.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--terra); border-color: var(--terra); }

.strip { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 14px; min-height: 10px; }
.strip i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.strip i.w { background: var(--sage); }
.strip i.l { background: color-mix(in srgb, var(--terra) 55%, var(--paper)); }

.chips.presets { margin: 0 0 14px; }
.chips.presets button { font-size: 11px; padding: 4px 11px; color: var(--muted); }
.chips.presets button:hover { color: var(--terra); }

/* ── responsive ───────────────────────────────────────────────── */
@media (max-width: 1020px) {
  .lab-grid { grid-template-columns: 1fr; }
  .duo, .duo-uneven { grid-template-columns: 1fr; }
  .controls-wide { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .wrap { padding: 0 18px; }
  .masthead-row { flex-direction: column; align-items: flex-start; }
  .stat-grid { grid-template-columns: 1fr; }
}
