:root {
  --mobile-dock-height: 116px;
  --bg-0: #050b16;
  --bg-1: #081428;
  --panel: rgba(8, 16, 31, 0.86);
  --panel-strong: rgba(5, 12, 25, 0.92);
  --border: rgba(122, 168, 225, 0.28);
  --ink: #eef5ff;
  --muted: #9eb0cb;
  --accent-a: #69e3ff;
  --accent-b: #39ef98;
  --danger: #ff7a7a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: radial-gradient(circle at 85% 12%, rgba(48, 220, 255, 0.16), transparent 30%),
    radial-gradient(circle at 12% 22%, rgba(112, 255, 188, 0.14), transparent 30%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body.game-signal-heist {
  --bg-0: #04121f;
  --bg-1: #082236;
  --panel: rgba(7, 22, 40, 0.86);
  --border: rgba(104, 201, 239, 0.3);
  --accent-a: #69e3ff;
  --accent-b: #39ef98;
}

body.game-batwing-drift {
  --bg-0: #130b08;
  --bg-1: #2b140d;
  --panel: rgba(40, 18, 12, 0.86);
  --border: rgba(255, 178, 111, 0.3);
  --accent-a: #ffc74a;
  --accent-b: #ff7f50;
}

body.game-echo-pulse {
  --bg-0: #100d1a;
  --bg-1: #1b1430;
  --panel: rgba(24, 18, 43, 0.86);
  --border: rgba(143, 190, 255, 0.3);
  --accent-a: #8fb9ff;
  --accent-b: #ff9e6a;
}

body.game-grapple-trials {
  --bg-0: #07120e;
  --bg-1: #0f231a;
  --panel: rgba(10, 29, 22, 0.86);
  --border: rgba(135, 235, 190, 0.3);
  --accent-a: #76ecbf;
  --accent-b: #57d2ff;
}

body.game-night-courier {
  --bg-0: #0a101b;
  --bg-1: #141e2e;
  --panel: rgba(14, 24, 39, 0.86);
  --border: rgba(156, 184, 222, 0.3);
  --accent-a: #9cc5ff;
  --accent-b: #ffd089;
}

input,
textarea,
select {
  -webkit-user-select: text;
  user-select: text;
}

.shell {
  max-width: 1260px;
  margin: 0 auto;
  padding: clamp(12px, 2.5vw, 24px);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}

.hud,
.meta-card,
.game-frame {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.hud {
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
}

.eyebrow {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent-a);
}

h1 {
  margin: 6px 0;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

.subcopy {
  margin: 0;
  max-width: 72ch;
  color: var(--muted);
  font-size: 0.94rem;
}

.stats {
  display: grid;
  gap: 6px;
  justify-items: end;
  align-content: start;
  font-size: 0.98rem;
}

.stats strong {
  color: #f4fbff;
}

.actions {
  margin-top: 4px;
  display: inline-flex;
  gap: 8px;
}

button {
  appearance: none;
  border: 1px solid rgba(136, 184, 240, 0.35);
  background: rgba(8, 19, 37, 0.92);
  color: #e4f2ff;
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 42px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(180, 219, 255, 0.64);
  background: rgba(12, 25, 48, 0.95);
}

button.is-primary {
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
  color: #061324;
  border-color: transparent;
}

button.is-danger {
  border-color: rgba(255, 151, 151, 0.45);
}

button.is-active-toggle {
  border-color: rgba(110, 255, 183, 0.65);
  box-shadow: 0 0 0 1px rgba(110, 255, 183, 0.24) inset;
}

.game-frame {
  position: relative;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 16 / 9;
  max-height: 62dvh;
  touch-action: none;
  background: #040912;
}

.hint {
  border-top: 1px solid rgba(129, 171, 227, 0.2);
  color: #9eb2cf;
  font-size: 0.8rem;
  padding: 7px 10px;
}

.fullscreen-hint {
  position: absolute;
  bottom: 44px;
  right: 14px;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.76rem;
  color: #082131;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.fullscreen-hint.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(3, 8, 18, 0.82);
}

.start-overlay.is-hidden {
  display: none;
}

.start-card {
  width: min(520px, 96%);
  max-height: 82dvh;
  overflow: auto;
  border: 1px solid rgba(130, 173, 230, 0.28);
  border-radius: 16px;
  background: rgba(5, 14, 29, 0.95);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.start-card h2 {
  margin: 0;
}

.start-card p {
  margin: 0;
  color: var(--muted);
}

.start-mini {
  font-size: 0.82rem;
}

.start-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.start-badges span {
  display: inline-flex;
  border: 1px solid rgba(133, 173, 229, 0.25);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.68rem;
  color: #c9dbf2;
}

input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(133, 172, 230, 0.35);
  border-radius: 10px;
  background: rgba(5, 13, 27, 0.92);
  font-size: 16px;
  color: #e8f4ff;
  padding: 9px 11px;
}

.start-actions,
.auth-actions,
.player-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.start-actions button,
.player-form button,
.auth-actions button {
  flex: 1 1 140px;
}

.start-btn-secondary {
  border-color: rgba(136, 182, 234, 0.32);
}

.start-btn-google {
  border-color: rgba(93, 196, 255, 0.52);
}

.start-btn-primary {
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
  border-color: transparent;
  color: #081322;
}

.meta-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.meta-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.meta-card h2 {
  margin: 0;
}

.meta-subcopy {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.meta-toggle,
.remember-choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #c3d5eb;
  font-size: 0.82rem;
}

.hall-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hall-tab {
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.hall-tab.is-active {
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
  color: #072032;
  border-color: transparent;
}

.hall-table-shell {
  overflow: auto;
  border: 1px solid rgba(127, 171, 230, 0.22);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 300px;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(126, 165, 222, 0.14);
  font-size: 0.84rem;
}

thead th {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #9db6d6;
}

tr.current-player td {
  color: #baf2ff;
}

.footer-note {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.83rem;
}

.footer-note a {
  color: #7ee6ff;
}

.simulated-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999;
  border-radius: 0;
  margin: 0;
}

body.mobile-immersive {
  min-height: 100dvh;
  overflow: hidden;
}

body.mobile-immersive .shell {
  max-width: none;
  padding: 0;
  gap: 0;
}

body.mobile-immersive .meta-grid,
body.mobile-immersive .footer-note {
  display: none;
}

body.mobile-immersive .hud {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 10001;
  border-radius: 14px;
  border: 1px solid rgba(129, 179, 242, 0.34);
  background: rgba(5, 13, 27, 0.92);
  backdrop-filter: blur(9px);
  padding: 8px 10px;
  display: block;
}

body.mobile-immersive.mobile-start-open .hud {
  display: none;
}

body.mobile-immersive .hud > :first-child {
  display: none;
}

body.mobile-immersive .stats {
  justify-items: stretch;
  align-items: center;
  gap: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

body.mobile-immersive .stats span {
  font-size: 0.8rem;
  color: #d0e5ff;
  background: rgba(17, 35, 62, 0.55);
  border: 1px solid rgba(135, 180, 232, 0.28);
  border-radius: 999px;
  padding: 4px 8px;
}

body.mobile-immersive .stats span:nth-child(2),
body.mobile-immersive .stats span:nth-child(4) {
  display: none;
}

body.mobile-immersive .actions {
  margin-top: 0;
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.mobile-immersive .actions button {
  min-height: 36px;
  font-size: 0.75rem;
  padding: 6px 4px;
}

body.mobile-immersive .game-frame {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: calc(var(--mobile-dock-height) + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  z-index: 9999;
  border-radius: 0;
  border: none;
  margin: 0;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) 6px
    max(6px, env(safe-area-inset-left));
}

body.mobile-immersive.mobile-start-open .game-frame {
  bottom: 0;
}

body.mobile-immersive .start-overlay {
  inset: 0;
}

body.mobile-immersive.mobile-start-open .start-overlay {
  place-items: end center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(2, 7, 16, 0.18), rgba(2, 8, 18, 0.86));
}

body.mobile-immersive.mobile-start-open .start-card {
  width: min(560px, 100%);
  max-height: min(76dvh, 620px);
  border-radius: 18px;
  border: 1px solid rgba(122, 173, 236, 0.42);
  padding: 14px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.5);
}

body.mobile-immersive.mobile-start-open .start-card h2 {
  font-size: clamp(1.3rem, 6vw, 2rem);
}

body.mobile-immersive.mobile-start-open .start-card p {
  font-size: 0.94rem;
  line-height: 1.35;
}

body.mobile-immersive.mobile-start-open .start-actions {
  position: sticky;
  bottom: 0;
  background: rgba(5, 14, 29, 0.95);
  padding-top: 8px;
}

body.mobile-immersive.mobile-start-open .start-actions button {
  min-height: 46px;
  font-size: 0.92rem;
}

body.mobile-immersive.game-signal-heist .actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.mobile-immersive.game-signal-heist #reset {
  order: -1;
  grid-column: 1 / -1;
}

body.mobile-immersive.game-signal-heist .stats span:nth-child(2),
body.mobile-immersive.game-signal-heist .stats span:nth-child(4) {
  display: none;
}

body.mobile-immersive.mobile-start-open.game-signal-heist .start-card {
  max-height: min(72dvh, 560px);
}

body.mobile-immersive.mobile-start-open.game-signal-heist .start-badges {
  display: none;
}

body.mobile-immersive.game-batwing-drift .actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.mobile-immersive.game-batwing-drift #reset {
  order: -1;
}

body.mobile-immersive.mobile-start-open.game-batwing-drift .start-card {
  border-color: rgba(245, 197, 66, 0.45);
}

body.mobile-immersive.game-echo-pulse .stats span:nth-child(3),
body.mobile-immersive.game-echo-pulse .stats span:nth-child(4) {
  display: none;
}

body.mobile-immersive.game-echo-pulse .stats span:nth-child(2),
body.mobile-immersive.game-night-courier .stats span:nth-child(2) {
  display: block;
}

body.mobile-immersive.game-echo-pulse .actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.mobile-immersive.game-echo-pulse #fullscreen {
  grid-column: 1 / -1;
}

body.mobile-immersive.game-grapple-trials .actions,
body.mobile-immersive.game-night-courier .actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.mobile-immersive.game-grapple-trials #reset,
body.mobile-immersive.game-night-courier #reset {
  order: -1;
  grid-column: 1 / -1;
}

body.mobile-immersive.game-night-courier .stats span:nth-child(3),
body.mobile-immersive.game-night-courier .stats span:nth-child(4) {
  display: none;
}

body.mobile-immersive canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: none;
}

body.mobile-immersive .hint {
  display: none;
}

body.mobile-immersive.mobile-start-open canvas {
  opacity: 0.5;
}

@media (max-width: 960px) {
  .hud {
    grid-template-columns: 1fr;
  }

  .stats {
    justify-items: start;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
    gap: 10px;
  }

  .hud,
  .meta-card {
    padding: 12px;
  }

  .stats {
    font-size: 0.92rem;
    gap: 4px;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .actions button {
    width: 100%;
    min-height: 44px;
    font-size: 0.8rem;
    padding: 8px;
  }

  .start-overlay {
    place-items: end center;
  }

  .start-card {
    width: 100%;
    border-radius: 14px;
  }

  .start-actions button,
  .player-form button,
  .auth-actions button {
    flex: 1 1 100%;
  }

  .player-form input,
  #playerName,
  #startPlayerName {
    flex: 1 1 100%;
  }

  .hint {
    font-size: 0.76rem;
    padding: 6px 8px;
  }

  .footer-note {
    font-size: 0.78rem;
  }

  canvas {
    max-height: 52dvh;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  canvas {
    max-height: 76dvh;
  }
}
