:root {
  --bg: #18181c;
  --surface: #212128;
  --surface-2: #292933;
  --border: #363645;
  --text: #f4f4f8;
  --muted: #9a9ab0;
  --gold: #e4d6a9;
  --gold-strong: #f0dfa3;
  --danger: #ff5e5b;
  --cyan: #4cc9f0;
  --mint: #00f5d4;
  --radius: 12px;
}

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

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: 'Kanit', sans-serif;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
}

.gold {
  color: var(--gold);
}

/* Topbar */
.topbar {
  min-height: 52px;
  padding: 6px 20px;
  background: rgba(24, 24, 28, 0.94);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-mark {
  color: var(--gold);
  font-size: 1.2rem;
}

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

.conn-badge {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.conn-badge.ok {
  color: var(--mint);
  border-color: rgba(0, 245, 212, 0.35);
}

.conn-badge.err {
  color: var(--danger);
  border-color: rgba(255, 94, 91, 0.45);
}

/* Buttons & Inputs */
button {
  font-family: 'Kanit', sans-serif;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

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

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

.btn {
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.98rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.14s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.btn-lg {
  padding: 12px 22px;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.88rem;
}

.btn-primary {
  background: var(--gold);
  color: #18181c;
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-strong);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--gold);
}

.btn-gold {
  background: rgba(228, 214, 169, 0.14);
  color: var(--gold);
  border: 1px solid rgba(228, 214, 169, 0.45);
}

.btn-gold:hover:not(:disabled) {
  background: rgba(228, 214, 169, 0.24);
}

.btn-icon {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.btn-icon.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(228, 214, 169, 0.14);
}

.btn-link {
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-link.danger:hover {
  color: var(--danger);
}

input[type='text'] {
  width: 100%;
  background: #141418;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: 'Kanit', sans-serif;
  font-size: 1rem;
  outline: none;
}

input[type='text']:focus {
  border-color: var(--gold);
}

/* Screens */
.screen {
  display: none;
  min-height: calc(100vh - 52px);
  padding: 24px 20px;
}

.screen.active {
  display: flex;
  flex: 1;
  animation: screen-enter 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
  max-width: 100%;
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 1.5px;
  color: var(--gold);
  display: block;
  margin-bottom: 4px;
}

/* Screen 1: Landing */
#screen-landing.active {
  align-items: center;
  justify-content: center;
}

.landing-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.landing-hero h1 {
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 24px;
}

.field label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.swatch.selected {
  border-color: #ffffff;
  transform: scale(1.14);
  box-shadow: 0 0 0 3px rgba(228, 214, 169, 0.35);
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 4px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider span {
  padding: 0 12px;
}

.join-row {
  display: flex;
  gap: 10px;
}

.code-input {
  max-width: 120px;
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 1.15rem !important;
  letter-spacing: 3px;
}

.join-row .btn {
  flex: 1;
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 14px;
  text-align: center;
}

.active-rooms-wrap {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.active-rooms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--muted);
}

.active-rooms-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.active-room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #141418;
  border: 1px solid var(--border);
}

.active-room-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.active-room-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.active-room-code {
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 1.5px;
}

.active-room-status {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--mint);
}

.active-room-status.playing {
  color: var(--cyan);
}

.active-room-sub {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Screen 2: Lobby */
#screen-lobby.active {
  justify-content: center;
}

.lobby-layout {
  width: 100%;
  max-width: 1280px;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

.lobby-sidebar {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 68px;
  min-width: 0;
  max-width: 100%;
}

.room-code-box {
  background: radial-gradient(circle at top, rgba(228, 214, 169, 0.1), #141418 72%);
  border: 1px solid rgba(228, 214, 169, 0.28);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
}

.room-code-box .label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 1px;
}

.big-code {
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--gold);
  margin: 4px 0 12px;
}

.player-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.92rem;
  color: var(--muted);
}

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 330px;
  overflow-y: auto;
  padding-right: 2px;
}

.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.player-item.me {
  border-color: rgba(228, 214, 169, 0.5);
  background: rgba(228, 214, 169, 0.07);
}

.player-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-rank {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 20px;
}

.player-rank.top {
  color: var(--gold);
}

.player-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.player-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 0.74rem;
}

.score-pill {
  background: #141418;
  color: var(--gold);
  border: 1px solid rgba(228, 214, 169, 0.25);
  border-radius: 6px;
  padding: 2px 7px;
  font-weight: 700;
}

.score-pill.spectator {
  color: var(--cyan);
  border-color: rgba(76, 201, 240, 0.35);
}

.ping-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
  background: #141418;
  border: 1px solid var(--border);
}

.ping-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.ping-badge.ping-good {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
}

.ping-badge.ping-warn {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}

.ping-badge.ping-bad {
  color: #ff5e5b;
  border-color: rgba(255, 94, 91, 0.38);
  background: rgba(255, 94, 91, 0.12);
}

.host-controls {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle-row input {
  accent-color: var(--gold);
  width: 16px;
  height: 16px;
}

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

/* Lobby Right */
.lobby-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  text-align: left;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.18s ease, box-shadow 0.2s ease, background-color 0.18s ease;
}

.game-card:hover:not(.locked) {
  border-color: rgba(228, 214, 169, 0.6);
  transform: translateY(-2px);
}

.game-card.selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(228, 214, 169, 0.14), var(--surface));
  box-shadow: 0 0 0 1px var(--gold);
  animation: selected-glow 2.4s ease-in-out infinite;
}

.game-card.locked {
  cursor: default;
}

.game-card-accent {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  margin-bottom: 2px;
}

.game-card-preview-wrap {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #121218;
  margin-bottom: 4px;
}

.game-card-preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 240 / 110;
}

.game-card-title {
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.25;
}

.game-card-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.game-card-desc {
  font-size: 0.77rem;
  color: #b8b8cc;
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.how-to-play {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: linear-gradient(135deg, rgba(228, 214, 169, 0.08), var(--surface) 55%);
  border-color: rgba(228, 214, 169, 0.35);
}

.htp-preview {
  width: 240px;
  height: 110px;
  flex-shrink: 0;
  border-radius: 10px;
  background: #121218;
  border: 1px solid var(--border);
  display: block;
}

.htp-info {
  flex: 1;
  min-width: 0;
}

.architect-picker {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border-color: rgba(241, 91, 181, 0.45);
}

.architect-picker-head {
  display: flex;
  flex-direction: column;
}

.game-settings-card {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.rounds-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.rounds-pills {
  display: flex;
  gap: 6px;
}

.round-pill {
  background: #141418;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.round-pill:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--text);
}

.round-pill.active {
  background: rgba(228, 214, 169, 0.16);
  color: var(--gold);
  border-color: var(--gold);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 12px;
}

.setting-item {
  background: #141418;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}

.setting-label {
  color: var(--text);
  font-weight: 500;
}

.setting-val {
  color: var(--gold);
  font-weight: 700;
}

.setting-range {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

.setting-range:disabled {
  cursor: default;
  opacity: 0.7;
}

.architect-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.architect-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.arch-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #141418;
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  font-weight: 500;
}

.arch-pill:hover:not(.locked) {
  border-color: #f15bb5;
}

.arch-pill.selected {
  background: rgba(241, 91, 181, 0.2);
  border-color: #f15bb5;
  color: #ffffff;
}

.arch-pill.locked {
  cursor: default;
}

.htp-info h3 {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.htp-info p {
  font-size: 0.9rem;
  color: #c8c8da;
}

.htp-hint {
  margin-top: 6px;
  color: var(--gold) !important;
  font-weight: 500;
}

.keycaps-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.keycap {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 8px;
  background: #141418;
  color: var(--gold);
  border: 1px solid var(--border);
  border-bottom-width: 3px;
}

/* Screen 3: Game */
.screen-game.active {
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

.game-hud {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  flex-shrink: 0;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-title {
  font-weight: 600;
  color: var(--gold);
}

.hud-pill {
  font-size: 0.82rem;
  background: #141418;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.hud-controls {
  font-size: 0.84rem;
  color: var(--muted);
}

.hud-center-badge {
  font-weight: 700;
  font-size: 0.95rem;
  color: #ffffff;
}

.spectator-badge {
  background: rgba(76, 201, 240, 0.16);
  color: var(--cyan);
  border: 1px solid rgba(76, 201, 240, 0.4);
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
}

.canvas-stage {
  position: relative;
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-canvas {
  background: #121216;
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1000 / 650;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Mobile Touch Controls */
.mobile-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body.mobile-controls-on .screen-game.active {
  padding-bottom: max(142px, calc(136px + env(safe-area-inset-bottom)));
}

.mobile-joystick {
  position: relative;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(33, 33, 40, 0.88);
  border: 2px solid rgba(228, 214, 169, 0.36);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.48);
}

.mobile-joystick.active {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(228, 214, 169, 0.28);
}

.mobile-joystick-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  pointer-events: none;
}

.joy-dir {
  position: absolute;
  font-size: 0.68rem;
  font-weight: 700;
  color: rgba(244, 244, 248, 0.45);
  pointer-events: none;
  transition: color 0.08s ease, transform 0.08s ease;
}

.joy-dir.active {
  color: var(--gold);
  transform: scale(1.2);
}

.joy-w { top: 6px; left: 50%; transform: translateX(-50%); }
.joy-s { bottom: 6px; left: 50%; transform: translateX(-50%); }
.joy-a { left: 8px; top: 50%; transform: translateY(-50%); }
.joy-d { right: 8px; top: 50%; transform: translateY(-50%); }

.joy-w.active { transform: translateX(-50%) scale(1.2); }
.joy-s.active { transform: translateX(-50%) scale(1.2); }
.joy-a.active { transform: translateY(-50%) scale(1.2); }
.joy-d.active { transform: translateY(-50%) scale(1.2); }

.mobile-joystick-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold-strong), #b59e62);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: transform 0.04s linear;
}

.mobile-controls-hint {
  font-size: 0.76rem;
  text-align: center;
  margin-bottom: 68px;
}

.mobile-action-btn {
  width: 98px;
  height: 98px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(76, 201, 240, 0.36), rgba(33, 33, 40, 0.94));
  border: 2.5px solid rgba(76, 201, 240, 0.76);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex-shrink: 0;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.48);
}

.mobile-action-btn.active {
  transform: scale(0.92);
  background: radial-gradient(circle at 30% 30%, rgba(0, 245, 212, 0.52), rgba(29, 78, 99, 0.96));
  border-color: var(--mint);
  box-shadow: 0 0 22px rgba(0, 245, 212, 0.45);
}

.mobile-action-icon {
  font-size: 1.55rem;
  line-height: 1;
}

.mobile-action-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--cyan);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(14, 14, 18, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  overflow: hidden;
}

.overlay:not([hidden]) {
  animation: overlay-fade 0.22s ease-out;
}

.overlay[hidden] {
  display: none;
}

.countdown-number {
  font-size: 6rem;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 32px rgba(228, 214, 169, 0.5);
  line-height: 1;
}

.countdown-number.pop {
  animation: countdown-pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

.countdown-sub {
  margin-top: 10px;
  font-size: 1.2rem;
  color: var(--text);
}

.roundover-card {
  width: 92%;
  max-width: 620px;
  padding: 26px;
  text-align: center;
  position: relative;
  z-index: 2;
  animation: modal-pop-in 0.38s cubic-bezier(0.18, 0.89, 0.32, 1.18);
}

.winner-banner {
  font-size: 1.8rem;
  margin: 4px 0;
  color: var(--gold);
  animation: winner-bounce 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.22) 0.1s both;
}

.winner-reason {
  color: #d0d0e0;
  margin-bottom: 18px;
}

.scoreboards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  text-align: left;
  margin-bottom: 18px;
}

.scoreboards h4 {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.score-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 8px;
  background: #141418;
  font-size: 0.85rem;
  border: 1px solid transparent;
  animation: score-row-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) calc(0.14s + var(--row-i, 0) * 60ms) both;
}

.score-row.me {
  border-color: rgba(255, 209, 102, 0.55);
  background: rgba(255, 209, 102, 0.1);
}

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
  animation: confetti-fall var(--dur, 2s) cubic-bezier(0.2, 0.7, 0.3, 1) var(--delay, 0s) forwards;
}

.roundover-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.roundover-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Reactions */
.reaction-stage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 55;
}

.floating-reaction {
  position: fixed;
  bottom: 74px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(33, 33, 40, 0.92);
  border: 1.5px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  animation: reaction-float 2.1s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

.floating-reaction .emoji {
  font-size: 1.35rem;
  line-height: 1;
}

@keyframes reaction-float {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.75);
  }
  12% {
    opacity: 1;
    transform: translateY(0) scale(1.06);
  }
  25% {
    transform: translateY(-22px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-190px) scale(0.95);
  }
}

.reaction-bar {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  right: 16px;
  max-width: calc(100vw - 32px);
  z-index: 60;
}

body.mobile-controls-on .reaction-bar {
  top: auto;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

body.mobile-controls-on .reaction-fab {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
}

.reaction-drawer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 18px;
  background: rgba(24, 24, 28, 0.94);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.reaction-drawer .react-btn {
  width: 38px;
  height: 38px;
  font-size: 1.25rem;
}

.reaction-fab {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(33, 33, 40, 0.94);
  border: 1.5px solid rgba(228, 214, 169, 0.55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  font-size: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.reaction-fab:hover {
  transform: scale(1.08);
  border-color: var(--gold);
  background: #2c2c38;
}

.reaction-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 12, 16, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;
  animation: overlay-fade 0.18s ease-out;
}

.reaction-modal {
  width: 100%;
  max-width: 360px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: modal-pop-in 0.24s cubic-bezier(0.18, 0.89, 0.32, 1.18);
}

.reaction-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reaction-modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold);
}

.reaction-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.reaction-close-btn:hover {
  border-color: var(--gold);
}

.reaction-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  justify-items: center;
}

.lobby-react-badge {
  font-size: 1.05rem;
  margin-left: 4px;
  animation: lobby-pop 0.2s ease-out;
}

@keyframes lobby-pop {
  from {
    transform: scale(0.5);
  }
  to {
    transform: scale(1);
  }
}

.react-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 1.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.react-btn:hover {
  transform: translateY(-3px) scale(1.08);
  border-color: var(--gold);
  background: #32323f;
}

.react-btn span {
  position: absolute;
  bottom: -2px;
  right: -2px;
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  background: #141418;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 3px;
  line-height: 1.2;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 64px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes screen-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes selected-glow {
  0%, 100% { box-shadow: 0 0 0 1px var(--gold), 0 0 12px rgba(228, 214, 169, 0.14); }
  50% { box-shadow: 0 0 0 1px var(--gold), 0 0 22px rgba(228, 214, 169, 0.32); }
}

@keyframes overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes countdown-pop {
  0% { opacity: 0; transform: scale(1.65); }
  55% { opacity: 1; transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes modal-pop-in {
  0% { opacity: 0; transform: scale(0.86) translateY(18px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes winner-bounce {
  0% { opacity: 0; transform: scale(0.75); }
  65% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes score-row-in {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(18px) scale(0.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift, 0px), 520px, 0) rotate(var(--rot, 540deg));
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1120px) {
  .game-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .lobby-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .lobby-sidebar {
    position: static;
  }
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .how-to-play {
    flex-direction: column;
    align-items: flex-start;
  }
  .htp-preview {
    width: 100%;
    max-width: 280px;
    height: auto;
    aspect-ratio: 240 / 110;
  }
}

@media (max-width: 768px) {
  .topbar {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding: 6px 12px;
    gap: 6px 10px;
  }
  .brand {
    font-size: 0.92rem;
    gap: 6px;
  }
  .topbar-actions {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .conn-badge {
    font-size: 0.72rem;
    padding: 4px 8px;
  }
  .btn-icon {
    font-size: 0.75rem;
    padding: 5px 8px;
  }
  .screen {
    padding: 12px 10px 78px;
  }
  .screen-game.active {
    padding: 6px 8px max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }
  .landing-card {
    padding: 20px 16px;
  }
  .lobby-sidebar,
  .game-settings-card,
  .how-to-play,
  .architect-picker {
    padding: 14px;
  }
  .big-code {
    font-size: 1.85rem;
    letter-spacing: 4px;
  }
  .player-list {
    max-height: 200px;
  }
  .roundover-card {
    max-height: 88dvh;
    overflow-y: auto;
    padding: 18px 14px;
  }
  .react-btn span {
    display: none;
  }
}

@media (max-width: 600px) {
  .scoreboards {
    grid-template-columns: 1fr;
  }
  .game-hud {
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px;
  }
  .hud-controls {
    display: none;
  }
  .mobile-controls-hint {
    display: none;
  }
  .reaction-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 440px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .join-row {
    flex-direction: column;
  }
  .code-input {
    max-width: none;
    width: 100%;
  }
  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .player-item {
    padding: 8px 9px;
  }
  .player-name {
    font-size: 0.84rem;
  }
  .player-meta {
    gap: 4px;
    font-size: 0.7rem;
  }
}

@media (max-height: 540px) and (pointer: coarse) {
  body.mobile-controls-on .screen-game.active {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .mobile-joystick,
  .mobile-action-btn {
    opacity: 0.85;
  }
  .mobile-controls-hint {
    display: none;
  }
}
