:root {
  color-scheme: dark;
  --bg: #070b14;
  --surface: #0e1628;
  --surface-2: #14203a;
  --border: #233457;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --cyan: #00aeef;
  --magenta: #ff318c;
  --danger: #ff4d6d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 18% 0%, #102446 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 18px rgba(0, 174, 239, 0.7);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.arena-panel,
.side-panel {
  background: rgba(14, 22, 40, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.stat-value.cyan {
  color: var(--cyan);
}

.stat-value.magenta {
  color: var(--magenta);
}

.timer-track {
  height: 6px;
  background: #1a2744;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  transform-origin: left center;
}

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #060a12;
  aspect-ratio: 7 / 4;
}

#arenaCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 20, 0.82);
  backdrop-filter: blur(6px);
  padding: 16px;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--cyan);
  font-weight: 700;
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.overlay-desc {
  margin: 0 0 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
}

.controls-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
  text-align: left;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.field select,
.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.92rem;
  font-weight: 600;
}

.field input {
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hotseat-banner {
  background: rgba(255, 49, 140, 0.14);
  border: 1px solid rgba(255, 49, 140, 0.45);
  color: #ffd0e5;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.overlay-btns {
  display: flex;
  justify-content: center;
}

.seed-meta {
  margin: 10px 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.arena-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.overdrive-pill {
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(0, 174, 239, 0.2);
  border: 1px solid var(--cyan);
  color: var(--cyan);
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), #0077c8);
  color: #03111d;
  padding: 11px 22px;
  font-size: 0.98rem;
}

.btn-accent {
  background: linear-gradient(135deg, var(--magenta), #9b1fff);
  color: #fff;
}

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.14);
}

.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.side-header h2,
.legend h3 {
  margin: 0;
  font-size: 1rem;
}

.leaderboard {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 24px 44px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid rgba(35, 52, 87, 0.7);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.lb-rank {
  color: var(--muted);
  font-weight: 700;
}

.lb-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  color: var(--cyan);
}

.lb-meta {
  color: var(--muted);
  font-size: 0.74rem;
}

.lb-score {
  font-weight: 700;
}

.legend {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.legend ul {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
}

.cyan-dot { background: var(--cyan); }
.mag-dot { background: var(--magenta); }
.red-dot { background: var(--danger); }
.ring-dot { border: 2px solid var(--cyan); background: transparent; }

/* Native Modal Dialog — modern-web-guidance compliant */
dialog {
  max-width: 520px;
  width: calc(100% - 32px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px 22px;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(3, 6, 14, 0.75);
  overflow: hidden;
  overscroll-behavior: contain;
}

dialog h1 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

.rules-list {
  margin: 0 0 16px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
}

.rules-list strong {
  color: var(--text);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
    transition: none !important;
  }
}
