:root {
  --ink: #0a0a0b;
  --panel: #111113;
  --panel2: #17171a;
  --line: #26262b;
  --text: #f4f4f2;
  --mute: #8d8d95;
  --red: #e5322d;
  --red-d: #b8241f;
  --r: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--text); text-decoration-color: var(--red); text-underline-offset: 3px; }
a:hover { color: var(--red); }
.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }

.top { border-bottom: 1px solid var(--line); background: rgba(10,10,11,.85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; text-decoration: none; }
.mark { width: 16px; height: 16px; border-radius: 50% 50% 50% 0; background: var(--red); transform: rotate(-45deg); }
.gh { font-size: 14px; color: var(--mute); text-decoration: none; padding: 8px 0; }

.hero { padding: 40px 0 24px; max-width: 760px; }
.hero h1 { font-size: clamp(30px, 7vw, 54px); line-height: 1.04; margin: 0 0 16px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--red); }
.hero p { color: var(--mute); margin: 0; font-size: 16px; }

.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; padding-bottom: 32px; }
.stage { display: grid; gap: 16px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; }
.controls { position: sticky; top: 72px; }
.ph { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--mute); margin: 0 0 12px; font-weight: 600; }
.ph h2 { margin: 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--mute); margin: 22px 0 10px; padding-top: 16px; border-top: 1px solid var(--line); font-weight: 600; }
.legend { font-size: 12px; color: var(--mute); display: inline-flex; gap: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; background: var(--red); }
.legend i.d { background: repeating-linear-gradient(90deg, #c9c9cf 0 4px, transparent 4px 7px); }

.field { margin-bottom: 14px; }
.field label, .lab { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 6px; }
output { font-variant-numeric: tabular-nums; color: var(--text); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; text-align: right; }
.grp[hidden] { display: none; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--line); border-radius: 4px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--line); border-radius: 4px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--text); border: 3px solid var(--red); margin-top: -8px; cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 3px solid var(--red); cursor: pointer; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.seg { display: flex; gap: 4px; background: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; min-height: 40px; padding: 6px 4px; border: 0; border-radius: 9px; background: transparent; color: var(--mute); font: inherit; font-size: 13px; cursor: pointer; }
.seg button[aria-checked=true] { background: var(--red); color: #fff; font-weight: 600; }
.seg.small { max-width: 220px; margin-bottom: 14px; }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--red); background: var(--red); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--red-d); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--mute); }
.chk { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--mute); min-height: 44px; }
.chk input { width: 18px; height: 18px; accent-color: var(--red); }
.note { min-height: 1.4em; margin: 6px 0 0; font-size: 13px; color: var(--mute); }
.note.bad { color: var(--red); }

canvas { width: 100%; height: 300px; display: block; }

.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 16px; margin: 12px 0 0; }
.kv dt, .kv dd { margin: 0; padding: 8px 0; border-top: 1px solid var(--line); }
.kv dt { color: var(--mute); font-size: 14px; }
.kv dd { text-align: right; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv dd.hl { color: var(--red); font-weight: 600; }
#derived { margin-top: 0; }

.trade { display: grid; gap: 6px; }
.trade label { font-size: 14px; color: var(--mute); }
.trade input { width: 100%; min-height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--ink); color: var(--text); font: 18px ui-monospace, Menlo, Consolas, monospace; }
.trade input:focus { border-color: var(--red); outline: none; }

.foot { padding: 28px 16px 40px; color: var(--mute); font-size: 13px; border-top: 1px solid var(--line); }
.foot p { margin: 4px 0; }

@media (max-width: 920px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .controls { position: static; }
}
@media (max-width: 420px) {
  .panel { padding: 14px; }
  canvas { height: 240px; }
  .seg button { font-size: 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .seg button { transition: background .15s, color .15s, border-color .15s; }
}
