:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --outline: #16233d;
  --font-fun: "Baloo 2", "Nunito", -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3, .section-title {
  font-family: var(--font-fun);
}

header.site-header {
  padding: 24px 32px;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.site-header a {
  color: var(--text);
  text-decoration: none;
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-fun);
}

.hidden {
  display: none !important;
}

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

/* --- QR share popover --- */
.qr-share {
  position: relative;
}

.qr-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--outline);
  background: #fff;
  color: #0f172a;
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--outline);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.qr-toggle span[aria-hidden] {
  font-size: 1.05rem;
  line-height: 1;
}

.qr-toggle:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--outline);
}

.qr-toggle[aria-expanded="true"] {
  background: #ffd85e;
}

.qr-popover {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 20;
  width: 176px;
  padding: 14px;
  background: #fff;
  border: 3px solid var(--outline);
  border-radius: 16px;
  box-shadow: 5px 5px 0 var(--outline);
  text-align: center;
  transform: rotate(-1deg);
}

.qr-popover.hidden {
  display: none;
}

.qr-link {
  display: block;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
}

.qr-popover img {
  display: block;
  width: 100%;
  height: auto;
}

.qr-popover p {
  margin: 10px 0 4px;
  color: #0f172a;
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 0.82rem;
}

.qr-popover code {
  display: block;
  color: #64748b;
  font-size: 0.72rem;
  word-break: break-all;
}

@media (max-width: 640px) {
  .qr-toggle-label {
    display: none;
  }

  .qr-toggle {
    padding: 8px 10px;
  }
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px;
}

#games {
  margin-top: -28px;
  padding-top: 0;
  position: relative;
  z-index: 3;
}

main.wide {
  max-width: 900px;
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.section-title {
  display: inline-block;
  font-size: 1.4rem;
  margin: 0 0 6px;
  background: #fff;
  color: #0f172a;
  padding: 8px 22px;
  border-radius: 14px;
  border: 3px solid var(--outline);
  box-shadow: 4px 4px 0 var(--outline);
  transform: rotate(-1.5deg);
}

#games .section-title {
  transform: rotate(-1.5deg) translateY(-4px);
}

#games .subtitle {
  margin-top: 10px;
}

.subtitle {
  color: var(--text-dim);
  margin-top: 0;
}

/* --- Hero --- */
.hero {
  position: relative;
  overflow: hidden;
  padding: 32px 32px 0;
  background: radial-gradient(circle at 20% 15%, #1c6fa8 0%, #124a78 55%),
    linear-gradient(160deg, #0e3a60 0%, #0a2a48 80%);
}

.hero-inner {
  position: relative;
  z-index: 2;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 20px;
}

.hero-text {
  flex: 1 1 380px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}

.hero-kicker {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  font-weight: 700;
  color: #0f172a;
  background: #ffd85e;
  border: 3px solid var(--outline);
  border-radius: 999px;
  padding: 5px 16px;
  margin: 0 0 10px;
  transform: rotate(-2deg);
}

.hero-title {
  font-family: var(--font-fun);
  font-size: clamp(1.8rem, 4.2vw, 2.8rem);
  line-height: 1.1;
  margin: 0 0 10px;
  font-weight: 800;
  color: #fff;
  text-shadow: 3px 3px 0 var(--outline);
}

.hero-title span {
  display: inline-block;
  color: #ffd85e;
  text-shadow: 3px 3px 0 var(--outline);
  transform: rotate(-3deg);
}

.hero-subtitle {
  color: #dceefc;
  font-size: 0.98rem;
  max-width: 480px;
  margin: 0 auto 16px;
}

.hero-cta {
  display: inline-block;
  background: #ffd85e;
  color: #0f172a;
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  padding: 12px 30px;
  border-radius: 999px;
  border: 3px solid var(--outline);
  box-shadow: 5px 5px 0 var(--outline);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.hero-cta:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 var(--outline);
}

.hero-cta:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--outline);
}

.stat-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.stat-chip {
  background: #fff;
  border: 3px solid var(--outline);
  border-radius: 14px;
  padding: 8px 16px;
  min-width: 78px;
  box-shadow: 4px 4px 0 var(--outline);
}

.stat-a { transform: rotate(-3deg); }
.stat-b { transform: rotate(2deg); }
.stat-c { transform: rotate(-1deg); }

.stat-chip strong {
  display: block;
  font-family: var(--font-fun);
  font-size: 1.35rem;
  color: #0891b2;
}

.stat-chip span {
  font-size: 0.68rem;
  color: #475569;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hero-art {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-barnaby {
  position: relative;
  z-index: 2;
  width: clamp(130px, 16vw, 190px);
  height: auto;
  transform: scaleX(-1);
  animation: barnaby-bob 3.2s ease-in-out infinite;
  filter: drop-shadow(4px 6px 0 rgba(0, 0, 0, 0.25));
}

.hero-art-glow {
  position: absolute;
  inset: 10%;
  z-index: 1;
  background: radial-gradient(circle, rgba(255, 216, 94, 0.35), rgba(255, 216, 94, 0));
  border-radius: 50%;
}

@keyframes barnaby-bob {
  0%, 100% { transform: scaleX(-1) translateY(0) rotate(-2deg); }
  50% { transform: scaleX(-1) translateY(-14px) rotate(2deg); }
}

.hero-wave {
  display: block;
  width: 100%;
  height: 48px;
}

.hero-wave path {
  fill: var(--bg);
}

.hero-bubbles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.hero-bubbles span {
  position: absolute;
  bottom: -60px;
  display: block;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.05));
  animation: bubble-rise linear infinite;
}

.hero-bubbles span:nth-child(1) { left: 6%; width: 18px; height: 18px; animation-duration: 9s; animation-delay: 0s; }
.hero-bubbles span:nth-child(2) { left: 18%; width: 30px; height: 30px; animation-duration: 13s; animation-delay: 2s; }
.hero-bubbles span:nth-child(3) { left: 38%; width: 14px; height: 14px; animation-duration: 8s; animation-delay: 1s; }
.hero-bubbles span:nth-child(4) { left: 58%; width: 24px; height: 24px; animation-duration: 11s; animation-delay: 3.5s; }
.hero-bubbles span:nth-child(5) { left: 76%; width: 16px; height: 16px; animation-duration: 10s; animation-delay: 0.5s; }
.hero-bubbles span:nth-child(6) { left: 90%; width: 26px; height: 26px; animation-duration: 14s; animation-delay: 4s; }

@keyframes bubble-rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.5; }
  100% { transform: translateY(-420px) translateX(12px); opacity: 0; }
}

.hero-seaweed {
  position: absolute;
  bottom: 44px;
  left: 0;
  right: 0;
  height: 90px;
  z-index: 1;
  pointer-events: none;
}

.hero-seaweed span {
  position: absolute;
  bottom: 0;
  width: 18px;
  height: 80px;
  background: #2fa86a;
  border: 3px solid var(--outline);
  border-radius: 40% 40% 8px 8px;
  transform-origin: bottom center;
  animation: seaweed-sway 3.5s ease-in-out infinite;
  opacity: 0.85;
}

.hero-seaweed span:nth-child(1) { left: 8%; height: 60px; animation-delay: 0s; }
.hero-seaweed span:nth-child(2) { left: 28%; height: 85px; animation-delay: 0.6s; }
.hero-seaweed span:nth-child(3) { left: 68%; height: 70px; animation-delay: 1.1s; }
.hero-seaweed span:nth-child(4) { left: 88%; height: 55px; animation-delay: 1.7s; }

@keyframes seaweed-sway {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .hero-bubbles span,
  .hero-seaweed span,
  .hero-barnaby {
    animation: none;
    display: none;
  }
}

/* --- Game grid --- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.game-card {
  position: relative;
  background: var(--bg-card);
  border-radius: 20px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  border: 3px solid var(--outline);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  display: flex;
  flex-direction: column;
}

.game-grid > :nth-child(1) { transform: rotate(-1.2deg); }
.game-grid > :nth-child(2) { transform: rotate(1deg); }
.game-grid > :nth-child(3) { transform: rotate(-0.6deg); }

.game-card:hover {
  transform: rotate(0deg) translate(-4px, -6px);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.35);
}

.badge-new {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  background: #facc15;
  color: #422006;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  border: 2px solid var(--outline);
  transform: rotate(-8deg);
}

.game-thumb {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  transition: transform 0.25s ease;
}

.game-card:hover .game-thumb {
  transform: scale(1.08);
}

.theme-swim .game-thumb {
  background: linear-gradient(135deg, #0c4a6e, #0891b2 60%, #22d3ee);
}

.theme-maze .game-thumb {
  background: linear-gradient(135deg, #4c1d95, #a855f7 60%, #f472b6);
}

.theme-defense .game-thumb {
  background: linear-gradient(135deg, #064e3b, #059669 60%, #facc15);
}

.game-info {
  position: relative;
  padding: 14px 16px 18px;
}

.game-info h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.game-info p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.play-pill {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-hover);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.game-card:hover .play-pill {
  opacity: 1;
  transform: translateX(0);
}

.badge-soon {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-dim);
  border: 1px solid #334155;
  padding: 2px 8px;
  border-radius: 999px;
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  color: var(--accent-hover);
}

footer {
  text-align: center;
  color: var(--text-dim);
  padding: 32px;
  font-size: 0.85rem;
}

footer .version {
  opacity: 0.7;
}

/* Small, unobtrusive version tag for game pages (whose main footer is
   hidden so the fullscreen game canvas has room). Positioned inside the
   game-wrap, which is the nearest `position: relative` ancestor. */
.version-tag {
  position: absolute;
  bottom: 10px;
  left: 14px;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(15, 23, 42, 0.35);
  padding: 3px 9px;
  border-radius: 999px;
  z-index: 4;
  pointer-events: none;
  font-family: var(--font-fun);
}

@media (max-width: 640px) {
  .version-tag {
    font-size: 0.6rem;
    padding: 2px 7px;
    bottom: 6px;
    left: 8px;
  }

  header.site-header {
    padding: 16px 20px;
  }

  header.site-header a {
    font-size: 1.15rem;
  }

  main {
    padding: 20px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .hero {
    padding: 40px 20px 28px;
  }

  .hero-subtitle {
    font-size: 0.9rem;
  }

  .stat-chip {
    padding: 8px 14px;
    min-width: 74px;
  }

  .section-title {
    font-size: 1.2rem;
  }

  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 18px;
  }

  .game-grid > :nth-child(1),
  .game-grid > :nth-child(2),
  .game-grid > :nth-child(3) {
    transform: none;
  }

  .hero-art {
    display: none;
  }

  .game-thumb {
    height: 100px;
    font-size: 2.2rem;
  }

  footer {
    padding: 20px;
  }
}

/* --- Immersive game layout ---
   Drops the header/title chrome so the game canvas fills the whole
   viewport. Turned on automatically on small-screen landscape (a phone
   rotated sideways) and can also be toggled manually via the
   fullscreen-layout button (see assets/js/immersive.js). This is a pure
   CSS layout mode, distinct from the native browser Fullscreen API that
   the existing "⛶" button already triggers. */
body.game-page.immersive header.site-header,
body.game-page.immersive .page-meta {
  display: none;
}

body.game-page.immersive main.wide {
  padding: 0;
}

body.game-page.immersive .game-wrap {
  margin-top: 0;
}

#immersive-btn.active {
  background: rgba(56, 189, 248, 0.55);
}

/* Small toast for hints like "Add to Home Screen for true fullscreen" */
.arcade-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  max-width: min(320px, 84vw);
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  border: 2px solid var(--outline);
  border-radius: 12px;
  font-size: 0.8rem;
  text-align: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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