:root {
  --night: #1b1446;
  --night-2: #2a2070;
  --sky: #4dd6ff;
  --red: #ff4b5c;
  --yellow: #ffd23f;
  --green: #7cff6b;
  --cream: #fff8e7;
  --ink: #1b1446;
  --radius: 18px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 600;
  font-size: 18px;
  line-height: 1.6;
}

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

.pixel { font-family: 'Press Start 2P', monospace; font-weight: 400; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--night);
  border-bottom: 4px solid var(--yellow);
}
.brand {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--yellow);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
}
.topbar nav a:hover, .topbar nav a:focus-visible { background: var(--night-2); color: var(--green); animation: wiggle 0.4s; }
@keyframes wiggle {
  25% { rotate: -8deg; }
  50% { rotate: 6deg; }
  75% { rotate: -3deg; }
}

/* Hero */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 100%);
  color: #fff;
  padding: 64px 20px 80px;
}
.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 30% 70%, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 55% 15%, var(--yellow) 50%, transparent 51%),
    radial-gradient(2px 2px at 75% 55%, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 90% 25%, var(--sky) 50%, transparent 51%),
    radial-gradient(2px 2px at 45% 90%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 85% 85%, var(--yellow) 50%, transparent 51%);
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

.hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 28px;
  background:
    linear-gradient(var(--green), var(--green)) top / 100% 8px no-repeat,
    repeating-linear-gradient(90deg, #c8742c 0 28px, #a85a1e 28px 32px);
}

.hero-inner {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 40px;
}
.robot-btn {
  position: relative;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.robot {
  display: block;
  width: 180px;
  animation: bob 2.4s ease-in-out infinite;
}
.robot .eye { transition: transform 0.1s; }
.robot-btn.jump .robot { animation: jump 0.8s cubic-bezier(0.34, 1.4, 0.64, 1); }
@keyframes jump {
  0% { translate: 0 0; rotate: 0deg; }
  15% { translate: 0 8px; scale: 1.1 0.9; }
  50% { translate: 0 -60px; rotate: 180deg; scale: 1; }
  100% { translate: 0 0; rotate: 360deg; }
}
.bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  z-index: 2;
  translate: -50% 0;
  white-space: nowrap;
  font: 800 16px 'Nunito', sans-serif;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 6px 12px;
  opacity: 0;
  scale: 0.4;
  transition: opacity 0.2s, scale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.bubble.show { opacity: 1; scale: 1; }
@keyframes bob { 50% { transform: translateY(-12px); } }
.antenna { animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { fill: var(--yellow); } }

.hero h1 {
  font-size: clamp(30px, 7vw, 64px);
  margin: 8px 0 12px;
  color: var(--yellow);
  text-shadow: 4px 4px 0 var(--red), 8px 8px 0 #000;
}
.hero .small { font-size: 12px; color: var(--green); margin: 0; }
.tagline { font-size: 22px; font-weight: 800; margin: 0 0 24px; }
.hero-buttons { display: flex; flex-wrap: wrap; gap: 12px; }

/* Buttons */
.btn {
  display: inline-block;
  font: 800 18px 'Nunito', sans-serif;
  color: var(--ink);
  text-decoration: none;
  padding: 12px 22px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
  --mx: 0px;
  --my: 0px;
  --lift: 0px;
  transform: translate(var(--mx), calc(var(--my) + var(--lift)));
  transition: transform 0.15s ease-out, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { --lift: -3px; box-shadow: 0 9px 0 var(--ink); }
.btn:active { --lift: 4px; box-shadow: 0 2px 0 var(--ink); }
.boing { animation: boing 0.6s; }
@keyframes boing {
  0% { scale: 1 1; }
  25% { scale: 1.2 0.8; }
  40% { scale: 0.85 1.15; }
  55% { scale: 1.08 0.92; }
  70% { scale: 0.96 1.04; }
  85% { scale: 1.02 0.98; }
  100% { scale: 1 1; }
}

/* Star bursts */
.spark {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  font-size: 18px;
  line-height: 1;
  translate: -50% -50%;
  animation: spark 0.7s ease-out forwards;
}
@keyframes spark {
  from { transform: translate(0, 0) scale(1) rotate(0); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.3) rotate(var(--rot)); opacity: 0; }
}

/* Bouncy titles */
.wavy span { display: inline-block; }
.wavy.wave span { animation: hop 0.5s ease-out calc(var(--i) * 0.05s); }
@keyframes hop {
  40% { translate: 0 -0.45em; rotate: -8deg; }
  70% { translate: 0 0.08em; }
}

/* Pop in as you scroll */
.js .reveal {
  opacity: 0;
  translate: 0 40px;
  scale: 0.94;
  transition: opacity 0.5s, translate 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), scale 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.js .reveal.in { opacity: 1; translate: 0 0; scale: 1; }
.btn-yellow { background: var(--yellow); }
.btn-green { background: var(--green); }

/* Sections */
.section {
  max-width: 1000px;
  margin: 0 auto;
  padding: 64px 20px;
  scroll-margin-top: 60px;
}
.section-title {
  font-size: clamp(18px, 4vw, 28px);
  text-align: center;
  margin: 0 0 40px;
}

/* Game cards */
.game-card {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
  align-items: center;
  background: #fff;
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 10px 10px 0 var(--ink);
  padding: 20px;
  margin-bottom: 48px;
  position: relative;
  transition: transform 0.3s ease-out;
  will-change: transform;
}
.game-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 13px;
  pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.55), transparent 45%);
  opacity: 0;
  transition: opacity 0.3s;
}
.game-card.tilting { transition: transform 0.08s linear; }
.game-card.tilting::after { opacity: 1; }
.game-card.flip img { order: 2; }
.game-card img {
  border: 4px solid var(--ink);
  border-radius: 12px;
}
.game-text h3 { font-size: 28px; font-weight: 900; margin: 10px 0 8px; line-height: 1.2; }
.game-text p { margin: 0 0 16px; }

.badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
}
.badge-red { background: var(--red); }
.badge-blue { background: #2f6bff; }

.stats {
  list-style: none;
  display: flex;
  gap: 12px;
  padding: 0;
  margin: 0;
}
.stats li {
  background: var(--night);
  color: var(--yellow);
  font-weight: 900;
  padding: 8px 14px;
  border-radius: 10px;
  transition: scale 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), rotate 0.2s;
}
.stats li:hover { scale: 1.12; rotate: -4deg; }
.stats li:nth-child(2):hover { rotate: 4deg; }
.stats span { display: block; font-size: 12px; color: var(--sky); text-transform: uppercase; }

/* Mini game */
.play { text-align: center; }
.mini-game + .mini-game { margin-top: 72px; }
.game-title { font-size: clamp(15px, 3vw, 20px); color: var(--red); margin: 0 0 12px; }
.play-help { margin: 0 0 24px; }
.hint-btn { margin-top: 20px; }
.hint-btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: 0 6px 0 var(--ink); }
.btn-white { background: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Puzzle cube */
.cube-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 24px;
  margin-bottom: 20px;
}
.pills { display: flex; gap: 6px; }
.pill {
  font: 800 16px 'Nunito', sans-serif;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: scale 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.pill:hover { scale: 1.08; }
.pill:active { scale: 0.92; }
.pill[aria-pressed="true"] { background: var(--sky); }
.game-wrap.cube-wrap {
  background: radial-gradient(circle at 50% 45%, #3d3196 0%, var(--night) 70%);
}
.cube-wrap canvas { cursor: grab; }
.cube-wrap canvas:active { cursor: grabbing; }
.cube-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}
.game-wrap {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 10px 10px 0 var(--ink);
  overflow: hidden;
  background: var(--night);
}
.game-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}
.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: rgba(27, 20, 70, 0.85);
  color: #fff;
}
.game-overlay[hidden] { display: none; }
.game-overlay .pixel { font-size: clamp(16px, 4vw, 24px); color: var(--yellow); margin: 0; }
.game-overlay p { margin: 0 0 8px; max-width: 420px; }
.scorebar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 24px;
  font-size: 13px;
}
.scorebar b { color: var(--red); }

/* About */
.about { text-align: center; max-width: 720px; }
.about p { font-size: 20px; }

/* Footer */
.footer {
  background: var(--night);
  color: #fff;
  text-align: center;
  padding: 24px 20px;
  border-top: 4px solid var(--yellow);
}
.footer p { margin: 0; font-size: 15px; }

/* Phones */
@media (max-width: 720px) {
  body { font-size: 17px; }
  .topbar { padding: 10px 16px; }
  .brand { font-size: 11px; }
  .topbar nav a { padding: 6px 8px; font-size: 15px; }
  .hero { padding: 40px 16px 64px; }
  .hero-inner { flex-direction: column; text-align: center; gap: 20px; }
  .robot { width: 120px; }
  .hero-buttons { justify-content: center; }
  .section { padding: 48px 16px; }
  .game-card { grid-template-columns: 1fr; box-shadow: 6px 6px 0 var(--ink); padding: 14px; }
  .game-card.flip img { order: 0; }
  .game-text h3 { font-size: 23px; }
  .game-wrap { box-shadow: 6px 6px 0 var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
  .js .reveal { opacity: 1; translate: none; scale: none; }
}
