:root {
  --bg-main: #090711;
  --bg-panel: #101222;
  --bg-card: #171b30;
  --border-subtle: rgba(148, 163, 184, 0.18);
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #f97316;
  --accent-cool: #38bdf8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 68% 30%, #1e132b 0%, var(--bg-main) 68%);
  color: var(--text-primary);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(16, 18, 34, 0.88);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 12px 18px;
  backdrop-filter: blur(10px);
}

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

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ea580c, #dc2626);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.4);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

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

.hud-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}

.phase-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}

.phase-badge.phase-1 {
  background: rgba(250, 204, 21, 0.16);
  color: #fde047;
}

.phase-badge.phase-2 {
  background: rgba(251, 146, 60, 0.20);
  color: #fdba74;
}

.phase-badge.phase-3 {
  background: rgba(239, 68, 68, 0.24);
  color: #fca5a5;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.95rem;
}

.speed-group {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 2px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button:not(:disabled):active {
  transform: scale(0.97);
}

.btn-chip {
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.84rem;
  padding: 6px 10px;
  border-radius: 8px;
}

.btn-chip.active {
  background: var(--accent-cool);
  color: #04101f;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 10px;
}

.btn-secondary:hover:not(:disabled) {
  background: #212644;
}

.btn-secondary.active-toggle {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.14);
  color: #bae6fd;
}

.btn-small {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 0.78rem;
  padding: 5px 10px;
  border-radius: 8px;
}

.btn-small:hover {
  background: #22294a;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #f97316, #eab308);
  color: #160903;
  font-weight: 800;
  font-size: 0.96rem;
  letter-spacing: 0.02em;
  padding: 13px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.32);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

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

.sidebar {
  background: rgba(16, 18, 34, 0.92);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.count-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fdba74;
  background: rgba(249, 115, 22, 0.16);
  padding: 3px 9px;
  border-radius: 999px;
}

.panel-hint {
  margin: 0 0 14px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.roster-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 8px;
}

.color-dot {
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
  cursor: pointer;
}

.roster-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
}

.roster-input::placeholder {
  color: #64748b;
}

.btn-roster-tag {
  width: 28px;
  height: 26px;
  padding: 0;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-roster-tag:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.45);
}

.btn-remove {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-remove:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
  color: #fca5a5;
}

.setup-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.setup-actions-row .btn-secondary {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.legend-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.legend-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.legend-grid span {
  display: inline-block;
  min-width: 22px;
  font-weight: 700;
}

.panel-subhint {
  margin: 0 0 10px;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-muted);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.lb-row {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.lb-row:hover {
  border-color: rgba(148, 163, 184, 0.42);
  background: #1d2340;
}

.lb-row.cam-following {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35), 0 4px 14px rgba(56, 189, 248, 0.16);
  background: rgba(26, 36, 62, 0.95);
}

.lb-row.eliminated {
  opacity: 0.52;
  cursor: default;
}

.lb-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lb-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.lb-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-height {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.88rem;
}

.lb-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.events-section h3 {
  margin: 0 0 8px;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

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

.event-item {
  background: rgba(23, 27, 48, 0.8);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #e2e8f0;
}

.arena-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.telemetry-bar {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(16, 18, 34, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 700;
}

.telemetry-item.lava {
  color: #fb923c;
}

.arena-stage {
  position: relative;
  width: 100%;
  max-width: 820px;
  aspect-ratio: 4 / 3;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: #0d0a18;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.65);
}

#arena-gl-canvas,
#arena-hud-canvas {
  position: absolute;
  inset: 0;
  display: block;
}

#arena-gl-canvas {
  z-index: 1;
  pointer-events: none;
}

#arena-hud-canvas {
  z-index: 2;
  cursor: grab;
}

#arena-hud-canvas:active {
  cursor: grabbing;
}

.camera-dock {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(9, 12, 24, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.28);
  backdrop-filter: blur(8px);
  max-width: calc(100% - 20px);
}

.cam-pill {
  background: transparent;
  color: #cbd5e1;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.cam-pill:hover {
  background: rgba(148, 163, 184, 0.16);
  color: #ffffff;
}

.cam-pill.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.65);
  color: #e0f2fe;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.22);
}

.cam-pill.active-xray {
  background: rgba(168, 85, 247, 0.22);
  border-color: rgba(192, 132, 252, 0.58);
  color: #f3e8ff;
}

.cam-pill.cam-reset {
  padding: 5px 9px;
  font-size: 0.85rem;
}

.cam-divider {
  width: 1px;
  height: 16px;
  background: rgba(148, 163, 184, 0.28);
  margin: 0 2px;
}

.winner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 7, 17, 0.68);
  backdrop-filter: blur(7px);
  padding: 20px;
  z-index: 10;
}

.winner-card {
  width: 100%;
  max-width: 420px;
  background: rgba(16, 18, 34, 0.96);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 26px 24px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
}

.winner-crown {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 8px;
}

.winner-kicker {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fde047;
}

.winner-title {
  margin: 8px 0 18px;
  font-size: 1.55rem;
  font-weight: 800;
  word-break: break-word;
}

.winner-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.stat-item strong {
  font-size: 0.98rem;
}

.winner-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-shell.is-spectator .host-only {
  display: none !important;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.live-pill.is-host {
  background: rgba(234, 179, 8, 0.16);
  border-color: rgba(250, 204, 21, 0.55);
  color: #fef08a;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 10px #ef4444;
  animation: livePulse 1.6s ease-in-out infinite;
}

.live-pill.is-host .live-dot {
  background: #facc15;
  box-shadow: 0 0 10px #facc15;
}

@keyframes livePulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.8);
  }
}

.spectator-count {
  padding-left: 6px;
  border-left: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.spectator-banner {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.38);
  color: #bae6fd;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 0.8rem;
  line-height: 1.38;
  margin-bottom: 12px;
}

.roster-row.readonly {
  justify-content: space-between;
  padding: 8px 10px;
}

.roster-readonly-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

.roster-readonly-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-trait-pill {
  font-size: 0.74rem;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.20);
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
}

.spectator-winner-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.spectator-winner-box p {
  margin: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 15, 0.76);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: rgba(16, 18, 34, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.72);
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 800;
}

.auth-hint {
  margin: 0 0 14px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.auth-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.94rem;
  outline: none;
  margin-bottom: 10px;
}

.auth-input:focus {
  border-color: var(--accent-cool);
}

.auth-error {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: #fca5a5;
  font-weight: 600;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

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

  .arena-stage,
  .telemetry-bar {
    max-width: 100%;
  }
}
