:root {
  --bg: #0a0d16;
  --bg-2: #0f1320;
  --panel: #131827;
  --panel-2: #192036;
  --line: #242c44;
  --text: #e9edf7;
  --muted: #8d97b0;
  --left: #3fd4ff;
  --left-dim: rgba(63, 212, 255, 0.16);
  --right: #ff6d5a;
  --right-dim: rgba(255, 109, 90, 0.16);
  --gold: #ffb84d;
  --good: #58e39a;
  --bad: #ff5f6d;
  --radius: 14px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bungee", "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -200px, #1a2140 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(10, 13, 22, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  font-size: 20px;
  color: var(--gold);
}

.brand-text {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.04em;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 600;
}

.topbar-nav {
  display: flex;
  gap: 4px;
}

.navlink {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
}

.navlink:hover {
  color: var(--text);
  background: var(--panel);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}

.pill.live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 10px var(--bad);
  animation: pulse 1.4s infinite;
}

.pill.warn {
  color: var(--bad);
  border-color: rgba(255, 95, 109, 0.5);
}

.pill .big {
  font-family: var(--font-display);
  font-size: 15px;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ── lobby ───────────────────────────────────────────────── */
.lobby {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 20px 80px;
}

.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 32px;
  align-items: start;
  margin-bottom: 44px;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  margin: 8px 0 16px;
}

.accent {
  background: linear-gradient(90deg, var(--left), var(--gold) 55%, var(--right));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  color: #c3cae0;
  font-size: 17px;
  max-width: 60ch;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: 600 15px var(--font-ui);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: #3a4566;
}

.btn-primary {
  background: linear-gradient(180deg, #ffc56b, #ff9f2e);
  color: #1a1206;
  border: none;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.connect h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.connect p {
  margin: 8px 0;
  color: #c3cae0;
}

.connect details {
  margin-top: 10px;
}

.connect summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.copyline {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.copyline code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  font: 13px var(--font-mono);
  background: #0b0f1b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.copy {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0 12px;
  font: 600 13px var(--font-ui);
  cursor: pointer;
}

.hint {
  font-size: 13px;
  color: var(--muted) !important;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.section-head h2 {
  margin: 0 0 14px;
}

.board-section {
  margin-bottom: 36px;
}

.board {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  font-size: 14px;
}

.board th,
.board td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.board th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.board tr:last-child td {
  border-bottom: none;
}

.board .model-cell {
  font-family: var(--font-mono);
  font-size: 13px;
}

.match-list {
  display: grid;
  gap: 10px;
}

.match-row {
  display: grid;
  grid-template-columns: 110px 1fr auto 1fr 120px;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-decoration: none;
}

.match-row:hover {
  border-color: #3a4566;
  background: var(--panel-2);
}

.match-row .vs {
  font-family: var(--font-display);
  color: var(--muted);
}

.match-row .p {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.match-row .p.right {
  text-align: right;
}

.match-row .p b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-row .p.left b {
  color: var(--left);
}

.match-row .p.right b {
  color: var(--right);
}

.match-row .p small {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.match-row .status {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

/* ── arena ───────────────────────────────────────────────── */
.arena {
  padding: 14px 16px 40px;
  max-width: 1600px;
  margin: 0 auto;
}

.stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #111626;
  aspect-ratio: 16 / 7;
  max-height: 64vh;
  width: 100%;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.plate {
  position: absolute;
  top: 12px;
  z-index: 3;
  width: min(300px, 40%);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(9, 12, 22, 0.72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
}

.plate-left {
  left: 12px;
  border-left: 3px solid var(--left);
}

.plate-right {
  right: 12px;
  border-right: 3px solid var(--right);
  text-align: right;
}

.plate .who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: space-between;
}

.plate-right .who {
  flex-direction: row-reverse;
}

.plate .name {
  font-family: var(--font-display);
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plate-left .name {
  color: var(--left);
}

.plate-right .name {
  color: var(--right);
}

.plate .score {
  font-family: var(--font-display);
  font-size: 22px;
}

.plate .model {
  font: 12px var(--font-mono);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plate .row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 7px;
  font-size: 12px;
  color: #c3cae0;
}

.plate-right .row {
  flex-direction: row-reverse;
}

.hp {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: #242b40;
  overflow: hidden;
}

.hp > i {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.plate-left .hp > i {
  background: linear-gradient(90deg, #1b9fd0, var(--left));
}

.plate-right .hp > i {
  background: linear-gradient(270deg, #d34a3a, var(--right));
  margin-left: auto;
}

.ammo {
  display: flex;
  gap: 3px;
}

.plate-right .ammo {
  flex-direction: row-reverse;
}

.ammo i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #6e7890;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35);
}

.ammo i.spent {
  background: #262d42;
  box-shadow: none;
}

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.tag.ok {
  color: var(--good);
  border-color: rgba(88, 227, 154, 0.35);
}

.tag.warn {
  color: var(--gold);
  border-color: rgba(255, 184, 77, 0.35);
}

.tag.iron {
  color: #ffcf5c;
  border-color: rgba(255, 207, 92, 0.4);
  background: #1d2027;
}

.iron-text {
  color: #ffcf5c;
}

.tag.bad {
  color: var(--bad);
  border-color: rgba(255, 95, 109, 0.35);
}

.banner {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -8px);
  z-index: 4;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(9, 12, 22, 0.85);
  border: 1px solid var(--line);
  font-weight: 800;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 34%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.result {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: radial-gradient(closest-side, rgba(8, 10, 18, 0.82), rgba(8, 10, 18, 0.55));
}

.result-card {
  text-align: center;
  padding: 26px 34px;
  border-radius: 18px;
  background: rgba(15, 19, 32, 0.92);
  border: 1px solid var(--line);
  max-width: 560px;
}

.result-card .label {
  color: var(--muted);
  letter-spacing: 0.2em;
  font-weight: 800;
  font-size: 12px;
}

.result-card .winner {
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 40px);
  margin: 6px 0;
}

.result-card table {
  margin: 14px auto 4px;
  border-collapse: collapse;
  font-size: 13px;
}

.result-card td,
.result-card th {
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
}

.result-card th {
  color: var(--muted);
  font-weight: 600;
}

.result-card .again {
  margin-top: 14px;
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1.05fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.code-panel#code-left h3 {
  color: var(--left);
}

.code-panel#code-right h3 {
  color: var(--right);
}

.code-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

pre.code {
  margin: 0;
  max-height: 340px;
  overflow: auto;
  background: #0b0f1b;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font: 12.5px/1.55 var(--font-mono);
  color: #d6dcef;
  white-space: pre;
}

pre.code .k {
  color: #c792ea;
}

pre.code .n {
  color: #f78c6c;
}

pre.code .s {
  color: #c3e88d;
}

pre.code .c {
  color: #697098;
  font-style: italic;
}

pre.code .f {
  color: #82aaff;
}

.attempts {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 12.5px;
}

.attempts li {
  padding: 7px 9px;
  border-radius: 8px;
  background: #0f1422;
  border: 1px solid var(--line);
}

.attempts li.bad {
  border-color: rgba(255, 95, 109, 0.35);
  color: #ffc5cb;
}

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 410px;
  overflow: auto;
  font-size: 13px;
}

.log li {
  padding: 8px 10px;
  border-radius: 9px;
  background: #0f1422;
  border: 1px solid var(--line);
}

.log li.left {
  border-left: 3px solid var(--left);
}

.log li.right {
  border-left: 3px solid var(--right);
}

.log li.sys {
  color: var(--muted);
}

.log b.hit {
  color: var(--gold);
}

.waiting-card {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .panels {
    grid-template-columns: 1fr;
  }

  .match-row {
    grid-template-columns: 1fr auto 1fr;
  }

  .match-row .id,
  .match-row .status {
    display: none;
  }

  .stage {
    aspect-ratio: 4 / 3;
  }

  .plate {
    width: 46%;
    padding: 7px 9px;
  }

  .plate .name {
    font-size: 13px;
  }

  .plate .score {
    font-size: 16px;
  }

  .topbar-nav {
    display: none;
  }
}
