:root {
  --bg: #05060a;
  --bg-card: #0a0c14;
  --fg: #e4f2ea;
  --muted: #7b8a93;
  --border: rgba(148, 210, 184, 0.16);
  --accent: #39ff88;
  --accent-bright: #6dffab;
  --accent-soft: rgba(57, 255, 136, 0.14);
  --danger: #ff2e6c;
  --danger-soft: rgba(255, 46, 108, 0.14);
  --cyan: #33e0ff;
  --purple: #b06bff;
  --radius: 18px;
  --font-display: "Sora", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-arcade: "Press Start 2P", var(--font-mono);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

::selection { background: var(--accent); color: #000; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #0f5c34; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(16px, 5vw, 48px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.brand em {
  font-style: normal;
  color: var(--accent-bright);
  font-family: var(--font-mono);
  font-size: 0.78em;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 2px;
}

.brand-icon {
  font-size: 1.4rem;
  display: inline-block;
  animation: invaderFloat 2.4s ease-in-out infinite;
  filter: drop-shadow(0 0 6px rgba(57, 255, 136, 0.6));
}

@keyframes invaderFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn, .lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.icon-btn { padding: 8px 10px; }

.icon-btn:hover, .lang-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.icon-btn:active, .lang-btn:active { transform: translateY(0); }

.flag { font-size: 1rem; }

/* ---------- Stage / Hero ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px 40px;
  gap: 30px;
}

.hero {
  text-align: center;
  max-width: 640px;
  margin-top: clamp(4px, 2vh, 18px);
}

.eyebrow {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: 0.25em;
  font-size: 0.72rem;
  margin: 0 0 10px;
  text-transform: uppercase;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
}

.title {
  margin: 0 0 14px;
  font-size: clamp(2rem, 5.6vw, 3.2rem);
  line-height: 1.1;
  font-weight: 800;
}

.title-line {
  display: block;
  opacity: 0;
  transform: translateY(16px);
  animation: fadeUp 0.7s ease forwards;
}

.title-line.accent {
  background: linear-gradient(100deg, var(--accent-bright), var(--cyan) 45%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation-delay: 0.12s;
}

.tagline {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 auto;
  max-width: 540px;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.24s;
}

@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Difficulty picker ---------- */
.difficulty-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.32s;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.2s ease;
  font-family: var(--font-display);
}

.diff-btn:hover { border-color: var(--accent); transform: translateY(-2px); }

.diff-btn.is-active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), rgba(57, 255, 136, 0.04));
  box-shadow: 0 0 0 1px var(--accent-soft), 0 8px 24px -8px rgba(57, 255, 136, 0.5);
}

.diff-name { font-weight: 700; font-size: 0.95rem; }
.diff-meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.diff-btn.is-active .diff-meta { color: var(--accent-bright); }

/* ---------- Game Card ---------- */
.game-card {
  position: relative;
  width: min(560px, 94vw);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px clamp(14px, 4vw, 26px) 20px;
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
  opacity: 0;
  animation: cardIn 0.7s cubic-bezier(.16,1,.3,1) forwards;
  animation-delay: 0.4s;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.game-card.shake { animation: shakeCard 0.4s ease; }
@keyframes shakeCard {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.game-card-glow {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: radial-gradient(600px circle at var(--mx, 50%) var(--my, 0%), rgba(57,255,136,0.10), transparent 60%);
  pointer-events: none;
  z-index: -1;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat:last-child { align-items: flex-end; }

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
}

.lives {
  display: flex;
  gap: 5px;
  min-height: 18px;
}

.life-icon {
  font-size: 1rem;
  filter: drop-shadow(0 0 4px rgba(57,255,136,0.7));
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Screen frame / canvas ---------- */
.screen-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 480 / 600;
  background: #010203;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(57, 255, 136, 0.22);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.85), 0 0 30px -8px rgba(57, 255, 136, 0.25);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 1px,
    rgba(0,0,0,0.16) 2px,
    rgba(0,0,0,0.16) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(1, 2, 3, 0.72);
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 20px;
  transition: opacity 0.25s ease;
  cursor: pointer;
}

.overlay-layer.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-kicker {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: 0.2em;
  font-size: 0.7rem;
  margin: 0;
  animation: blinkSoft 1.6s ease-in-out infinite;
}

.overlay-title {
  font-family: var(--font-arcade);
  font-size: clamp(0.85rem, 3.2vw, 1.3rem);
  color: var(--accent-bright);
  margin: 0;
  text-shadow: 0 0 14px rgba(57,255,136,0.7);
  animation: blinkSoft 1.6s ease-in-out infinite;
}

.overlay-sub {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0;
}

@keyframes blinkSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.toast {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translate(-50%, -8px);
  font-family: var(--font-arcade);
  font-size: clamp(0.7rem, 2.6vw, 0.95rem);
  color: var(--cyan);
  text-shadow: 0 0 16px rgba(51, 224, 255, 0.8);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Controls row ---------- */
.controls-row {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.hint-note {
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.7;
  text-align: center;
  font-family: var(--font-mono);
  margin: 0;
}

.touch-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.touch-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.touch-btn:hover { border-color: var(--accent); }
.touch-btn:active, .touch-btn.is-pressed {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(0.94);
}

.touch-fire {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  color: var(--danger);
  border-color: rgba(255, 46, 108, 0.35);
  font-size: 1.4rem;
}

.touch-fire:active, .touch-fire.is-pressed {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.touch-pause {
  font-size: 0.95rem;
  color: var(--cyan);
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 24px 20px 30px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p { margin: 0 0 8px; }
.site-footer strong { color: var(--fg); }

.footer-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.footer-links a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover { color: var(--accent); text-decoration: underline; }
.footer-links .dot { color: var(--border); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 5, 0.78);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
}

.modal-overlay.is-open { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.modal {
  position: relative;
  width: min(420px, 88vw);
  background: linear-gradient(180deg, #10141a, #0a0c14);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 26px 26px;
  text-align: center;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7);
  animation: modalIn 0.4s cubic-bezier(.16,1,.3,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 10px;
  animation: pop 0.5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.modal-title {
  font-size: 1.5rem;
  margin: 0 0 8px;
  font-weight: 800;
}

.modal-text {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
}

.modal-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 22px;
  font-family: var(--font-mono);
}

.modal-stats .m-stat { display: flex; flex-direction: column; gap: 2px; }
.modal-stats .m-stat-value { font-weight: 800; font-size: 1.2rem; color: var(--accent-bright); }
.modal-stats .m-stat-label { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Intro splash ---------- */
.intro-modal {
  width: min(440px, 90vw);
}

.intro-credit {
  margin: 4px 0 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.intro-credit-line {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--fg);
}

.intro-credit-line strong {
  color: var(--accent-bright);
}

.intro-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.intro-links a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

.intro-links a:hover { color: var(--accent); text-decoration: underline; }
.intro-links .dot { color: var(--border); }

.intro-skip {
  margin: 0 auto 16px;
  display: block;
}

.intro-progress {
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.intro-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
}

.intro-progress-fill.is-running {
  animation: introFill 3.2s linear forwards;
}

@keyframes introFill {
  from { width: 0%; }
  to { width: 100%; }
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: #041008;
  border: none;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 0 24px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.98rem;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 8px 20px -8px rgba(57, 255, 136, 0.7);
}

.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.primary-btn:active { transform: translateY(0); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0 16px;
  height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.ghost-btn:hover { color: var(--accent-bright); border-color: var(--accent); }

/* ---------- Responsive ---------- */
.desktop-only { display: block; }

@media (max-width: 640px) {
  .desktop-only { display: none; }
  .touch-btn { width: 46px; height: 46px; font-size: 1.05rem; }
  .touch-fire { width: 54px; height: 54px; }
}

@media (min-width: 641px) {
  .touch-controls { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
