/* ========== reset / base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  background: #0a0a1e;
  color: #fff;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  overflow: hidden;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; }

/* ========== stage + canvas ========== */
#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 75%, #1a0635 0%, #0a0a1e 60%, #05050f 100%);
}
#game {
  display: block;
  max-width: 100vw;
  max-width: 100dvw;
  max-height: 100vh;
  max-height: 100dvh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ========== CRT scanlines ========== */
#scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  z-index: 10;
}

/* ========== chromatic aberration text ========== */
.chrom {
  display: inline-block;
  color: #fff;
  text-shadow:
    2px 0 0 #ff006e,
    -2px 0 0 #00f5ff,
    0 0 6px rgba(255, 255, 255, 0.25);
}

/* ========== screens (splash + game over) ========== */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(24px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(24px + env(safe-area-inset-left));
  gap: 22px;
  pointer-events: none;
}
.screen * { pointer-events: auto; }
.hidden { display: none !important; }

/* splash */
.wordmark {
  font-size: clamp(28px, 11vw, 104px);
  letter-spacing: 0.04em;
  line-height: 1;
}
.subtitle {
  font-size: clamp(9px, 2.2vw, 14px);
  color: #06ffa5;
  letter-spacing: 0.12em;
}
.tap-prompt {
  font-size: clamp(11px, 2.5vw, 16px);
  color: #ffd60a;
  animation: pulse 1.1s ease-in-out infinite;
  margin-top: 24px;
}
.tap-prompt.retry { color: #00f5ff; }
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.06); }
}
.daily-tag {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: calc(18px + env(safe-area-inset-left));
  font-size: 10px;
  color: #00f5ff;
  letter-spacing: 0.1em;
}

/* game over */
.collapse {
  font-size: clamp(20px, 6vw, 44px);
  color: #ef233c;
  letter-spacing: 0.05em;
  text-shadow: 0 0 6px rgba(239, 35, 60, 0.6);
}
.glitch { animation: glitch 0.4s steps(4, end) 1; }
@keyframes glitch {
  0%   { transform: translate(0, 0);   filter: hue-rotate(0deg);   }
  20%  { transform: translate(-3px, 2px); filter: hue-rotate(20deg); }
  40%  { transform: translate(3px, -2px); filter: hue-rotate(-15deg); }
  60%  { transform: translate(-2px, -1px); filter: hue-rotate(10deg); }
  80%  { transform: translate(2px, 1px);  filter: hue-rotate(-5deg);  }
  100% { transform: translate(0, 0);   filter: hue-rotate(0deg);   }
}
.final-floor {
  font-size: clamp(56px, 18vw, 132px);
  line-height: 1;
  letter-spacing: 0.02em;
}
.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  font-size: clamp(8px, 1.8vw, 12px);
  color: #fff;
  letter-spacing: 0.08em;
}
.stats b { color: #ffd60a; font-weight: normal; }
.stats .sep { color: rgba(255,255,255,0.3); }

.scorecard {
  background: rgba(10, 10, 30, 0.85);
  border: 2px solid #8338ec;
  box-shadow: 0 0 0 2px #0a0a1e, 0 0 16px rgba(131, 56, 236, 0.5);
  padding: 14px 18px;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: clamp(10px, 2vw, 13px);
  line-height: 1.55;
  color: #fff;
  white-space: pre;
  max-width: 92vw;
  overflow-x: auto;
}

/* arcade buttons */
.buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.arcade {
  background: #ff006e;
  color: #fff;
  border: none;
  padding: 14px 22px;
  font-size: clamp(10px, 2vw, 13px);
  letter-spacing: 0.12em;
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.4),
    inset 0 4px 0 rgba(255,255,255,0.2),
    0 0 0 3px #0a0a1e,
    0 0 0 5px #ff006e,
    0 0 18px rgba(255, 0, 110, 0.6);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.arcade:nth-of-type(2) {
  background: #00f5ff;
  color: #0a0a1e;
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.35),
    inset 0 4px 0 rgba(255,255,255,0.35),
    0 0 0 3px #0a0a1e,
    0 0 0 5px #00f5ff,
    0 0 18px rgba(0, 245, 255, 0.6);
}
.arcade:active { transform: translateY(2px); }
.arcade.copied { background: #06ffa5; color: #0a0a1e; }

/* ========== HUD ========== */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}
#hud-floor {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(32px, 8vw, 64px);
  letter-spacing: 0.04em;
  transition: transform 0.18s ease-out;
}
#hud-floor.bump { transform: translateX(-50%) scale(1.18); }

#hud-perfect {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  font-size: clamp(9px, 1.8vw, 13px);
  letter-spacing: 0.12em;
  text-shadow: 0 0 6px currentColor;
}
#hud-today {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top));
  right: calc(56px + env(safe-area-inset-right));
  font-size: clamp(8px, 1.6vw, 11px);
  color: #06ffa5;
  letter-spacing: 0.1em;
}
#mute {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  background: transparent;
  border: 2px solid rgba(255,255,255,0.2);
  color: #fff;
  width: 34px;
  height: 34px;
  font-size: 16px;
  border-radius: 6px;
  pointer-events: auto;
  display: grid;
  place-items: center;
}

/* perfect popup (managed by JS) */
#perfect-popup {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translate(-50%, 0);
  font-size: clamp(18px, 4vw, 30px);
  letter-spacing: 0.15em;
  color: #fff;
  text-shadow: 0 0 10px #fff, 0 0 20px #ff006e;
  pointer-events: none;
  z-index: 16;
  opacity: 0;
}
#perfect-popup.show { animation: perfectPop 0.7s ease-out forwards; }
@keyframes perfectPop {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  20%  { opacity: 1; transform: translate(-50%, 0)   scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -20px) scale(1);   }
}

/* small screens: tighten splash spacing */
@media (max-height: 600px) {
  .screen { gap: 14px; }
  .tap-prompt { margin-top: 10px; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .tap-prompt        { animation: none; opacity: 1; }
  .glitch            { animation: none; }
  #perfect-popup.show{ animation: none; opacity: 0; }
  #hud-floor         { transition: none; }
  .arcade            { transition: none; }
}
