:root {
  color-scheme: dark;
  font-family: "Press Start 2P", "Pixelify Sans", "Courier New", ui-monospace, SFMono-Regular, Consolas, monospace;
  background: #1a1020;
  color: #fff7fb;
  --pixel-bg: #1a1020;
  --pixel-panel: #2a1730;
  --pixel-panel-light: #42213d;
  --pixel-pink: #ff8fbd;
  --pixel-pink-soft: #ffc2dc;
  --pixel-cream: #fff1c7;
  --pixel-mint: #80e0b5;
  --pixel-line: #ffd6e6;
  --pixel-shadow: #07050d;
}

* {
  box-sizing: border-box;
}

html,
body,
button,
canvas {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(rgba(255, 143, 189, 0.06) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 143, 189, 0.06) 2px, transparent 2px),
    radial-gradient(circle at 18% 18%, rgba(255, 143, 189, 0.28), transparent 20rem),
    radial-gradient(circle at 82% 12%, rgba(128, 224, 181, 0.13), transparent 19rem),
    linear-gradient(135deg, #371a34 0%, #1a1020 52%, #101327 100%);
  background-size: 18px 18px, 18px 18px, auto, auto, auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.045) 0,
    rgba(255, 255, 255, 0.045) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: soft-light;
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 24vw, 280px);
  gap: clamp(10px, 1.5vw, 18px);
  width: min(1280px, calc(100vw - 20px));
  height: 100vh;
  margin: 0 auto;
  padding: 10px 0;
  align-items: center;
}

.arcade-dashboard .shell {
  grid-template-columns: minmax(0, 1fr);
  width: 100vw;
  padding: 0;
}

.arcade-dashboard .panel {
  display: none;
}

.arcade-dashboard .stage {
  width: 100vw;
  height: 100vh;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.stage {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 20px);
  aspect-ratio: 4 / 3;
  min-height: 0;
  overflow: hidden;
  border: 4px solid var(--pixel-line);
  border-radius: 0;
  background: var(--pixel-shadow);
  box-shadow:
    8px 8px 0 var(--pixel-shadow),
    0 0 0 4px #7d315d,
    0 24px 80px rgba(61, 16, 42, 0.45);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 12;
  display: none;
  gap: 8px;
}

.arcade-playing .game-actions {
  display: flex;
}

.stage:has(.overlay:not(.hidden)) .game-actions {
  display: none;
}

.game-action {
  min-width: 86px;
  min-height: 38px;
  border: 3px solid var(--pixel-line);
  border-radius: 0;
  background: var(--pixel-panel);
  color: #fff7fb;
  box-shadow: 4px 4px 0 var(--pixel-shadow);
  backdrop-filter: none;
}

.game-action.danger {
  background: var(--pixel-pink);
  color: #2b1220;
}

.game-action:disabled {
  opacity: 0.5;
  cursor: default;
}

.touch-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  left: 16px;
  display: none;
  grid-template-columns: 54px 64px 54px;
  justify-content: space-between;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-key {
  appearance: none;
  -webkit-appearance: none;
  min-width: 54px;
  min-height: 54px;
  border: 3px solid var(--pixel-line);
  border-radius: 0;
  background: var(--pixel-panel);
  color: #ffffff;
  font-size: 1.3rem;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-key.fire {
  min-width: 64px;
  min-height: 64px;
  background: var(--pixel-pink);
  color: #2b1220;
}

.stage:has(.overlay:not(.hidden)) .touch-controls {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: clamp(16px, 3vw, 28px);
  text-align: center;
  background:
    linear-gradient(rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    linear-gradient(rgba(43, 18, 32, 0.42), rgba(25, 13, 25, 0.86));
  background-size: 24px 24px, 24px 24px, auto;
}

.overlay.hub-mode {
  align-content: center;
  justify-content: center;
  overflow: auto;
  background:
    linear-gradient(rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    radial-gradient(circle at 50% 16%, rgba(255, 143, 189, 0.24), transparent 18rem),
    linear-gradient(rgba(43, 18, 32, 0.9), rgba(14, 10, 22, 0.94));
  background-size: 24px 24px, 24px 24px, auto, auto;
}

.overlay:not(.hub-mode) .arcade-grid {
  display: none;
}

.overlay.result-mode {
  background:
    linear-gradient(rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 143, 189, 0.08) 2px, transparent 2px),
    linear-gradient(rgba(43, 18, 32, 0.62), rgba(14, 10, 22, 0.92));
  background-size: 24px 24px, 24px 24px, auto;
}

.overlay.result-mode .mark {
  display: none;
}

.overlay.hidden {
  display: none;
}

.mark {
  color: var(--pixel-pink);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 12ch;
  font-size: clamp(2rem, 6vw, 5.4rem);
  line-height: 0.92;
  color: #fff7fb;
  text-shadow:
    4px 0 0 #7d315d,
    0 4px 0 #7d315d,
    6px 6px 0 var(--pixel-shadow);
}

.overlay p {
  max-width: 32rem;
  color: var(--pixel-cream);
  font-size: 0.92rem;
  line-height: 1.55;
}

.arcade-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  width: min(760px, calc(100vw - 44px));
  margin: 4px 0;
}

.game-tile {
  display: grid;
  grid-column: span 2;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  min-height: 112px;
  padding: 10px;
  border: 3px solid #7d315d;
  border-radius: 0;
  background: var(--pixel-panel);
  color: #fff7fb;
  text-align: left;
  box-shadow: 4px 4px 0 var(--pixel-shadow);
}

.game-tile:last-child:nth-child(3n + 1) {
  grid-column: 3 / span 2;
}

.game-tile:nth-last-child(2):nth-child(3n + 1) {
  grid-column: 2 / span 2;
}

.game-tile:last-child:nth-child(3n + 2) {
  grid-column: 4 / span 2;
}

.game-tile.selected {
  border-color: var(--pixel-line);
  background: var(--pixel-panel-light);
  box-shadow:
    4px 4px 0 var(--pixel-shadow),
    inset 0 0 0 3px rgba(255, 143, 189, 0.25);
}

.preview {
  position: relative;
  display: block;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border: 3px solid #7d315d;
  border-radius: 0;
  background:
    linear-gradient(rgba(255, 143, 189, 0.09) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 143, 189, 0.09) 2px, transparent 2px),
    linear-gradient(145deg, #241529, #3a192c);
  background-size: 12px 12px, 12px 12px, auto;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.24);
}

.preview i,
.preview b {
  position: absolute;
  display: block;
  border-radius: 0;
  background: #ffb3d2;
}

.preview.invaders i { width: 14px; height: 10px; top: 18px; }
.preview.invaders i:nth-child(1) { left: 16px; }
.preview.invaders i:nth-child(2) { left: 32px; background: #f8d27a; }
.preview.invaders i:nth-child(3) { left: 48px; }
.preview.invaders b { left: 30px; bottom: 14px; width: 22px; height: 10px; background: #fff7fb; }

.preview.maze i { width: 8px; height: 8px; border-radius: 0; }
.preview.maze i:nth-child(1) { left: 16px; top: 18px; background: #f8d27a; }
.preview.maze i:nth-child(2) { left: 38px; top: 34px; }
.preview.maze i:nth-child(3) { left: 56px; top: 52px; }
.preview.maze b { left: 14px; bottom: 12px; width: 12px; height: 12px; border-radius: 0; background: #ff6f91; }

.preview.blocks i { width: 20px; height: 20px; }
.preview.blocks i:nth-child(1) { left: 18px; top: 16px; background: #ffb3d2; }
.preview.blocks i:nth-child(2) { left: 38px; top: 16px; background: #f8d27a; }
.preview.blocks i:nth-child(3) { left: 18px; top: 36px; background: #7dd3b0; }
.preview.blocks i:nth-child(4) { left: 38px; top: 36px; background: #ff8fb8; }

.preview.galiga i { width: 18px; height: 14px; top: 18px; }
.preview.galiga i:nth-child(1) { left: 20px; background: #f8d27a; }
.preview.galiga i:nth-child(2) { left: 44px; background: #ff8fb8; }
.preview.galiga b { left: 31px; bottom: 13px; width: 16px; height: 18px; background: #fff7fb; clip-path: polygon(50% 0, 100% 100%, 0 100%); }

.preview.snake i { width: 14px; height: 14px; border-radius: 0; top: 34px; }
.preview.snake i:nth-child(1) { left: 18px; background: #f8d27a; }
.preview.snake i:nth-child(2) { left: 33px; }
.preview.snake i:nth-child(3) { left: 48px; }
.preview.snake b { right: 12px; top: 16px; width: 12px; height: 12px; border-radius: 0; background: #7dd3b0; }

.preview.frogger i { left: 28px; bottom: 13px; width: 20px; height: 17px; border-radius: 0; background: #7dd3b0; }
.preview.frogger b { width: 28px; height: 12px; border-radius: 0; }
.preview.frogger b:nth-child(2) { left: 12px; top: 18px; background: #ff8fb8; }
.preview.frogger b:nth-child(3) { right: 12px; top: 42px; background: #f8d27a; }

.preview.tapper i { width: 42px; height: 6px; left: 17px; background: rgba(255, 247, 251, 0.7); }
.preview.tapper i:nth-child(1) { top: 22px; }
.preview.tapper i:nth-child(2) { top: 48px; }
.preview.tapper b { border-radius: 0; }
.preview.tapper b:nth-child(3) { left: 15px; top: 32px; width: 16px; height: 16px; background: #ff8fb8; }
.preview.tapper b:nth-child(4) { right: 14px; top: 31px; width: 18px; height: 18px; background: #f8d27a; }

.preview.tower i { width: 48px; height: 6px; left: 14px; background: #ff8fbd; }
.preview.tower i:nth-child(1) { top: 18px; transform: skewY(-8deg); }
.preview.tower i:nth-child(2) { top: 38px; transform: skewY(8deg); }
.preview.tower i:nth-child(3) { top: 58px; transform: skewY(-8deg); }
.preview.tower b:nth-child(4) { left: 21px; top: 25px; width: 8px; height: 34px; background: #80e0b5; }
.preview.tower b:nth-child(5) { right: 18px; top: 43px; width: 12px; height: 12px; background: #f8d27a; }

.tile-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.tile-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  color: var(--pixel-cream);
}

.tile-copy small {
  color: #ffd6e6;
  font-size: 0.68rem;
  line-height: 1.5;
}

button {
  min-width: 148px;
  min-height: 44px;
  border: 3px solid var(--pixel-line);
  border-radius: 0;
  background: var(--pixel-pink);
  color: #2b1220;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--pixel-shadow);
}

button:hover,
button:focus-visible {
  background: var(--pixel-cream);
  outline: 0;
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 var(--pixel-shadow);
}

.panel {
  display: grid;
  gap: 10px;
  align-content: start;
  max-height: calc(100vh - 20px);
  min-width: 0;
  overflow: hidden;
}

.brand,
.stats,
.controls,
.discord,
.leaderboard {
  border: 3px solid #7d315d;
  border-radius: 0;
  background: var(--pixel-panel);
  box-shadow: 4px 4px 0 var(--pixel-shadow);
  backdrop-filter: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  font-weight: 900;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 0;
  background: var(--pixel-mint);
  box-shadow: 0 0 0 3px #0d1c18;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  overflow: hidden;
}

.stats div {
  min-height: 66px;
  padding: 10px 12px;
  border-bottom: 3px solid rgba(255, 214, 230, 0.16);
}

.stats div:nth-child(odd) {
  border-right: 3px solid rgba(255, 214, 230, 0.16);
}

.stats div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

dt {
  color: var(--pixel-pink);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  color: var(--pixel-cream);
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  font-weight: 900;
}

.controls,
.discord,
.leaderboard {
  display: grid;
  gap: 7px;
  padding: 12px;
}

h2 {
  color: var(--pixel-cream);
  font-size: 0.82rem;
}

.controls p,
.discord p {
  color: #ffd6e6;
  font-size: 0.72rem;
  line-height: 1.55;
}

.leaderboard ol {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: min(218px, 32vh);
  overflow: hidden;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 24px;
  color: #ffd6e6;
  font-size: 0.7rem;
}

.leaderboard .rank {
  color: var(--pixel-pink);
  font-weight: 900;
}

.leaderboard .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .score {
  color: var(--pixel-cream);
  font-weight: 900;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  min-height: 24px;
  margin: 0 3px;
  padding: 0 7px;
  border: 2px solid var(--pixel-line);
  border-radius: 0;
  background: var(--pixel-shadow);
  color: var(--pixel-cream);
  font: 700 0.78rem ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 900px) {
  body {
    min-height: 100vh;
    height: auto;
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    align-content: start;
  }

  .arcade-dashboard .shell {
    height: 100vh;
    min-height: 100vh;
    padding: 0;
  }

  .stage,
  .panel {
    max-height: none;
  }

  .arcade-dashboard .stage {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .panel {
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }

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

  .game-tile,
  .game-tile:nth-last-child(2):nth-child(3n + 1),
  .game-tile:last-child:nth-child(3n + 2) {
    grid-column: span 2;
  }

  .game-tile:last-child:nth-child(3n + 1) {
    grid-column: span 2;
  }

  .game-tile:last-child:nth-child(2n + 1) {
    grid-column: 2 / span 2;
  }

  .brand,
  .stats {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  body {
    background:
      linear-gradient(rgba(255, 143, 189, 0.07) 2px, transparent 2px),
      linear-gradient(90deg, rgba(255, 143, 189, 0.07) 2px, transparent 2px),
      radial-gradient(circle at 24% 14%, rgba(255, 143, 189, 0.28), transparent 18rem),
      linear-gradient(135deg, #371a34 0%, #1a1020 52%, #101327 100%);
    background-size: 18px 18px, 18px 18px, auto, auto;
  }

  .shell {
    width: 100vw;
    gap: 10px;
    padding: 8px 8px calc(112px + env(safe-area-inset-bottom));
  }

  .stage {
    min-height: auto;
    max-height: none;
    border-radius: 8px;
  }

  .arcade-dashboard .shell {
    padding: 0;
  }

  .arcade-dashboard .stage {
    border-radius: 0;
  }

  .touch-controls {
    display: grid;
    position: fixed;
    right: 16px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: 16px;
    z-index: 20;
    grid-template-columns: 58px 58px 70px 58px 58px;
    justify-content: center;
    gap: 7px;
  }

  .game-actions {
    top: 10px;
    right: 10px;
    gap: 6px;
  }

  .game-action {
    min-width: 74px;
    min-height: 36px;
    font-size: 0.88rem;
  }

  .touch-key {
    min-width: 58px;
    min-height: 58px;
    border-width: 2px;
    font-size: 1.45rem;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  }

  .touch-key.fire {
    min-width: 70px;
    min-height: 70px;
    font-size: 1.8rem;
  }

  .overlay {
    gap: 12px;
    padding: 20px;
  }

  .arcade-grid {
    grid-template-columns: 1fr;
    width: min(420px, calc(100vw - 32px));
    max-height: 48vh;
    overflow: auto;
  }

  .game-tile,
  .game-tile:last-child:nth-child(3n + 1),
  .game-tile:nth-last-child(2):nth-child(3n + 1),
  .game-tile:last-child:nth-child(3n + 2),
  .game-tile:last-child:nth-child(2n + 1) {
    grid-column: auto;
  }

  .game-tile {
    min-height: 92px;
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .preview {
    width: 64px;
    height: 64px;
  }

  .mark {
    font-size: 0.78rem;
  }

  h1 {
    font-size: clamp(2.4rem, 14vw, 4.2rem);
  }

  .overlay p {
    max-width: 18rem;
    font-size: 1rem;
    line-height: 1.35;
  }

  button {
    min-width: 164px;
    min-height: 52px;
    font-size: 1rem;
  }

  .panel {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .brand {
    min-height: 48px;
    font-size: 1rem;
  }

  .stats div {
    min-height: 76px;
    padding: 12px;
  }

  dt {
    font-size: 0.82rem;
  }

  dd {
    font-size: 2rem;
  }

  .controls,
  .discord,
  .leaderboard {
    padding: 14px;
    gap: 9px;
  }

  h2 {
    font-size: 1rem;
  }

  .controls p,
  .discord p {
    font-size: 0.96rem;
  }

  .leaderboard li {
    min-height: 34px;
    font-size: 0.96rem;
  }

  .stats div {
    min-height: 72px;
  }
}

@media (orientation: landscape) and (max-height: 560px) and (max-width: 900px) {
  body {
    height: 100vh;
    overflow: hidden;
  }

  .shell {
    grid-template-columns: minmax(0, calc((100vh - 12px) * 4 / 3)) minmax(186px, 30vw);
    height: 100vh;
    min-height: 0;
    width: 100vw;
    padding: 6px;
    gap: 8px;
    align-items: center;
  }

  .stage {
    width: 100%;
    height: calc(100vh - 12px);
    max-height: calc(100vh - 12px);
  }

  .arcade-dashboard .shell {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .arcade-dashboard .stage {
    width: 100vw;
    height: 100vh;
    max-height: none;
  }

  .panel {
    max-height: calc(100vh - 12px);
    overflow: hidden;
    gap: 7px;
  }

  .brand,
  .discord,
  .controls {
    display: none;
  }

  .stats div {
    min-height: 54px;
    padding: 8px;
  }

  dd {
    font-size: 1.45rem;
  }

  .leaderboard {
    padding: 10px;
  }

  .leaderboard ol {
    max-height: 36vh;
  }

  h1 {
    font-size: clamp(2rem, 8vw, 3.4rem);
  }

  .overlay p {
    max-width: 24rem;
    font-size: 0.92rem;
  }

  button {
    min-height: 46px;
  }

  .touch-controls {
    position: absolute;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: auto;
    grid-template-columns: 64px 76px 64px;
  }

  .touch-key {
    min-width: 64px;
    min-height: 64px;
  }

  .touch-key.fire {
    min-width: 76px;
    min-height: 76px;
  }
}

@media (max-height: 680px) and (min-width: 901px) {
  .controls {
    display: none;
  }

  .leaderboard ol {
    max-height: 172px;
  }
}

@media (max-height: 590px) and (min-width: 901px) {
  .discord {
    display: none;
  }

  .leaderboard ol {
    max-height: 134px;
  }
}
