:root {
  --bg-top: #051019;
  --bg-bottom: #14051c;
  --panel: rgba(8, 15, 28, 0.9);
  --card: rgba(12, 22, 39, 0.85);
  --accent: #2ff0ff;
  --accent-2: #ffb84d;
  --accent-3: #ff4f8b;
  --text: #f4fbff;
  --text-dim: #8fafc7;
  --grid: rgba(53, 242, 255, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 10% 0%, rgba(53, 242, 255, 0.18), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, rgba(255, 79, 139, 0.22), transparent 58%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.game-shell {
  width: min(100%, 980px);
  background: linear-gradient(180deg, rgba(11, 18, 34, 0.94), rgba(9, 14, 26, 0.9));
  border: 1px solid rgba(53, 242, 255, 0.26);
  border-radius: 24px;
  padding: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(53, 242, 255, 0.06), transparent 35%),
    linear-gradient(300deg, rgba(255, 79, 139, 0.05), transparent 35%);
  pointer-events: none;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

h1 {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin: 0;
  font-family: "Bungee", cursive;
  font-size: clamp(1.1rem, 3vw, 1.8rem);
  letter-spacing: 0.04em;
  color: #fff2cb;
}

.title-credit {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.42em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.78rem;
}

.stats strong {
  color: var(--accent);
}

.canvas-wrap {
  position: relative;
  margin-top: 16px;
  width: 100%;
  aspect-ratio: 900 / 560;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgba(53, 242, 255, 0.18);
  background: linear-gradient(180deg, rgba(5, 10, 18, 0.9), rgba(8, 12, 21, 0.98));
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, rgba(9, 20, 35, 0.92), rgba(4, 8, 14, 1));
  background-size: 26px 26px, 26px 26px, 100% 100%;
}

.controls {
  position: relative;
  z-index: 3;
  margin-top: 12px;
}

.rotate-hint {
  display: none;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 184, 77, 0.42);
  background: rgba(255, 184, 77, 0.12);
  font-size: 0.78rem;
  text-align: center;
  color: #fff3d2;
}

.touch-controls {
  display: grid;
  gap: 10px;
  width: 100%;
}

.bottom-controls {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-areas: "left action right pause quit";
  align-items: stretch;
}

#leftBtn {
  grid-area: left;
}

#rightBtn {
  grid-area: right;
}

#actionBtn {
  grid-area: action;
}

#pauseBtn {
  grid-area: pause;
}

#quitBtn {
  grid-area: quit;
}

.bottom-controls button {
  min-height: 46px;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid rgba(53, 242, 255, 0.26);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(16, 28, 51, 0.95), rgba(10, 18, 34, 0.95));
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(53, 242, 255, 0.58);
  outline: none;
}

.action-main {
  background: linear-gradient(180deg, rgba(255, 184, 77, 0.24), rgba(255, 79, 139, 0.2));
  border-color: rgba(255, 184, 77, 0.4);
  color: #fff8eb;
}

.move-zone {
  display: none;
  min-height: 58px;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(53, 242, 255, 0.25);
  background: rgba(5, 14, 28, 0.9);
  touch-action: none;
}

.move-zone::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 50%;
  width: 1px;
  background: rgba(53, 242, 255, 0.32);
}

.move-handle {
  position: absolute;
  top: 8px;
  left: calc(50% - 20px);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(53, 242, 255, 0.75);
  background: rgba(53, 242, 255, 0.2);
  box-shadow: 0 0 18px rgba(53, 242, 255, 0.35);
  transition: left 70ms linear;
  pointer-events: none;
}

.help-panel {
  margin-top: 10px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(5, 12, 24, 0.72);
  overflow: hidden;
}

.help-toggle {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 0;
  border-radius: 0;
  background: rgba(53, 242, 255, 0.08);
  font-weight: 700;
}

.help-content {
  display: grid;
  gap: 10px;
  padding: 14px;
  max-height: 40vh;
  overflow: auto;
  font-size: 0.9rem;
  color: #d9edff;
}

.difficulty-switch,
.audio-controls,
.legend-items,
.pseudo-actions,
.menu-panel {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-choice.active {
  border-color: rgba(255, 184, 77, 0.7);
  color: #fff4d7;
}

.audio-controls {
  align-items: center;
}

#volumeSlider {
  flex: 1 1 180px;
}

.powerup-legend,
.leaderboard-wrap {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.leaderboard-live {
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.leaderboard-live summary {
  cursor: pointer;
  font-weight: 700;
  color: #d9edff;
  list-style: none;
}

.leaderboard-live summary::-webkit-details-marker {
  display: none;
}

.leaderboard-live summary::after {
  content: " +";
  color: #8fafc7;
}

.leaderboard-live[open] summary::after {
  content: " -";
}

.leaderboard-live .leaderboard {
  margin-top: 10px;
  max-height: 132px;
  overflow: auto;
}

.leaderboard-live .leaderboard li {
  padding: 6px 8px;
}

.legend-item {
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
}


.leaderboard {
  margin: 10px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.leaderboard li {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: grid;
  justify-items: center;
  align-content: safe center;
  overflow: auto;
  gap: 14px;
  padding: 22px;
  background: rgba(3, 8, 16, 0.74);
  backdrop-filter: blur(6px);
  text-align: center;
  pointer-events: auto;
}

#overlayText {
  margin: 0;
  max-width: 600px;
  font-family: "Bungee", cursive;
  font-size: clamp(1rem, 2.8vw, 1.6rem);
  color: #fff2cb;
  text-shadow: 0 0 18px rgba(255, 184, 77, 0.2);
}

.overlay-start {
  min-width: min(90vw, 320px);
  min-height: 52px;
  padding: 12px 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.scores-panel,
.pseudo-panel,
.overlay-leaderboard,
.menu-panel {
  width: min(100%, 420px);
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(53, 242, 255, 0.18);
  background: rgba(6, 14, 26, 0.94);
  justify-content: center;
}

.scores-title {
  margin: 0 0 10px;
  font-family: "Bungee", cursive;
  color: #fff2cb;
}

.overlay-leaderboard .leaderboard {
  margin-top: 8px;
  max-height: 26vh;
  overflow: auto;
}

.pseudo-panel input {
  width: 100%;
  min-height: 44px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(53, 242, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.hidden-element {
  display: none;
}

.games-nav {
  position: static;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px auto 8px;
  z-index: 70;
}

.game-link {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  border: 1px solid rgba(50, 215, 255, 0.44);
  background: linear-gradient(180deg, rgba(7, 15, 30, 0.9), rgba(5, 10, 22, 0.92));
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.game-link:hover {
  transform: translateY(-2px) scale(1.04);
  border-color: rgba(50, 215, 255, 0.78);
  box-shadow: 0 10px 24px rgba(50, 215, 255, 0.24);
}

.game-link.is-current,
.game-link[aria-current="page"] {
  border-color: rgba(255, 205, 69, 0.9);
  background: linear-gradient(180deg, rgba(255, 205, 69, 0.2), rgba(14, 22, 38, 0.94));
  box-shadow: 0 0 0 1px rgba(255, 205, 69, 0.38), 0 10px 24px rgba(255, 205, 69, 0.24);
}

.game-link img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 12px;
    border-radius: 18px;
  }

  .stats {
    justify-content: flex-start;
  }

  .stats span {
    font-size: 0.72rem;
    padding: 7px 9px;
  }

  .bottom-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "left action right"
      "pause quit quit";
  }

  .games-nav {
    right: 8px;
    bottom: 8px;
    gap: 8px;
  }

  .game-link {
    width: 50px;
    height: 50px;
  }

  .game-link img {
    width: 36px;
    height: 36px;
  }
}

/* Small-screen improvements */
@media (max-width: 680px) {
  .games-nav { display: none !important; }
  .controls { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .move-zone { min-height: 64px; }
}

@media (orientation: portrait) and (max-width: 1024px) {
  .rotate-hint {
    display: block;
  }

  .bottom-controls {
    grid-template-columns: 1.6fr 1fr 1fr;
    grid-template-areas:
      "move action pause"
      "move quit quit";
  }

  .desktop-move {
    display: none;
  }

  .move-zone {
    display: block;
    grid-area: move;
  }

  .action-main {
    min-height: 58px;
    border-radius: 18px;
  }
}

@media (max-width: 520px) {
  h1 {
    gap: 0.45rem;
  }

  .title-credit {
    width: 100%;
  }

  .help-content {
    font-size: 0.82rem;
  }

  .overlay {
    padding: 14px;
  }

  .leaderboard-live {
    padding: 10px;
  }

  .leaderboard-live .leaderboard {
    max-height: 112px;
  }
}
.canvas-wrap { position: relative; }
.game-logo { max-height: 42px; width: auto; vertical-align: middle; margin-right: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: rgba(4, 15, 35, 0.8); border: 1px solid currentColor; font-size: 0.75rem; font-weight: 700; }
.legend-item canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.difficulty-pick { width: 100%; display: flex; gap: 8px; justify-content: center; }
.difficulty-pick button { flex: 1 1 0; max-width: 200px; display: grid; gap: 3px; padding: 8px 10px; background: rgba(4, 15, 35, 0.8); border: 1px solid rgba(50, 215, 255, 0.3); }
.difficulty-pick button strong { font-size: 0.9rem; }
.difficulty-pick button span { font-size: 0.68rem; font-weight: 400; color: #94b9d8; line-height: 1.25; }
.difficulty-pick button.active { border-color: #ffcd45; background: rgba(255, 205, 69, 0.22); }
@media (max-width: 720px) { .difficulty-pick { flex-direction: column; align-items: stretch; } .difficulty-pick button { max-width: none; } }

.guide { display: grid; gap: 6px; margin-bottom: 12px; }
.guide-item { border: 1px solid rgba(53, 242, 255, 0.2); border-radius: 10px; background: rgba(4, 15, 35, 0.55); }
.guide-item summary { cursor: pointer; padding: 8px 12px; font-weight: 700; color: var(--accent-2); list-style: none; }
.guide-item summary::-webkit-details-marker { display: none; }
.guide-item summary::before { content: "+ "; color: var(--accent); }
.guide-item[open] summary::before { content: "– "; }
.guide-item p { margin: 0; padding: 0 12px 10px; line-height: 1.45; }
.end-card { width: min(420px, 92%); display: grid; gap: 6px; padding: 12px 16px; border: 1px solid rgba(255, 184, 77, 0.4); border-radius: 12px; background: rgba(4, 15, 35, 0.85); }
.end-card.hidden-element { display: none; }
.end-row { display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; color: #cfefff; }
.end-row strong { color: #ffb84d; }
.end-cta { margin-top: 6px; text-align: center; color: #7dffb0; font-size: 0.85rem; text-decoration: underline; }
.overlay-short { min-width: min(90vw, 320px); }
.overlay-short.hidden-element { display: none; }
