:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel2: #1b2030;
  --line: #262c3d;
  --fg: #eef1f7;
  --muted: #8b93a7;
  --accent: #ffb020;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --r: 14px;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
kbd {
  display: inline-block; font: 600 10px/1 Inter, sans-serif; padding: 3px 5px; border-radius: 4px;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); color: var(--muted); vertical-align: middle;
}
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; }

/* ---------------------------------------------------- header */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  background: rgba(11, 13, 18, .88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.ball { width: 20px; height: 20px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffb561, #e8590c); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25); }
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 12px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button.on { background: var(--panel2); color: var(--fg); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); }
.conn.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }

main { padding: 16px 18px 60px; max-width: 1680px; margin: 0 auto; }
.tab { display: none; }
.tab.on { display: block; }

/* ---------------------------------------------------- buttons */
.btn {
  border: 1px solid transparent; background: var(--panel2); padding: 9px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; transition: background .12s, transform .06s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.btn:hover { background: #262d42; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--panel2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.primary { background: var(--accent); color: #111; }
.btn.danger { background: rgba(239, 68, 68, .15); color: #fca5a5; }
.btn.on { background: var(--accent); color: #111; border-color: transparent; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ---------------------------------------------------- game */
.board3 { display: grid; grid-template-columns: 1fr minmax(360px, 440px) 1fr; gap: 14px; align-items: stretch; }
.teamcard, .clockcard, .panel, .roster, .log { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.teamcard { padding: 14px 16px 16px; position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
.teamcard::before { content: ''; position: absolute; left: 0; top: 0; right: 0; height: 4px; background: var(--tc); }
.tc-head { display: flex; align-items: center; gap: 10px; }
.tc-head img { width: 34px; height: 34px; object-fit: contain; }
.tc-name { font: 700 22px/1.1 var(--cond); text-transform: uppercase; letter-spacing: .02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-score { font: 800 96px/0.95 var(--cond); text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pts { display: grid; grid-template-columns: repeat(3, 1fr) .7fr; gap: 8px; }
.pts .btn { font: 800 24px/1 var(--cond); padding: 14px 0; }
.pts .btn.plus { background: #2a3040; background: color-mix(in srgb, var(--tc) 28%, var(--panel2)); }
.pts .btn.plus:hover { background: #333a4d; background: color-mix(in srgb, var(--tc) 42%, var(--panel2)); }
.tc-line { display: flex; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.tc-line .lbl { flex: 1; color: var(--muted); font-weight: 600; font-size: 13px; }
.tc-line b { font: 800 26px/1 var(--cond); min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
.badge { font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 3px 6px; border-radius: 5px; background: var(--red); color: #fff; }
.pips { display: flex; gap: 3px; }
.pips i { width: 12px; height: 6px; border-radius: 3px; background: var(--line); }
.pips i.on { background: var(--accent); }
.pips.bonus i.on { background: var(--red); }

.clockcard { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.period-row { display: flex; align-items: center; gap: 6px; }
.period-lbl { font: 700 20px/1 var(--cond); text-transform: uppercase; letter-spacing: .06em; min-width: 110px; text-align: center; }
#nextPeriod { margin-left: auto; }
.bigclock {
  font: 700 104px/1 var(--cond); text-align: center; font-variant-numeric: tabular-nums; cursor: pointer; border-radius: 12px;
  padding: 8px 0 4px; background: #07090d; border: 1px solid var(--line);
}
.bigclock.running { color: var(--green); }
.bigclock.low { color: var(--red); }
.startbtn {
  border: 0; border-radius: 12px; padding: 16px; font: 800 26px/1 var(--cond); letter-spacing: .08em; cursor: pointer;
  background: var(--green); color: #04130a; display: flex; align-items: center; justify-content: center; gap: 12px; touch-action: manipulation;
}
.startbtn.running { background: var(--red); color: #fff; }
.startbtn kbd { background: rgba(0, 0, 0, .15); color: inherit; border-color: rgba(0, 0, 0, .2); }
.adj { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.shotrow { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: stretch; }
.shotclock {
  font: 800 72px/1 var(--cond); text-align: center; background: #07090d; border: 1px solid var(--line); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; color: var(--accent); cursor: pointer; font-variant-numeric: tabular-nums;
}
.shotclock.running { box-shadow: inset 0 0 0 2px rgba(255, 176, 32, .5); }
.shotclock.low { color: var(--red); }
.shotclock.off { opacity: .35; }
.shotbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shotbig { font: 800 30px/1 var(--cond); padding: 12px 0; }
.shotbig kbd { font-size: 9px; }
.possrow { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-weight: 600; font-size: 13px; }
.poss { width: 64px; font-size: 16px; }
.poss.on { background: var(--accent); color: #111; border-color: transparent; }

.rosters2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.roster { padding: 10px 10px 12px; }
.r-head { display: flex; align-items: center; gap: 8px; padding: 2px 6px 8px; }
.r-head h3 { margin: 0; font: 700 18px/1 var(--cond); text-transform: uppercase; letter-spacing: .04em; flex: 1; }
.r-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--tc); }
.r-empty { color: var(--muted); padding: 16px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.prow {
  display: grid; grid-template-columns: 30px 40px 1fr auto auto auto; gap: 8px; align-items: center; padding: 5px 6px;
  border-radius: 9px;
}
.prow:hover { background: rgba(255, 255, 255, .025); }
.prow.on { background: rgba(255, 255, 255, .05); background: color-mix(in srgb, var(--tc) 12%, transparent); }
.prow.out { opacity: .5; }
.court { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: transparent; cursor: pointer; padding: 0; }
.prow.on .court { background: var(--tc); border-color: var(--tc); }
.pnum { font: 800 22px/1 var(--cond); text-align: center; color: var(--muted); }
.prow.on .pnum { color: var(--fg); }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.pstat { font: 700 18px/1 var(--cond); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.pstat small { font: 600 10px Inter, sans-serif; color: var(--muted); margin-left: 2px; }
.pstat.pf.warn { color: var(--accent); }
.pstat.pf.max { color: var(--red); }
.pbtns { display: flex; gap: 4px; }
.pbtns .btn { padding: 7px 0; width: 38px; font: 800 16px/1 var(--cond); border-radius: 8px; }
.pbtns .btn.f { background: rgba(239, 68, 68, .14); color: #fca5a5; }
.pbtns .btn.more { background: transparent; border-color: var(--line); }

.log { margin-top: 14px; padding: 12px 14px; }
.log-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.log h3 { margin: 0; font-size: 14px; }
#eventLog { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; max-height: 240px; overflow: auto; }
.ev { display: grid; grid-template-columns: 90px 12px 1fr auto; gap: 10px; align-items: center; padding: 5px 8px; border-radius: 7px; font-size: 13px; }
.ev:nth-child(odd) { background: rgba(255, 255, 255, .02); }
.ev .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev .d { width: 10px; height: 10px; border-radius: 50%; background: var(--tc); }
.ev .v { font-weight: 700; }

/* ---------------------------------------------------- popover / toast / dialog */
.popover {
  position: fixed; z-index: 50; display: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; box-shadow: 0 20px 50px rgba(0, 0, 0, .5); width: 290px;
}
.popover.on { display: block; }
.popover h4 { margin: 0 0 8px; font-size: 13px; }
.pop-grid { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; font-size: 13px; }
.pop-grid b { text-align: center; min-width: 24px; font-variant-numeric: tabular-nums; }
.pop-grid .btn { padding: 5px 10px; }
.pop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 60; pointer-events: none;
  background: #fff; color: #111; padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: .25s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); color: #fff; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 16px; padding: 20px; min-width: 320px; max-width: 94vw; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 0 0 12px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
dialog input { width: 100%; }

/* ---------------------------------------------------- panels / forms */
.panel { padding: 16px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head h2 { margin: 0; flex: 1; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols2 > .panel { margin-bottom: 0; }
.cols2 + .panel, .cols2 + .cols2 { margin-top: 14px; }
input, select, textarea {
  background: #0d1017; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=color] { padding: 2px; width: 44px; height: 36px; cursor: pointer; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
input[type=range] { accent-color: var(--accent); padding: 0; }
textarea { width: 100%; min-height: 110px; resize: vertical; }
.field-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-row > input, .field-row > select { flex: 1; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; margin-bottom: 8px; }
.grid-form label, .fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.grid-form label input, .grid-form label select { color: var(--fg); font-weight: 500; font-size: 14px; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.checks label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }

/* roster editor */
.ed-team { display: grid; grid-template-columns: 1fr 110px 50px 50px; gap: 8px; align-items: end; }
.ed-logo { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.ed-logo .img { width: 54px; height: 54px; border-radius: 10px; background: #0d1017 center/contain no-repeat; border: 1px solid var(--line); }
.ed-players { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.ed-p { display: grid; grid-template-columns: 58px 1fr 180px 40px 34px; gap: 6px; align-items: center; }
.ed-p .ph { width: 36px; height: 36px; border-radius: 8px; background: #0d1017 center/cover no-repeat; border: 1px dashed var(--line); cursor: pointer; }
.ed-p .ph.has { border-style: solid; }
.ed-p .x { padding: 6px 0; }
.ed-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.liblist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.libitem { display: flex; align-items: center; gap: 10px; background: var(--panel2); border-radius: 10px; padding: 10px 12px; }
.libitem .sw { width: 12px; height: 34px; border-radius: 4px; }
.libitem .nm { flex: 1; min-width: 0; }
.libitem .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.libitem .nm span { color: var(--muted); font-size: 12px; }

/* graphics */
.gfx { display: grid; grid-template-columns: minmax(380px, 560px) 1fr; gap: 14px; align-items: start; }
.gfx-preview { position: sticky; top: 70px; }
.preview-box {
  position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line);
  background: repeating-conic-gradient(#1a1e28 0% 25%, #141821 0% 50%) 50% / 28px 28px;
}
.preview-box iframe { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; border: 0; transform-origin: 0 0; background: transparent; }
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.toggles .btn { justify-content: flex-start; }
.toggles .btn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.toggles .btn.on::before { background: #111; }
.links { display: flex; flex-direction: column; gap: 6px; }
.link { display: grid; grid-template-columns: 150px 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; }
.link span { color: var(--muted); }
.link input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; padding: 6px 8px; }
.widgets summary { cursor: pointer; font-weight: 600; margin-top: 14px; }

/* stats */
.tbl-wrap { overflow-x: auto; margin-top: 10px; }
table.box { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.box th { text-align: right; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.box td { text-align: right; padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, .04); white-space: nowrap; }
table.box th:nth-child(-n+2), table.box td:nth-child(-n+2) { text-align: left; }
table.box tr.tot td { font-weight: 800; border-top: 1px solid var(--line); }
table.box td.b { font-weight: 800; }
.box-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 0; font-weight: 700; }
.box-title i { width: 10px; height: 10px; border-radius: 50%; }
.rec { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0 4px; }
.rec div { background: var(--panel2); border-radius: 10px; padding: 8px 14px; }
.rec b { font: 800 26px/1 var(--cond); display: block; }
.rec span { color: var(--muted); font-size: 12px; }
table.keys td { padding: 5px 10px 5px 0; vertical-align: top; }
table.keys td:first-child { white-space: nowrap; }

/* ---------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .board3 { grid-template-columns: 1fr 1fr; }
  .clockcard { grid-column: 1 / -1; order: -1; }
  .gfx { grid-template-columns: 1fr; }
  .gfx-preview { position: static; order: -1; }
}
@media (max-width: 860px) {
  .rosters2, .cols2 { grid-template-columns: 1fr; }
  .cols2 > .panel + .panel { margin-top: 14px; }
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .tabs { order: 3; width: 100%; }
  main { padding: 12px 10px 60px; }
  .tc-score { font-size: 72px; }
  .bigclock { font-size: 84px; }
  kbd { display: none; }
  .prow { grid-template-columns: 26px 30px 1fr auto auto; }
  .prow .pstat.pf { display: none; }
  .pbtns .btn { width: 34px; }
  .link { grid-template-columns: 1fr auto; }
  .link span { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .board3 { gap: 8px; }
  .teamcard { padding: 10px; }
  .tc-score { font-size: 60px; }
  .pts .btn { font-size: 20px; padding: 12px 0; }
  .tc-line { flex-wrap: wrap; justify-content: center; }
  .tc-line .lbl { flex-basis: 100%; font-size: 11px; text-align: center; }
  .tc-head .btn { display: none; }
  .pips, .tc-line .badge { display: none; }
  .prow { grid-template-columns: 26px 30px 1fr auto; row-gap: 6px; padding: 8px 6px; }
  .pbtns { grid-column: 1 / -1; }
  .pbtns .btn { flex: 1; width: auto; padding: 10px 0; }
  .ed-team { grid-template-columns: 1fr 80px; }
  .ed-p { grid-template-columns: 50px 1fr 36px 30px; }
  .ed-p .pos { display: none; }
}

/* ---------------------------------------------------- эфир, сцены, тема */
.airbar { display: flex; align-items: center; gap: 12px; margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.airbar-lbl { font-weight: 800; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--red); display: flex; align-items: center; gap: 6px; }
.airbar-lbl::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.airbar-btns { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.airbar-btns .btn { padding: 7px 12px; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 12.5px; cursor: pointer; }
.chip:hover { background: #262d42; }
.chip small { color: var(--muted); }
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; }
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.brand-logo { width: 64px; height: 64px; border-radius: 12px; background: #0d1017 center/contain no-repeat; border: 1px solid var(--line); flex: none; }
.spons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spons .sp { position: relative; width: 110px; height: 56px; border-radius: 10px; background: #0d1017 center/contain no-repeat; border: 1px solid var(--line); }
.spons .sp button { position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--red); color: #fff; cursor: pointer; font-size: 12px; line-height: 22px; padding: 0; }
@media (max-width: 860px) { .airbar { flex-direction: column; align-items: stretch; } }

/* язык графики */
.langsel { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.langsel select { padding: 6px 8px; font-size: 13px; font-weight: 600; color: var(--fg); }
@media (max-width: 860px) { .langsel span { display: none; } }
