:root {
  --bg: #0b0d12;
  --panel: rgba(14, 17, 24, 0.9);
  --panel-solid: #121620;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e9edf3;
  --muted: #8b95a7;
  --accent: #ffb020;
  --accent-ink: #1b1202;
  --good: #4cc38a;
  --bad: #ff6b5b;
  --radius: 10px;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--body); font-size: 14px; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }

/* ---------- scorebug ---------- */
#scorebug {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: stretch; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0,0,0,.45);
  font-family: var(--display); user-select: none;
}
.sb-team { display: grid; grid-template-columns: 8px auto auto; grid-template-rows: auto auto; align-items: center; column-gap: 12px; padding: 6px 16px 5px 0; min-width: 150px; }
.sb-team.away { grid-template-columns: auto auto 8px; padding: 6px 0 5px 16px; }
.sb-swatch { grid-row: 1 / span 2; width: 8px; height: 100%; }
.sb-abbr { font-size: 22px; font-weight: 600; letter-spacing: .04em; }
.sb-score { font-size: 38px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.sb-team.away .sb-score { text-align: left; }
.sb-meta { grid-column: 2 / span 2; font-family: var(--body); font-size: 10.5px; color: var(--muted); display: flex; gap: 10px; }
.sb-team.away .sb-meta { grid-column: 1 / span 2; justify-content: flex-end; }
.sb-meta .bonus { color: var(--accent); font-weight: 600; }
.sb-center { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 18px; background: rgba(255,255,255,.04); border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-width: 104px; }
.sb-period { font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: .08em; }
.sb-clock { font-size: 28px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.sb-shot { font-size: 14px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.sb-shot.low { color: var(--bad); }

#banner {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-weight: 700;
  letter-spacing: .12em; padding: 4px 16px; border-radius: 6px; font-size: 16px;
}
#ticker {
  position: absolute; top: 128px; left: 50%; transform: translateX(-50%);
  max-width: min(560px, 90vw); text-align: center; font-size: 13px; padding: 6px 12px; border-radius: 8px;
  background: rgba(0,0,0,.45); color: #fff; transition: opacity .4s; pointer-events: none;
}

/* ---------- side panel ---------- */
#panel {
  position: absolute; top: 14px; right: 14px; bottom: 76px; width: min(470px, calc(100vw - 28px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.tabs { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); align-items: center; }
.tab { background: none; border: 0; padding: 7px 12px; border-radius: 7px; color: var(--muted); cursor: pointer; font-weight: 600; }
.tab.active { background: rgba(255,255,255,.08); color: var(--text); }
.icon-btn { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 10px; border-radius: 6px; }
.icon-btn:hover { background: rgba(255,255,255,.07); color: var(--text); }
#panel-open { position: absolute; top: 14px; right: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.tab-body { flex: 1; overflow: auto; padding: 8px 10px 12px; }

.box-team { margin-bottom: 14px; }
.box-team h3 { display: flex; align-items: center; gap: 8px; margin: 6px 2px 6px; font-family: var(--display); font-size: 18px; letter-spacing: .03em; font-weight: 600; }
.box-team h3 .dot { width: 10px; height: 10px; border-radius: 3px; }
.box-team h3 .pts { margin-left: auto; font-size: 20px; }
table.box { width: 100%; border-collapse: collapse; font-size: 11.5px; font-variant-numeric: tabular-nums; }
table.box th { color: var(--muted); font-weight: 500; text-align: right; padding: 3px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel-solid); }
table.box td { text-align: right; padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,.04); white-space: nowrap; }
table.box th:first-child, table.box td:first-child { text-align: left; }
table.box tr.player { cursor: pointer; }
table.box tr.player:hover td { background: rgba(255,255,255,.05); }
table.box tr.oncourt td:first-child { box-shadow: inset 3px 0 0 var(--good); }
table.box tr.selected td { background: rgba(255,176,32,.14); }
table.box tr.fouledout td { color: var(--muted); text-decoration: line-through; }
table.box tr.totals td { font-weight: 600; border-top: 1px solid var(--line-strong); }
.pname { display: inline-block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.pnum { color: var(--muted); display: inline-block; width: 22px; }
.quarters { font-size: 11.5px; width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.quarters th, .quarters td { padding: 3px 6px; text-align: center; border-bottom: 1px solid var(--line); }
.quarters th { color: var(--muted); font-weight: 500; }
.quarters td:first-child, .quarters th:first-child { text-align: left; }

#pbp { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; }
#pbp li { display: grid; grid-template-columns: 58px 1fr 52px; gap: 8px; padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,.05); font-size: 12.5px; align-items: baseline; }
#pbp .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
#pbp .s { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; }
#pbp li .txt { border-left: 3px solid transparent; padding-left: 7px; }
#pbp li.k-score .txt, #pbp li.k-three .txt { font-weight: 600; }
#pbp li.k-three .txt::after { content: ' ●'; color: var(--accent); }
#pbp li.k-period, #pbp li.k-final { background: rgba(255,255,255,.05); }
#pbp li.k-period .txt, #pbp li.k-final .txt { font-weight: 700; font-family: var(--display); font-size: 15px; letter-spacing: .03em; }
#pbp li.k-sub .txt, #pbp li.k-miss .txt { color: var(--muted); }
#pbp li.k-foul .txt { color: #ffcf8a; }
#pbp li.k-tov .txt, #pbp li.k-steal .txt { color: #ffb4a8; }
#pbp li.k-block .txt { color: #9fd8ff; }

/* ---------- controls ---------- */
#controls {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0,0,0,.45);
  max-width: calc(100vw - 20px); flex-wrap: wrap; justify-content: center;
}
.ctl { background: rgba(255,255,255,.07); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; min-width: 40px; font-weight: 600; }
.ctl:hover { background: rgba(255,255,255,.13); }
.ctl.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg { display: flex; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 7px 11px; cursor: pointer; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.seg button.active { background: rgba(255,255,255,.14); color: var(--text); }
.select-wrap { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
select { background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px; }
.toggle { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0 4px; }

/* ---------- inspector ---------- */
#inspector {
  position: absolute; left: 14px; bottom: 76px; width: 300px; max-height: calc(100vh - 170px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.insp-head { display: flex; align-items: center; gap: 10px; }
.insp-num { font-family: var(--display); font-size: 34px; font-weight: 700; width: 52px; height: 52px; border-radius: 10px; display: grid; place-items: center; }
.insp-name { font-family: var(--display); font-size: 21px; font-weight: 600; line-height: 1.1; }
.insp-sub { color: var(--muted); font-size: 12px; }
.insp-close { margin-left: auto; align-self: flex-start; }
.insp-intent { margin: 10px 0 8px; padding: 7px 9px; border-radius: 7px; background: rgba(255,176,32,.1); border: 1px solid rgba(255,176,32,.25); font-size: 12.5px; }
.insp-intent b { color: var(--accent); font-weight: 600; font-size: 10.5px; letter-spacing: .08em; display: block; margin-bottom: 2px; }
.insp-line { font-size: 12px; color: var(--muted); margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.insp-line strong { color: var(--text); font-weight: 600; }
.bars { display: grid; grid-template-columns: 88px 1fr 26px; gap: 4px 8px; align-items: center; font-size: 11.5px; }
.bars .lbl { color: var(--muted); }
.bars .val { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
.stam { margin: 4px 0 10px; }

/* ---------- loading ---------- */
#loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); z-index: 20; color: var(--muted); }
.ball-spin { font-size: 48px; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modals ---------- */
.modal { position: absolute; inset: 0; background: rgba(4,6,10,.72); display: grid; place-items: center; z-index: 15; padding: 16px; backdrop-filter: blur(3px); }
.modal-card { background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); max-height: calc(100vh - 32px); overflow: auto; }
.setup-card { width: min(760px, 100%); padding: 26px 28px; }
.setup-card h1 { font-family: var(--display); font-size: 42px; margin: 0; letter-spacing: .02em; }
.setup-card .sub { color: var(--muted); margin: 4px 0 22px; line-height: 1.5; }
.matchup { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: start; }
.vs { font-family: var(--display); font-size: 26px; color: var(--muted); align-self: center; font-weight: 700; }
.team-pick { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.pick-label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.team-select { width: 100%; font-size: 15px; padding: 8px; }
.team-preview { font-size: 12px; color: var(--muted); min-height: 110px; }
.team-preview .banner { height: 6px; border-radius: 3px; margin-bottom: 8px; }
.team-preview .row { display: flex; justify-content: space-between; padding: 2px 0; }
.team-preview .row span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }
.setup-row { display: flex; gap: 20px; margin: 20px 0 6px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.setup-row label { display: flex; align-items: center; gap: 8px; }
.setup-row input { background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px; }
.setup-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 9px; padding: 10px 22px; font-weight: 700; cursor: pointer; font-size: 15px; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: var(--text); }
button.ghost:hover { background: rgba(255,255,255,.06); }
button.ghost.danger { color: #ffb4a8; border-color: rgba(255,107,91,.4); }

.editor-card { width: min(1280px, 100%); padding: 18px 20px; display: flex; flex-direction: column; }
.editor-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.editor-head input { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; }
.ed-title { font-family: var(--display); font-size: 22px; font-weight: 600; flex: 1; min-width: 200px; }
.ed-abbr { width: 70px; text-transform: uppercase; font-family: var(--display); font-size: 20px; }
.color-in { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.color-in input { padding: 0; width: 34px; height: 30px; border-radius: 6px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 60vh; }
#ed-table { border-collapse: collapse; font-size: 12px; width: 100%; }
#ed-table th { position: sticky; top: 0; background: var(--panel-solid); color: var(--muted); font-weight: 500; padding: 6px 3px; border-bottom: 1px solid var(--line-strong); z-index: 1; }
#ed-table td { padding: 2px 2px; border-bottom: 1px solid rgba(255,255,255,.04); }
#ed-table tr:nth-child(5) td { border-bottom: 2px solid var(--line-strong); }
#ed-table input, #ed-table select { background: transparent; border: 1px solid transparent; border-radius: 5px; padding: 4px 3px; width: 100%; font-variant-numeric: tabular-nums; }
#ed-table input:hover, #ed-table input:focus { border-color: var(--line-strong); background: rgba(255,255,255,.04); outline: none; }
#ed-table input[type=number] { width: 44px; text-align: right; -moz-appearance: textfield; }
#ed-table input::-webkit-outer-spin-button, #ed-table input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#ed-table .ovr { font-weight: 700; text-align: center; color: var(--accent); padding: 0 6px; }
#ed-table .name-in { min-width: 150px; }
.editor-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 900px) {
  #panel { top: auto; bottom: 120px; height: 38vh; }
  #inspector { bottom: 120px; width: min(300px, calc(100vw - 28px)); }
  .matchup { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
  .sb-team { min-width: 0; column-gap: 7px; padding-right: 10px; }
  .sb-team.away { padding-left: 10px; }
  .sb-score { font-size: 30px; }
  .sb-abbr { font-size: 18px; }
}
