:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --line: #2c2c2a;
  --axis: #383835;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); }
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; justify-content: center; }
.row { display: flex; gap: .5rem; align-items: center; }
.wrap { flex-wrap: wrap; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: calc(.5rem + env(safe-area-inset-top)) 16px .5rem; background: rgba(13,13,13,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: .45rem; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(12,163,12,.25); }
.tabs { display: flex; gap: .25rem; overflow-x: auto; }
.tabs a { color: var(--ink-2); text-decoration: none; padding: .35rem .7rem; border-radius: 999px; white-space: nowrap; }
.tabs a.active { background: var(--surface-2); color: var(--ink); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 3rem; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }

/* buttons */
.btn { font: inherit; border: 1px solid var(--axis); background: var(--surface-2); color: var(--ink); padding: .5rem .9rem; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--bad); color: #ff8a8a; }
.btn.stop { background: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.big-btn { font-size: 1.1rem; padding: .8rem 1.6rem; min-width: 11rem; justify-content: center; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 1.2rem; cursor: pointer; }
.icon-btn.on { background: var(--accent); }
.link { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }
select, input[type=number], input[type=text], textarea { font: inherit; background: var(--surface-2); color: var(--ink); border: 1px solid var(--axis); border-radius: 10px; padding: .45rem .6rem; }
.file-btn { cursor: pointer; }

/* exercise chips */
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .5rem; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--axis); background: var(--surface); color: var(--ink-2); padding: .4rem .8rem; border-radius: 999px; cursor: pointer; font: inherit; }
.chip.active { background: var(--ink); color: #000; border-color: var(--ink); font-weight: 600; }
.chip small { opacity: .6; margin-left: .25rem; }

/* stage */
.stage-wrap { display: flex; justify-content: center; }
.stage { position: relative; width: 100%; max-height: 72vh; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.stage.portrait { aspect-ratio: 9 / 16; max-width: calc(72vh * 9 / 16); }
.stage canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.stage-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; padding: 1rem; text-align: center; background: radial-gradient(ellipse at center, #1c1c1b 0%, #000 75%); }
.stage-empty .big { font-size: 1.25rem; font-weight: 600; margin: 0; }
.stage-empty p { margin: 0; max-width: 32rem; }
.stage-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px; }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 8rem; font-weight: 800; color: #fff; text-shadow: 0 4px 30px rgba(0,0,0,.8); pointer-events: none; }
.bar-hint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.75); padding: .4rem .8rem; border-radius: 999px; }
.stage.set-bar canvas { cursor: crosshair; }
.train-actions { display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap; margin-top: .9rem; }
.toggle { display: inline-flex; align-items: center; gap: .35rem; color: var(--ink-2); cursor: pointer; }

/* tiles + cards */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin: .5rem 0 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; }
.tile .k { color: var(--muted); font-size: .8rem; }
.tile .v { font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.tile .s { color: var(--ink-2); font-size: .8rem; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: .8rem; }
.chart-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.chart-card figcaption { color: var(--ink-2); font-size: .9rem; margin-bottom: .4rem; }
.chart-box { position: relative; height: 240px; }

/* history */
.day { margin-top: 1rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.sess { display: grid; grid-template-columns: 1fr auto auto; gap: .8rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-top: .4rem; cursor: pointer; text-decoration: none; color: var(--ink); }
.sess:hover { border-color: var(--axis); }
.sess .t { font-weight: 600; }
.sess .sub { color: var(--muted); font-size: .85rem; }
.sess .metric { font-size: 1.4rem; font-weight: 700; text-align: right; }
.sess .metric small { font-size: .75rem; color: var(--muted); font-weight: 400; display: block; }

/* score chip — color + text label, never color alone */
.score { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; border: 1px solid; }
.score.good { color: #7ee07e; border-color: var(--good); background: rgba(12,163,12,.14); }
.score.warn { color: var(--warn); border-color: var(--warn); background: rgba(250,178,25,.12); }
.score.bad { color: #ff8a8a; border-color: var(--bad); background: rgba(208,59,59,.14); }
.score.neutral { color: var(--muted); border-color: var(--axis); }

/* session detail */
.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.player video { width: 100%; max-height: 70vh; display: block; background: #000; }
.markers { position: relative; height: 22px; background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); cursor: pointer; }
.markers .m { position: absolute; top: 4px; width: 4px; height: 14px; border-radius: 2px; transform: translateX(-2px); }
.markers .m.good { background: var(--good); } .markers .m.warn { background: var(--warn); } .markers .m.bad { background: var(--bad); } .markers .m.info { background: var(--muted); height: 8px; top: 7px; }
.markers .ph { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; pointer-events: none; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
.faults { display: grid; gap: .35rem; }
.fbar { display: grid; grid-template-columns: 11rem 1fr 2.5rem; gap: .5rem; align-items: center; font-size: .9rem; }
.fbar .track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.fbar .fill { height: 100%; background: var(--warn); border-radius: 5px; }
.events { max-height: 320px; overflow-y: auto; font-size: .88rem; border: 1px solid var(--line); border-radius: var(--radius); }
.ev { display: grid; grid-template-columns: 4.2rem 1.4rem 1fr; gap: .4rem; padding: .35rem .6rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:hover { background: var(--surface-2); }
.ev .tm { color: var(--muted); font-variant-numeric: tabular-nums; }
.notes { width: 100%; min-height: 4rem; }
.back { display: inline-block; margin-bottom: .5rem; }

/* settings */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: .6rem 1.2rem; margin-bottom: 1rem; }
.settings label { display: flex; flex-direction: column; gap: .25rem; color: var(--ink-2); font-size: .9rem; }
.settings label.inline { flex-direction: row; align-items: center; gap: .5rem; }
.settings .hint { color: var(--muted); font-size: .78rem; }
.help { margin-top: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; }
.help li { margin: .3rem 0; color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--axis); padding: .6rem 1rem; border-radius: 999px; z-index: 50; max-width: calc(100% - 32px); }

@media (max-width: 600px) {
  .stage { max-height: 64vh; }
  .fbar { grid-template-columns: 8rem 1fr 2rem; }
  .sess { grid-template-columns: 1fr auto; }
  .sess .score { grid-column: 2; }
}

/* print: clean black-on-white report */
@media print {
  :root { --page: #fff; --surface: #fff; --surface-2: #f3f3f3; --line: #ddd; --axis: #bbb; --ink: #000; --ink-2: #222; --muted: #555; }
  html, body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .topbar, .toast, .stage-controls, button, .btn, select, .file-btn, .player, .markers { display: none !important; }
  main { max-width: none; padding: 0; }
  .tile, .chart-card, .sess { break-inside: avoid; border-color: #ccc; }
  .events { max-height: none; overflow: visible; }
  .chart-box { height: 220px; }
  a { color: #000; text-decoration: none; }
  .score.good { color: #075c07; } .score.warn { color: #7a5200; } .score.bad { color: #8b1d1d; }
}
