:root {
  --bg: #f6f7f9;
  --card: #fff;
  --ink: #1d2430;
  --muted: #6b7484;
  --line: #d9dee6;
  --accent: #2f7d4f;
  --canvas: #fbfcfd;
  --button: #fff;
  --bar: rgba(47, 125, 79, 0.16);
  --chart-before: #8a94a6;
  --chart-raw: #b5651d;
  --chart-after: #2f7d4f;
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --card: #161a20;
  --ink: #e6e9ee;
  --muted: #9aa4b2;
  --line: #262c35;
  --accent: #46a06a;
  --canvas: #11151a;
  --button: #1c222a;
  --bar: rgba(70, 160, 106, 0.3);
  --chart-before: #7f8b9c;
  --chart-raw: #d98650;
  --chart-after: #4fbf7f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
.wrap { max-width: 980px; margin: 0 auto; padding: 0 20px; }
header { background: var(--card); border-bottom: 1px solid var(--line); padding: 28px 0 20px; }
h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; }
.sub { margin: 0; color: var(--muted); max-width: 70ch; }
.bar { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.pill {
  font-size: 12px; padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 999px; color: var(--muted); background: var(--bg);
}
.pill.lang, .pill.theme { cursor: pointer; user-select: none; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin: 20px 0;
}
.file { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type="file"] { font: inherit; color: var(--ink); }
button {
  font: inherit; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--button); color: var(--ink); cursor: pointer; margin-left: 10px;
}
button:disabled { opacity: 0.45; cursor: default; }
#run:not(:disabled) { background: var(--accent); color: #fff; border-color: var(--accent); }
button:last-child { margin-left: 0; }
.status { color: var(--muted); font-size: 13px; margin: 12px 0 0; min-height: 18px; }
.stats { display: flex; gap: 26px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: 12px; color: var(--muted); }
.stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
canvas { width: 100%; display: block; background: var(--canvas); border-radius: 8px; }
#spectrum { height: 260px; }
#signal { height: 200px; }
.note { color: var(--muted); font-size: 13px; padding-bottom: 30px; }
.note a { color: var(--accent); }
.note.small { font-size: 12px; padding-bottom: 8px; }

/* profiler */
.profile { margin-top: 18px; }
.profile summary { cursor: pointer; color: var(--ink); opacity: .8; }
.profile table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.profile th, .profile td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--line); }
.profile th:nth-child(2), .profile td:nth-child(2),
.profile th:nth-child(3), .profile td:nth-child(3) { text-align: right; }
/* each row is its own bar: the background fills as much as the stage took */
.profile tbody tr {
  background: linear-gradient(
    90deg,
    var(--bar) 0 var(--share, 0%),
    transparent var(--share, 0%)
  );
}
.profile tr.sum td { font-weight: 600; border-top: 1px solid var(--line); }
.muted { opacity: .7; font-size: 13px; margin: 6px 0 0; }

.picker { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.picker select, .picker input[type="url"] {
  font: inherit; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--button); color: var(--ink);
}
.picker select { min-width: 320px; }
.picker input[type="url"] { min-width: 320px; flex: 1; }
.picker button { margin-left: 0; }

.atten { font-variant-numeric: tabular-nums; margin: 14px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }

.sub.small { font-size: 13px; margin-top: 10px; }
.sub a, .hint a { color: var(--accent); }

/* chart legends */
.legend { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px; font-size: 12px; color: var(--muted); }
.legend .swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .swatch.after { background: var(--chart-after); margin-left: 10px; }
.legend.spectrum .swatch.before { background: var(--chart-raw); }
.legend.signal .swatch.before { background: var(--chart-before); }

/* mode radios */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.modes { border: 0; margin: 0 0 8px; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; }
.modes label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.modes input { accent-color: var(--accent); }

/* the chart handles its own gestures; without this the page zooms instead */
canvas { touch-action: none; }

/* phones: keep the run button reachable after choosing a file */
@media (max-width: 700px) {
  #run { position: sticky; bottom: 10px; z-index: 5; }
  .picker select, .picker input[type="url"] { min-width: 0; width: 100%; }
  .modes { gap: 10px; }
  .modes label { font-size: 13px; }
}

@media (max-width: 700px) {
  .wrap { padding: 0 8px; }
  .card { padding: 10px; margin: 12px 0; }
  h1 { font-size: 21px; }
}

/* mode selector as a segmented control: the chosen option is filled */
.modes { gap: 8px; }
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes label {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; background: var(--button);
  transition: background .15s, color .15s, border-color .15s;
}
.modes label.checked {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.modes label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* advanced filter settings */
.advanced { margin: 4px 0 10px; font-size: 14px; }
.advanced summary { cursor: pointer; color: var(--muted); }
.advanced .grid { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.advanced label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.advanced input {
  font: inherit; padding: 6px 8px; width: 120px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--button); color: var(--ink);
}
