/* ═══════════════════════════════════════════════════════
   SLOTY TRIP — Main Stylesheet
   Global variables, reset, utilities, neon effects, CRT
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─── */
:root {
  --bg-dark: #020208;
  --bg-wall: #0a0818;
  --bg-cabinet: #100e25;
  --bg-screen: #030306;

  --neon-red: #ff1744;
  --neon-cyan: #00e5ff;
  --neon-gold: #ffd600;
  --neon-green: #76ff03;
  --neon-purple: #e040fb;
  --neon-orange: #ff9100;

  --chrome-light: #ddd;
  --chrome-mid: #999;
  --chrome-dark: #444;

  --text-dim: #333;
  --text-mid: #555;
  --border-subtle: #1a1a28;

  --font-main: 'Press Start 2P', monospace;
  --reel-cell-size: 64px;
  --cabinet-max-width: 520px;
}

/* ─── Reset ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  background: var(--bg-dark);
  font-family: var(--font-main);
  color: #eee;
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  outline: none;
}

input {
  font-family: var(--font-main);
  outline: none;
  border: none;
}

/* ─── Screen System ─── */
.screen {
  display: flex;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex-direction: column;
  align-items: center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-in-out, visibility 0s linear 200ms;
}

.screen.active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 200ms ease-in-out, visibility 0s linear 0s;
}

/* ─── Overlay System ─── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.overlay.active {
  display: flex;
}

/* ─── CRT Scanline Overlay ─── */
.crt-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
}

/* ─── Neon Text Utilities ─── */
.neon-text-red {
  color: var(--neon-red);
  text-shadow:
    0 0 7px var(--neon-red),
    0 0 10px var(--neon-red),
    0 0 21px var(--neon-red),
    0 0 42px rgba(255, 23, 68, 0.4);
}

.neon-text-cyan {
  color: var(--neon-cyan);
  text-shadow:
    0 0 7px var(--neon-cyan),
    0 0 10px var(--neon-cyan),
    0 0 21px var(--neon-cyan),
    0 0 42px rgba(0, 229, 255, 0.4);
}

.neon-text-gold {
  color: var(--neon-gold);
  text-shadow:
    0 0 7px var(--neon-gold),
    0 0 10px var(--neon-gold),
    0 0 21px var(--neon-gold),
    0 0 42px rgba(255, 214, 0, 0.4);
}

.neon-text-green {
  color: var(--neon-green);
  text-shadow:
    0 0 7px var(--neon-green),
    0 0 10px var(--neon-green),
    0 0 21px var(--neon-green),
    0 0 42px rgba(118, 255, 3, 0.4);
}

.neon-text-purple {
  color: var(--neon-purple);
  text-shadow:
    0 0 7px var(--neon-purple),
    0 0 10px var(--neon-purple),
    0 0 21px var(--neon-purple),
    0 0 42px rgba(224, 64, 251, 0.4);
}

/* ─── Neon Flicker Animations (irregular!) ─── */
@keyframes neonFlicker1 {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: 0.4; }
  22% { opacity: 0.7; }
}

@keyframes neonFlicker2 {
  0%, 8%, 10%, 40%, 42%, 70%, 72%, 100% { opacity: 1; }
  9% { opacity: 0.5; }
  41% { opacity: 0.3; }
  71% { opacity: 0.6; }
}

@keyframes neonFlicker3 {
  0%, 30%, 32%, 60%, 62%, 85%, 87%, 100% { opacity: 1; }
  31% { opacity: 0.2; }
  61% { opacity: 0.6; }
  86% { opacity: 0.4; }
}

.flicker-1 { animation: neonFlicker1 4s infinite; }
.flicker-2 { animation: neonFlicker2 5s infinite; }
.flicker-3 { animation: neonFlicker3 6s infinite; }

/* ─── Blink ─── */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.blink {
  animation: blink 1.2s infinite;
}

/* ─── Star Background ─── */
.star-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.star-bg::before,
.star-bg::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  animation: starPulse 3s ease-in-out infinite alternate;
}

.star-bg::before {
  box-shadow:
    20px 30px 0 #fff, 80px 60px 0 rgba(255,255,255,0.6),
    150px 20px 0 #fff, 200px 80px 0 rgba(255,255,255,0.4),
    270px 40px 0 rgba(255,255,255,0.8), 320px 90px 0 #fff,
    50px 130px 0 rgba(255,255,255,0.5), 180px 160px 0 #fff,
    100px 200px 0 rgba(255,255,255,0.7), 250px 170px 0 #fff,
    30px 250px 0 rgba(255,255,255,0.3), 300px 230px 0 rgba(255,255,255,0.8),
    370px 50px 0 #fff, 400px 150px 0 rgba(255,255,255,0.5),
    60px 300px 0 #fff, 230px 280px 0 rgba(255,255,255,0.6),
    350px 200px 0 #fff, 120px 350px 0 rgba(255,255,255,0.4),
    280px 320px 0 #fff, 400px 300px 0 rgba(255,255,255,0.7);
}

.star-bg::after {
  box-shadow:
    45px 15px 0 rgba(255,255,255,0.5), 130px 45px 0 #fff,
    210px 110px 0 rgba(255,255,255,0.6), 90px 180px 0 #fff,
    310px 70px 0 rgba(255,255,255,0.4), 170px 250px 0 #fff,
    380px 120px 0 rgba(255,255,255,0.7), 50px 350px 0 rgba(255,255,255,0.5),
    260px 300px 0 #fff, 140px 400px 0 rgba(255,255,255,0.3),
    330px 350px 0 #fff, 80px 420px 0 rgba(255,255,255,0.6),
    200px 380px 0 #fff, 360px 420px 0 rgba(255,255,255,0.5),
    25px 480px 0 #fff, 290px 450px 0 rgba(255,255,255,0.7);
  animation-delay: 1.5s;
}

@keyframes starPulse {
  0% { opacity: 0.6; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.3); }
}

/* ─── Floor Grid (Perspective) ─── */
.floor-grid {
  position: absolute;
  bottom: 0;
  left: -20%;
  width: 140%;
  height: 40%;
  background:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 38px,
      rgba(224, 64, 251, 0.1) 38px,
      rgba(224, 64, 251, 0.1) 40px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 38px,
      rgba(224, 64, 251, 0.1) 38px,
      rgba(224, 64, 251, 0.1) 40px
    );
  transform: perspective(400px) rotateX(55deg);
  transform-origin: center top;
  opacity: 0.6;
}

/* ─── Buttons ─── */
.btn {
  padding: 10px 20px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border: 2px solid var(--border-subtle);
  background: rgba(10, 8, 24, 0.9);
  color: #eee;
  transition: all 0.2s;
}

.btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.btn:active:not(:disabled) {
  transform: scale(0.95);
}

.btn--green {
  border-color: var(--neon-green);
  color: var(--neon-green);
  box-shadow: 0 0 10px rgba(118, 255, 3, 0.3), inset 0 0 10px rgba(118, 255, 3, 0.1);
}

.btn--green:hover:not(:disabled) {
  background: rgba(118, 255, 3, 0.1);
  box-shadow: 0 0 20px rgba(118, 255, 3, 0.5);
}

.btn--cyan {
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3), inset 0 0 10px rgba(0, 229, 255, 0.1);
}

.btn--cyan:hover:not(:disabled) {
  background: rgba(0, 229, 255, 0.1);
}

.btn--red {
  border-color: var(--neon-red);
  color: var(--neon-red);
  box-shadow: 0 0 10px rgba(255, 23, 68, 0.3);
}

.btn--gold {
  border-color: var(--neon-gold);
  color: var(--neon-gold);
  box-shadow: 0 0 10px rgba(255, 214, 0, 0.3);
}

.btn--chrome {
  border-color: var(--chrome-mid);
  color: var(--chrome-light);
  background: linear-gradient(180deg, #2a2a3a, #1a1a2a);
}

.btn--small {
  padding: 5px 10px;
  font-size: 8px;
}

.btn--spin {
  padding: 12px 24px;
  font-size: 12px;
  border: 2px solid var(--neon-green);
  color: var(--neon-green);
  background: rgba(118, 255, 3, 0.1);
  box-shadow: 0 0 15px rgba(118, 255, 3, 0.3), inset 0 0 15px rgba(118, 255, 3, 0.1);
}

.btn--spin:hover:not(:disabled) {
  box-shadow: 0 0 30px rgba(118, 255, 3, 0.6);
  background: rgba(118, 255, 3, 0.2);
}

.btn--spin:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--chrome-dark);
  border-radius: 3px;
}

/* ─── Level Up Overlay ─── */
.levelup-content {
  text-align: center;
  animation: levelUpPop 0.5s ease-out;
}

.levelup-content h2 {
  font-size: 24px;
  margin-bottom: 10px;
}

.levelup-content p {
  font-size: 14px;
}

@keyframes levelUpPop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ─── Shake Animation ─── */
@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake-anim {
  animation: shakeX 0.4s ease-in-out;
}

/* ─── Flash Red Button ─── */
@keyframes flashRedBtn {
  0%, 100% { border-color: var(--neon-green); }
  50% { border-color: var(--neon-red); box-shadow: 0 0 20px rgba(255, 23, 68, 0.6); }
}

.flash-red {
  animation: flashRedBtn 0.4s ease-in-out;
}

/* ─── Responsive ─── */

/* Small phones (< 360px width) */
@media (max-width: 359px) {
  :root {
    --reel-cell-size: 44px;
    --cabinet-max-width: 280px;
  }
}

/* Phones (360-479px) */
@media (min-width: 360px) and (max-width: 479px) {
  :root {
    --reel-cell-size: 52px;
    --cabinet-max-width: 340px;
  }
}

@media (min-width: 480px) {
  :root {
    --reel-cell-size: 64px;
  }
}

@media (min-width: 768px) {
  :root {
    --reel-cell-size: 80px;
  }
}

@media (min-width: 1024px) {
  :root {
    --reel-cell-size: 88px;
  }
}

/* Landscape mode — prioritize height */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --reel-cell-size: 40px;
    --cabinet-max-width: 320px;
  }
}

@media (orientation: landscape) and (min-height: 501px) and (max-height: 700px) {
  :root {
    --reel-cell-size: 52px;
    --cabinet-max-width: 380px;
  }
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  .screen {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ═══════════════════════════════════════════════════════
   GARAGE GAME OVERLAY
   ═══════════════════════════════════════════════════════ */
.garage-game-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gg-container {
  background: var(--bg-wall);
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.3);
  max-width: 340px;
  width: 95%;
}

.gg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0, 229, 255, 0.08);
  border-bottom: 1px solid rgba(0, 229, 255, 0.2);
}

.gg-title {
  font-family: var(--font-main);
  font-size: 10px;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan);
}

.gg-score {
  font-family: var(--font-main);
  font-size: 12px;
  color: var(--neon-gold);
  text-shadow: 0 0 6px var(--neon-gold);
}

.gg-close {
  font-family: var(--font-main);
  font-size: 10px;
  background: transparent;
  border: 1px solid var(--neon-red);
  color: var(--neon-red);
  cursor: pointer;
  padding: 4px 8px;
  transition: all 0.2s;
}
.gg-close:hover { background: rgba(255, 23, 68, 0.2); }

#gg-canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
}

.gg-controls {
  padding: 10px;
  display: flex;
  justify-content: center;
}

.gg-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.gg-dpad-row {
  display: flex;
  gap: 30px;
}

.gg-dpad-btn {
  font-family: var(--font-main);
  font-size: 14px;
  width: 44px;
  height: 44px;
  background: rgba(0, 229, 255, 0.08);
  border: 2px solid rgba(0, 229, 255, 0.3);
  color: var(--neon-cyan);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.1s;
}

.gg-dpad-btn:active {
  background: rgba(0, 229, 255, 0.2);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.gg-lr-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.gg-fire {
  font-size: 9px;
  width: 60px;
  background: rgba(255, 23, 68, 0.1);
  border-color: var(--neon-red);
  color: var(--neon-red);
}

.gg-fire:active {
  background: rgba(255, 23, 68, 0.3);
  box-shadow: 0 0 10px rgba(255, 23, 68, 0.5);
}

/* ═══════════════════════════════════════════════════════
   COMPLETED LEVEL — Glitch Effects
   ═══════════════════════════════════════════════════════ */

.glitch-active {
  animation: glitchScreen 0.3s steps(2) 6;
}

@keyframes glitchScreen {
  0% { filter: none; transform: translate(0); }
  20% { filter: hue-rotate(90deg) saturate(3); transform: translate(-3px, 2px); }
  40% { filter: hue-rotate(180deg) invert(0.2); transform: translate(3px, -2px); }
  60% { filter: hue-rotate(270deg) saturate(2); transform: translate(-2px, -3px); }
  80% { filter: hue-rotate(45deg) brightness(1.5); transform: translate(2px, 3px); }
  100% { filter: none; transform: translate(0); }
}

/* Upside-down toggle button (top-right corner) */
.upside-toggle-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 100;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 214, 0, 0.4);
  color: #ffd600;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}
.upside-toggle-btn:hover {
  border-color: var(--neon-gold);
  box-shadow: 0 0 12px rgba(255, 214, 0, 0.4);
}
.upside-toggle-btn.active {
  background: rgba(255, 214, 0, 0.2);
  border-color: var(--neon-gold);
  box-shadow: 0 0 15px rgba(255, 214, 0, 0.5);
  transform: rotate(180deg);
}

/* Completed level inverted look */
.theme-completed .cabinet-screen {
  filter: hue-rotate(180deg) saturate(0.7);
}

.theme-completed .cabinet-marquee {
  filter: hue-rotate(180deg);
}

.theme-completed .reel-container {
  transform: scaleY(-1);
}

.theme-completed .symbol-cell {
  transform: scaleY(-1);
}

/* Stuck reel blink */
@keyframes stuckBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.stuck-reel-msg {
  animation: stuckBlink 0.5s infinite !important;
}
