:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --qb: #2a78d6;   /* slot 1 blue */
  --rb: #008300;   /* slot 2 green */
  --wr: #e87ba4;   /* slot 3 magenta */
  --te: #eda100;   /* slot 4 yellow */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --wash: rgba(42, 120, 214, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --qb: #3987e5;
    --rb: #008300;
    --wr: #d55181;
    --te: #c98500;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --critical: #d03b3b;
    --accent: #3987e5;
    --wash: rgba(57, 135, 229, 0.12);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
.app { max-width: 1100px; margin: 0 auto; padding: 16px 20px 60px; }
header.top {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 6px 0 12px;
}
header.top h1 { font-size: 18px; font-weight: 650; margin: 0; }
header.top .sub { color: var(--muted); font-size: 12.5px; }

/* Tabs */
nav.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--grid); margin-bottom: 18px; flex-wrap: wrap; }
nav.tabs button {
  appearance: none; background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 550; color: var(--ink-2);
  padding: 8px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav.tabs button:hover { background: var(--wash); border-radius: 6px 6px 0 0; }
nav.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Cards */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
}
.card h2 { font-size: 13px; font-weight: 650; margin: 0 0 4px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.cols { display: flex; gap: 16px; flex-wrap: wrap; }
.cols > .card { flex: 1 1 300px; margin-bottom: 0; }
.rowgap { margin-bottom: 16px; }

/* Controls */
label.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
label.field span.lbl { color: var(--ink-2); }
input[type="number"], input[type="text"], select {
  font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; width: 90px;
}
input[type="text"] { width: 160px; }
select { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  width: 100%; min-height: 220px; resize: vertical;
}
button.btn {
  appearance: none; font: inherit; font-weight: 550; cursor: pointer;
  background: var(--accent); color: #fff; border: none; border-radius: 7px;
  padding: 7px 14px;
}
button.btn.secondary { background: none; color: var(--ink); border: 1px solid var(--border); }
button.btn.small { padding: 4px 10px; font-size: 12.5px; }
button.btn:hover { filter: brightness(1.06); }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button {
  appearance: none; border: 1px solid var(--border); background: var(--page); color: var(--ink);
  width: 26px; height: 26px; cursor: pointer; font-size: 15px; line-height: 1;
}
.stepper button:first-child { border-radius: 6px 0 0 6px; }
.stepper button:last-child { border-radius: 0 6px 6px 0; }
.stepper button:hover { background: var(--wash); }
.stepper .val { min-width: 30px; text-align: center; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); height: 26px; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }

/* Position chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chips button {
  appearance: none; font: inherit; font-size: 12.5px; font-weight: 550; cursor: pointer;
  background: none; color: var(--ink-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
}
.chips button.active { background: var(--ink); color: var(--surface-1); border-color: var(--ink); }
.poskey { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.poskey.QB { background: var(--qb); } .poskey.RB { background: var(--rb); }
.poskey.WR { background: var(--wr); } .poskey.TE { background: var(--te); }

/* Tables */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 10px; border-bottom: 1px solid var(--grid);
}
td { padding: 6px 10px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--wash); }
td.num, th.num { text-align: right; }
tr.sold td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--baseline); }
tr.sold td .tag { text-decoration: none; }
tr.mine td { text-decoration: none; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 600; border-radius: 5px;
  padding: 1px 7px; border: 1px solid var(--border); color: var(--ink-2);
}
.tag.me { background: var(--wash); color: var(--accent); border-color: transparent; }

/* Stat tiles */
.tiles { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; flex: 1 1 140px; min-width: 140px;
}
.tile .lbl { color: var(--ink-2); font-size: 12px; }
.tile .val { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .d { font-size: 12px; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.tile .d.good { color: var(--good-text); }
.tile .d.bad { color: var(--critical); }
.tile .d.warn { color: var(--ink-2); }

/* Teams grid */
.teamgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.team {
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; background: var(--surface-1);
}
.team .nm { font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.team .meta { color: var(--ink-2); font-size: 12px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.meter { height: 5px; background: var(--wash); border-radius: 3px; margin-top: 7px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Chart */
.chartwrap { position: relative; }
svg.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 4px 2px 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px;
  font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,0.10); display: none; z-index: 5;
  min-width: 130px;
}
.tooltip .t { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }

/* Draft form */
.saleform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.saleform input[type="text"] { flex: 1 1 220px; }
.saleform input[type="number"] { width: 80px; }
.log-undo { color: var(--accent); cursor: pointer; background: none; border: none; font: inherit; font-size: 12.5px; padding: 0; }
.slotrow td input[type="number"] { width: 70px; padding: 3px 6px; }
.empty { color: var(--muted); font-style: normal; }
.footer-note { color: var(--muted); font-size: 12px; margin-top: 22px; }
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: none;
  align-items: center; justify-content: center; z-index: 20;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface-1); border-radius: 12px; padding: 18px 20px;
  width: min(560px, 92vw); max-height: 84vh; overflow: auto;
}
.modal h3 { margin: 0 0 8px; font-size: 14px; }
.modal textarea { min-height: 160px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }


/* ---------- Welcome / first visit ---------- */
.card.welcome { border-color: var(--accent); }
.card.welcome ol.steps { margin: 0 0 10px; padding-left: 20px; font-size: 13px; color: var(--ink-2); }
.card.welcome ol.steps li { margin: 4px 0; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .app { padding: 10px 12px 40px; }
  header.top { gap: 8px; }
  header.top h1 { font-size: 16px; }
  nav.tabs { overflow-x: auto; flex-wrap: nowrap; white-space: nowrap; scrollbar-width: none; }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button { padding: 8px 10px; }
  .cols { flex-direction: column; }
  .cols > .card { flex-basis: auto; }
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tile { flex: 1 1 42%; min-width: 120px; }
  .tile .val { font-size: 22px; }
  textarea { min-height: 150px; }
  input[type="text"] { width: 130px; }
}
