:root {
  color-scheme: dark;
  --mobile-dock-height: 112px;
  --bg: #0b0d14;
  --panel: #111624;
  --panel-edge: rgba(255, 255, 255, 0.08);
  --accent: #f5c542;
  --accent-2: #6ce5ff;
  --accent-3: #ff8f66;
  --text: #e8edf7;
  --muted: #9aa6bd;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at top, rgba(108, 229, 255, 0.17), transparent 38%),
    radial-gradient(circle at 80% 0%, rgba(245, 197, 66, 0.16), transparent 30%),
    radial-gradient(circle at 20% 120%, rgba(255, 143, 102, 0.11), transparent 36%),
    repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 9px),
    var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

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

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 5rem);
  line-height: 0.95;
}

.subcopy {
  max-width: 44rem;
  color: var(--muted);
  margin: 10px 0 0;
}

.stats {
  display: grid;
  gap: 10px;
  justify-items: end;
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: rgba(7, 11, 20, 0.35);
}

.actions {
  display: flex;
  gap: 10px;
}

.stats button {
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.stats button:hover {
  transform: translateY(-1px);
  border-color: rgba(108, 229, 255, 0.38);
  background: rgba(108, 229, 255, 0.16);
}

.game-frame {
  position: relative;
  border: 1px solid var(--panel-edge);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(17, 22, 36, 0.92), rgba(10, 13, 21, 0.92));
  padding: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.start-overlay {
  position: absolute;
  inset: 16px;
  border-radius: 16px;
  background:
    radial-gradient(circle at 12% 8%, rgba(108, 229, 255, 0.19), transparent 38%),
    radial-gradient(circle at 90% 6%, rgba(245, 197, 66, 0.17), transparent 40%),
    rgba(8, 10, 16, 0.78);
  backdrop-filter: blur(9px);
  display: grid;
  place-items: center;
  z-index: 4;
  overflow: hidden;
}

.start-overlay::before,
.start-overlay::after {
  content: "";
  position: absolute;
  inset: -18% -8%;
  pointer-events: none;
}

.start-overlay::before {
  background:
    repeating-linear-gradient(
      0deg,
      rgba(108, 229, 255, 0.08) 0 2px,
      rgba(108, 229, 255, 0) 2px 20px
    );
  transform: perspective(720px) rotateX(60deg) translateY(18%);
  transform-origin: center bottom;
  animation: laneDrift 8.5s linear infinite;
}

.start-overlay::after {
  background:
    radial-gradient(circle at center, rgba(108, 229, 255, 0.2), transparent 42%),
    radial-gradient(circle at 70% 10%, rgba(255, 143, 102, 0.2), transparent 38%);
  opacity: 0.52;
  animation: overlayPulse 3.4s ease-in-out infinite alternate;
}

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

.start-card {
  position: relative;
  width: min(460px, 92%);
  border: 1px solid rgba(108, 229, 255, 0.24);
  border-radius: 18px;
  background:
    linear-gradient(140deg, rgba(108, 229, 255, 0.14), transparent 35%),
    linear-gradient(180deg, rgba(17, 22, 36, 0.99), rgba(10, 13, 21, 0.99));
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.52);
  animation: startCardIn 260ms ease-out;
}

.start-card h2 {
  margin: 0;
  font-size: 1.24rem;
  letter-spacing: 0.03em;
}

.start-card p {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.start-mini {
  margin: 0 0 10px;
  color: rgba(232, 237, 247, 0.86);
  font-size: 0.84rem;
}

.start-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.start-badges span {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  color: rgba(232, 237, 247, 0.88);
  background: rgba(255, 255, 255, 0.04);
}

.start-card input {
  width: 100%;
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 11px 12px;
  font-size: 1rem;
}

.remember-choice,
.meta-toggle {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.remember-choice input,
.meta-toggle input {
  accent-color: var(--accent-2);
}

.start-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.start-actions button {
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
}

.start-btn-secondary {
  border-color: rgba(255, 255, 255, 0.22);
}

.start-btn-google {
  border-color: rgba(108, 229, 255, 0.45);
  background: rgba(108, 229, 255, 0.16);
}

.start-btn-primary,
#startGame {
  border-color: rgba(245, 197, 66, 0.55);
  background: linear-gradient(180deg, rgba(245, 197, 66, 0.35), rgba(255, 143, 102, 0.3));
  color: #fff8df;
}

.start-actions button:hover {
  transform: translateY(-1px);
}

@keyframes startCardIn {
  from {
    transform: translateY(12px) scale(0.985);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes laneDrift {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 0 320px;
  }
}

@keyframes overlayPulse {
  from {
    opacity: 0.35;
    filter: saturate(0.95);
  }
  to {
    opacity: 0.6;
    filter: saturate(1.08);
  }
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: 72dvh;
  touch-action: none;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(108, 229, 255, 0.08), transparent 30%),
    linear-gradient(180deg, #151d2e 0%, #0d111b 55%, #0a0c13 100%);
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.fullscreen-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.2em;
}

.meta-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 14px;
}

.meta-card {
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(17, 22, 36, 0.88), rgba(10, 13, 21, 0.88));
  padding: 14px;
}

.meta-card h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

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

.player-form {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}

.player-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 9px 10px;
}

.player-form button {
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.auth-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-actions button {
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

#authSignIn {
  border-color: rgba(108, 229, 255, 0.4);
  background: rgba(108, 229, 255, 0.16);
}

.hall-tabs {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.hall-tab {
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.hall-tab.is-active {
  background: rgba(108, 229, 255, 0.22);
  border-color: rgba(108, 229, 255, 0.45);
}

.hall-table-shell {
  margin-top: 10px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  position: sticky;
  top: 0;
  background: rgba(13, 17, 27, 0.95);
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.current-player {
  background: rgba(108, 229, 255, 0.12);
}

@media (max-width: 900px) {
  .shell {
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .hud {
    display: block;
    margin-bottom: 14px;
  }

  .stats {
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 14px;
  }

  .actions {
    margin-left: auto;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-frame {
    padding: 10px;
    border-radius: 18px;
  }

  .start-overlay {
    inset: 10px;
  }

  .start-overlay::before {
    animation-duration: 10s;
    opacity: 0.85;
  }

  .start-card {
    width: min(520px, 100%);
  }

  .start-actions {
    flex-direction: column-reverse;
  }

  .start-actions button {
    width: 100%;
    min-height: 46px;
  }

  canvas {
    max-height: 60dvh;
  }

  .hint {
    font-size: 0.88rem;
    line-height: 1.45;
  }

  .meta-grid {
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .hall-table-shell {
    max-height: 180px;
  }

  .hall-tabs {
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

@media (max-width: 640px) {
  canvas {
    max-height: 52dvh;
  }

  .hint {
    font-size: 0.84rem;
  }

  .fullscreen-hint {
    font-size: 0.75rem;
  }
}

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

body.simulated-fullscreen {
  overflow: hidden;
}

body.simulated-fullscreen .shell {
  max-width: none;
  padding: 0;
  margin: 0;
}

body.simulated-fullscreen .hud {
  display: none;
}

body.simulated-fullscreen .game-frame {
  position: fixed;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
  border: none;
  padding: 8px;
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body.simulated-fullscreen .meta-grid {
  display: none;
}

body.simulated-fullscreen canvas {
  max-height: calc(100dvh - 92px);
  border-radius: 10px;
}

body.simulated-fullscreen .hint,
body.simulated-fullscreen .fullscreen-hint {
  text-align: center;
}

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

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

body.mobile-immersive .meta-grid,
body.mobile-immersive .shell > .meta-card:last-child {
  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;
  margin: 0;
  border-radius: 14px;
  border: 1px solid rgba(132, 184, 243, 0.34);
  background: rgba(7, 14, 28, 0.92);
  backdrop-filter: blur(8px);
  padding: 8px 10px;
  display: block;
}

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

body.mobile-immersive .stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  justify-items: stretch;
  gap: 6px;
  padding: 0;
  border: none;
  background: transparent;
}

body.mobile-immersive .stats span {
  border: 1px solid rgba(126, 174, 228, 0.28);
  border-radius: 999px;
  background: rgba(15, 31, 55, 0.56);
  padding: 4px 8px;
  font-size: 0.82rem;
}

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

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

body.mobile-immersive .stats button {
  min-height: 38px;
  border-radius: 10px;
  padding: 7px 6px;
}

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

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

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

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

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

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

body.mobile-immersive.mobile-start-open .start-overlay {
  inset: 0;
  border-radius: 0;
  place-items: end center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

body.mobile-immersive.mobile-start-open .start-card {
  width: min(560px, 100%);
  max-height: min(76dvh, 640px);
  overflow: auto;
  border-radius: 18px;
  padding: 15px;
}

body.mobile-immersive.mobile-start-open .start-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(16, 21, 34, 0.55), rgba(16, 21, 34, 0.95));
  padding-top: 8px;
}

@media (max-width: 520px) {
  h1 {
    font-size: clamp(2.3rem, 14vw, 3.5rem);
  }

  .subcopy {
    font-size: 0.95rem;
    line-height: 1.35;
    max-width: none;
  }

  .actions {
    width: 100%;
    justify-content: flex-end;
  }

  .stats button {
    padding: 9px 14px;
  }

  .start-overlay {
    inset: 0;
    border-radius: 0;
    place-items: end center;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .start-overlay::before {
    transform: perspective(560px) rotateX(62deg) translateY(24%);
    animation-duration: 12s;
  }

  .start-overlay::after {
    opacity: 0.38;
  }

  .start-card {
    width: 100%;
    max-height: 82dvh;
    overflow: auto;
    border-radius: 18px;
    padding: 16px;
  }

  .start-card input {
    font-size: 16px;
  }

  .remember-choice,
  .meta-toggle {
    font-size: 0.9rem;
  }

  .player-form {
    flex-direction: column;
  }

  .player-form button {
    width: 100%;
  }

  .auth-actions button {
    width: 100%;
  }
}
