:root {
  --bg: #0b0c0f;
  --panel: #121419;
  --raise: #181b21;
  --line: #23262e;
  --line-2: #2e323b;
  --text: #e8e9ec;
  --dim: #9a9ea8;
  --faint: #60646e;
  --p1: #e5484d;
  --p2: #3e8bf0;
  --ok: #46a758;
  --warn: #d6a13b;
  --bad: #e5484d;
  --top-h: 48px;
  --side-w: 244px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 13px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--raise); padding: 1px 4px; border-radius: 3px; }
.p1 { --seat: var(--p1); }
.p2 { --seat: var(--p2); }

/* Top bar */
.top {
  height: var(--top-h); flex: none; display: flex; align-items: center; gap: 14px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; text-decoration: none; white-space: nowrap; }
.search { flex: 1; display: flex; gap: 6px; max-width: 640px; }
.search input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--line-2); outline: none;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { border-color: #5a5f6b; }
.top-actions { display: flex; gap: 6px; margin-left: auto; }
.btn {
  height: 30px; padding: 0 11px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--raise);
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: #20242c; border-color: #3a3f4a; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover:not(:disabled) { background: #fff; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
#btn-files .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
#btn-files .dot.ok { background: var(--ok); }

/* Layout */
.layout {
  flex: 1; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--side-w); gap: 12px;
  padding: 12px; width: 100%; max-width: 1680px; margin: 0 auto; align-items: start;
}
.center { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Score bug */
.scorebug {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch;
  height: 54px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
.sb-side { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 12px; position: relative; }
.sb-side::before { content: ""; position: absolute; top: 0; bottom: 0; width: 4px; background: var(--seat); }
.sb-side.p1::before { left: 0; }
.sb-side.p2::before { right: 0; }
.sb-side.p2 { justify-content: flex-end; text-align: right; }
.sb-mono {
  flex: none; width: 32px; height: 32px; border-radius: 4px; display: grid; place-items: center;
  background: var(--raise); border: 1px solid var(--line-2); font: 700 12px ui-monospace, Menlo, monospace; color: var(--dim);
}
.sb-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sb-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sub { display: flex; gap: 6px; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; }
.sb-side.p2 .sb-sub { justify-content: flex-end; }
.sb-char { color: var(--text); font-weight: 500; }
.sb-char:empty { display: none; }
.mb-rank { flex: none; font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--dim); border: 1px solid var(--line-2); border-radius: 3px; padding: 0 4px; }
.mb-rank:empty { display: none; }
.sb-plate { display: flex; align-items: stretch; background: #07080a; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.sb-num {
  width: 56px; display: grid; place-items: center; font: 700 30px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums; color: var(--text); position: relative;
}
.sb-num::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px; background: var(--seat); }
.sb-num.lead { color: var(--seat); }
.sb-num.bump { animation: bump 0.9s ease-out; }
@keyframes bump {
  0% { transform: scale(1); background: transparent; }
  15% { transform: scale(1.35); background: color-mix(in srgb, var(--seat) 30%, transparent); }
  100% { transform: scale(1); background: transparent; }
}
.sb-mid { min-width: 64px; padding: 0 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.sb-ft { font: 700 12px ui-monospace, Menlo, monospace; letter-spacing: 0.06em; color: var(--dim); }
.sb-game { font-size: 11px; color: var(--faint); white-space: nowrap; }
.sb-game:empty { display: none; }
.sb-meta { margin: -2px 0 0; display: flex; justify-content: center; gap: 8px; font-size: 12px; color: var(--dim); }
.sb-meta #mb-game { color: var(--text); font-weight: 600; }
.sb-meta #mb-meta:empty { display: none; }

/* Game and set results over the stage */
.game-banner {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%); z-index: 3; pointer-events: none;
  display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 12px; white-space: nowrap;
  background: rgba(7, 8, 10, 0.92); border: 1px solid var(--line-2); border-left: 4px solid var(--seat); border-radius: 4px;
  font-weight: 600; font-size: 15px; animation: banner 3.2s ease forwards;
}
.game-banner b { color: var(--seat); }
.game-banner .score { font: 700 15px ui-monospace, Menlo, monospace; color: var(--dim); }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  8%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}
.winner.p1 { --seat: var(--p1); }
.winner.p2 { --seat: var(--p2); }
.winner .crest {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; position: relative;
  border: 3px solid var(--seat); font: 700 22px ui-monospace, Menlo, monospace; background: var(--raise);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--seat) 18%, transparent);
  animation: crest 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.winner .label { font: 700 11px ui-monospace, Menlo, monospace; letter-spacing: 0.18em; color: var(--seat); margin-top: 6px; }
.winner h2 { font-size: 22px !important; font-weight: 700 !important; }
.winner .final { font: 700 26px ui-monospace, Menlo, monospace; display: flex; gap: 10px; align-items: center; }
.winner .final .p1 { color: var(--p1); }
.winner .final .p2 { color: var(--p2); }
.winner .final .dash { color: var(--faint); font-size: 18px; }
@keyframes crest { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.overlay.celebrate { background: rgba(11, 12, 15, 0.72); }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }

/* Player box */
.player-box {
  width: min(100%, calc((100vh - var(--top-h) - 128px) * 4 / 3)); margin: 0 auto;
  background: #000; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  display: flex; flex-direction: column;
}
.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 { width: 100vw; border: 0; border-radius: 0; justify-content: center; }
.player-box:fullscreen .stage { width: min(100vw, calc((100vh - 40px) * 4 / 3)); margin: 0 auto; }

.controls {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 8px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.icon-btn { width: 28px; height: 28px; border-radius: 4px; border: 0; background: transparent; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--raise); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.time { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--dim); white-space: nowrap; padding: 0 4px; }
.timeline { flex: 1; height: 28px; display: flex; align-items: center; cursor: pointer; position: relative; }
.timeline .track { position: relative; width: 100%; height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.timeline:hover .track { height: 6px; }
.timeline .loaded { position: absolute; inset: 0 auto 0 0; background: #3c414c; width: 0; }
.timeline .loaded.live { background: repeating-linear-gradient(90deg, #3c414c 0 6px, #30343d 6px 12px); }
.timeline .played { position: absolute; inset: 0 auto 0 0; background: var(--text); width: 0; }
.timeline .hover-time { position: absolute; bottom: 26px; transform: translateX(-50%); font: 11px ui-monospace, Menlo, monospace; background: var(--raise); border: 1px solid var(--line-2); padding: 1px 5px; border-radius: 3px; pointer-events: none; }
.segmented { display: flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; flex: none; }
.segmented button { border: 0; background: transparent; padding: 3px 7px; font: 11px ui-monospace, Menlo, monospace; color: var(--dim); }
.segmented button + button { border-left: 1px solid var(--line-2); }
.segmented button.on { background: var(--raise); color: var(--text); }
.volume { display: flex; align-items: center; flex: none; }
.volume input[type="range"] { width: 64px; accent-color: var(--text); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(11, 12, 15, 0.86); }
.overlay.clear { background: transparent; pointer-events: none; }
.overlay-card { max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.overlay-card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.overlay-card p { margin: 0; color: var(--dim); }
.overlay-card .actions { display: flex; gap: 6px; margin-top: 6px; }
.overlay-card .err { width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--bad); color: var(--bad); display: grid; place-items: center; font-weight: 700; }
.big-play { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.big-play:hover { background: #fff; }
.big-play svg { width: 22px; height: 22px; margin-left: 3px; }
.big-play.again svg { margin-left: 0; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--text); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-mini { width: 200px; height: 3px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.progress-mini div { height: 100%; width: 0; background: var(--text); }
.buffer-chip { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 3px; background: rgba(0, 0, 0, 0.8); border: 1px solid var(--line-2); font-size: 11px; color: var(--warn); }

.statusline { margin: 0; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--faint); padding: 0 2px; }
#status { color: var(--dim); }
#status.error { color: var(--bad); }

/* Player panels */
.who { position: relative; overflow: hidden; }
.who::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 2px; background: var(--seat); }
.who-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px; }
.mono {
  flex: none; width: 36px; height: 36px; border-radius: 4px; display: grid; place-items: center;
  background: var(--raise); border: 1px solid var(--line-2); font-weight: 700; font-size: 13px; color: var(--dim);
}
.who-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.name { font-size: 14px; font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.name[href]:hover { text-decoration: underline; }
.where { color: var(--dim); font-size: 12px; display: flex; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat { flex: none; align-self: flex-start; font: 600 10px ui-monospace, Menlo, monospace; color: var(--seat); border: 1px solid var(--seat); border-radius: 3px; padding: 0 4px; }
.stats { margin: 0; border-top: 1px solid var(--line); }
.stats > div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px; }
.stats > div + div { border-top: 1px solid var(--line); }
.stats dt { color: var(--faint); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.stats a { color: var(--dim); text-decoration: none; }
.stats a:hover { color: var(--text); }
.rank-tag { font: 600 12px ui-monospace, Menlo, monospace; }

/* Pad */
.pad { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 14px 12px; }
.gate { position: relative; flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line-2); }
.gate::before, .gate::after { content: ""; position: absolute; background: var(--line); }
.gate::before { left: 50%; top: 8px; bottom: 8px; width: 1px; }
.gate::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.ball {
  position: absolute; z-index: 1; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%;
  background: #3a3f4a; border: 1px solid #4a505c; transition: transform 0.03s linear;
}
.ball.on { background: var(--seat); border-color: var(--seat); }
.buttons { display: grid; grid-template-columns: repeat(3, 24px); gap: 6px; }
.buttons.neo { grid-template-columns: repeat(4, 24px); }
.key {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--line-2); font: 600 9px ui-monospace, Menlo, monospace; color: var(--faint);
}
.key.on { background: var(--c); border-color: var(--c); color: #0b0c0f; }

.fold {
  width: 100%; display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 12px;
  border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--dim); font-size: 12px;
}
.fold:hover { color: var(--text); }
.fold svg { width: 14px; height: 14px; transition: transform 0.15s; }
.fold[aria-expanded="false"] svg { transform: rotate(-90deg); }
.log {
  list-style: none; margin: 0; padding: 0 0 4px; border-top: 1px solid var(--line);
  height: calc(100vh - var(--top-h) - 360px); min-height: 160px; max-height: 420px; overflow: hidden;
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fold[aria-expanded="false"] + .log { display: none; }
.log li { display: grid; grid-template-columns: 30px 18px 1fr; align-items: center; gap: 6px; height: 21px; padding: 0 12px; }
.log li:first-child { background: var(--raise); }
.log .n { color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; }
.log .dir { color: var(--text); text-align: center; font-size: 13px; }
.log .dir.neutral { color: var(--faint); }
.log .ks { display: flex; gap: 3px; }
.log .k { min-width: 18px; height: 15px; padding: 0 3px; border-radius: 2px; display: grid; place-items: center; font-size: 9px; font-weight: 700; background: var(--c); color: #0b0c0f; }
.log .k.sys { background: var(--line-2); color: var(--dim); }
.log:empty::before { content: "No inputs yet"; display: block; padding: 10px 12px; color: var(--faint); font-family: inherit; }

/* Sheets (dialogs) */
.sheet {
  width: min(460px, calc(100vw - 32px)); padding: 0; border-radius: 8px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.sheet-hint { margin: 12px 16px 4px; color: var(--dim); }
#game-rows { padding: 0 16px 8px; }
.game-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.game-row:first-child { border-top: 0; }
.game-row.drag { background: var(--raise); }
.game-row .info { flex: 1; min-width: 0; }
.game-row .title { font-weight: 600; }
.game-row .sub { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; }
.game-row .sub.bad { color: var(--warn); }
.chip { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 3px; border: 1px solid currentColor; }
.chip.ok { color: var(--ok); }
.chip.warn { color: var(--warn); }
.link-btn { border: 0; background: none; color: var(--dim); font-size: 12px; padding: 4px; }
.link-btn:hover { color: var(--bad); }

.share .copy-row { display: flex; gap: 6px; padding: 14px 16px 8px; }
.share .copy-row input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px; border-radius: 4px; background: var(--bg);
  border: 1px solid var(--line-2); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; outline: none;
}
.check { display: flex; align-items: center; gap: 8px; padding: 0 16px 12px; color: var(--dim); cursor: pointer; }
.check input { accent-color: var(--text); margin: 0; }
.check b { color: var(--text); font: 500 12px ui-monospace, Menlo, monospace; }
.targets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 12px 16px; border-top: 1px solid var(--line); }
.targets .btn { justify-content: center; }
.sheet-foot { margin: 0; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; }
.sheet-foot a { color: var(--dim); text-decoration: none; }
.sheet-foot a:hover { color: var(--text); }

.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 12px); opacity: 0; background: var(--raise); border: 1px solid var(--line-2); padding: 7px 12px; border-radius: 4px; transition: all 0.15s; 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(11, 12, 15, 0.9); border: 2px dashed var(--line-2); font-size: 15px; font-weight: 600; pointer-events: none; }

/* Narrower screens: both players sit under the screen. */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .center { grid-column: 1 / -1; grid-row: 1; }
  .player-box { width: min(100%, calc((100vh - var(--top-h) - 128px) * 4 / 3), 960px); }
  .log { height: 220px; }
}
@media (max-width: 680px) {
  .top { gap: 8px; padding: 0 10px; }
  .brand { display: none; }
  .btn svg { display: none; }
  .layout { grid-template-columns: 1fr; padding: 8px; }
  .side.p2 { grid-row: 3; }
  .time, .volume input[type="range"], .statusline .keys { display: none; }
  .scorebug { height: 46px; }
  .sb-side { padding: 0 8px; gap: 6px; }
  .sb-mono, .sb-sub, .mb-rank { display: none; }
  .sb-name { font-size: 13px; }
  .sb-num { width: 40px; font-size: 24px; }
  .sb-mid { min-width: 44px; }
  .sb-game { display: none; }
}
