/* Dark first. Light theme is opt in through data-theme="light". */
:root {
  --bg: #0d1117;
  --bg-glow: #182029;
  --panel: #161b22;
  --panel2: #1c232c;
  --line: #2a3441;
  --ink: #e6edf3;
  --muted: #8b98a5;
  --swim: #3fb6ff;
  --swim-ink: #06202e;
  --row: #f7524a;
  --row-ink: #2b0705;
  --accent: var(--swim);
  --accent-ink: var(--swim-ink);
  --good: #39d98a;
  --warn: #f5b74e;
  --bad: #ff7b72;
  --zone: rgba(255, 255, 255, 0.045);
  --radius: 14px;
  --mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5f8;
  --bg-glow: #e6ecf3;
  --panel: #ffffff;
  --panel2: #f0f3f7;
  --line: #d6dde6;
  --ink: #131a22;
  --muted: #5d6b79;
  --swim: #0b6fa4;
  --swim-ink: #ffffff;
  --row: #c93a32;
  --row-ink: #ffffff;
  --good: #0a8f4d;
  --warn: #a86300;
  --bad: #b3261e;
  --zone: rgba(0, 0, 0, 0.05);
  color-scheme: light;
}
:root[data-sport="row"] { --accent: var(--row); --accent-ink: var(--row-ink); }

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-glow) 0%, var(--bg) 60%);
  color: var(--ink); font-family: var(--sans); line-height: 1.45; min-height: 100vh;
  padding: 22px 16px 60px;
}
a { color: var(--accent); }
.wrap { max-width: 1080px; margin: 0 auto; }
.grow { flex: 1; }

/* header */
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.brand { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; text-decoration: none; color: var(--ink); }
.brand-accent { color: var(--accent); }
.tag { color: var(--muted); font-size: 14px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  border-radius: 999px; width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--muted); }

/* segmented control */
.seg { display: flex; gap: 4px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg > a, .seg > label, .seg > button {
  flex: 1; text-align: center; background: transparent; border: none; color: var(--muted);
  font-family: var(--sans); font-size: 13px; padding: 8px 12px; border-radius: 7px; cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none;
}
.seg > a:hover, .seg > label:hover, .seg > button:hover { color: var(--ink); }
.seg > a[aria-selected="true"], .seg > label.on, .seg > button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg.sport { flex: 0 0 auto; }
.seg.sport > a { min-width: 72px; }

/* tool tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 999px; font-size: 13.5px;
  border: 1px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); border-color: var(--line); }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600; }

/* layout */
.grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.grid > * { min-width: 0; }
@media (max-width: 820px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 18px; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); margin: 0 0 14px; font-weight: 600; }
.card h2 .sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.intro h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.3px; }
.intro p { color: var(--muted); margin: 0 0 16px; font-size: 14.5px; }

/* inputs */
.field { margin-top: 14px; }
.field:first-child { margin-top: 0; }
.field > label, .field > .lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field > label b, .field > .lbl b { color: var(--ink); font-family: var(--mono); font-weight: 500; }
input[type="text"], input[type="number"], select {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
  font-family: var(--mono); font-size: 20px; padding: 10px 12px; border-radius: 10px; outline: none;
}
select { font-family: var(--sans); font-size: 14px; padding: 9px 10px; }
input:focus, select:focus { border-color: var(--accent); }
input.bad { border-color: var(--bad); }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.hint code { font-family: var(--mono); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.presets button {
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  font-family: var(--mono); font-size: 12.5px; padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.presets button:hover { color: var(--ink); border-color: var(--muted); }
.presets button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 6px; }
.range-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.field[hidden] { display: none; }

/* hero stats */
.hero { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { flex: 1; min-width: 130px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 28px; margin-top: 4px; letter-spacing: -0.5px; line-height: 1.15; }
.stat.big .v { font-size: 34px; color: var(--accent); }
.stat .u { font-size: 12px; color: var(--muted); font-family: var(--sans); margin-left: 4px; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; }
td:first-child, th:first-child { text-align: left; }
tbody tr td:first-child { font-weight: 600; }
td.n, th.n { font-family: var(--mono); }
td.t { text-align: left; font-weight: 400; color: var(--muted); white-space: normal; min-width: 180px; }
tr.hl td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
.delta-neg { color: var(--good); } .delta-pos { color: var(--warn); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; vertical-align: middle; background: var(--muted); }
.dot.first { background: var(--swim); } .dot.last { background: var(--row); }
:root[data-sport="swim"] .dot.first { background: var(--row); } :root[data-sport="swim"] .dot.last { background: var(--swim); }
details { margin-top: 10px; }
summary { cursor: pointer; font-size: 13px; color: var(--muted); }
details table { margin-top: 12px; }

/* messages and actions */
.msg { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; border: 1px solid var(--line); background: var(--panel2); margin-bottom: 14px; }
.msg.err { border-color: var(--bad); color: var(--bad); }
.msg.warn { border-color: var(--warn); color: var(--warn); }
.msg.hint { color: var(--muted); }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; line-height: 1.55; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions a, .actions button {
  font: inherit; font-size: 13px; padding: 8px 12px; border-radius: 8px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
}
.actions a:hover, .actions button:hover { border-color: var(--accent); }
.actions a.primary, .actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.actions .done { color: var(--good); font-size: 13px; align-self: center; }

/* chart */
.chart { position: relative; }
.pc { width: 100%; height: auto; display: block; }
.pc-zone { fill: var(--zone); }
.pc-grid { stroke: var(--line); stroke-width: 1; }
.pc-tick { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.pc-target { stroke: var(--muted); stroke-width: 1.4; stroke-dasharray: 5 4; opacity: 0.9; }
.pc-target-label { fill: var(--ink); }
.pc-line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.pc-xh { stroke: var(--ink); stroke-width: 1; opacity: 0.5; pointer-events: none; }
.pc-dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2; pointer-events: none; }
.pc-hit { cursor: crosshair; }
.tip {
  position: absolute; top: 8px; transform: translateX(-50%); pointer-events: none;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; color: var(--muted); white-space: nowrap; display: none;
}
.tip b { color: var(--ink); font-family: var(--mono); font-size: 14px; font-weight: 600; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.line { background: var(--accent); height: 3px; border-radius: 2px; }
.sw.target { background: var(--muted); height: 2px; border-radius: 1px; }
.sw.zone { background: var(--zone); border: 1px solid var(--line); }

/* footer */
.foot { color: var(--muted); font-size: 12px; margin-top: 30px; text-align: center; line-height: 1.7; }
.foot p { margin: 4px 0; }

@media (max-width: 560px) {
  body { padding: 16px 12px 40px; }
  .brand { font-size: 22px; }
  .tag { display: none; }
  .stat .v { font-size: 24px; } .stat.big .v { font-size: 30px; }
  .card { padding: 14px; }
  .pc-tick { font-size: 17px; }
}
