*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0b0f16;
  --bg-1: #0f1522;
  --panel: rgba(18, 24, 38, 0.72);
  --panel-border: rgba(255,255,255,0.06);
  --text: rgba(240,244,255,0.92);
  --muted: rgba(240,244,255,0.52);

  --board-surface: #EDE8DD;
  --board-frame: #3B4856;

  --red:    #E53935;
  --blue:   #1E88E5;
  --yellow: #FBC02D;
  --green:  #2E7D32;

  --sp-1: 2px;
  --sp-2: 4px;
  --sp-3: 6px;
  --sp-4: 8px;
  --sp-5: 12px;
  --sp-6: 16px;
  --sp-7: 24px;
  --sp-8: 32px;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --shadow-0: none;
  --shadow-1: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 3px 6px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-3: 0 6px 16px rgba(0,0,0,0.5), 0 3px 6px rgba(0,0,0,0.35);
  --shadow-4: 0 12px 28px rgba(0,0,0,0.55), 0 4px 10px rgba(0,0,0,0.4);

  --border-subtle: rgba(255,255,255,0.04);
  --border-medium: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);

  --hud-height: 90px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(800px 600px at 50% 40%, rgba(160,120,255,.18), transparent 55%),
    radial-gradient(600px 500px at 25% 25%, rgba(255,100,180,.10), transparent 50%),
    radial-gradient(600px 500px at 75% 25%, rgba(80,200,255,.10), transparent 50%),
    radial-gradient(700px 500px at 30% 80%, rgba(255,180,60,.08), transparent 50%),
    radial-gradient(700px 500px at 70% 80%, rgba(60,220,160,.08), transparent 50%),
    radial-gradient(1100px 800px at 50% 50%, rgba(100,60,180,.25), transparent 60%),
    linear-gradient(160deg, #1a0a2e 0%, #16103a 30%, #0d1b3c 55%, #0a1628 80%, #0c0e24 100%);
  background-color: #0c0e24;
  background-attachment: fixed;
}
body > * { position: relative; z-index: 1; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(255,255,255,.06), transparent 45%),
    radial-gradient(circle at 15% 20%, rgba(255,180,255,.04), transparent 35%),
    radial-gradient(circle at 85% 15%, rgba(120,220,255,.04), transparent 35%),
    radial-gradient(circle at 20% 85%, rgba(255,200,100,.03), transparent 30%),
    radial-gradient(circle at 80% 85%, rgba(100,255,180,.03), transparent 30%);
  opacity: 1;
  z-index: 0;
  pointer-events: none;
  animation: bgShimmer 12s ease-in-out infinite alternate;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 42%, rgba(8,6,20,.50) 75%);
  opacity: .7;
  z-index: 0;
  pointer-events: none;
}
@keyframes bgShimmer {
  0%   { opacity: .85; filter: hue-rotate(0deg); }
  50%  { opacity: 1;   filter: hue-rotate(8deg); }
  100% { opacity: .9;  filter: hue-rotate(-5deg); }
}

header {
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  flex-wrap: wrap;
  background: var(--panel);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 10;
}

.header-left { flex-shrink: 0; }

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.header-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}

h1 {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.info-bar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
}

.tag {
  background: rgba(15, 21, 34, 0.85);
  padding: var(--sp-1) var(--sp-4);
  border-radius: 100px;
  font-size: 0.68rem;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  white-space: nowrap;
  border: 1px solid var(--border-subtle);
  line-height: 1.6;
}

.tag.red    { border-color: var(--red); color: var(--red); }
.tag.blue   { border-color: var(--blue); color: var(--blue); }
.tag.yellow { border-color: var(--yellow); color: var(--yellow); }
.tag.green  { border-color: var(--green); color: var(--green); }

.winner-banner {
  color: rgba(240,244,255,0.95);
  text-align: center;
  padding: 14px;
  font-size: 1.2rem;
  font-weight: 700;
  display: none;
}

.winner-banner.you-win {
  background: linear-gradient(135deg, var(--green), #059669);
}

.winner-banner.you-lose {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
}

.game-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.main-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  padding: var(--sp-3) var(--sp-4);
  overflow: hidden;
}

.board-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-height: 100%;
}

#board-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
}

.bottom-hud {
  width: 100%;
  max-width: 760px;
  height: var(--hud-height);
  background: linear-gradient(180deg, rgba(22, 28, 44, 0.94) 0%, rgba(14, 18, 30, 0.96) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.3), 0 4px 24px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  margin: var(--sp-3) var(--sp-4) var(--sp-4);
  flex-shrink: 0;
  z-index: 100;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: 1;
  min-width: 0;
}

.hud-player-chip {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.hud-player-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.hud-player-name {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.hud-turn-status {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.hud-turn-status.your-turn {
  color: #4caf50;
  font-weight: 600;
}

.hud-turn-status.ai-thinking {
  color: var(--blue);
  font-style: italic;
}

.hud-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.hud-dice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.06) 0%, transparent 70%);
  border: 1.5px solid rgba(255,255,255,0.1);
  cursor: pointer;
  padding: 6px 10px 4px;
  border-radius: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.hud-dice-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  border-color: rgba(255,255,255,0.18);
}

.hud-dice-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.hud-dice-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
  border-color: rgba(255,255,255,0.04);
}

.hud-dice-btn:disabled .hud-dice-label {
  color: var(--muted);
}

#hud-dice-canvas {
  width: 56px;
  height: 56px;
  border-radius: var(--r-md);
  pointer-events: none;
}

.hud-dice-label {
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(240,244,255,0.7);
  transition: color 0.2s;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: 1;
  justify-content: flex-end;
}

.hud-last-roll {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 4px 10px;
  line-height: 1.3;
}

.hud-last-roll:empty {
  display: none;
}

.hud-new-game {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-md);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  white-space: nowrap;
  min-height: 38px;
  min-width: 76px;
}

.hud-new-game:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.22);
}

.hud-new-game:active {
  transform: scale(0.97);
}

.game-token .token-body,
.game-token .sel-ring,
.game-token .hit-area,
.game-token .stack-badge circle,
.game-token .stack-badge text {
  transition: cx 300ms ease-out, cy 300ms ease-out, x 300ms ease-out, y 300ms ease-out, opacity 300ms ease-out, transform 300ms ease-out;
}

.game-token .token-body {
  transition: transform 300ms ease-out, opacity 300ms ease-out, filter 200ms ease;
}

.game-token.selectable { cursor: pointer; }

.game-token.selectable:hover .token-body {
  filter: url(#warrior-lift) brightness(1.1);
}

.game-token.selectable:active .token-body {
  filter: url(#warrior-shadow) brightness(0.92);
}

.bonk-anim {
  pointer-events: none;
}

.warrior-crown {
  animation: crown-pop 400ms ease-out forwards;
}

@keyframes crown-pop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.game-token.selectable .warrior-figure {
  transition: transform 150ms ease;
}

.game-token.selectable:hover .warrior-figure {
  transform: translateY(-1px);
}

@keyframes breathing {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes idle-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-0.4%) rotate(0.5deg); }
  50% { transform: translateY(-0.15%) rotate(0deg); }
  75% { transform: translateY(-0.4%) rotate(-0.5deg); }
}

.idle-ready .warrior-figure {
  animation: idle-bob 2.4s ease-in-out infinite;
  transform-origin: center bottom;
  transform-box: fill-box;
}

@keyframes pick-me-jump {
  0%, 100% { transform: translateY(0) scaleY(1) scaleX(1); }
  10% { transform: translateY(0.5%) scaleY(0.96) scaleX(1.02); }
  30% { transform: translateY(-3%) scaleY(1.04) scaleX(0.98); }
  50% { transform: translateY(0) scaleY(0.97) scaleX(1.01); }
  65% { transform: translateY(-1.5%) scaleY(1.02) scaleX(0.99); }
  80% { transform: translateY(0) scaleY(0.98) scaleX(1.005); }
}

.pick-me-bounce .warrior-figure {
  animation: pick-me-jump 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
  transform-origin: center bottom;
  transform-box: fill-box;
}

@keyframes bubble-float {
  0%, 100% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(-1px); opacity: 1; }
}

.pick-me-bubble {
  animation: bubble-float 1.5s ease-in-out infinite;
}

@keyframes soft-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.selectable-glow {
  animation: soft-glow 2s ease-in-out infinite;
}

@keyframes sel-ring-pulse {
  0%, 100% { stroke-opacity: 0.85; stroke-width: 1.8; }
  50% { stroke-opacity: 0.35; stroke-width: 1.2; }
}

.sel-ring {
  animation: sel-ring-pulse 1.6s ease-in-out infinite;
}

@keyframes gate-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.5; }
}

.gate-active {
  animation: gate-pulse 2.4s ease-in-out infinite;
}

@keyframes legal-pulse {
  0%, 100% { stroke-opacity: 0.85; }
  50% { stroke-opacity: 0.3; }
}

.legal-dest-highlight {
  animation: legal-pulse 1.4s ease-in-out infinite;
}

@keyframes capture-flash {
  0%, 100% { stroke-opacity: 0.6; }
  50% { stroke-opacity: 0.15; }
}

.capture-threat {
  animation: capture-flash 1.1s ease-in-out infinite;
}

.breathing-glow {
  animation: breathing 1.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .sel-ring,
  .gate-active,
  .legal-dest-highlight,
  .capture-threat,
  .breathing-glow,
  .idle-ready .warrior-figure,
  .pick-me-bounce .warrior-figure,
  .pick-me-bubble,
  .selectable-glow {
    animation: none !important;
  }
}

body.calm .sel-ring,
body.calm .legal-dest-highlight,
body.calm .capture-threat,
body.calm .gate-active {
  animation: none;
}

body.calm .game-token {
  filter: none;
}

body.calm .breathing-glow,
body.calm .idle-ready .warrior-figure,
body.calm .pick-me-bounce .warrior-figure,
body.calm .pick-me-bubble,
body.calm .selectable-glow {
  animation: none;
}

.direction-marks { pointer-events: none; }
.path-preview { pointer-events: none; }
.last-move-hl { pointer-events: none; }

.seed-input {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--border-medium);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  width: 100%;
  font-size: 0.8rem;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.seed-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(59, 111, 242, 0.15);
}

label {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text);
  white-space: nowrap;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--blue);
  width: 14px;
  height: 14px;
}

.game-controls-row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.game-controls-row .seed-label {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.game-controls-row .seed-input { flex: 1; }

.dev-section-floating {
  position: fixed;
  bottom: calc(var(--hud-height) + 8px + env(safe-area-inset-bottom, 0px));
  left: 8px;
  z-index: 50;
  background: rgba(14, 18, 30, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-medium);
  border-radius: var(--r-md);
  max-width: 200px;
}

.dev-section-floating summary {
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  opacity: 0.6;
}

.dev-section-floating summary::before {
  content: '\25B8';
  font-size: 0.6rem;
  transition: transform 0.2s;
}

.dev-section-floating[open] summary::before {
  transform: rotate(90deg);
}

.dev-section-floating .dev-body {
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

@keyframes dice-tumble {
  0% { transform: rotate(0deg) scale(0.6); opacity: 0.3; }
  20% { transform: rotate(90deg) scale(1.1); opacity: 0.8; }
  40% { transform: rotate(200deg) scale(0.9); opacity: 1; }
  60% { transform: rotate(310deg) scale(1.05); opacity: 1; }
  80% { transform: rotate(350deg) scale(0.98); opacity: 1; }
  100% { transform: rotate(360deg) scale(1); opacity: 1; }
}

@keyframes dice-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); }
  60% { transform: scale(0.92); }
  80% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes hud-dice-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  50% { transform: rotate(10deg); }
  75% { transform: rotate(-6deg); }
}

@media (max-width: 767px) {
  :root { --hud-height: 84px; }
  .game-dock {
    padding-bottom: 0;
  }
  .main-layout {
    flex: 1;
    padding: var(--sp-2) var(--sp-3);
    padding-bottom: var(--hud-height);
  }
  .bottom-hud {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: none;
    border-radius: 16px 16px 0 0;
    margin: 0;
    padding: 0 var(--sp-5);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .hud-last-roll { display: none; }
  .hud-player-name { font-size: 0.72rem; }
  .hud-player-chip { width: 28px; height: 28px; }
  .header-center { justify-content: flex-start; }
  #hud-dice-canvas { width: 48px; height: 48px; }
  .hud-dice-btn { padding: 5px 8px 3px; }
}

@media (min-width: 768px) {
  :root { --hud-height: 78px; }
  .main-layout {
    padding: var(--sp-3) var(--sp-4);
  }
  .bottom-hud {
    margin: 0 auto var(--sp-4);
  }
  #hud-dice-canvas { width: 56px; height: 56px; }
}

.screen { display: none; }
.screen.active-screen { display: block; }
#screen-game.active-screen { display: flex; flex-direction: column; height: 100vh; }

.auth-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: var(--sp-7);
}
.auth-brand { text-align: center; margin-bottom: var(--sp-7); }
.auth-brand h1 { font-size: 2.4rem; letter-spacing: 2px; }
.auth-subtitle { color: var(--muted); margin-top: var(--sp-2); font-size: 1rem; }
.auth-card {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--r-lg); padding: var(--sp-7); width: 100%; max-width: 380px;
  box-shadow: var(--shadow-3);
}
.auth-tabs { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-6); }
.auth-tab {
  flex: 1; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border-medium);
  background: transparent; color: var(--muted); border-radius: var(--r-sm);
  cursor: pointer; font-size: 0.9rem; transition: all 0.2s;
}
.auth-tab.active {
  background: rgba(30,136,229,0.15); color: var(--text);
  border-color: var(--blue);
}
.auth-card label {
  display: block; font-size: 0.8rem; color: var(--muted);
  margin-bottom: var(--sp-1); margin-top: var(--sp-4);
}
.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
  width: 100%; padding: var(--sp-3) var(--sp-4);
  background: rgba(255,255,255,0.06); border: 1px solid var(--border-medium);
  border-radius: var(--r-sm); color: var(--text); font-size: 0.95rem;
  outline: none; transition: border-color 0.2s;
}
.auth-card input:focus { border-color: var(--blue); }
.auth-error { color: var(--red); font-size: 0.8rem; margin-top: var(--sp-3); min-height: 1.2em; }
.auth-submit { width: 100%; margin-top: var(--sp-5); }
.auth-divider {
  text-align: center; margin: var(--sp-6) 0; color: var(--muted); font-size: 0.8rem;
  display: flex; align-items: center; gap: var(--sp-3);
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border-medium);
}
.auth-guest { width: 100%; }
.btn-google-login {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
  width: 100%; padding: var(--sp-3) var(--sp-6); background: #fff; color: #3c4043;
  border: 1px solid #dadce0; border-radius: var(--r-sm); cursor: pointer;
  font-size: 0.95rem; font-weight: 600; text-decoration: none;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}
.btn-google-login:hover { background: #f7f8f8; box-shadow: 0 1px 3px rgba(0,0,0,0.15); transform: translateY(-1px); }
.btn-google-login:active { transform: translateY(0); }

.btn-primary {
  padding: var(--sp-3) var(--sp-6); background: var(--blue); color: #fff;
  border: none; border-radius: var(--r-sm); cursor: pointer;
  font-size: 0.9rem; font-weight: 600; transition: background 0.2s;
}
.btn-primary:hover { background: #1976D2; }
.btn-secondary {
  padding: var(--sp-3) var(--sp-6); background: transparent;
  color: var(--text); border: 1px solid var(--border-medium);
  border-radius: var(--r-sm); cursor: pointer; font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-sm { padding: var(--sp-2) var(--sp-4); font-size: 0.8rem; }

.lobby-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-4) var(--sp-6);
  background: var(--panel); border-bottom: 1px solid var(--panel-border);
}
.lobby-header h1 { font-size: 1.2rem; letter-spacing: 1px; }
.lobby-header .header-right { display: flex; align-items: center; gap: var(--sp-4); }
.user-badge {
  font-size: 0.85rem; color: var(--text); padding: var(--sp-2) var(--sp-4);
  background: rgba(30,136,229,0.12); border-radius: var(--r-sm);
}

.lobby-body {
  max-width: 600px; margin: 0 auto; padding: var(--sp-6);
}
.lobby-body h2 { font-size: 1.1rem; margin-bottom: var(--sp-4); color: var(--text); }
.lobby-choices {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: calc(100vh - 60px); padding: var(--sp-7);
}
.lobby-welcome {
  font-size: 1.4rem; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text); margin-bottom: var(--sp-7);
  text-align: center;
}
.lobby-mode-cards {
  display: flex; gap: var(--sp-6); margin-bottom: var(--sp-6);
  flex-wrap: wrap; justify-content: center;
}
.mode-card {
  background: var(--panel); border: 1px solid var(--border-medium);
  border-radius: var(--r-lg); padding: var(--sp-7) var(--sp-8);
  cursor: pointer; text-align: center; transition: all 0.25s;
  width: 220px; color: var(--text);
}
.mode-card:hover {
  border-color: var(--blue); transform: translateY(-4px);
  box-shadow: var(--shadow-3);
}
.mode-card-primary { border-color: rgba(30,136,229,0.3); }
.mode-card-primary:hover { border-color: var(--blue); background: rgba(30,136,229,0.08); }
.mode-icon { font-size: 2.8rem; margin-bottom: var(--sp-4); opacity: 0.9; }
.mode-title { font-size: 1.1rem; font-weight: 700; margin-bottom: var(--sp-2); }
.mode-desc { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }

/* Character-first home lobby */
#screen-lobby.active-screen {
  display: block;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.home-lobby {
  --lobby-ink: #090b22;
  --lobby-yellow: #f3ff20;
  position: relative;
  isolation: isolate;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: #fff;
  background: #120e35;
}

.home-lobby-art,
.home-lobby-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.home-lobby-art {
  z-index: -3;
  background:
    url('assets/backgrounds/ludo-sunset-arena.webp') center center / cover no-repeat,
    linear-gradient(145deg, #201144, #a83b76 60%, #ff934d);
  transform: scale(1.01);
}

.home-lobby-shade {
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(7, 8, 30, .88) 0%, rgba(10, 10, 35, .54) 23%, transparent 50%),
    linear-gradient(180deg, rgba(7, 8, 30, .72) 0%, transparent 17%, transparent 70%, rgba(7, 8, 30, .48) 100%),
    radial-gradient(circle at 69% 52%, transparent 0 28%, rgba(10, 7, 30, .12) 62%, rgba(5, 7, 26, .4) 100%);
}

.home-nav {
  position: relative;
  z-index: 30;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: clamp(18px, 2.4vw, 38px);
  width: 100%;
  min-height: 76px;
  padding: 12px clamp(18px, 2.4vw, 40px);
  border: 0;
  background: linear-gradient(180deg, rgba(6, 7, 28, .72), rgba(6, 7, 28, .08));
  backdrop-filter: none;
}

.home-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: clamp(.84rem, 1vw, 1rem);
  font-weight: 950;
  letter-spacing: .09em;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .45);
}

.home-brand b {
  color: #cad4ff;
  font-weight: 700;
}

.home-brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  place-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  border: 2px solid rgba(255, 255, 255, .88);
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  box-shadow: 0 5px 18px rgba(8, 7, 27, .34);
  transform: rotate(-4deg);
}

.home-brand-mark i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.home-tabs {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}

.home-tab {
  position: relative;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, .8);
  cursor: pointer;
  font-size: clamp(.69rem, .86vw, .84rem);
  font-weight: 900;
  letter-spacing: .035em;
  text-transform: uppercase;
  transition: color .18s ease, background .18s ease, transform .18s ease;
  white-space: nowrap;
}

.home-tab:hover,
.home-tab:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, .1);
}

.home-tab.active {
  color: var(--lobby-ink);
  background: #eef0ff;
  box-shadow: 0 7px 22px rgba(4, 5, 25, .28);
}

.home-tab.active::after {
  content: '';
  position: absolute;
  right: 12px;
  bottom: 5px;
  left: 12px;
  height: 2px;
  border-radius: 99px;
  background: #6557ff;
}

.home-account {
  position: relative;
  flex: 0 0 auto;
}

.home-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 5px 10px 5px 6px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(8, 9, 34, .4);
  color: #fff;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 8px 22px rgba(6, 6, 24, .18);
  backdrop-filter: blur(10px);
}

.home-profile:hover,
.home-profile:focus-visible {
  border-color: rgba(255, 255, 255, .42);
  background: rgba(8, 9, 34, .62);
}

.home-profile-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #8174ff, #3430c9);
  box-shadow: inset 0 1px rgba(255, 255, 255, .35), 0 0 0 2px rgba(255, 255, 255, .14);
  font-size: .82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.home-profile-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 120px;
}

.home-profile-copy strong {
  overflow: hidden;
  font-size: .78rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-profile-copy small {
  color: rgba(255, 255, 255, .58);
  font-size: .63rem;
  line-height: 1.25;
}

.home-profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 170px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 14px;
  background: rgba(12, 12, 40, .94);
  box-shadow: 0 18px 45px rgba(3, 3, 16, .42);
  backdrop-filter: blur(18px);
}

.home-profile-menu span {
  display: block;
  padding: 7px 10px 9px;
  color: rgba(255, 255, 255, .54);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.home-profile-menu button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  text-align: left;
}

.home-profile-menu button:hover,
.home-profile-menu button:focus-visible {
  background: rgba(255, 255, 255, .15);
}

.home-stage {
  position: absolute;
  inset: 0;
}

.home-party {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.party-status {
  position: absolute;
  z-index: 12;
  top: clamp(88px, 11vh, 118px);
  left: 67%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 2px 14px rgba(6, 4, 24, .75);
}

.party-status strong {
  max-width: 260px;
  overflow: hidden;
  font-size: clamp(.78rem, 1.15vw, 1rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-status > span:last-child {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  color: rgba(255, 255, 255, .68);
  font-size: .68rem;
  font-weight: 700;
}

.party-status > span:last-child i,
.mode-live-dot i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #75f7a2;
  box-shadow: 0 0 10px #50ef87;
}

.party-crown {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 4px;
  border-radius: 9px;
  color: #1b1542;
  background: var(--lobby-yellow);
  box-shadow: 0 0 20px rgba(243, 255, 32, .3);
  font-size: .7rem;
}

.lobby-character {
  --character-color: #7d86ff;
  position: absolute;
  z-index: 3;
  bottom: clamp(82px, 8.5vh, 112px);
  left: var(--character-x);
  width: clamp(144px, 15vw, 244px);
  transform: translateX(-50%);
  filter: drop-shadow(0 22px 25px rgba(8, 5, 30, .46));
  transform-origin: 50% 100%;
  animation: lobby-character-idle 4.4s ease-in-out infinite;
}

.lobby-character::before {
  content: '';
  position: absolute;
  z-index: -1;
  right: 3%;
  bottom: -3%;
  left: 3%;
  height: 13%;
  border: 2px solid color-mix(in srgb, var(--character-color), white 18%);
  border-radius: 50%;
  background: color-mix(in srgb, var(--character-color), transparent 62%);
  box-shadow:
    0 0 22px var(--character-color),
    0 0 58px color-mix(in srgb, var(--character-color), transparent 35%),
    inset 0 0 24px color-mix(in srgb, var(--character-color), white 20%);
}

.lobby-character img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

.lobby-character > span {
  position: absolute;
  bottom: -26px;
  left: 50%;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 999px;
  background: rgba(8, 8, 30, .58);
  color: rgba(255, 255, 255, .76);
  font-size: clamp(.55rem, .65vw, .7rem);
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
  transform: translateX(-50%);
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.lobby-character-blue {
  --character-x: 41%;
  --character-color: #52aaff;
  z-index: 5;
  animation-delay: -.8s;
}

.lobby-character-yellow {
  --character-x: 55%;
  --character-color: #ffd751;
  z-index: 4;
  width: clamp(142px, 14.6vw, 236px);
  animation-delay: -2.1s;
}

.lobby-character-red {
  --character-x: 69%;
  --character-color: #ff5b6c;
  z-index: 5;
  animation-delay: -1.4s;
}

.lobby-character-green {
  --character-x: 83%;
  --character-color: #50e997;
  z-index: 4;
  width: clamp(142px, 14.6vw, 236px);
  animation-delay: -3.2s;
}

@keyframes lobby-character-idle {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(-.2deg); }
  50% { transform: translateX(-50%) translateY(-7px) rotate(.25deg); }
}

.home-mode-panel {
  position: absolute;
  z-index: 20;
  bottom: clamp(26px, 4.6vh, 52px);
  left: clamp(20px, 3vw, 48px);
  width: clamp(280px, 23.5vw, 350px);
  padding: clamp(18px, 2vw, 28px);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 22px;
  background:
    linear-gradient(155deg, rgba(31, 29, 72, .94), rgba(11, 12, 36, .9)),
    rgba(10, 10, 34, .92);
  box-shadow: 0 26px 70px rgba(5, 5, 24, .48), inset 0 1px rgba(255, 255, 255, .08);
  backdrop-filter: blur(18px);
}

.mode-eyebrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #b9b8d5;
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.mode-eyebrow > span:first-child {
  padding: 5px 7px;
  border-radius: 7px;
  color: #1b1639;
  background: #c9c6ff;
}

.mode-live-dot {
  display: flex;
  align-items: center;
  gap: 6px;
}

.home-mode-panel h2 {
  margin: 0;
  color: #fff;
  font-family: Impact, 'Arial Black', 'Segoe UI', sans-serif;
  font-size: clamp(2.1rem, 3vw, 3rem);
  font-style: italic;
  font-weight: 900;
  letter-spacing: -.025em;
  line-height: .98;
  text-transform: uppercase;
  text-shadow: 0 3px 14px rgba(0, 0, 0, .28);
}

.home-mode-panel > p {
  margin: 8px 0 18px;
  color: rgba(255, 255, 255, .64);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .025em;
  text-transform: uppercase;
}

.queue-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.queue-choice {
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 11px;
  background: rgba(255, 255, 255, .07);
  color: rgba(255, 255, 255, .64);
  cursor: pointer;
  text-align: left;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.queue-choice:hover,
.queue-choice:focus-visible {
  border-color: rgba(255, 255, 255, .32);
  transform: translateY(-1px);
}

.queue-choice.active {
  border-color: rgba(255, 255, 255, .58);
  background: #eeefff;
  color: #15142f;
  box-shadow: 0 6px 18px rgba(4, 4, 20, .25);
}

.queue-choice span,
.queue-choice small {
  display: block;
}

.queue-choice span {
  font-size: .75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.queue-choice small {
  margin-top: 3px;
  color: inherit;
  font-size: .62rem;
  opacity: .72;
}

.home-play-button,
.home-change-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 56px;
  padding: 10px 15px;
  border-radius: 12px;
  cursor: pointer;
  text-transform: uppercase;
}

.home-play-button {
  border: 2px solid rgba(255, 255, 255, .78);
  background: var(--lobby-yellow);
  color: #151724;
  box-shadow: 0 7px 0 #8f9900, 0 16px 28px rgba(6, 6, 25, .3);
  transition: transform .13s ease, box-shadow .13s ease, filter .13s ease;
}

.home-play-button:hover,
.home-play-button:focus-visible {
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 9px 0 #8f9900, 0 19px 32px rgba(6, 6, 25, .36);
}

.home-play-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #8f9900, 0 9px 18px rgba(6, 6, 25, .3);
}

.home-play-button span {
  font-size: 1.18rem;
  font-weight: 950;
}

.home-play-button small,
.home-change-button small {
  font-size: .59rem;
  font-weight: 800;
  letter-spacing: .035em;
}

.home-change-button {
  min-height: 48px;
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.home-change-button:hover,
.home-change-button:focus-visible {
  border-color: rgba(255, 255, 255, .36);
  background: rgba(255, 255, 255, .13);
}

.home-change-button span {
  font-size: .78rem;
  font-weight: 900;
}

.home-change-button small {
  color: rgba(255, 255, 255, .5);
}

.home-footer {
  position: absolute;
  right: 22px;
  bottom: 18px;
  z-index: 12;
  display: flex;
  gap: 15px;
  color: rgba(255, 255, 255, .55);
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.home-footer kbd {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  min-height: 21px;
  margin-right: 3px;
  padding: 2px 5px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 6px;
  background: rgba(9, 9, 32, .55);
  color: rgba(255, 255, 255, .82);
  font: inherit;
}

.lobby-toast {
  position: fixed;
  z-index: 50;
  top: 84px;
  left: 50%;
  max-width: min(90vw, 460px);
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  background: rgba(10, 10, 36, .92);
  box-shadow: 0 14px 38px rgba(4, 4, 19, .38);
  color: #fff;
  font-size: .76rem;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity .2s ease, transform .2s ease;
  backdrop-filter: blur(14px);
}

.lobby-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1060px) {
  .home-nav {
    gap: 12px;
  }

  .home-brand > span:last-child {
    display: none;
  }

  .home-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .home-tabs::-webkit-scrollbar {
    display: none;
  }

  .home-profile-copy {
    display: none;
  }

  .home-profile {
    padding-right: 6px;
  }

  .lobby-character {
    width: clamp(130px, 17.5vw, 205px);
  }

  .lobby-character-yellow,
  .lobby-character-green {
    width: clamp(128px, 17vw, 200px);
  }
}

@media (max-width: 760px) {
  .home-lobby-art {
    background-position: 62% center;
  }

  .home-lobby-shade {
    background:
      linear-gradient(180deg, rgba(7, 8, 30, .7) 0%, transparent 20%, transparent 53%, rgba(7, 8, 30, .7) 71%, rgba(7, 8, 30, .94) 100%),
      radial-gradient(circle at 50% 38%, transparent 0 32%, rgba(5, 6, 24, .32) 100%);
  }

  .home-nav {
    min-height: 64px;
    padding: 8px 10px;
  }

  .home-brand-mark {
    width: 34px;
    height: 34px;
  }

  .home-tabs {
    order: 2;
    gap: 2px;
  }

  .home-tab {
    padding: 8px 9px;
    font-size: .65rem;
  }

  .home-tab:nth-child(n+5) {
    display: none;
  }

  .home-profile-avatar {
    width: 34px;
    height: 34px;
  }

  .home-profile {
    min-height: 44px;
  }

  .party-status {
    top: 72px;
    left: 50%;
  }

  .party-status strong {
    max-width: 180px;
  }

  .lobby-character {
    bottom: min(43vh, 380px);
    width: clamp(106px, 27vw, 170px);
  }

  .lobby-character-yellow,
  .lobby-character-green {
    width: clamp(104px, 26vw, 166px);
  }

  .lobby-character-blue { --character-x: 15%; }
  .lobby-character-yellow { --character-x: 38%; }
  .lobby-character-red { --character-x: 62%; }
  .lobby-character-green { --character-x: 85%; }

  .lobby-character > span {
    display: none;
  }

  .home-mode-panel {
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    max-height: 42vh;
    padding: 15px;
    border-radius: 19px;
  }

  .home-mode-panel h2 {
    font-size: clamp(1.7rem, 8vw, 2.2rem);
  }

  .home-mode-panel > p {
    margin: 5px 0 11px;
  }

  .queue-choice {
    min-height: 50px;
    padding: 7px 9px;
  }

  .home-play-button {
    min-height: 50px;
  }

  .home-change-button {
    min-height: 42px;
    margin-top: 8px;
  }

  .home-footer {
    display: none;
  }

  .lobby-toast {
    top: 70px;
  }
}

@media (max-height: 660px) and (orientation: landscape) {
  .party-status {
    display: none;
  }

  .lobby-character {
    bottom: 44px;
    width: clamp(112px, 16vw, 160px);
  }

  .home-mode-panel {
    bottom: 14px;
    left: 18px;
    width: 285px;
    max-height: calc(100vh - 88px);
    padding: 14px;
  }

  .home-mode-panel h2 {
    font-size: 1.75rem;
  }

  .home-mode-panel > p {
    margin: 4px 0 10px;
  }

  .queue-choice {
    min-height: 46px;
    padding: 6px 8px;
  }

  .home-play-button {
    min-height: 46px;
  }

  .home-change-button {
    min-height: 40px;
    margin-top: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-character {
    animation: none;
  }

  .home-tab,
  .queue-choice,
  .home-play-button,
  .lobby-toast {
    transition: none;
  }
}

.muted { color: var(--muted); font-size: 0.85rem; }

.arena-body {
  max-width: 500px; margin: 0 auto; padding: var(--sp-7);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  min-height: calc(100vh - 60px); justify-content: center;
}
.arena-title {
  font-size: 1.6rem; font-weight: 800; letter-spacing: 2px;
  text-transform: uppercase; color: var(--text); margin-bottom: var(--sp-3);
}
.arena-subtitle {
  color: var(--muted); font-size: 0.95rem; margin-bottom: var(--sp-7);
}
.arena-slots {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4);
  width: 100%; margin-bottom: var(--sp-7);
}
.arena-slot {
  display: flex; align-items: center; gap: var(--sp-4);
  background: var(--panel); border: 1px solid var(--border-medium);
  border-radius: var(--r-md); padding: var(--sp-5);
  transition: all 0.3s;
}
.arena-slot-filled {
  border-color: var(--slot-color, var(--border-strong));
  background: rgba(255,255,255,0.03);
}
.arena-slot-color {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  opacity: 0.4; transition: opacity 0.3s;
}
.arena-slot-filled .arena-slot-color { opacity: 1; }
.arena-slot-info { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.arena-slot-team { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.arena-slot-filled .arena-slot-team { color: var(--text); }
.arena-slot-name { color: var(--text); font-size: 0.95rem; font-weight: 600; }
.arena-slot-empty { color: var(--muted); font-style: italic; font-size: 0.85rem; }
.arena-actions { text-align: center; }
.arena-play-btn {
  padding: var(--sp-4) var(--sp-8); font-size: 1.1rem; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  border-radius: var(--r-md);
}
.arena-hint { margin-top: var(--sp-3); font-size: 0.78rem; }
.arena-cancel-btn { margin-top: var(--sp-3); }
