:root {
  --bg: #0e0f14;
  --panel: #171923;
  --panel-2: #1f2230;
  --text: #f2f2f7;
  --muted: #8a8fa3;
  --accent: #f5b82e;
  --live: #39c6ff;
  --danger: #ff6b6b;
  --radius: 12px;
  --u: 8px;
  --font: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: calc(var(--u) * 2); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent { color: var(--accent); }

:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }

/* Buttons */
button { font-family: inherit; font-size: 14px; cursor: pointer; }
.btn {
  border-radius: var(--radius);
  padding: var(--u) calc(var(--u) * 2);
  min-height: 40px;
  font-weight: 600;
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
}
.btn.primary { background: var(--accent); color: #1a1405; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: #2c3042; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 2);
  padding: var(--u) calc(var(--u) * 3);
  min-height: 56px;
  background: var(--panel);
  border-bottom: 1px solid #23273a;
  flex: none;
}
.logo { font-weight: 800; letter-spacing: 0.08em; color: var(--accent); white-space: nowrap; }
.spacer { flex: 1; }
.live-pill {
  display: inline-flex; align-items: center; gap: var(--u);
  padding: 4px 12px; border-radius: 999px;
  background: rgba(57, 198, 255, 0.12); color: var(--live);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.auth-area { display: flex; align-items: center; gap: var(--u); }
.handle { font-weight: 600; margin-right: var(--u); }

/* Layout */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 280px;
  gap: calc(var(--u) * 2);
  padding: calc(var(--u) * 2);
}
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: calc(var(--u) * 2);
  overflow-y: auto;
  min-height: 0;
}

.now { display: flex; justify-content: space-between; align-items: baseline; margin-top: var(--u); gap: var(--u); }
.now-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-timer { font-variant-numeric: tabular-nums; color: var(--live); font-weight: 700; }
.queue-list { list-style: none; margin: var(--u) 0 0; padding: 0; display: grid; gap: 4px; }
.queue-row {
  display: flex; align-items: center; gap: var(--u);
  padding: var(--u) calc(var(--u) * 1.5);
  border-radius: var(--u);
  background: var(--panel-2);
}
.queue-row .pos { color: var(--muted); width: 24px; font-variant-numeric: tabular-nums; }
.queue-row .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-row.me { background: rgba(57, 198, 255, 0.14); outline: 1px solid var(--live); }
.queue-row.me .who { color: var(--live); font-weight: 600; }

/* Stage */
.stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #090a0e;
  min-height: 0;
  min-width: 0;
}
.canvas-host { position: absolute; inset: 0; touch-action: none; }
.stage-canvas { width: 100%; height: 100%; display: block; }
.conn {
  position: absolute; top: calc(var(--u) * 2); left: 50%; transform: translateX(-50%);
  background: rgba(23, 25, 35, 0.92); padding: var(--u) calc(var(--u) * 2);
  border-radius: 999px; color: var(--accent); font-weight: 600;
}
.toast {
  position: absolute; top: 20%; left: 50%; transform: translate(-50%, 0);
  color: var(--accent); font-size: 28px; font-weight: 800;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
  opacity: 0; pointer-events: none;
}
.toast.show { animation: toast 1.1s ease-out; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 12px); }
  20% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -28px); }
}
.live-banner {
  position: absolute; top: calc(var(--u) * 2); right: calc(var(--u) * 2);
  background: rgba(57, 198, 255, 0.16); color: var(--live);
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
}

/* HUD */
.hud {
  position: absolute; left: calc(var(--u) * 2); right: calc(var(--u) * 2); bottom: calc(var(--u) * 2);
  display: flex; align-items: center; justify-content: center; gap: calc(var(--u) * 3);
  padding: calc(var(--u) * 1.5) calc(var(--u) * 3);
  background: rgba(23, 25, 35, 0.88);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  user-select: none;
  flex-wrap: wrap;
}
.hud[data-state='spectator'] { opacity: 0.8; }
.hud[data-state='none'] { display: none; }
.hud-item { display: grid; gap: 2px; text-align: center; }
.hud-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.hud-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.meter-wrap { flex: 1; min-width: 160px; max-width: 360px; display: grid; gap: 4px; }
.meter { height: 12px; border-radius: 999px; background: #262a3b; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ff8a3d); }
.meter-hint { font-size: 12px; color: var(--muted); text-align: center; }
.hud-msg { font-weight: 600; }
.hud-sub { color: var(--muted); font-size: 12px; }

/* Stats and events */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--u); margin-top: calc(var(--u) * 1.5); }
.stat { background: var(--panel-2); border-radius: var(--u); padding: var(--u) calc(var(--u) * 1.5); display: grid; gap: 2px; }
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.events { list-style: none; margin: var(--u) 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.events li { padding: 4px 0; border-bottom: 1px solid #23273a; color: var(--muted); }
.events li.payout { color: var(--accent); }
.events li.gutter { color: var(--danger); }
.skin-chip {
  display: inline-flex; align-items: center; gap: var(--u); margin-top: var(--u);
  background: var(--panel-2); color: var(--text); border: 1px solid #2c3042;
  border-radius: var(--radius); padding: var(--u) calc(var(--u) * 1.5);
}
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); display: inline-block; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(5, 6, 9, 0.7);
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--u) * 2);
}
.modal {
  width: 100%; max-width: 400px;
  background: var(--panel); border-radius: var(--radius);
  padding: calc(var(--u) * 3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: var(--u); margin: calc(var(--u) * 2) 0; }
.tabs button {
  flex: 1; background: var(--panel-2); color: var(--muted);
  border: 0; border-radius: var(--u); padding: var(--u); font-weight: 600;
}
.tabs button[aria-selected='true'] { background: var(--accent); color: #1a1405; }
form { display: grid; gap: var(--u); }
label { font-size: 12px; color: var(--muted); margin-top: var(--u); }
input {
  background: var(--bg); color: var(--text);
  border: 1px solid #2c3042; border-radius: var(--u);
  padding: calc(var(--u) * 1.25) calc(var(--u) * 1.5); font: inherit;
}
.form-error { color: var(--danger); min-height: 20px; font-size: 13px; }

.drawer-overlay { justify-content: flex-end; align-items: stretch; padding: 0; }
.drawer {
  width: 100%; max-width: 420px; background: var(--panel);
  padding: calc(var(--u) * 3); overflow-y: auto;
}
.skin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--u) * 1.5); margin-top: calc(var(--u) * 2); }
.skin-card {
  background: var(--panel-2); border: 1px solid #2c3042; border-radius: var(--radius);
  padding: calc(var(--u) * 2); display: grid; justify-items: center; gap: var(--u);
  color: var(--text); text-align: center;
}
.skin-card .coin { width: 56px; height: 56px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.25); }
.skin-card[aria-pressed='true'] { border-color: var(--accent); }
.skin-card.locked { opacity: 0.6; cursor: default; }
.skin-card .tag { font-size: 12px; color: var(--muted); }
.skin-card[aria-pressed='true'] .tag { color: var(--accent); font-weight: 600; }

/* Breakpoint: tablet, narrower side panels */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr) 220px; gap: var(--u); padding: var(--u); }
}

/* Breakpoint: mobile, stacked (frame 06) */
@media (max-width: 820px) {
  body { overflow-y: auto; display: block; }
  .topbar { flex-wrap: wrap; padding: var(--u) calc(var(--u) * 2); }
  .logo { font-size: 13px; }
  .layout { display: flex; flex-direction: column; padding: var(--u); }
  .stage { order: 1; flex: none; height: 56vh; min-height: 320px; }
  .queue-panel { order: 2; flex: none; overflow: visible; }
  .turn-panel { order: 3; flex: none; overflow: visible; }
  .hud { left: var(--u); right: var(--u); bottom: var(--u); gap: calc(var(--u) * 2); padding: var(--u) calc(var(--u) * 2); }
  .drawer { max-width: none; }
}

/* Breakpoint: very small phones */
@media (max-width: 420px) {
  .live-pill { font-size: 11px; padding: 4px 8px; }
  .hud-value { font-size: 18px; }
  .skin-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .live-pill .dot, .toast.show { animation: none; }
}
