:root {
  --ink: #000;
  --g1: #555;
  --g2: #8a8a8a;
  --hair: #e3e3e3;
  --bg: #fff;
  --accent: #ff4f00;
  --sans: 'Geist', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --gap: 24px;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 var(--gap) 32px;
}

/* ---------------------------------------------------------------- header */

.masthead {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  align-items: end;
  padding: 28px 0 16px;
  border-bottom: 1px solid var(--ink);
}
.masthead .title { grid-column: 1 / span 9; }
.masthead .head-actions { grid-column: 10 / span 3; justify-self: end; }

h1 {
  margin: 0;
  font-weight: 500;
  font-size: 56px;
  line-height: 1;
  letter-spacing: -0.035em;
}
.sub { margin: 8px 0 0; color: var(--g1); font-size: 15px; }

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

.layout {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
}
.plot-col { grid-column: 1 / span 7; grid-row: 1; min-width: 0; }
.loss-col { grid-column: 1 / span 7; grid-row: 2; min-width: 0; }
.side-col { grid-column: 8 / span 5; grid-row: 1 / span 2; min-width: 0; border-left: 1px solid var(--ink); padding-left: var(--gap); }

.col-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--hair);
  min-height: 40px;
}
.formula { font-family: var(--mono); font-size: 12px; color: var(--g1); }

.label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0;
}
.hint { text-transform: none; letter-spacing: 0; color: var(--g2); font-weight: 400; margin-left: 8px; }
.small { font-family: var(--mono); font-size: 11px; color: var(--g1); margin: 4px 0 0; }

.plot-wrap { position: relative; padding-top: 8px; }
#contour {
  display: block;
  width: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}
.loss-wrap { padding-top: 8px; }
#loss { display: block; width: 100%; }

.notes { border-top: 1px solid var(--ink); padding: 10px 0 16px; margin-top: 8px; }
.notes ul { margin: 6px 0 0; padding: 0; list-style: none; }
.notes li { padding: 3px 0 3px 18px; position: relative; color: var(--ink); max-width: 68ch; }
.notes li::before { content: '—'; position: absolute; left: 0; color: var(--g2); }

/* ---------------------------------------------------------------- side blocks */

.block { border-top: 1px solid var(--ink); padding: 10px 0 18px; }
.side-col .block:first-child { border-top: 0; }
.block > h2.label { margin-bottom: 8px; }

.readout { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--gap); }
.readout-cell { min-width: 0; }
.big {
  font-family: var(--mono);
  font-size: 52px;
  line-height: 1.05;
  font-weight: 400;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 6px;
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.btn {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  min-width: 72px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.btn:hover { background: #f2f2f2; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { background: #222; }
.btn:focus-visible, input:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

.field-grid { display: grid; grid-template-columns: 1fr 120px; gap: 0 16px; }
.field-grid.two { grid-template-columns: 1fr 1fr; }
.field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; min-width: 0; padding-top: 6px; }
.val { color: var(--ink); }

input[type='number'], input[type='text'] {
  font-family: var(--mono);
  font-size: 14px;
  min-height: 40px;
  width: 100%;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
input[type='number'] { -moz-appearance: textfield; }
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input.invalid { border-bottom-style: dashed; }

/* range: thin track, square thumb */
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6.5px;
  background: var(--ink);
  border: 0;
  border-radius: 0;
}
input[type='range']::-moz-range-track { height: 1px; background: var(--ink); border: 0; }
input[type='range']::-moz-range-thumb { width: 14px; height: 14px; background: var(--ink); border: 0; border-radius: 0; }

/* checkbox: hairline square */
input[type='checkbox'] {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  vertical-align: middle;
  cursor: pointer;
  display: inline-grid;
  place-content: center;
}
input[type='checkbox']:checked { background: var(--ink); }
input[type='checkbox']:checked::after { content: ''; width: 6px; height: 6px; background: var(--bg); }
input[type='checkbox']:disabled { border-color: var(--g2); cursor: default; }

.check-inline { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-family: var(--mono); font-size: 12px; cursor: pointer; }

/* surface selector */
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--ink); border-left: 1px solid var(--ink); }
.seg button {
  font-family: var(--mono);
  font-size: 12px;
  min-height: 44px;
  padding: 4px 8px;
  border: 0;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.seg button:hover { background: #f2f2f2; }
.seg button[aria-checked='true'] { background: var(--ink); color: var(--bg); }

.custom { margin-top: 8px; }
.custom input[type='text'] { font-size: 15px; }
.expr-error {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  margin: 8px 0 0;
  padding: 8px 0;
  border-top: 1px dashed var(--ink);
  border-bottom: 1px dashed var(--ink);
  white-space: pre-wrap;
  overflow-x: auto;
}

/* runs table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--gap)) 0 0; }
table.runs {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.runs th {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--g1);
  text-align: right;
  padding: 6px 6px;
  border-bottom: 1px solid var(--ink);
  white-space: nowrap;
}
.runs td {
  text-align: right;
  padding: 0 6px;
  height: 44px;
  border-bottom: 1px solid var(--hair);
  white-space: nowrap;
}
.runs th.mk, .runs td.mk { width: 34px; padding-left: 0; text-align: left; }
.runs th.on, .runs td.on { width: 40px; text-align: center; padding: 0; }
.runs th.nm, .runs td.nm { text-align: left; }
.runs th.st, .runs td.st { text-align: left; }
.runs tbody tr { cursor: pointer; }
.runs tbody tr:hover td { background: #f6f6f6; }
.runs tr.sel td { font-weight: 600; }
.runs tr.off td:not(.on) { color: var(--g2); }
.runs td.on label { display: inline-flex; width: 40px; height: 44px; align-items: center; justify-content: center; cursor: pointer; }
.runs svg { display: block; }

.rule { font-family: var(--mono); font-size: 12px; color: var(--g1); margin: 0 0 4px; }
.hp-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 0 16px; align-items: end; padding-top: 4px; }
.hp-row .label { grid-column: 1 / -1; padding-top: 6px; text-transform: none; letter-spacing: 0.02em; font-size: 12px; }
#reset-defaults { margin-top: 12px; }

.foot { border-top: 1px solid var(--ink); margin-top: 16px; padding-top: 10px; }
.foot p { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--g1); max-width: 110ch; }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  :root { --gap: 16px; }
  .masthead .title { grid-column: 1 / -1; }
  .masthead .head-actions { grid-column: 1 / -1; justify-self: start; margin-top: 12px; }
  h1 { font-size: 44px; }
  .plot-col, .loss-col, .side-col { grid-column: 1 / -1; grid-row: auto; }
  .plot-col { order: 1; }
  .side-col { order: 2; border-left: 0; padding-left: 0; }
  .loss-col { order: 3; }
  .side-col .block:first-child { border-top: 1px solid var(--ink); }
  .big { font-size: 40px; }
  .seg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 16px stops iOS Safari from zooming into focused inputs */
  input[type='number'], input[type='text'], .custom input[type='text'] { font-size: 16px; }
  .table-wrap { margin-right: calc(-1 * var(--gap)); }
}
