:root {
  color-scheme: light;
  --bg: #171629;
  --panel: #ffffff;
  --ink: #15131f;
  --line: #111111;
  --muted: #706b83;
  --cell: #f6f3ff;
  --player-one: #18a0fb;
  --player-two: #ff4f81;
  --arrow: #2f6df6;
  --bonus: #ffd23f;
  --gray: #9da3ad;
  --mint: #27d9a3;
  --orange: #ff8c2f;
  --hot: #ff2bd6;
  --electric: #7cf7ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --board-width: calc(29 * 32px);
  --stage-width: calc(var(--board-width) + 32px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 210, 63, 0.2), transparent 24%),
    radial-gradient(circle at 82% 18%, rgba(39, 217, 163, 0.2), transparent 26%),
    linear-gradient(135deg, #171629 0%, #252449 48%, #132f3b 100%);
  color: var(--ink);
  font-family: Impact, "Arial Black", "Trebuchet MS", Arial, Helvetica, sans-serif;
}

button,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 20px 0 28px;
  position: relative;
}

.shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(115deg, transparent 0 45%, rgba(255, 255, 255, 0.08) 45% 48%, transparent 48% 100%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 58px);
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  color: #ffffff;
}

h1 {
  margin: 0;
  color: #ffffff;
  font-size: 54px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow:
    3px 3px 0 var(--hot),
    6px 6px 0 #111111,
    0 0 24px rgba(124, 247, 255, 0.5);
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select,
button {
  min-height: 38px;
  border: 2px solid #111111;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  box-shadow: 0 4px 0 #111111;
  font-weight: 800;
  letter-spacing: 0;
}

button {
  cursor: pointer;
  background: var(--bonus);
  text-transform: uppercase;
}

button:hover {
  transform: translateY(1px);
  box-shadow: 0 3px 0 #111111;
  background: #ffe274;
}

button:active {
  transform: translateY(4px);
  box-shadow: none;
}

#endRoundButton {
  background: var(--mint);
}

#endRoundButton:hover {
  background: #5be8bd;
}

.icon-button {
  width: 48px;
  height: 48px;
  min-height: 0;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  border-radius: 50%;
  background: var(--electric);
}

.icon-button span {
  width: 20px;
  height: 3px;
  display: block;
  border-radius: 999px;
  background: #111111;
}

.settings-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 0;
  border: 3px solid #111111;
  border-radius: 12px;
  background: transparent;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
}

.settings-dialog::backdrop {
  background: rgba(11, 10, 22, 0.72);
}

.settings-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  background:
    radial-gradient(circle at 100% 0%, rgba(255, 43, 214, 0.18), transparent 38%),
    linear-gradient(145deg, #ffffff, #e8faff);
}

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

h2 {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  font-weight: 900;
  text-transform: uppercase;
}

.close-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  background: var(--player-two);
  position: relative;
}

.close-button::before,
.close-button::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 16px;
  height: 3px;
  border-radius: 999px;
  background: #ffffff;
}

.close-button::before {
  transform: rotate(45deg);
}

.close-button::after {
  transform: rotate(-45deg);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.secondary-button {
  background: var(--mint);
}

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

.scoreboard {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(190px, 1fr);
  align-items: stretch;
  gap: 18px;
  margin-bottom: 16px;
  position: relative;
}

.scoreboard::after {
  content: "VS";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 3px solid #111111;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--bonus), var(--orange));
  box-shadow: 0 6px 0 #111111, 0 0 26px rgba(255, 210, 63, 0.55);
  color: #111111;
  font-size: 22px;
  font-weight: 900;
  transform: translate(-50%, -50%) rotate(-8deg);
}

.score {
  border: 3px solid var(--line);
  background: var(--panel);
  min-height: 86px;
  padding: 12px 16px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  overflow: hidden;
}

.score span,
.player-name-input {
  color: var(--muted);
  font-size: 18px;
  font-weight: 900;
  text-transform: uppercase;
}

.player-name-input {
  width: min(220px, 100%);
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  font-family: inherit;
  letter-spacing: 0;
}

.player-name-input:focus {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

.score strong {
  color: #ffffff;
  min-width: 86px;
  padding: 8px 10px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--player-one);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22);
  font-size: 38px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.24);
}

.score.active {
  outline: 4px solid var(--bonus);
  outline-offset: 3px;
}

#scoreRight.active {
  outline-color: var(--bonus);
}

#scoreRight strong {
  background: var(--player-two);
}

.score.score-pop strong {
  animation: score-bump 0.32s ease-out;
}

.game-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 12px;
  border: 4px solid #111111;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 43, 214, 0.3), transparent 34%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    #23213d;
  background-size: 24px 24px;
  box-shadow: var(--shadow), inset 0 0 0 5px rgba(255, 255, 255, 0.08);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(29, 32px);
  grid-template-rows: repeat(20, 32px);
  width: var(--board-width);
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #111111;
  box-shadow:
    0 10px 0 rgba(0, 0, 0, 0.35),
    0 0 0 3px var(--electric),
    0 0 34px rgba(124, 247, 255, 0.38);
  user-select: none;
  overflow: hidden;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 1px solid #d5d1e8;
  border-radius: 0;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(228, 223, 247, 0.95));
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.cell.start {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.5), transparent 48%),
    linear-gradient(145deg, #d8f7ff, #9fe8ff);
}

.cell.goal {
  color: #ffffff;
  background: linear-gradient(145deg, #29253f, #171629);
  font-size: 11px;
}

.cell.selectable {
  cursor: pointer;
}

.cell:hover,
.cell:active {
  transform: none;
}

.cell.selectable:hover {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.55), transparent 48%),
    linear-gradient(145deg, #fff6a8, #ffd23f);
  filter: none;
  box-shadow: inset 0 0 0 2px #111111, 0 0 14px rgba(255, 210, 63, 0.9);
}

.cell.path::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--hot), var(--orange));
  opacity: 0.5;
  box-shadow: 0 0 12px rgba(255, 43, 214, 0.8);
}

.ball {
  position: relative;
  z-index: 2;
  width: 21px;
  height: 21px;
  border: 3px solid #111111;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: inset -4px -5px 0 rgba(0, 0, 0, 0.22), 0 2px 0 rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 255, 255, 0.55);
}

.ball.p1 {
  background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, #6bd0ff 13% 36%, var(--player-one) 37% 100%);
}

.ball.p2 {
  background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, #ff9fba 13% 36%, var(--player-two) 37% 100%);
}

.falling {
  animation: pulse 0.35s linear infinite alternate;
}

.turn-summary {
  position: fixed;
  left: 50%;
  top: 48%;
  z-index: 20;
  min-width: 220px;
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 18px 28px;
  border: 4px solid #111111;
  border-radius: 14px;
  background: linear-gradient(145deg, #ffffff, #d8f7ff);
  box-shadow: 0 12px 0 #111111, 0 0 44px rgba(124, 247, 255, 0.48);
  color: var(--ink);
  text-align: center;
  transform: translate(-50%, -50%) scale(0.8);
  animation: summary-in 0.28s ease-out forwards;
  pointer-events: none;
}

.turn-summary.p2 {
  background: linear-gradient(145deg, #ffffff, #ffe1ea);
  box-shadow: 0 12px 0 #111111, 0 0 44px rgba(255, 79, 129, 0.42);
}

.turn-summary.leaving {
  animation: summary-out 0.22s ease-in forwards;
}

.turn-summary span {
  color: var(--muted);
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
}

.turn-summary strong {
  color: #ffffff;
  padding: 4px 18px 7px;
  border: 3px solid #111111;
  border-radius: 10px;
  background: var(--player-one);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.24);
  font-size: 56px;
  line-height: 1;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.turn-summary.p2 strong {
  background: var(--player-two);
}

.turn-summary.next-turn {
  min-width: 280px;
  background: linear-gradient(145deg, #ffffff, #fff5c8);
}

.turn-summary.next-turn strong {
  font-size: 36px;
  white-space: nowrap;
}

.confetti {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 14px;
  border: 2px solid #111111;
  border-radius: 2px;
  background: var(--bonus);
  animation: confetti-pop 0.95s ease-out var(--d) forwards;
}

.confetti:nth-child(3n) {
  background: var(--hot);
}

.confetti:nth-child(4n) {
  background: var(--mint);
}

.confetti:nth-child(5n) {
  background: var(--electric);
}

.tile {
  width: 25px;
  height: 25px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #111111;
  border-radius: 5px;
  font-style: normal;
  line-height: 1;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
}

.cell .tile {
  position: relative;
  z-index: 1;
}

.arrow {
  background: linear-gradient(145deg, #5f9dff, var(--arrow));
  color: #ffffff;
  font-size: 0;
  font-weight: 900;
}

.arrow.left::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 12px solid #ffffff;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
}

.arrow.right::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 12px solid #ffffff;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35));
}

.arrow.random::before {
  content: "";
  width: 11px;
  height: 11px;
  border: 3px solid #ffffff;
  border-left-color: transparent;
  border-radius: 50%;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
}

.hole {
  background:
    conic-gradient(from 25deg, #050505, #5b2dff, #00e5ff, #050505, #ff2bd6, #050505),
    radial-gradient(circle, #2f2a47 0 24%, #050505 25% 100%);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px #050505, 0 0 12px rgba(124, 247, 255, 0.45);
}

.hole::before {
  content: "?";
  width: 13px;
  height: 13px;
  display: grid;
  place-items: center;
  border: 2px solid #111111;
  border-radius: 50%;
  background: var(--electric);
  color: #111111;
  font-size: 8px;
  font-weight: 900;
  box-shadow: 0 0 8px rgba(124, 247, 255, 0.8);
}

.hole.revealed::before {
  content: attr(data-pair);
  background: var(--electric);
}

.cell.teleport-source,
.cell.teleport-target {
  z-index: 4;
}

.cell.teleport-source::before,
.cell.teleport-target::before {
  content: "";
  position: absolute;
  inset: -7px;
  z-index: 5;
  border: 3px solid var(--electric);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(124, 247, 255, 0.95);
  pointer-events: none;
  animation: portal-ring 0.52s ease-out forwards;
}

.cell.teleport-target::before {
  border-color: var(--hot);
  box-shadow: 0 0 18px rgba(255, 43, 214, 0.95);
}

.teleport-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8;
  padding: 6px 12px;
  border: 3px solid #111111;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--electric), var(--hot));
  color: #111111;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%) scale(0.7);
  box-shadow: 0 5px 0 #111111, 0 0 22px rgba(124, 247, 255, 0.8);
  animation: teleport-flash 0.52s ease-out forwards;
  pointer-events: none;
}

.bonus {
  background: linear-gradient(145deg, #fff4a8, var(--bonus));
  color: #171629;
  font-size: 0;
  font-weight: 900;
}

.bonus::before {
  content: "";
  width: 17px;
  height: 17px;
  background: #171629;
  clip-path: polygon(50% 0%, 61% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 34%);
  filter: drop-shadow(1px 1px 0 rgba(255, 255, 255, 0.55));
}

.gray {
  background:
    linear-gradient(135deg, transparent 0 38%, rgba(255, 255, 255, 0.6) 38% 45%, transparent 45% 100%),
    linear-gradient(145deg, #cfd4dc, var(--gray));
}

.wall {
  background: #545454;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  width: fit-content;
  margin: 14px auto 0;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 13px;
}

.legend .tile {
  width: 18px;
  height: 18px;
  font-size: 11px;
}

@keyframes pulse {
  from {
    transform: scale(0.92);
  }
  to {
    transform: scale(1.12);
  }
}

@keyframes score-bump {
  0% {
    transform: translateX(0) scale(1);
  }
  28% {
    transform: translateX(-5px) scale(1.12);
  }
  55% {
    transform: translateX(5px) scale(1.08);
  }
  100% {
    transform: translateX(0) scale(1);
  }
}

@keyframes summary-in {
  from {
    opacity: 0;
    transform: translate(-50%, -42%) scale(0.8) rotate(-3deg);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-1deg);
  }
}

@keyframes summary-out {
  to {
    opacity: 0;
    transform: translate(-50%, -56%) scale(0.94) rotate(2deg);
  }
}

@keyframes confetti-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) rotate(0);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), -155px) scale(1) rotate(var(--r));
  }
}

@keyframes portal-ring {
  from {
    opacity: 1;
    transform: scale(0.45);
  }
  to {
    opacity: 0;
    transform: scale(1.45);
  }
}

@keyframes teleport-flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7) rotate(-6deg);
  }
  30% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.12) rotate(4deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.32) rotate(0deg);
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: center;
  }

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

  .score {
    min-height: 82px;
    padding: 10px;
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }

  .score strong {
    min-width: 74px;
    font-size: 30px;
  }
}
