/* League Zero GM — private local test interface. Tokens first; every component reads them. */
:root {
  --bg: #edf1ee;
  --surface: #ffffff;
  --surface-2: #f5f8f6;
  --ink: #15201b;
  --muted: #56655e;
  --line: #d2dad4;
  --accent: #1b6b5a;
  --accent-ink: #ffffff;
  --accent-soft: #dcece6;
  --warn: #8a5200;
  --warn-soft: #fbeccd;
  --bad: #a4261d;
  --bad-soft: #f8dbd7;
  --ok: #17713a;
  --ok-soft: #d6eedc;
  --focus: #0b57d0;
  --radius: 6px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1411; --surface: #151d19; --surface-2: #1b2520; --ink: #e5ede8; --muted: #9db0a6; --line: #2b3932;
    --accent: #4fb89d; --accent-ink: #06241c; --accent-soft: #1b3a32; --warn: #f0b957; --warn-soft: #3a2e12;
    --bad: #ff8a80; --bad-soft: #3e1d1a; --ok: #6dd58c; --ok-soft: #17331f; --focus: #8ab4ff;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1411; --surface: #151d19; --surface-2: #1b2520; --ink: #e5ede8; --muted: #9db0a6; --line: #2b3932;
  --accent: #4fb89d; --accent-ink: #06241c; --accent-soft: #1b3a32; --warn: #f0b957; --warn-soft: #3a2e12;
  --bad: #ff8a80; --bad-soft: #3e1d1a; --ok: #6dd58c; --ok-soft: #17331f; --focus: #8ab4ff;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
.mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- chrome */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px var(--gutter);
  background: var(--accent); color: var(--accent-ink); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand-mark { width: 18px; height: 18px; border-radius: 50%; border: 3px solid currentColor; position: relative; display: inline-block; }
.brand-mark::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 3px; margin-left: -1.5px; background: currentColor; }
.world-chip { flex: 1; min-width: 0; font-size: .85rem; opacity: .95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-pick select { max-width: 11rem; min-height: 40px; border-radius: var(--radius); border: 1px solid transparent; padding: 0 8px; background: var(--surface); color: var(--ink); }
.provenance { padding: 8px var(--gutter); font-size: .88rem; border-bottom: 1px solid var(--line); background: var(--warn-soft); color: var(--ink); }
.provenance strong { letter-spacing: .04em; }
.provenance.kind-legacy { background: var(--surface-2); }
.nav {
  display: flex; gap: 2px; padding: 0 var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; position: sticky; top: 56px; z-index: 15;
}
.nav a { padding: 12px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; min-height: 44px; }
.nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.view { max-width: 1120px; margin: 0 auto; padding: var(--gutter); display: block; }
.view:focus { outline: none; }
.loading { color: var(--muted); padding: 24px 0; }

.error-banner { margin: var(--gutter) auto 0; max-width: 1088px; background: var(--bad-soft); border: 1px solid var(--bad); color: var(--ink); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 12px; align-items: flex-start; }
.error-banner[hidden] { display: none; }
.error-banner .code { font-family: var(--mono); font-weight: 700; color: var(--bad); }
.error-banner button { margin-left: auto; }
.toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(92vw, 380px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 12px; border-radius: var(--radius); font-size: .9rem; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---- layout primitives */
.page-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card > h2 { margin-bottom: 10px; }
.card.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.stat { display: flex; flex-direction: column; }
.stat .big { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stats-row { display: flex; flex-wrap: wrap; gap: 14px 28px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 650; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.pill.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.pill.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.pill.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ---- controls */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-small { min-height: 40px; padding: 0 12px; font-size: .88rem; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  min-height: 44px; padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; max-width: 100%;
}
input[type="number"] { width: 6.5rem; font-variant-numeric: tabular-nums; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
label.check { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; cursor: pointer; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }
.field-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); }
.tab[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; font-weight: 650; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.mine td { background: var(--accent-soft); }
tbody th.sticky, td.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead th.sticky { background: var(--surface-2); z-index: 3; }
tbody th { text-transform: none; letter-spacing: normal; font-size: inherit; color: var(--ink); font-weight: 600; }
tr.mine td.sticky, tr.mine th.sticky { background: var(--accent-soft); }
.bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--accent); vertical-align: middle; min-width: 2px; }
.bar-track { display: inline-block; width: 90px; height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.bar-track .bar { display: block; height: 100%; border-radius: 0; }

/* ---- rotation editor + bracket */
.minutes-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.minutes-total.ok { color: var(--ok); }
.minutes-total.bad { color: var(--bad); }
.bracket { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px; }
.bracket-round { min-width: 220px; display: flex; flex-direction: column; gap: 10px; }
.matchup { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.matchup .side { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; }
.matchup .side + .side { border-top: 1px solid var(--line); }
.matchup .winner { font-weight: 700; background: var(--accent-soft); }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); max-width: min(92vw, 440px); padding: 18px; }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
details > summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.notice { border-left: 4px solid var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 0 var(--radius) var(--radius) 0; }
.notice.info { border-left-color: var(--accent); background: var(--accent-soft); }
.empty { color: var(--muted); padding: 12px 0; }

/* ---- narrow screens: bottom navigation, single column */
@media (max-width: 720px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .card.span-2 { grid-column: auto; }
  .nav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; justify-content: space-between; padding: 0 4px calc(0px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); border-bottom: 0; overflow-x: auto;
  }
  .nav a { flex: 1 0 auto; padding: 10px 10px; font-size: .8rem; text-align: center; border-bottom: 0; border-top: 3px solid transparent; min-width: 56px; }
  .nav a[aria-current="page"] { border-top-color: var(--accent); }
  .view { padding-bottom: 84px; }
  .toasts { bottom: 76px; }
  .team-pick select { max-width: 8rem; }
  h1 { font-size: 1.25rem; }
  .brand-name { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ---- Rotation Builder */
input[type="search"] { min-height: 44px; padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; max-width: 100%; }
.rb-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) { .rb-grid { grid-template-columns: minmax(0, 1fr) 380px; } .rb-side { position: sticky; top: 112px; max-height: calc(100vh - 128px); overflow: auto; } }
.rb-bar { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; padding: 8px 0; position: sticky; top: 104px; background: var(--surface); z-index: 5; }
.rb-hints { margin: 4px 0 8px; padding-left: 20px; }
.rb-filters { margin: 4px 0 8px; }
.rb-filters select, .rb-filters input { min-height: 44px; }
.rb-table-wrap { max-height: 70vh; overflow: auto; }
.rb-table-wrap th { top: 0; }
.rb-table-wrap button.sort { all: unset; cursor: pointer; display: inline-block; min-height: 40px; line-height: 40px; padding: 0 2px; text-transform: inherit; letter-spacing: inherit; font-weight: inherit; }
.rb-table-wrap button.sort:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.rb-table-wrap th.sorted { color: var(--ink); }
.rb-table-wrap td.ctl { padding-top: 0; padding-bottom: 0; }
.rb-table-wrap tr.starter th.sticky, .rb-table-wrap tr.starter td { background: var(--accent-soft); }
.rb-table-wrap tr.invalid th.sticky, .rb-table-wrap tr.invalid td { background: var(--bad-soft); }
.rb-table-wrap th.sticky { min-width: 9.5rem; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.rb-five { margin: 0 0 8px; padding-left: 22px; display: flex; flex-direction: column; gap: 4px; }
.rb-rel { border-top: 1px solid var(--line); padding-top: 8px; }
td.hi { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
td.lo { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
tr.group th { background: var(--surface-2); text-align: left; position: static; }
@media (max-width: 720px) { .rb-bar { top: 56px; } .rb-table-wrap { max-height: none; } }
.view.wide { max-width: 1680px; }

/* ---- hosted mode: account chip and sign-in page */
.account-chip[hidden] { display: none; }
.maintenance-banner[hidden] { display: none; }
.maintenance-banner { padding: 10px var(--gutter); background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); font-size: .92rem; }
.account-chip { display: flex; align-items: center; gap: 8px; font-size: .85rem; white-space: nowrap; }
.account-chip .btn { min-height: 40px; background: var(--surface); color: var(--ink); }
.account-chip .muted { color: inherit; opacity: .85; }
@media (max-width: 720px) { .account-chip .muted { display: none; } .account-chip strong { max-width: 5.5rem; overflow: hidden; text-overflow: ellipsis; } }
.login-wrap { max-width: 26rem; margin: 12vh auto 0; padding: 0 var(--gutter); }
.login-wrap .card { display: grid; gap: 14px; }
.login-wrap label { display: grid; gap: 6px; font-weight: 600; }
.login-wrap input[type="text"], .login-wrap input[type="password"] { min-height: 44px; font-size: 1rem; }
.login-error { color: var(--bad); min-height: 1.4em; }
