/* Matches the personal site (../../index.html): Instrument Serif + IBM Plex,
   amber-on-ink, light / dark aware via tokens, Canvas waveform in the masthead. */
:root {
  --ground: #e7e9ec;
  --panel: #f1f2f4;
  --sunk: #dee1e5;
  --ink: #131820;
  --ink-soft: #48515e;
  --ink-faint: #7b8391;
  --line: #c6cbd3;
  --amber: #b4651a;
  --amber-text: #9a560f;
  --live: #2f8a5c;
  --loss: #b23b32;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0a0e14;
    --panel: #111722;
    --sunk: #0b1119;
    --ink: #dfe4ec;
    --ink-soft: #8b95a3;
    --ink-faint: #616b79;
    --line: #222b38;
    --amber: #e6972f;
    --amber-text: #eaa64d;
    --live: #43ac7c;
    --loss: #e0655a;
  }
}
:root[data-theme="dark"] {
  --ground: #0a0e14;
  --panel: #111722;
  --sunk: #0b1119;
  --ink: #dfe4ec;
  --ink-soft: #8b95a3;
  --ink-faint: #616b79;
  --line: #222b38;
  --amber: #e6972f;
  --amber-text: #eaa64d;
  --live: #43ac7c;
  --loss: #e0655a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  position: relative;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- toolbar ---------- */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 28px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--ground) 86%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s;
}
.toolbar.stuck { border-bottom-color: var(--line); }
.toolbar .back {
  text-decoration: none;
  color: var(--ink-soft);
  transition: color 0.15s;
}
.toolbar .back:hover { color: var(--amber-text); }
.toolbar .back span { color: var(--ink-faint); }
.toolbar button {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--ink-faint);
  background: none;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.toolbar button:hover { color: var(--amber-text); border-color: var(--amber); }
.toolbar .back:focus-visible,
.toolbar button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- background waveform ---------- */
#bg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 520px;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 30%, transparent 88%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 30%, transparent 88%);
}

main {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 28px 110px;
}

/* ---------- masthead ---------- */
.masthead {
  position: relative;
  padding: 124px 0 52px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 40px;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 46px 46px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--amber-text);
  margin: 0 0 20px;
}
.eyebrow .sep { color: var(--ink-faint); margin: 0 9px; }

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(36px, 6.5vw, 68px);
  line-height: 1.05;
  letter-spacing: 0.005em;
  margin: 0 0 22px;
  text-wrap: balance;
}

.lede {
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 0 26px;
}

.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}
.badge.warn { border-color: color-mix(in srgb, var(--loss) 42%, var(--line)); color: var(--loss); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 28px;
  margin-bottom: 18px;
}

h2 {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

p { margin: 0 0 14px; }
.panel p:last-child { margin-bottom: 0; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
}

.rules { margin: 0 0 16px; padding-left: 20px; }
.rules li { margin-bottom: 7px; }

.muted { color: var(--ink-soft); font-size: 14.5px; }

/* ---------- run control ---------- */
.run-btn {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ground);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 12px 24px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.06s;
}
.run-btn:hover { background: var(--amber); border-color: var(--amber); color: #fff; }
.run-btn:active { transform: translateY(1px); }
.run-btn:disabled { cursor: default; opacity: 0.6; }
.run-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.run-btn.loading .run-label::after {
  content: "";
  display: inline-block;
  width: 11px; height: 11px;
  margin-left: 10px;
  vertical-align: -1px;
  border: 2px solid color-mix(in srgb, var(--ground) 40%, transparent);
  border-top-color: var(--ground);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.run-note {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
}

/* ---------- results ---------- */
.results { animation: fade 0.5s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chart-frame {
  background: var(--panel);
}
.chart { width: 100%; height: 600px; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: right;
  padding: 9px 13px;
  border-bottom: 1px solid var(--line);
}
th:first-child, td:first-child { text-align: left; font-family: var(--sans); }
thead th {
  color: var(--ink-faint);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom-color: var(--ink);
}
tbody tr:last-child td { border-bottom: none; }
.metrics tbody tr:hover td { background: var(--sunk); }

.pos { color: var(--live); }
.neg { color: var(--loss); }
.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 2px;
  border: 1px solid currentColor;
  letter-spacing: 0.04em;
}
.tag-win { color: var(--live); }
.tag-loss { color: var(--loss); }
.tag-open { color: var(--amber-text); }

.verdict {
  margin: 18px 0 0;
  padding: 15px 18px;
  background: var(--sunk);
  border-left: 3px solid var(--amber);
  border-radius: 3px;
  font-size: 14.5px;
  color: var(--ink);
}

footer {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 13px;
  max-width: 66ch;
}
footer a { color: var(--amber-text); }

@media (max-width: 620px) {
  main { padding: 0 18px 80px; }
  .toolbar { padding: 11px 18px; }
  .masthead { padding-top: 84px; }
  .panel { padding: 20px; }
  .chart { height: 480px; }
}

@media (prefers-reduced-motion: reduce) {
  .results { animation: none; }
  .run-btn.loading .run-label::after { animation: none; }
  #bg { display: none; }
}
