:root {
  --bg: #0c0910;
  --panel: #171221;
  --panel-2: #211930;
  --border: #38294d;
  --crimson: #e03a5a;
  --crimson-hover: #f24b6b;
  --cyan: #48d5ff;
  --gold: #ffd466;
  --ok: #46e092;
  --text: #f3effa;
  --muted: #a699bc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #231129 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.hidden { display: none !important; }

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--crimson);
  box-shadow: 0 0 12px var(--crimson);
}
.brand h1 { margin: 0; font-size: 1.2rem; letter-spacing: 0.3px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 0.85rem; margin-left: 6px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px 3px 6px;
}
.btn-icon {
  border: none;
  background: transparent;
  padding: 2px 4px;
  font-size: 0.95rem;
  line-height: 1;
}
.btn-icon:hover { background: transparent; border-color: transparent; }
#volume-slider {
  width: 84px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  accent-color: var(--crimson);
  cursor: pointer;
}
.vol-label {
  font-size: 0.76rem;
  color: var(--muted);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge.ok { border-color: var(--ok); color: var(--ok); }
.badge.warn { border-color: var(--gold); color: var(--gold); }
.badge.p1 { border-color: var(--gold); color: var(--gold); }
.badge.p2 { border-color: var(--cyan); color: var(--cyan); }

.card {
  background: rgba(23, 18, 33, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.center-card { max-width: 520px; margin: 60px auto; text-align: center; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 18px;
}
@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

h2 { margin: 0 0 6px; font-size: 1.15rem; }
.sub { margin: 0 0 16px; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 12px; }

.progress-track {
  height: 10px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--crimson), var(--cyan));
  transition: width 0.2s ease;
}

.field-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field-row.inline { flex-direction: row; gap: 8px; }
.field-row label { font-size: 0.8rem; color: var(--muted); }

input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.92rem;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--crimson); }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 16px;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--crimson); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--crimson-hover); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-sm:hover { border-color: var(--cyan); }
.btn-danger { border-color: #6b2234; color: #ff8ea2; }
.btn-danger:hover { border-color: var(--crimson); color: #fff; background: #6b2234; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0; color: var(--muted); font-size: 0.8rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.error-text { color: #ff7c96; font-size: 0.85rem; margin: 8px 0 0; }

.room-banner {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.room-banner .label { display: block; font-size: 0.7rem; color: var(--muted); letter-spacing: 1px; }
.room-code { font-size: 1.45rem; letter-spacing: 3px; color: var(--gold); }
.room-actions { display: flex; gap: 8px; }

.conn-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  font-size: 0.78rem; padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill-ok { border-color: var(--ok); color: var(--ok); }
.pill-wait { border-color: var(--gold); color: var(--gold); }

.players-box { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.player-slot {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.tag { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.8px; }
.tag-p1 { color: var(--gold); }
.tag-p2 { color: var(--cyan); }
.ready-pill { font-size: 0.76rem; color: var(--muted); }
.ready-pill.is-ready { color: var(--ok); font-weight: 600; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .settings-grid { grid-template-columns: 1fr; } }

.controls-card {
  margin-top: 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.controls-card h3 { margin: 0 0 8px; font-size: 0.92rem; color: var(--gold); }
.controls-card ul { margin: 0; padding-left: 18px; font-size: 0.84rem; color: var(--muted); line-height: 1.55; }
.controls-card code { background: #0f0b16; color: var(--text); padding: 1px 5px; border-radius: 4px; }

.game-stage { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.canvas-wrap {
  position: relative;
  width: min(92vw, 853px);
  aspect-ratio: 4 / 3;
  background: #000;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6);
}
#canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  image-rendering: pixelated;
}

.waiting-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 9, 16, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  font-weight: 600;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.game-footer { font-size: 0.84rem; color: var(--muted); text-align: center; }
.game-footer code { background: var(--panel-2); color: var(--text); padding: 2px 6px; border-radius: 4px; }
