:root {
  --bg: #071018;
  --panel: rgba(11, 20, 33, 0.92);
  --panel-border: rgba(255, 255, 255, 0.1);
  --path: #153245;
  --wall: #09131d;
  --monster: #ff5a6b;
  --boss: #ffd84d;
  --p1: #00e5ff;
  --p2: #ffcc4d;
  --text-dim: rgba(255, 255, 255, 0.72);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Outfit', sans-serif;
  color: white;
  background:
    radial-gradient(circle at top left, rgba(0, 201, 255, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 216, 77, 0.18), transparent 24%),
    var(--bg);
  overflow-x: hidden;
}

.app-shell {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 20px;
  min-height: 100dvh;
  align-items: start;
}

.hero-panel,
.game-panel,
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
}

.hero-panel,
.game-panel {
  padding: 22px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
}

h1,
h2 {
  margin: 0;
}

.hero-copy {
  color: var(--text-dim);
  line-height: 1.7;
}

.lobby-card {
  margin-top: 20px;
  display: grid;
  gap: 14px;
}

.step-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.step-card h2 {
  margin-bottom: 12px;
  font-size: 18px;
}

.signal-box,
button {
  font: inherit;
}

.signal-box {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

button {
  cursor: pointer;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.primary-btn,
.ghost-btn,
.upgrade-btn,
.pad-btn {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.primary-btn,
.ghost-btn {
  padding: 12px 16px;
}

.primary-btn {
  background: linear-gradient(135deg, #00d4ff, #7be0ff);
  color: #03131b;
  font-weight: 800;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.primary-btn:hover,
.ghost-btn:hover,
.upgrade-btn:hover,
.pad-btn:hover {
  transform: translateY(-1px);
}

.room-meta,
.player-pills,
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.room-meta {
  color: var(--text-dim);
}

.player-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.player-pill.is-down {
  color: rgba(255, 120, 120, 0.96);
  border: 1px solid rgba(255, 90, 107, 0.4);
}

.player-pill.muted {
  color: var(--text-dim);
}

.hud {
  margin-bottom: 16px;
}

.hud-block {
  min-width: 110px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud-block.wide {
  min-width: 150px;
}

.hud-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 12px;
}

.board {
  --cell-size: 24px;
  display: grid;
  grid-template-columns: repeat(21, var(--cell-size));
  grid-template-rows: repeat(21, var(--cell-size));
  gap: 1px;
  justify-content: center;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 24px;
  overflow: auto;
  max-width: 100%;
  max-height: min(70dvh, 640px);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  border-radius: 6px;
  background: var(--wall);
}

.cell.path {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent), var(--path);
}

.cell::after,
.cell::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.cell.player-self::after,
.cell.player-other::after,
.cell.monster::after,
.cell.boss::after {
  inset: 15%;
}

.cell.player-self::after {
  background: var(--p1);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.65);
}

.cell.player-other::after {
  background: var(--p2);
  box-shadow: 0 0 12px rgba(255, 204, 77, 0.65);
}

.cell.is-down::after {
  opacity: 0.35;
  filter: grayscale(1);
}

.cell.is-down::before {
  content: "X";
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.95);
  font-weight: 900;
  font-size: 14px;
  text-shadow: 0 0 10px rgba(255, 90, 107, 0.8);
}

.cell.monster::after {
  background: var(--monster);
  box-shadow: 0 0 12px rgba(255, 90, 107, 0.55);
}

.cell.boss::after {
  inset: 6%;
  background: var(--boss);
  box-shadow: 0 0 16px rgba(255, 216, 77, 0.65);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  color: var(--text-dim);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

.legend-swatch.player-one { background: var(--p1); }
.legend-swatch.player-two { background: var(--p2); }
.legend-swatch.monster { background: var(--monster); }
.legend-swatch.boss { background: var(--boss); }

.mobile-pad {
  display: none;
  width: fit-content;
  margin: 18px auto 0;
  gap: 10px;
  justify-items: center;
}

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

.pad-btn {
  width: 58px;
  height: 58px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font-size: 24px;
}

.pad-btn.center {
  opacity: 0.45;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.overlay.hidden,
.toast.hidden,
.hidden {
  display: none !important;
}

.overlay-card {
  width: min(560px, 100%);
  padding: 24px;
}

.upgrade-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.upgrade-btn {
  width: 100%;
  padding: 16px;
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.upgrade-btn strong {
  display: block;
  margin-bottom: 6px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(8, 18, 28, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: white;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .board {
    --cell-size: 18px;
    max-height: 52dvh;
  }
}

@media (pointer: coarse), (max-width: 760px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .app-shell {
    padding: 12px;
    gap: 14px;
  }

  .hero-panel,
  .game-panel {
    padding: 16px;
    border-radius: 20px;
  }

  .step-card {
    padding: 14px;
  }

  .hud-block {
    min-width: calc(50% - 10px);
    flex: 1 1 calc(50% - 10px);
  }

  .hud-block.wide {
    min-width: 100%;
  }

  .board {
    --cell-size: min(16px, calc((100vw - 64px) / 21));
    padding: 8px;
    border-radius: 18px;
    max-height: 46dvh;
  }

  .legend {
    gap: 10px;
    font-size: 13px;
  }

  .mobile-pad {
    display: grid;
  }
}

.gameover-panel {
  margin-top: 22px;
  padding: 20px;
  border-radius: 18px;
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid rgba(255, 90, 107, 0.28);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.gameover-panel p {
  margin: 0;
}

#gameover-title {
  font-size: 22px;
  font-weight: 900;
  color: rgba(255, 120, 130, 0.95);
}

#gameover-detail {
  font-size: 14px;
  color: var(--text-dim);
}

@media (max-height: 760px) {
  .app-shell {
    padding: 12px;
    gap: 14px;
  }

  .hero-panel,
  .game-panel {
    padding: 16px;
  }

  .board {
    max-height: 44dvh;
  }
}
