:root {
  color-scheme: dark;
  --ink: #05030b;
  --panel: #100b20;
  --violet: #8b5cf6;
  --cyan: #2cf4ff;
  --pink: #ff3ca6;
  --yellow: #ffe34e;
  --white: #fff8dc;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--white);
  background:
    radial-gradient(circle at 50% 0, rgba(139, 92, 246, 0.28), transparent 38%),
    linear-gradient(180deg, #090511 0%, #020105 100%);
  font-family: "SFMono-Regular", "Cascadia Mono", "PingFang SC", "Microsoft YaHei", monospace;
  user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(44, 244, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 244, 255, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, transparent, #000 22%, #000);
}

.cabinet {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1180px, calc(100vw - 40px));
  height: calc(100vh - 32px);
  margin: 16px auto;
  border: 4px solid #2a1f49;
  border-radius: 22px;
  background: #080510;
  box-shadow:
    0 0 0 2px #090510,
    0 0 0 6px rgba(139, 92, 246, 0.42),
    0 30px 90px #000,
    0 0 80px rgba(139, 92, 246, 0.18);
  overflow: hidden;
}

.marquee {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 4vw, 48px);
  min-height: 90px;
  padding: 16px;
  border-bottom: 4px solid #241a3f;
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(255, 60, 166, 0.16) 8% 9%, transparent 9% 91%, rgba(44, 244, 255, 0.16) 91% 92%, transparent 92%),
    linear-gradient(180deg, #1b0e33, #090612);
}

.marquee::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255, 227, 78, 0.3);
  border-radius: 9px;
  pointer-events: none;
}

.marquee h1 {
  margin: 0;
  color: var(--yellow);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  font-style: italic;
  letter-spacing: 0.08em;
  line-height: 0.8;
  text-shadow:
    4px 4px 0 var(--pink),
    8px 8px 0 #4c1d95,
    0 0 24px rgba(255, 227, 78, 0.62);
  transform: skew(-5deg);
}

.marquee-star {
  color: var(--cyan);
  font-size: clamp(1.3rem, 3vw, 2.4rem);
  text-shadow: 0 0 18px var(--cyan);
  animation: star-pulse 1.2s steps(2, end) infinite;
}

.screen {
  position: relative;
  min-height: 0;
  padding: 18px clamp(14px, 3vw, 34px) 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(42, 18, 86, 0.78), transparent 72%),
    #05030a;
}

.screen-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 90px #000;
}

.scanlines {
  position: absolute;
  z-index: 5;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(255, 255, 255, 0.13) 4px
  );
}

.select-bar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--cyan);
  font-size: clamp(0.72rem, 1.5vw, 0.96rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-shadow: 0 0 10px currentColor;
}

.game-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 16px);
  height: calc(100% - 28px);
  padding: 3px;
  overflow: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
}

.game-grid::-webkit-scrollbar {
  display: none;
}

.game-tile {
  --tile-accent: var(--cyan);
  position: relative;
  display: grid;
  min-height: 112px;
  padding: 16px 14px 13px;
  overflow: hidden;
  color: rgba(255, 248, 220, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.11);
  border-radius: 5px;
  outline: 0;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--tile-accent) 13%, transparent), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015)),
    #0c0816;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.42);
}

.game-tile::before {
  content: attr(data-number);
  position: absolute;
  top: 8px;
  right: 10px;
  color: color-mix(in srgb, var(--tile-accent) 50%, transparent);
  font-family: Impact, sans-serif;
  font-size: 2rem;
  font-style: italic;
}

.game-tile::after {
  content: "";
  position: absolute;
  right: -24px;
  bottom: -28px;
  width: 86px;
  height: 86px;
  border: 10px solid color-mix(in srgb, var(--tile-accent) 13%, transparent);
  border-radius: 50%;
}

.game-title {
  position: relative;
  z-index: 1;
  align-self: end;
  max-width: 88%;
  font-weight: 900;
  font-size: clamp(0.83rem, 1.35vw, 1.05rem);
  line-height: 1.35;
  letter-spacing: 0.04em;
}

.game-chip {
  position: relative;
  z-index: 1;
  align-self: start;
  justify-self: start;
  color: var(--tile-accent);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.game-tile.is-selected {
  color: #fff;
  border-color: var(--yellow);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--tile-accent) 34%, transparent), transparent 58%),
    #171025;
  box-shadow:
    inset 0 0 26px color-mix(in srgb, var(--tile-accent) 16%, transparent),
    0 0 0 2px #ff3ca6,
    0 0 22px rgba(255, 60, 166, 0.85),
    0 0 42px color-mix(in srgb, var(--tile-accent) 42%, transparent);
  transform: scale(1.025);
  animation: selected-flicker 1.5s steps(2, end) infinite;
}

.game-tile.is-selected .game-title::before {
  content: "▶";
  margin-right: 8px;
  color: var(--yellow);
  text-shadow: 0 0 10px var(--yellow);
}

.game-tile.is-legacy {
  --tile-accent: #d2c5ef;
  border-style: dashed;
}

.controls {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 72px;
  padding: 12px 18px;
  border-top: 4px solid #241a3f;
  background: linear-gradient(180deg, #140d24, #08050e);
}

.key-group {
  display: inline-flex;
  gap: 4px;
}

kbd {
  min-width: 28px;
  padding: 6px 7px;
  color: #12081e;
  border: 0;
  border-radius: 3px;
  background: var(--yellow);
  box-shadow: 0 4px 0 #9f7111, 0 0 12px rgba(255, 227, 78, 0.24);
  font: 900 0.68rem/1 monospace;
  text-align: center;
}

.control-label {
  margin-right: 10px;
  color: rgba(255, 248, 220, 0.56);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.loading {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--yellow);
  background: #05030a;
  font-size: clamp(1rem, 3vw, 1.8rem);
  font-weight: 900;
  letter-spacing: 0.2em;
  text-shadow: 0 0 16px var(--yellow);
}

.loading.is-hidden {
  display: none;
}

.game-stage {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: none;
  background: #000;
}

.game-stage.is-open {
  display: block;
}

.game-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.stage-label {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 2;
  padding: 6px 11px;
  color: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.58);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}

.stage-label.is-visible {
  animation: label-fade 2.4s ease;
}

.exit-hint {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 4;
  display: none;
  padding: 10px 16px;
  color: #12081e;
  border-radius: 5px;
  background: var(--yellow);
  box-shadow: 0 0 24px rgba(255, 227, 78, 0.48);
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: translateX(-50%);
}

.exit-hint.is-visible {
  display: block;
}

@keyframes star-pulse {
  50% {
    opacity: 0.38;
  }
}

@keyframes selected-flicker {
  50% {
    border-color: #fff7a8;
  }
}

@keyframes label-fade {
  0%,
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 820px) {
  .cabinet {
    width: calc(100vw - 20px);
    height: calc(100vh - 20px);
    margin: 10px auto;
  }

  .marquee {
    min-height: 74px;
  }

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

  .game-tile {
    min-height: 102px;
  }

  .controls {
    gap: 7px;
    min-height: 62px;
    padding-inline: 8px;
  }

  .control-label {
    display: none;
  }
}

@media (max-width: 560px) {
  .marquee {
    min-height: 64px;
  }

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

  .game-tile {
    min-height: 92px;
    padding: 12px 10px 10px;
  }

  .game-tile::before {
    font-size: 1.45rem;
  }

  .controls {
    flex-wrap: wrap;
  }

  kbd {
    min-width: 24px;
    padding: 5px;
    font-size: 0.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
  }
}
