:root {
  --bg-0: #0b0f1b;
  --bg-1: #121a2e;
  --accent-1: #00f6ff;
  --accent-2: #ff2bd6;
  --text: #f7f8fb;
  --muted: #aab3c8;
  --panel: rgba(13, 20, 36, 0.72);
  --border: rgba(255, 255, 255, 0.18);
  --neon-glow-small: 6px;
  --neon-glow-medium: 16px;
  --neon-glow-large: 30px;
  --vh: 100vh;
  --board-w: clamp(160px, calc((var(--vh) - 7.5rem) / 2), 52vw);
  --wide-max: 60vw;
}

@supports (height: 100dvh) {
  :root {
    --vh: 100dvh;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 8% 20%, #3a1a7a 0%, #150a35 28%, #05030f 70%);
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 80% 8%, rgba(0, 246, 255, 0.35), transparent 38%),
    radial-gradient(circle at 20% 85%, rgba(255, 43, 214, 0.3), transparent 38%);
  animation: drift 9s ease-in-out infinite alternate;
}

.game-shell {
  width: min(1600px, 98vw);
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(200px, 1fr);
  gap: 1.2rem;
  align-items: start;
  padding: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

h1 {
  margin: 0;
  font-family: "Bungee", cursive;
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 0 6px rgba(0, 246, 255, 0.45), 0 0 18px rgba(255, 43, 214, 0.35);
}

.neon-word {
  white-space: nowrap;
}

.neon-letter {
  display: inline-block;
  text-shadow: 0 0 var(--neon-glow-small) currentColor, 0 0 var(--neon-glow-medium) currentColor,
    0 0 var(--neon-glow-large) currentColor;
}

.neon-letter-cyan {
  color: #00f6ff;
}

.neon-letter-yellow {
  color: #ffee00;
}

.neon-letter-purple {
  color: #d633ff;
}

.neon-letter-green {
  color: #2bff88;
}

.subtitle {
  margin: 0.4rem 0 1rem;
  color: var(--muted);
}

.hud,
.help {
  display: grid;
  gap: 0.7rem;
  width: 100%;
}

.hud {
  justify-self: end;
  max-width: 280px;
}

.help {
  justify-self: start;
  max-width: 340px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  background: rgba(255, 255, 255, 0.04);
}

.card h2,
.help h2 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
  color: var(--accent-1);
  text-shadow: 0 0 8px rgba(0, 246, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.card p {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.mode-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mode-btn.active {
  border-color: rgba(0, 231, 255, 0.7);
  background: rgba(0, 231, 255, 0.15);
}

.mode-btn + .mode-btn {
  margin-top: 0.5rem;
}

.depth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.depth-row span {
  font-size: 1.4rem;
  font-weight: 700;
}

.depth-btn {
  width: 2.4rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 0.4rem 0;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

.depth-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#fps,
#perf-status {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.board-col {
  justify-self: center;
  width: var(--board-w);
  display: grid;
  gap: 0.6rem;
}

/* 3D view: 1.5x wider at the same height (3:4 instead of 1:2). */
.board-col.wide {
  width: min(calc(var(--board-w) * 1.5), var(--wide-max));
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.slider-row input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--accent-1);
  cursor: pointer;
}

.slider-row output {
  min-width: 3ch;
  text-align: right;
  color: var(--text);
}

.play-area {
  position: relative;
  width: 100%;
  background: linear-gradient(180deg, #050912 0%, #0a1020 100%);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--accent-1);
  box-shadow: 0 0 10px var(--accent-1), 0 0 28px rgba(0, 246, 255, 0.55), 0 0 60px rgba(255, 43, 214, 0.35),
    inset 0 0 30px rgba(0, 246, 255, 0.2);
}

#board,
#board3d {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
}

#board3d {
  aspect-ratio: 3 / 4;
}

#board,
#next {
  display: block;
  background: linear-gradient(180deg, #050912 0%, #0a1020 100%);
}

#next {
  width: 100%;
  max-width: 128px;
  margin: 0 auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(5, 9, 18, 0.75);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 1rem;
}

.hidden {
  display: none !important;
}

#board3d {
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  filter: drop-shadow(0 0 5px rgba(0, 246, 255, 0.55)) drop-shadow(0 0 14px rgba(255, 43, 214, 0.35));
}

#board3d.dragging {
  cursor: grabbing;
}

.help ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  line-height: 1.35;
}

.help kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.08rem 0.35rem;
  border: 1px solid rgba(0, 246, 255, 0.45);
  border-radius: 0.35rem;
  background: rgba(0, 246, 255, 0.1);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.touch-controls {
  display: none;
  grid-column: 1 / -1;
  justify-self: center;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  width: min(520px, 100%);
}

html.has-touch .touch-controls {
  display: grid;
}

/* Hints are shown only for the input devices that are actually available. */
.hint-touch,
.hint-keys,
.hint-mouse {
  display: none;
}

html.has-touch .hint-touch,
html.has-keys .hint-keys,
html.has-mouse .hint-mouse {
  display: list-item;
}

.ctrl-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  font: inherit;
  font-weight: 600;
  touch-action: manipulation;
}

.ctrl-btn:active {
  transform: translateY(1px);
  background: rgba(0, 231, 255, 0.15);
}

@keyframes drift {
  from {
    transform: translateY(-8px);
  }
  to {
    transform: translateY(10px);
  }
}

@media (min-width: 981px) {
  html.is-fullscreen {
    --board-w: clamp(160px, calc((var(--vh) - 4rem) / 2), 52vw);
  }
}

html.is-fullscreen .game-shell {
  width: 100vw;
  min-height: var(--vh);
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  align-items: center;
}

html.is-fullscreen .help {
  display: none;
}

@media (max-width: 980px) {
  :root {
    --board-w: min(92vw, max(220px, calc((var(--vh) - 10rem) / 2)));
    --wide-max: 94vw;
  }

  .game-shell {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .hud,
  .help {
    justify-self: center;
    max-width: none;
    width: min(420px, 100%);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud > h1,
  .hud > .subtitle {
    grid-column: 1 / -1;
  }

  .help h2,
  .help ul {
    grid-column: 1 / -1;
  }

  .touch-controls {
    width: min(420px, 100%);
  }
}
