:root {
  color-scheme: dark;
  --bg: #07080d;
  --surface: #10141d;
  --surface-2: #171d28;
  --surface-3: #202838;
  --text: #fff7db;
  --muted: #aeb8c8;
  --line: #304154;
  --mint: #28f7c8;
  --blue: #4cc9ff;
  --coral: #ff4d7d;
  --sun: #ffe66d;
  --berry: #c45cff;
  --danger: #f04455;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  background: #050608;
}

body.in-match {
  background: var(--bg);
  overflow: hidden;
}

.ambient-root {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
  background: #050608;
}

.ambient-root.is-hidden {
  display: none;
}

.ambient-root.has-static-fallback {
  background: #050608;
}

.ambient-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, auto) minmax(180px, 1fr) minmax(430px, 560px);
  gap: 16px;
  align-items: center;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 247, 219, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(5, 7, 14, 0.88), rgba(8, 9, 18, 0.7)),
    rgba(8, 10, 18, 0.78);
}

.brand {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 70px;
  height: 70px;
  place-items: center;
  border: 1px solid rgba(76, 201, 255, 0.28);
  border-radius: 8px;
  background: #05070c;
  box-shadow:
    0 0 18px rgba(76, 201, 255, 0.22),
    0 0 24px rgba(255, 77, 125, 0.16);
}

.brand-logo {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 7px;
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  color: #fffdf2;
  font-size: 1.12rem;
  letter-spacing: 0;
}

.brand small,
.handle-form label,
.game-card-meta,
.board-name small,
.seat-badge,
.country-badge,
.result-kicker {
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-title {
  display: grid;
  justify-items: center;
  min-width: 0;
}

.welcome-neon-sign {
  position: relative;
  display: flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  min-width: min(100%, 250px);
  min-height: 50px;
  place-items: center;
  padding: 7px 18px;
  border: 1px solid rgba(255, 230, 109, 0.42);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(12, 6, 19, 0.92), rgba(5, 7, 14, 0.94)),
    #090b12;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 0 18px rgba(255, 230, 109, 0.18),
    0 0 28px rgba(196, 92, 255, 0.14);
  color: var(--sun);
  font-size: 0.82rem;
  font-weight: 1000;
  line-height: 1;
  text-transform: uppercase;
}

.welcome-neon-sign span:first-child {
  color: #4cc9ff;
  text-shadow:
    0 0 7px rgba(76, 201, 255, 0.9),
    0 0 17px rgba(76, 201, 255, 0.58);
}

.welcome-neon-sign span:last-child {
  color: #ff4d7d;
  text-shadow:
    0 0 7px rgba(255, 77, 125, 0.9),
    0 0 17px rgba(255, 77, 125, 0.62),
    0 0 26px rgba(255, 230, 109, 0.34);
}

.topbar-controls {
  display: grid;
  grid-template-columns: auto minmax(190px, 240px) minmax(132px, 1fr);
  gap: 8px;
  align-items: stretch;
  justify-self: end;
  width: 100%;
  min-width: 0;
}

.connection-pill,
.party-code,
.score-pill,
.arcade-stat,
.match-status {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(76, 201, 255, 0.22);
  border-radius: 8px;
  padding: 7px 11px;
  background: rgba(23, 29, 40, 0.86);
  color: var(--muted);
  font-weight: 850;
}

.connection-pill {
  min-width: 84px;
  min-height: 54px;
}

.connection-pill.online,
.turn-badge {
  color: #06130f;
  background: var(--mint);
}

.handle-form {
  display: grid;
  gap: 4px;
  min-width: 0;
  min-height: 54px;
  border: 1px solid rgba(76, 201, 255, 0.18);
  border-radius: 8px;
  padding: 6px;
  background: rgba(10, 14, 22, 0.92);
}

.handle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(76, 201, 255, 0.24);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #0b1018;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(40, 247, 200, 0.16);
}

.primary-button,
.secondary-button,
.danger-button,
.queue-button,
.arcade-command {
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 13px;
  font-weight: 850;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.primary-button,
.queue-button,
.arcade-command {
  color: #18120a;
  background: linear-gradient(90deg, var(--sun), #ff9f1c);
}

.secondary-button {
  color: var(--text);
  border: 1px solid rgba(76, 201, 255, 0.24);
  background: #151c28;
}

.danger-button {
  color: white;
  background: var(--danger);
}

.compact-button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

button:not(:disabled):active {
  transform: translateY(1px);
}

.party-panel {
  min-width: 0;
}

.party-create-button {
  display: grid;
  min-width: 128px;
  min-height: 54px;
  align-content: center;
  justify-items: start;
  border: 1px solid rgba(255, 230, 109, 0.24);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  background: rgba(16, 20, 29, 0.94);
}

.party-create-button span,
.party-kicker {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.party-create-button strong {
  color: var(--sun);
  font-size: 0.95rem;
}

.party-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 8px;
  align-items: center;
  min-width: 0;
  min-height: 75px;
  border: 1px solid rgba(255, 247, 219, 0.12);
  border-radius: 8px;
  padding: 8px;
  background: rgba(13, 18, 27, 0.94);
}

.party-head,
.party-actions,
.party-player,
.result-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.party-head h2,
.party-head p {
  margin: 0;
}

.party-summary {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.party-summary strong,
.party-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-summary span {
  color: var(--muted);
  font-size: 0.76rem;
}

.party-link {
  display: none;
}

.party-actions {
  grid-column: 2;
  grid-row: 1 / span 2;
  margin-top: 0;
  justify-content: start;
}

.party-roster {
  display: none;
  gap: 6px;
  margin-top: 7px;
  overflow-x: auto;
  scrollbar-width: none;
}

.party-roster::-webkit-scrollbar {
  display: none;
}

.party-player {
  flex: 0 0 auto;
  min-height: 26px;
  border: 1px solid rgba(255, 247, 219, 0.1);
  border-radius: 8px;
  padding: 4px 6px;
  background: rgba(32, 40, 56, 0.72);
}

.party-player-name,
.party-player-actions,
.player-name {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

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

.game-grid.is-hidden,
.arena {
  display: none;
}

.game-card-button {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  border: 1px solid rgba(255, 247, 219, 0.12);
  border-radius: 8px;
  padding: 10px 10px 10px 14px;
  color: var(--text);
  text-align: left;
  background: linear-gradient(135deg, color-mix(in srgb, var(--cab-a, #4cc9ff) 18%, rgba(16, 20, 29, 0.88)), rgba(16, 20, 29, 0.88));
  overflow: hidden;
}

.game-card-button::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--cab-a, #4cc9ff), var(--cab-b, #ff4d7d));
}

.game-card-button:hover:not(:disabled) {
  background: linear-gradient(135deg, color-mix(in srgb, var(--cab-a, #4cc9ff) 26%, #10141d), #151c28);
}

.game-card-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.game-card-title,
.game-card-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-card-title {
  font-weight: 950;
}

.game-card-cta {
  border-radius: 999px;
  padding: 6px 9px;
  color: #06130f;
  background: var(--mint);
  font-size: 0.78rem;
  font-weight: 900;
}

.arena.active {
  --game-width: 560px;
  --game-aspect: 1 / 1;
  --stage-width: 582px;
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(2, 4, 9, 0.78);
  overflow: auto;
}

.arena.game-pool,
.arena.game-battleship,
.arena.game-falconlander,
.arena.game-starshiplander,
.arena.game-flappy,
.arena.game-pinball,
.arena.game-blackjack,
.arena.game-poker {
  --game-width: 720px;
  --game-aspect: 16 / 9;
  --stage-width: 742px;
}

.board-stage {
  width: min(100%, var(--stage-width));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: 1px solid rgba(255, 247, 219, 0.12);
  border-radius: 8px;
  background: #0d121b;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.52);
}

.board-stage {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
}

.board-stage.live-turn {
  border-color: rgba(40, 247, 200, 0.42);
}

.board-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.board-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.board-name {
  display: grid;
  min-width: 0;
}

.board-name strong,
.board-name small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  width: min(100%, var(--game-width));
  margin: 0 auto;
}

.webgl-stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--game-aspect);
  min-height: 0;
  overflow: hidden;
  border-radius: 6px;
  background: #07080d;
  touch-action: none;
  contain: strict;
}

.webgl-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.webgl-label-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.webgl-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", Arial, sans-serif;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(5, 6, 8, 0.42);
}

.control-mount {
  width: min(100%, var(--game-width));
  margin: 0 auto;
}

.empty-arena {
  border: 1px solid rgba(255, 247, 219, 0.1);
  border-radius: 8px;
  padding: 9px;
  background: #111722;
}

.turn-badge,
.seat-badge,
.country-badge {
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 900;
}

.seat-badge,
.country-badge {
  background: #202838;
}

.match-result-overlay {
  display: grid;
  place-items: center;
}

.match-offer-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(2, 4, 9, 0.58);
}

.match-offer-card {
  display: grid;
  gap: 10px;
  width: min(420px, 100%);
  border: 1px solid color-mix(in srgb, var(--cab-a, #28f7c8) 42%, rgba(255, 247, 219, 0.18));
  border-radius: 8px;
  padding: 16px;
  background: #111722;
}

.match-offer-card h2,
.match-offer-card p {
  margin: 0;
}

.match-result-card {
  display: grid;
  gap: 10px;
  width: min(420px, 100%);
  border: 1px solid rgba(255, 247, 219, 0.14);
  border-radius: 8px;
  padding: 14px;
  background: #111722;
}

.result-actions.single-action {
  justify-content: end;
}

.arcade-controls,
.pool-controls,
.score-strip,
.holdem-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.slider-control {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: min(260px, 100%);
}

input[type="range"] {
  accent-color: var(--mint);
}

.reaction-shell,
.typeracer-shell,
.color-shell,
.frequency-shell,
.arcade-shell {
  display: grid;
  gap: 12px;
  width: min(100%, 620px);
  margin: 0 auto;
}

.reaction-stage,
.color-stage,
.frequency-stage {
  display: grid;
  min-height: 280px;
  place-items: center;
  border: 1px solid rgba(255, 247, 219, 0.12);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 34%, rgba(76, 201, 255, 0.12), transparent 32%),
    linear-gradient(180deg, #101827, #0d121b);
  animation: game-stage-in 260ms ease-out both;
}

.reaction-button {
  width: min(260px, 80vw);
  aspect-ratio: 1;
  border-radius: 50%;
  color: #06130f;
  background: var(--sun);
  font-size: clamp(1.4rem, 5vw, 2.3rem);
  font-weight: 1000;
  box-shadow: 0 0 0 0 rgba(255, 230, 109, 0.28);
}

.reaction-button.is-live {
  animation: reaction-live 620ms ease-in-out infinite;
}

.reaction-ring {
  position: relative;
  width: min(180px, 48vw);
  aspect-ratio: 1;
  border: 2px solid rgba(40, 247, 200, 0.34);
  border-radius: 50%;
  box-shadow:
    inset 0 0 28px rgba(40, 247, 200, 0.12),
    0 0 28px rgba(76, 201, 255, 0.12);
}

.reaction-core {
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--sun), var(--coral));
  box-shadow: 0 0 24px rgba(255, 230, 109, 0.32);
}

.reaction-readout,
.type-phrase,
.progress-lane,
.color-match-value,
.target-chip,
.guess-chip {
  border: 1px solid rgba(255, 247, 219, 0.12);
  border-radius: 8px;
  padding: 10px;
  background: #111722;
}

.type-lanes {
  display: grid;
  gap: 8px;
}

.progress-track,
.color-match-meter,
.frequency-wave {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #202838;
}

.progress-track > span,
.color-match-meter > span {
  display: block;
  width: var(--match-score, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--sun));
  transition: width 160ms ease-out;
}

.progress-track > span {
  width: 0;
  min-width: var(--lane-progress, 0%);
}

.progress-track > span[style] {
  min-width: 0;
}

.frequency-wave {
  width: min(360px, 78vw);
  height: 96px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(76, 201, 255, 0.2) 0 2px, transparent 2px var(--wave-spacing, 42px)),
    linear-gradient(180deg, rgba(76, 201, 255, 0.1), rgba(196, 92, 255, 0.06)),
    #0d121b;
  box-shadow: inset 0 0 34px rgba(76, 201, 255, 0.1);
}

.target-marker,
.guess-marker,
.frequency-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: var(--sun);
}

.target-marker {
  left: var(--target-pos, 50%);
}

.guess-marker {
  left: var(--guess-pos, 50%);
  background: var(--coral);
}

.color-chip {
  width: 74px;
  height: 74px;
  border: 1px solid rgba(255, 247, 219, 0.18);
  border-radius: 8px;
  background: var(--chip, var(--mint));
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24);
  transition: transform 140ms ease-out, background 120ms linear;
}

.color-chip:hover {
  transform: translateY(-2px);
}

@keyframes game-stage-in {
  from {
    opacity: 0.72;
    transform: translateY(7px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes reaction-live {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 230, 109, 0.28);
  }
  50% {
    transform: scale(1.035);
    box-shadow: 0 0 0 16px rgba(255, 230, 109, 0);
  }
}

.color-input {
  width: 70px;
  height: 44px;
  padding: 4px;
}

.wide {
  width: 100%;
}

.flag-badge {
  font-size: 1rem;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: minmax(250px, 1fr) minmax(430px, 560px);
  }

  .topbar-title {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .topbar-controls {
    grid-template-columns: auto minmax(190px, 240px) minmax(132px, 1fr);
  }

  .party-card {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .topbar,
  .arena.active {
    grid-template-columns: 1fr;
  }

  .topbar-controls {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .party-panel {
    grid-column: 1 / -1;
  }

  .party-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .party-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .party-create-button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 8px;
  }

  .arena.active {
    place-items: stretch;
    padding: 0;
  }

  .board-stage {
    width: 100%;
    min-height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .game-card-button {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .game-card-cta {
    justify-self: start;
  }

  .board-title {
    grid-template-columns: 1fr;
  }

  .webgl-stage {
    aspect-ratio: var(--game-aspect);
  }
}
