/* ═══════════════════════════════════════════════════════════════════════
   ARCADE CABINET · style.css
   One stylesheet, top-to-bottom in the order you meet things:
   1. tokens & reset        4. secret transition       7. game frame
   2. calculator scene      5. arcade CRT shell        8. memory cards
   3. LCD + keys            6. attract + menu          9. touch & small screens
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 1 · DESIGN TOKENS & RESET ─────────────────────────────────────────── */
:root {
  /* neon palette (the classic arcade trio + phosphor green) */
  --cyan:    #00f0ff;
  --magenta: #ff2d95;
  --yellow:  #ffe600;
  --green:   #52ff7a;

  /* calculator plastics */
  --body-1: #23262b;          /* charcoal top */
  --body-2: #16181c;          /* charcoal bottom */
  --lcd-bg: #0c1f10;          /* dark phosphor well */
  --lcd-ink: #7dff9c;         /* glowing green digits */

  --font-arcade: 'Press Start 2P', 'Courier New', monospace;
  --font-lcd: 'VT323', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* the `hidden` attribute must ALWAYS win, even over display:flex/grid */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-arcade);
  background: #05060a;
  color: #e8ecf1;
  overflow: hidden;                 /* each screen fits the viewport */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ── 2 · CALCULATOR SCENE ──────────────────────────────────────────────── */
/* A quiet, expensive-looking void: deep gradient + faint blueprint grid,
   with a slow breathing glow under the calculator. */
.stage {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  perspective: 1400px;              /* enables the 3D flip later */
  background:
    radial-gradient(ellipse 80% 60% at 50% 115%, rgba(0,240,255,.10), transparent 60%),
    radial-gradient(ellipse 70% 55% at 50% -15%, rgba(255,45,149,.07), transparent 60%),
    linear-gradient(#070910, #05060a 55%, #04050d);
}
.stage::before {                    /* the blueprint grid */
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(120,160,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,255,.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 75% 75% at 50% 50%, #000 30%, transparent 85%);
  -webkit-mask-image: radial-gradient(ellipse 75% 75% at 50% 50%, #000 30%, transparent 85%);
}
.stage::after {                     /* breathing pool of light under the calc */
  content: '';
  position: absolute; left: 50%; top: 58%;
  width: min(560px, 90vw); height: 260px;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, rgba(82,255,122,.13), transparent 65%);
  filter: blur(10px);
  animation: pool-breathe 5s ease-in-out infinite;
}
@keyframes pool-breathe {
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}

/* ── CALCULATOR BODY ── */
.calc {
  position: relative; z-index: 1;
  width: min(360px, 92vw);
  padding: 22px 22px 14px;
  border-radius: 26px;
  background: linear-gradient(170deg, var(--body-1), var(--body-2) 70%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.09),      /* top bevel highlight   */
    inset 0 -2px 6px rgba(0,0,0,.6),          /* bottom inner shade    */
    0 24px 60px rgba(0,0,0,.75),              /* drop onto the void    */
    0 6px 18px rgba(0,0,0,.5);
  transform-style: preserve-3d;
  animation: calc-arrive .8s cubic-bezier(.2,.9,.25,1.15) backwards;
}
@keyframes calc-arrive {
  from { opacity: 0; transform: translateY(48px) rotateX(14deg) scale(.94); }
  to   { opacity: 1; transform: translateY(0)    rotateX(0)     scale(1); }
}

/* brand strip + fake solar cell */
.calc-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.calc-brand  { font-size: 15px; color: #f2f5f9; letter-spacing: 1px; }
.calc-model  { font-size: 7px;  color: #6d7480; letter-spacing: 2px; margin-top: 4px; }
.calc-solar  { margin-left: auto; display: flex; gap: 2px;
               padding: 3px; border-radius: 3px; background: #0a0c10;
               box-shadow: inset 0 1px 3px rgba(0,0,0,.9); }
.calc-solar i { width: 9px; height: 14px; background: linear-gradient(#2a3040, #171b24); }

/* ── 3 · THE LCD ── */
.lcd {
  border-radius: 12px;
  padding: 5px;
  background: linear-gradient(#0a0b0d, #14161a);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.9), inset 0 -1px 0 rgba(255,255,255,.05);
}
.lcd-glass {
  position: relative;
  border-radius: 8px;
  height: 92px;
  padding: 8px 14px 6px;
  background:
    linear-gradient(rgba(255,255,255,.045), transparent 45%),   /* glass sheen */
    var(--lcd-bg);
  overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  animation: lcd-boot 1.1s steps(1) .35s backwards;             /* power-on flicker */
}
@keyframes lcd-boot {
  0%   { opacity: 0; }
  40%  { opacity: 1; }
  50%  { opacity: .2; }
  62%  { opacity: 1; }
  70%  { opacity: .4; }
  100% { opacity: 1; }
}
.lcd-glass::after {                 /* micro scanlines on the LCD itself */
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(transparent 0 2px, rgba(0,0,0,.22) 2px 3px);
  pointer-events: none;
}
.lcd-tag {
  font-family: var(--font-lcd);
  font-size: 15px; color: rgba(125,255,156,.45);
  letter-spacing: 3px;
}
.lcd-main {
  font-family: var(--font-lcd);
  font-size: 58px; line-height: 1;
  text-align: right;
  color: var(--lcd-ink);
  text-shadow: 0 0 6px rgba(125,255,156,.75), 0 0 22px rgba(125,255,156,.35);
  white-space: nowrap;
  letter-spacing: 2px;
}
/* quick pulse whenever the display updates (added/removed by JS) */
.lcd-main.tick { animation: lcd-tick .12s ease-out; }
@keyframes lcd-tick { from { opacity: .45; } to { opacity: 1; } }

/* LCD freak-out when the secret code lands */
.lcd-glass.glitch { animation: lcd-glitch .55s steps(2) both; }
@keyframes lcd-glitch {
  0%   { filter: none; }
  20%  { filter: invert(1) hue-rotate(90deg); transform: translateX(-3px); }
  40%  { filter: none;      transform: translateX(3px); }
  60%  { filter: invert(1); transform: translateX(-2px); }
  100% { filter: none;      transform: none; }
}

/* ── CALCULATOR KEYS ── */
.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.key {
  position: relative;
  height: 56px;
  border-radius: 14px;
  font-size: 17px;
  color: #dfe5ec;
  background: linear-gradient(#3a3f47, #24272d 60%, #1b1e23);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.14),      /* keycap top light  */
    inset 0 -3px 0 rgba(0,0,0,.45),           /* keycap front face */
    0 5px 10px rgba(0,0,0,.55);               /* lift off the deck */
  transition: transform .06s ease, box-shadow .06s ease, filter .06s ease;
}
.key:active,
.key.pressed {                       /* .pressed lets the keyboard animate keys too */
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    inset 0 -1px 0 rgba(0,0,0,.45),
    0 1px 3px rgba(0,0,0,.6);
  filter: brightness(1.25);
}
.key-zero { grid-column: span 2; }
.key-fn   { background: linear-gradient(#2c3138, #1d2026 60%, #16181d); color: #9aa3ae; font-size: 14px; }
.key-op   {
  background: linear-gradient(#4a3a12, #33280c 60%, #241c07);
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255,230,0,.5);
  font-size: 20px;
}
.key-eq {
  background: linear-gradient(#12403a, #0c2f2b 60%, #07211e);
  color: var(--green);
  text-shadow: 0 0 10px rgba(82,255,122,.65);
  font-size: 20px;
}

/* serial-number hint — visible if you look, invisible if you don't */
.calc-foot { margin-top: 14px; text-align: center; }
.calc-serial {
  font-size: 7px; letter-spacing: 2px;
  color: #4a5058;
  transition: color .4s, text-shadow .4s;
}
.calc-serial:hover { color: var(--green); text-shadow: 0 0 8px rgba(82,255,122,.6); }

/* ── 4 · THE SECRET TRANSITION ─────────────────────────────────────────── */
/* Step 1: the whole calculator flips away into the depth of the screen… */
.calc.flip-away {
  animation: calc-flip .9s cubic-bezier(.6,-.2,.7,.2) forwards;
  pointer-events: none;
}
@keyframes calc-flip {
  0%   { transform: rotateY(0)      translateZ(0)      scale(1); filter: brightness(1); }
  55%  { transform: rotateY(200deg) translateZ(-260px) scale(.82); filter: brightness(1.6); }
  100% { transform: rotateY(540deg) translateZ(-900px) scale(.1); filter: brightness(4); opacity: 0; }
}
/* Step 2: …then an old-TV power-on: a blinding horizontal line that opens up */
.crt-flash {
  position: fixed; inset: 0; z-index: 50;
  background: #fff;
  transform: scaleY(.004);
  pointer-events: none;
}
.crt-flash.on { animation: crt-open .55s cubic-bezier(.2,.8,.3,1) forwards; }
@keyframes crt-open {
  0%   { opacity: 1; transform: scaleY(.004); }
  35%  { opacity: 1; transform: scaleY(.004) scaleX(1.05); }
  60%  { opacity: 1; transform: scaleY(1); }
  100% { opacity: 0; transform: scaleY(1); }
}

/* ── 5 · ARCADE CRT SHELL ─────────────────────────────────────────────── */
.arcade {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #101322, #05060a 75%);
}
.starfield { position: absolute; inset: 0; width: 100%; height: 100%; }

.crt {
  position: relative;
  width: min(720px, 96vw);
  height: min(640px, 92dvh);
  border-radius: 24px;
  background: rgba(6, 8, 16, .88);
  box-shadow:
    0 0 0 3px #191d2c,                          /* bezel            */
    0 0 0 6px #0b0d16,
    0 0 42px rgba(0,240,255,.16),               /* cyan spill       */
    0 0 90px rgba(255,45,149,.10),              /* magenta spill    */
    inset 0 0 80px rgba(0,0,0,.75);
  overflow: hidden;
}
/* the two cosmetic layers that make it feel like glass-and-phosphor */
.scanlines {
  position: absolute; inset: 0; z-index: 8; pointer-events: none;
  background: repeating-linear-gradient(transparent 0 3px, rgba(0,0,0,.24) 3px 4px);
  mix-blend-mode: multiply;
}
.vignette {
  position: absolute; inset: 0; z-index: 9; pointer-events: none;
  background: radial-gradient(ellipse 78% 72% at 50% 48%, transparent 58%, rgba(0,0,0,.55) 100%);
  border-radius: 24px;
}
/* every panel inside the CRT is centered content */
.screen-panel {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px; padding: 24px;
  text-align: center;
}

/* neon text helpers */
.neon-cyan    { color: var(--cyan);    text-shadow: 0 0 8px var(--cyan),    0 0 32px rgba(0,240,255,.55); }
.neon-magenta { color: var(--magenta); text-shadow: 0 0 8px var(--magenta), 0 0 32px rgba(255,45,149,.55); }
.neon-yellow  { color: var(--yellow);  text-shadow: 0 0 8px var(--yellow),  0 0 32px rgba(255,230,0,.55); }

/* ── 6 · ATTRACT + MENU ── */
.attract-title {
  font-size: clamp(30px, 7vw, 52px);
  display: flex; gap: .5em; flex-wrap: wrap; justify-content: center;
  animation: title-flicker 4s linear infinite;
}
@keyframes title-flicker {           /* the classic dying-neon stutter */
  0%, 6.5%, 8%, 100% { opacity: 1; }
  7%  { opacity: .45; }
  7.5%{ opacity: .85; }
  42% { opacity: 1; }
  43% { opacity: .6; }
  44% { opacity: 1; }
}
.attract-sub    { font-size: 10px; color: #8b93a5; letter-spacing: 3px; }
.attract-coin   { font-size: clamp(10px, 2.4vw, 15px); color: var(--yellow);
                  text-shadow: 0 0 10px rgba(255,230,0,.6); }
.attract-credit { position: absolute; bottom: 18px; font-size: 8px; color: #4c5364; letter-spacing: 2px; }
.blink { animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.menu-title { font-size: clamp(16px, 3.4vw, 24px); letter-spacing: 4px; color: #f0f3f8;
              text-shadow: 0 0 14px rgba(255,255,255,.35); }
.menu-cards {
  display: flex; gap: 20px; flex-wrap: wrap; justify-content: center;
}
.card {
  --glow: var(--cyan);
  width: 168px; padding: 20px 12px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  border-radius: 14px;
  color: var(--glow);
  background: rgba(10, 13, 24, .85);
  border: 2px solid var(--glow);
  box-shadow: 0 0 14px color-mix(in srgb, var(--glow) 35%, transparent),
              inset 0 0 22px rgba(0,0,0,.6);
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover, .card.selected {
  transform: translateY(-6px) scale(1.04);
  box-shadow: 0 0 26px color-mix(in srgb, var(--glow) 65%, transparent),
              0 14px 30px rgba(0,0,0,.5),
              inset 0 0 22px rgba(0,0,0,.6);
}
.card:active { transform: translateY(-2px) scale(1.0); }
.card.selected { outline: none; animation: card-pulse 1.2s ease-in-out infinite; }
@keyframes card-pulse {
  50% { box-shadow: 0 0 38px color-mix(in srgb, var(--glow) 85%, transparent),
                    0 14px 30px rgba(0,0,0,.5), inset 0 0 22px rgba(0,0,0,.6); }
}
.card-snake    { --glow: var(--green); }
.card-breakout { --glow: var(--magenta); }
.card-memory   { --glow: var(--yellow); }
.card-icon svg { width: 52px; height: 52px; filter: drop-shadow(0 0 6px currentColor); }
.card-name     { font-size: 12px; letter-spacing: 1px; }
.card-hi       { font-size: 8px; color: #99a1b3; letter-spacing: 1px; }
.menu-help     { font-size: 8px; color: #626a7c; letter-spacing: 2px; line-height: 2; }

.ghost-btn {
  font-size: 9px; letter-spacing: 2px;
  color: #7c8496; padding: 8px 12px;
  border: 1px solid #2b3040; border-radius: 8px;
  background: rgba(8,10,18,.6);
  transition: color .15s, border-color .15s, box-shadow .15s;
}
.ghost-btn:hover { color: var(--cyan); border-color: var(--cyan);
                   box-shadow: 0 0 12px rgba(0,240,255,.35); }

/* ── 7 · GAME FRAME ── */
.game { justify-content: flex-start; gap: 14px; padding-top: 18px; }
.game-bar {
  width: 100%; max-width: 520px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.game-title { font-size: 13px; letter-spacing: 2px; }
.game-score { font-size: 10px; color: #cdd4e2; letter-spacing: 1px; text-align: right; }

.canvas-wrap { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; width: 100%; }
#game-canvas {
  max-width: 100%; max-height: 100%;
  border-radius: 10px;
  background: #070a12;
  box-shadow: 0 0 0 2px #1c2133, 0 0 30px rgba(0,240,255,.12), inset 0 0 40px rgba(0,0,0,.6);
  touch-action: none;                /* we handle swipes ourselves */
}
.game-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(4, 6, 12, .72);
  backdrop-filter: blur(2px);
  border-radius: 10px;
}
.overlay-big   { font-size: clamp(18px, 4.5vw, 30px); letter-spacing: 3px; animation: overlay-pop .35s cubic-bezier(.2,1.6,.4,1) backwards; }
.overlay-small { font-size: 9px; color: #aab2c4; letter-spacing: 2px; animation: blink 1.2s steps(2) infinite; }
@keyframes overlay-pop { from { transform: scale(.4); opacity: 0; } }

/* ── 8 · MEMORY MATCH CARDS ── */
.memory-board {
  flex: 1; width: 100%; max-width: 440px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  align-content: center;
  padding-bottom: 12px;
}
.mcard {
  position: relative;
  aspect-ratio: 3 / 4;
  perspective: 600px;
}
.mcard-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.3,1.4,.4,1);
}
.mcard.flipped .mcard-inner { transform: rotateY(180deg); }
.mcard-face {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border-radius: 10px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(20px, 5vw, 34px);
}
.mcard-back {                        /* the "?" side you see first */
  background: linear-gradient(160deg, #141a2e, #0b0e1c);
  border: 2px solid #26439e;
  box-shadow: 0 0 10px rgba(60,110,255,.25), inset 0 0 14px rgba(0,0,0,.6);
  color: #3f5db8; font-family: var(--font-arcade); font-size: 16px;
}
.mcard:hover .mcard-back { border-color: var(--cyan); box-shadow: 0 0 14px rgba(0,240,255,.4); }
.mcard-front {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #101726, #0a0f1a);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 14px rgba(0,240,255,.35), inset 0 0 14px rgba(0,0,0,.5);
}
.mcard.matched .mcard-front {
  border-color: var(--green);
  box-shadow: 0 0 18px rgba(82,255,122,.55);
  animation: match-pop .4s cubic-bezier(.2,1.8,.4,1);
}
@keyframes match-pop { 50% { transform: rotateY(180deg) scale(1.12); } }
.mcard.matched { pointer-events: none; }

/* ── 9 · TOUCH CONTROLS + SMALL SCREENS ── */
.dpad {
  position: absolute; right: 14px; bottom: 14px; z-index: 12;
  display: grid;
  grid-template-areas: ". u ." "l . r" ". d .";
  gap: 6px;
  opacity: .85;
}
.dpad-btn {
  width: 46px; height: 46px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--cyan);
  background: rgba(10, 14, 26, .8);
  border: 1px solid rgba(0,240,255,.4);
}
.dpad-btn:active { background: rgba(0,240,255,.25); }
.dpad-up { grid-area: u; } .dpad-down { grid-area: d; }
.dpad-left { grid-area: l; } .dpad-right { grid-area: r; }

.mute-btn {
  position: fixed; top: 14px; right: 16px; z-index: 20;
  font-size: 18px; opacity: .5; transition: opacity .2s;
}
.mute-btn:hover { opacity: 1; }

@media (max-width: 560px) {
  .crt { height: 96dvh; border-radius: 14px; }
  .menu-cards { gap: 12px; }
  .card { width: 138px; padding: 14px 10px 12px; }
  .memory-board { max-width: 96%; gap: 8px; }
}

/* Respect players who turn animations off at the OS level */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; transition-duration: .01s !important; }
}
