:root {
  --bg: #07080c;
  --panel: #10131b;
  --line: #1f2531;
  --text: #eef1f7;
  --muted: #858ea2;
  --accent: #ff5a36;
  --p1: #ff4458;
  --p2: #3a8bff;
  --ok: #3ccf91;
  --warn: #ffb020;
  --bad: #ff5d6c;
  --bar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
  background:
    radial-gradient(900px 600px at 0% 40%, rgba(255, 68, 88, 0.09), transparent 65%),
    radial-gradient(900px 600px at 100% 40%, rgba(58, 139, 255, 0.09), transparent 65%),
    var(--bg);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: #1a2030; padding: 1px 5px; border-radius: 5px; }

/* Top bar */
.bar {
  height: var(--bar-h); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 20px;
  border-bottom: 1px solid var(--line); background: rgba(7, 8, 12, 0.7); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: 0.06em; font-size: 17px; color: var(--text); text-decoration: none; }
.brand em { font-style: normal; color: var(--accent); }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; color: #140a05; background: linear-gradient(135deg, var(--accent), #ffb020); }
.search { flex: 1; display: flex; gap: 8px; max-width: 620px; margin: 0 auto; }
.search input {
  flex: 1; min-width: 0; height: 38px; padding: 0 14px; border-radius: 10px;
  background: #0f121a; border: 1px solid var(--line); outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 90, 54, 0.16); }
.btn {
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #161b26;
  font-weight: 600; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { background: #1e2433; }
.btn.primary { background: var(--accent); border-color: transparent; color: #1a0b05; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.files-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4255; }
.files-btn .dot.ok { background: var(--ok); }

/* Arena */
.arena { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 18px 20px 14px; gap: 14px; min-height: 0; }

.scorebug {
  display: grid; grid-template-columns: 1fr auto auto auto 1fr; align-items: center;
  width: min(100%, 900px); background: linear-gradient(90deg, rgba(255, 68, 88, 0.16), rgba(16, 19, 27, 0.9) 30%, rgba(16, 19, 27, 0.9) 70%, rgba(58, 139, 255, 0.16));
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.bug-name { padding: 8px 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bug-name.p2 { text-align: right; }
.bug-score { font-size: 26px; font-weight: 800; min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; padding: 2px 0; }
.bug-score.p1 { background: var(--p1); color: #fff; }
.bug-score.p2 { background: var(--p2); color: #fff; }
.bug-mid { display: flex; flex-direction: column; align-items: center; padding: 4px 18px; line-height: 1.2; }
.bug-game { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
.bug-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }

.match {
  --stage-w: min(calc(100vw - 2 * 250px - 80px), calc((100vh - var(--bar-h) - 200px) * 4 / 3));
  display: grid; grid-template-columns: 230px var(--stage-w) 230px; gap: 22px; align-items: start; justify-content: center;
  width: 100%;
}

/* Fighter panels */
.fighter { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding-top: 6px; }
.avatar {
  position: relative; width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center; font-size: 46px; font-weight: 800; letter-spacing: 0.02em;
  background: var(--avatar-bg, #1b2130); color: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--seat), 0 18px 50px rgba(0, 0, 0, 0.5);
}
.p1 { --seat: var(--p1); }
.p2 { --seat: var(--p2); }
.avatar-flag { position: absolute; right: 2px; bottom: 4px; font-size: 30px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); }
.fighter-name { margin-top: 10px; font-size: 21px; font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fighter-meta { color: var(--muted); font-size: 13.5px; min-height: 20px; }
.rank-row { display: flex; align-items: center; gap: 8px; }
.rank-label { font-size: 12px; color: var(--muted); }
.rank { min-width: 30px; height: 26px; padding: 0 8px; border-radius: 7px; display: inline-grid; place-items: center; font-weight: 900; font-size: 14px; background: #232a3a; }
.rank[data-rank="S"] { background: linear-gradient(135deg, #ffd34d, #ff9d2e); color: #2a1600; }
.rank[data-rank="A"] { background: #ff5a8a; color: #2a0012; }
.rank[data-rank="B"] { background: #7a6cff; color: #fff; }
.rank[data-rank="C"] { background: #2fb7a6; color: #00241f; }
.rank[data-rank="D"] { background: #5d8f3a; color: #fff; }
.rank[data-rank="E"] { background: #5a6274; color: #fff; }
.rounds { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.rounds-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.pips { display: flex; gap: 7px; }
.pip { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #343c50; transition: all 0.2s; }
.pip.on { background: var(--seat); border-color: var(--seat); box-shadow: 0 0 12px var(--seat); }

/* Live inputs */
.inputs { display: flex; align-items: center; gap: 16px; margin-top: 14px; padding: 14px 16px; border-radius: 14px; background: rgba(16, 19, 27, 0.8); border: 1px solid var(--line); }
.stick { position: relative; width: 54px; height: 54px; border-radius: 50%; background: #0a0c12; border: 2px solid #262d3c; }
.stick-dot {
  position: absolute; left: 50%; top: 50%; width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8a8a, var(--seat) 70%); transition: transform 0.04s;
}
.p2 .stick-dot { background: radial-gradient(circle at 35% 30%, #8ab8ff, var(--seat) 70%); }
.buttons { display: grid; grid-template-columns: repeat(3, 22px); gap: 6px; }
.buttons.neo { grid-template-columns: repeat(4, 22px); }
.btn-dot { width: 22px; height: 22px; border-radius: 50%; background: #1c2230; border: 2px solid #2b3345; font-size: 9px; font-weight: 800; color: #6e778b; display: grid; place-items: center; transition: background 0.04s; }
.btn-dot.on { color: #111; border-color: transparent; background: var(--c, #fff); box-shadow: 0 0 10px var(--c, #fff); }

/* Screen */
.screen-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.player-box { position: relative; border-radius: 14px; overflow: hidden; background: #000; border: 1px solid var(--line); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6); }
.stage { position: relative; aspect-ratio: 4 / 3; width: 100%; background: #000; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.player-box:fullscreen { border: 0; border-radius: 0; display: flex; align-items: center; justify-content: center; }
.player-box:fullscreen .stage { width: min(100vw, 133.333vh); }

.controls {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 26px 12px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85)); opacity: 0; transition: opacity 0.2s;
}
.player-box:hover .controls, .controls:focus-within, .player-box.idle-show .controls { opacity: 1; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; display: grid; place-items: center; color: #fff; flex: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: #d6dae4; white-space: nowrap; }
.timeline { flex: 1; height: 24px; display: flex; align-items: center; cursor: pointer; position: relative; }
.timeline .track { position: relative; width: 100%; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.18); overflow: hidden; transition: height 0.1s; }
.timeline:hover .track { height: 8px; }
.timeline .loaded { position: absolute; inset: 0 auto 0 0; background: rgba(255, 255, 255, 0.25); width: 0; }
.timeline .loaded.live { background: repeating-linear-gradient(45deg, rgba(255,255,255,0.28) 0 8px, rgba(255,255,255,0.16) 8px 16px); background-size: 22px 22px; animation: stripes 0.8s linear infinite; }
@keyframes stripes { to { background-position: 22px 0; } }
.timeline .played { position: absolute; inset: 0 auto 0 0; background: var(--accent); width: 0; }
.timeline .hover-time { position: absolute; bottom: 24px; transform: translateX(-50%); font-size: 12px; background: #000; padding: 2px 6px; border-radius: 5px; pointer-events: none; }
.segmented { display: flex; background: rgba(255, 255, 255, 0.1); border-radius: 8px; padding: 2px; flex: none; }
.segmented button { border: 0; background: transparent; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #b8bfcd; }
.segmented button.on { background: rgba(255, 255, 255, 0.2); color: #fff; }
.volume { display: flex; align-items: center; flex: none; }
.volume input[type="range"] { width: 70px; accent-color: var(--accent); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(7, 8, 12, 0.82); }
.overlay.clear { background: transparent; pointer-events: none; }
.overlay-card { max-width: 420px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.overlay-card h2 { margin: 0; font-size: 21px; }
.overlay-card p { margin: 0; color: var(--muted); font-size: 14px; }
.overlay-card .actions { display: flex; gap: 10px; margin-top: 4px; }
.big-play { width: 80px; height: 80px; border-radius: 50%; border: 0; background: var(--accent); color: #1a0b05; display: grid; place-items: center; box-shadow: 0 12px 40px rgba(255, 90, 54, 0.45); transition: transform 0.12s; }
.big-play:hover { transform: scale(1.06); }
.big-play svg { width: 34px; height: 34px; margin-left: 4px; }
.big-play.again svg { margin-left: 0; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #252c3b; border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-mini { width: 220px; height: 5px; border-radius: 3px; background: #252c3b; overflow: hidden; }
.progress-mini div { height: 100%; width: 0; background: var(--accent); }
.buffer-chip { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); padding: 5px 12px; border-radius: 99px; background: rgba(0, 0, 0, 0.75); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.buffer-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.fineprint { margin: 0; text-align: center; font-size: 12.5px; color: #5f6779; }
.fineprint [title] { cursor: help; border-bottom: 1px dotted #3b4253; }
#status.error { color: var(--bad); }

/* Games dialog */
.files-dialog {
  width: min(480px, calc(100vw - 32px)); padding: 18px 20px 20px; border-radius: 16px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}
.files-dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.files-head { display: flex; align-items: center; justify-content: space-between; margin: 0; }
.files-head h2 { margin: 0; font-size: 18px; }
.files-hint { margin: 4px 0 14px; color: var(--muted); font-size: 13.5px; }
.game-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.game-row.drag { background: rgba(255, 90, 54, 0.08); }
.game-row .info { flex: 1; min-width: 0; }
.game-row .title { font-weight: 700; }
.game-row .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.game-row .sub.bad { color: var(--warn); }
.chip { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.chip.ok { background: rgba(60, 207, 145, 0.14); color: var(--ok); }
.chip.warn { background: rgba(255, 176, 32, 0.14); color: var(--warn); }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 12.5px; padding: 4px; text-decoration: underline; }
.link-btn:hover { color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; background: #1a2030; border: 1px solid var(--line); padding: 9px 15px; border-radius: 10px; font-size: 14px; transition: all 0.2s; z-index: 60; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.page-drop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(7, 8, 12, 0.85); border: 3px dashed var(--accent); font-size: 20px; font-weight: 700; pointer-events: none; }

/* Narrow screens: players become compact rows above the screen. */
@media (max-width: 1100px) {
  .match { --stage-w: min(100%, calc((100vh - var(--bar-h) - 260px) * 4 / 3)); grid-template-columns: 1fr 1fr; gap: 12px; }
  .screen-col { grid-column: 1 / -1; grid-row: 2; width: max(var(--stage-w), min(100%, 420px)); justify-self: center; }
  .fighter { flex-direction: row; flex-wrap: wrap; text-align: left; gap: 4px 12px; padding: 10px 12px; border-radius: 12px; background: rgba(16, 19, 27, 0.7); border: 1px solid var(--line); }
  .fighter.p2 { flex-direction: row-reverse; text-align: right; }
  .avatar { width: 52px; height: 52px; font-size: 19px; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--seat); }
  .avatar-flag { font-size: 15px; right: -2px; bottom: -2px; }
  .fighter-name { margin: 0; font-size: 16px; }
  .fighter-meta, .rank-row, .inputs { display: none; }
  .rounds { margin: 0; }
  .rounds-label { display: none; }
}
@media (max-width: 640px) {
  .bar { padding: 0 12px; gap: 10px; }
  .brand .word { display: none; }
  .arena { padding: 12px 10px; }
  .volume input[type="range"], .time { display: none; }
  .bug-name { padding: 6px 10px; font-size: 13px; }
}
#sync { color: var(--ok); margin-right: 6px; }
#sync::before { content: "● "; }
