/* Kelly criterion simulator (/tools/kelly). Public page, built on tokens.css,
   components.css and public.css. Prose first; controls sit on the paper with
   rules between them rather than inside boxes. */

.kelly {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(48px, 7vw, 88px) var(--m) clamp(64px, 8vw, 112px);
}

.kelly p,
.kelly li {
  font: 400 17px/1.55 var(--sans);
  color: var(--ink-2);
}

.kelly strong { font-weight: 600; color: var(--ink); }

.kelly-head h1 {
  max-width: 20ch;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(36px, 4.4vw, 60px);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.kelly .kelly-lede {
  max-width: 58ch;
  margin-top: 20px;
  font: 400 clamp(18px, 1.5vw, 21px)/1.45 var(--sans);
  color: var(--ink-2);
}

.kelly-intro,
.kelly-lessons {
  max-width: 68ch;
  margin-top: 40px;
}

.kelly-intro p + p,
.kelly-lessons p + p { margin-top: 16px; }

.kelly-sec {
  margin-top: clamp(48px, 6vw, 72px);
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.kelly-lessons h2,
.ksec-h h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(28px, 3vw, 38px);
  line-height: 1.12;
  letter-spacing: -0.02em;
}

.ksec-h {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.pill.step {
  background: var(--paper-2);
  color: var(--ink-3);
}

.kelly .sec-lede {
  max-width: 68ch;
  margin-top: 12px;
}

.kelly-lessons h2 { margin-bottom: 16px; }

.kelly .kelly-note {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- Setup ---------- */

.setup {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: clamp(28px, 4vw, 56px);
  align-items: start;
  margin-top: 20px;
}

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px 28px;
  padding: 20px 0;
  border-bottom: 1px solid var(--rule);
}

.field:first-child { padding-top: 4px; }

.fields-mc {
  max-width: 880px;
  margin-top: 12px;
}

.field-txt label,
.field-txt .lbl,
.sub label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font: 600 16px/1.3 var(--sans);
  color: var(--ink);
}

.kelly .field-txt p {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

.val {
  font: 500 16px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--bronze-f);
  white-space: nowrap;
}

.field-ctl {
  display: grid;
  align-content: start;
  gap: 8px;
}

.money {
  display: flex;
  align-items: center;
  height: 44px;
  max-width: 260px;
  padding: 0 12px;
  background: var(--stone);
  border: 1px solid var(--control);
  border-radius: var(--r);
  font: 500 17px/1 var(--mono);
  color: var(--muted);
}

.money:focus-within { outline: 3px solid var(--gold); outline-offset: 1px; }

.money input,
.num-in {
  width: 100%;
  border: 0;
  background: transparent;
  font: 500 17px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  padding: 0 0 0 6px;
}

.money input:focus { outline: none; }

.num-in {
  height: 44px;
  max-width: 160px;
  padding: 0 12px;
  background: var(--stone);
  border: 1px solid var(--control);
  border-radius: var(--r);
}

.money.bad,
.num-in.bad { border-color: var(--down); }

.kelly .err {
  font-size: 14px;
  line-height: 1.4;
  color: var(--down-ink);
}

.kelly .hint {
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  margin: 6px 0 0;
  accent-color: var(--bronze);
}

.ticks {
  display: flex;
  justify-content: space-between;
  font: 500 12px/1 var(--sans);
  color: var(--muted);
}

/* Segmented pills */

.kseg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.kseg-btn,
.pill-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--control);
  border-radius: 999px;
  background: transparent;
  font: 600 14px/1 var(--sans);
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}

.pill-btn {
  height: 28px;
  padding: 0 12px;
  font-size: 13px;
}

.kseg-btn:hover,
.pill-btn:hover { border-color: var(--ink-3); }

.kseg-btn[aria-checked="true"],
.pill-btn.on {
  background: var(--ink);
  border-color: var(--ink);
  color: #f3eee4;
}

.sub {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.sub[hidden] { display: none; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.marker-track {
  position: relative;
  height: 18px;
  margin: 0 8px;
}

.marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 8px;
  background: var(--up);
  transform: translateX(-1px);
}

.marker-lbl {
  position: absolute;
  top: 8px;
  font: 600 11px/1 var(--sans);
  color: var(--up);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Readout */

.readout {
  position: sticky;
  top: calc(var(--bar-h) + 16px);
  display: grid;
  gap: 12px;
  padding-left: clamp(0px, 3vw, 32px);
  border-left: 1px solid var(--line);
}

.kelly .readout-k {
  font: 600 13px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bronze-f);
}

.kelly .readout p:not(.readout-k) {
  font-size: 16px;
}

.readout b {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.readout b.up { color: var(--up); }
.readout b.down { color: var(--down); }

.curve { margin: 8px 0 0; }

.curve canvas,
.chart-fig canvas {
  display: block;
  width: 100%;
}

.curve figcaption,
.chart-fig figcaption {
  margin-top: 8px;
  font: 400 13px/1.45 var(--sans);
  color: var(--muted);
}

/* ---------- Play ---------- */

.play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: clamp(24px, 4vw, 56px);
  margin-top: 24px;
  align-items: start;
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.kelly .btn {
  height: 40px;
  padding: 0 18px;
  font-size: 15px;
}

.kelly .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.kelly .btn-ghost {
  background: transparent;
  border: 1px solid var(--control);
  color: var(--ink);
}

.kelly .btn-ghost:hover { border-color: var(--ink-3); background: transparent; }

.kelly .btn-ghost[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #f3eee4;
}

.speed {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  max-width: 360px;
  margin: 18px 0 10px;
  font: 600 15px/1 var(--sans);
}

.speed input { margin: 0; }

.kelly .bal-k {
  font: 600 13px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.kelly .bal {
  margin-top: 8px;
  font: 500 clamp(40px, 5vw, 60px)/1 var(--serif);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.kelly .bal-d {
  margin-top: 8px;
  font: 500 16px/1.3 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.kelly .bal-d.up { color: var(--up); }
.kelly .bal-d.down { color: var(--down); }

.kelly .last {
  margin-top: 14px;
  font-size: 15px;
}

.kstats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.kstats .pill {
  height: 26px;
  padding: 0 12px;
  gap: 6px;
  background: var(--stone);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

.kstats .pill b {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.kelly .banner {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 15px;
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.kelly .banner.down { background: var(--down-bg); color: var(--down-ink); }
.kelly .banner.up { background: var(--up-bg); color: var(--up-ink); }

.chart-fig { margin: 28px 0 0; }

/* ---------- Monte Carlo ---------- */

.mc-out { margin-top: 24px; }
.mc-out[hidden] { display: none; }

.kelly .mc-read {
  max-width: 70ch;
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink);
}

.mc-read b { font-weight: 600; font-variant-numeric: tabular-nums; }

.tbl-wrap {
  margin-top: 28px;
  overflow-x: auto;
}

.mc-tbl {
  width: 100%;
  border-collapse: collapse;
  font: 400 15px/1.4 var(--sans);
  font-variant-numeric: tabular-nums;
}

.mc-tbl th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ink);
  font: 600 13px/1.3 var(--sans);
  color: var(--muted);
  text-align: left;
  vertical-align: bottom;
}

.mc-tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

.mc-tbl th.num,
.mc-tbl td.num { text-align: right; }

.mc-tbl tr.mine td { background: var(--stone); font-weight: 600; }
.mc-tbl tr.mine td:first-child { border-radius: var(--r) 0 0 var(--r); }
.mc-tbl tr.mine td:last-child { border-radius: 0 var(--r) var(--r) 0; }

.mc-tbl td .up { color: var(--up); }
.mc-tbl td .down { color: var(--down); }

.mc-out > .hint { margin-top: 12px; max-width: 80ch; }

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  .setup,
  .play { grid-template-columns: 1fr; }
  .readout {
    position: static;
    padding-left: 0;
    padding-top: 20px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .field { grid-template-columns: 1fr; }
}
