:root {
  --bg: #0b1220;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --team-a: #2563eb;
  --team-a-dark: #1d4ed8;
  --team-a-soft: #dbeafe;
  --team-b: #e11d48;
  --team-b-dark: #be123c;
  --team-b-soft: #ffe4e6;
  --green: #16a34a;
  --amber: #d97706;
  --gold: #facc15;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f1f5f9; color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
.hidden { display: none !important; }

/* Top Bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(15, 23, 42, 0.94); backdrop-filter: blur(10px);
  color: #f8fafc; padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 16px; }
.brand-icon {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #e11d48);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.nav-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.06);
  color: #e2e8f0; padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 13px;
  cursor: pointer; transition: all 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.nav-btn.active { background: #2563eb; border-color: #60a5fa; color: #fff; box-shadow: 0 4px 14px rgba(37,99,235,0.4); }

/* Buttons & Form Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 700; font-size: 13.5px; cursor: pointer; transition: all 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--team-a); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--team-a-dark); }
.btn-red { background: var(--team-b); color: #fff; }
.btn-red:hover:not(:disabled) { background: var(--team-b-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: #15803d; }
.btn-amber { background: var(--amber); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-outline:hover:not(:disabled) { background: #f8fafc; }
.btn-glass { background: rgba(15,23,42,0.74); color: #fff; border-color: rgba(255,255,255,0.22); backdrop-filter: blur(8px); }
.btn-glass:hover:not(:disabled) { background: rgba(30,41,59,0.92); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: 13px; }

.card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--team-a); box-shadow: 0 0 0 3px rgba(37,99,235,0.16);
}
.label { display: block; font-size: 12.5px; font-weight: 700; color: #334155; margin-bottom: 5px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800;
}
.badge-blue { background: var(--team-a-soft); color: #1d4ed8; }
.badge-red { background: var(--team-b-soft); color: #be123c; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-slate { background: #e2e8f0; color: #334155; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.alert { padding: 11px 14px; border-radius: 11px; font-size: 13.5px; font-weight: 600; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Full-Bleed 3D Display Stage */
.stage-wrapper {
  position: relative; width: 100%; height: calc(100vh - 57px); min-height: 580px;
  background: #0b1220; overflow: hidden;
}
#arena3d-mount { position: absolute; inset: 0; width: 100%; height: 100%; }

.hud-top {
  position: absolute; top: 14px; left: 16px; right: 16px; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.team-hud {
  min-width: 210px; max-width: 290px; padding: 12px 16px; border-radius: 16px; color: #fff;
  backdrop-filter: blur(10px); box-shadow: 0 12px 30px rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.22);
}
.team-hud-a { background: linear-gradient(135deg, rgba(37,99,235,0.92), rgba(29,78,216,0.88)); }
.team-hud-b { background: linear-gradient(135deg, rgba(225,29,72,0.92), rgba(190,18,60,0.88)); text-align: right; }
.team-hud-score { font-size: 28px; font-weight: 900; line-height: 1.05; margin: 2px 0; }
.team-hud-meta { font-size: 12px; opacity: 0.92; font-weight: 600; }

.center-hud {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: rgba(15, 23, 42, 0.78); backdrop-filter: blur(10px);
  padding: 10px 18px; border-radius: 16px; color: #fff;
  border: 1px solid rgba(255,255,255,0.18); box-shadow: 0 10px 26px rgba(0,0,0,0.28);
}
.timer-pill {
  font-size: 22px; font-weight: 900; padding: 3px 14px; border-radius: 999px;
  background: var(--gold); color: #0f172a;
}
.timer-pill.urgent { background: #ef4444; color: #fff; animation: pulse 0.6s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

.hud-question {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(1040px, calc(100% - 28px)); z-index: 12;
  background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(12px);
  border-radius: 20px; padding: 16px 20px;
  box-shadow: 0 18px 46px rgba(0,0,0,0.38); border: 2px solid rgba(255,255,255,0.8);
}
.hud-q-text {
  font-size: clamp(16px, 2vw, 22px); font-weight: 800; color: #0f172a;
  line-height: 1.38; margin-bottom: 12px; white-space: pre-wrap;
}
.hud-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
@media (max-width: 680px) { .hud-options { grid-template-columns: 1fr; } }
.hud-opt {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 12px; background: #f8fafc; border: 2px solid #cbd5e1;
  font-weight: 700; font-size: 14.5px; color: #0f172a;
}
.hud-opt.correct { background: #dcfce7; border-color: #16a34a; color: #14532d; }
.hud-opt-key {
  width: 30px; height: 30px; border-radius: 8px; background: #0f172a; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0;
}
.hud-opt.correct .hud-opt-key { background: #16a34a; }

.hud-floating-controls {
  position: absolute; right: 16px; top: 106px; z-index: 12;
  display: flex; flex-direction: column; gap: 8px;
}
.hud-overlay-center {
  position: absolute; inset: 0; z-index: 18;
  background: rgba(11, 18, 32, 0.52); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pin-box {
  background: rgba(255,255,255,0.97); color: #0f172a; border-radius: 24px;
  padding: 28px 34px; max-width: 620px; width: 100%; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.pin-digits {
  font-size: clamp(44px, 7vw, 72px); font-weight: 900; letter-spacing: 0.16em;
  color: var(--team-a); margin: 8px 0;
}
.quick-team-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.quick-team-box { padding: 10px 12px; border-radius: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.quick-team-a { background: #eff6ff; border: 2px solid #93c5fd; }
.quick-team-b { background: #fff1f2; border: 2px solid #fda4af; }

/* Mobile-First Play View */
.play-wrap {
  min-height: calc(100vh - 57px);
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 60%, #0f172a 100%);
  padding: 18px 14px; display: flex; justify-content: center; align-items: flex-start;
}
.play-inner { width: 100%; max-width: 540px; display: grid; gap: 14px; }
.ans-touch {
  width: 100%; min-height: 58px; padding: 12px 14px; border-radius: 14px;
  border: 2px solid #cbd5e1; background: #f8fafc; color: #0f172a;
  font-size: 16px; font-weight: 700; text-align: left;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.ans-touch.selected { border-color: var(--team-a); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }

/* Admin View */
.admin-wrap { max-width: 1220px; margin: 0 auto; padding: 22px 18px 60px; display: grid; gap: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 9px 10px; border-bottom: 2px solid #e2e8f0; color: #475569; font-size: 12px; text-transform: uppercase; }
td { padding: 10px; border-bottom: 1px solid #e2e8f0; vertical-align: top; }

/* Rope Mini Bar */
.rope-mini { position: relative; height: 22px; border-radius: 999px; background: linear-gradient(90deg, #2563eb, #93c5fd 46%, #fff 50%, #fda4af 54%, #e11d48); border: 2px solid #0f172a; }
.rope-mini-pin { position: absolute; top: 50%; width: 24px; height: 24px; border-radius: 50%; background: #facc15; border: 3px solid #0f172a; transform: translate(-50%, -50%); transition: left 0.4s ease; }
