/* Self-hosted fonts (CSP: font-src 'self') — Baloo 2 + Nunito, latin subset */
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/Baloo2-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Baloo2-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('fonts/Baloo2-800.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Nunito-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/Nunito-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Nunito-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('fonts/Nunito-800.woff2') format('woff2');
}

/* ============================================================
   Corgi Chomp redesign — 3 kawaii directions, all driven by
   CSS custom properties. To adopt on the live site: pick ONE
   theme block, paste its variables into :root, and copy the
   component styles below. No markup surgery required.
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

/* Sky-to-grass fallback on the root; the farm photo itself lives on the fixed
   .farm-anim layer below so the grazing-animal crops share its exact geometry. */
html {
  background-color: #6aa24a;
  background-image: linear-gradient(180deg, #8ec9ee 0%, #aed884 48%, #6fa24e 100%);
  background-size: cover;
  background-repeat: no-repeat;
}
body {
  --radius: 18px;
  --game-font: "Baloo 2","Segoe UI",sans-serif;
  background: transparent;
  color: var(--ink);
  font-family: 'Nunito', "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* Per-theme wash so the photo harmonizes with each palette */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--photo-tint, transparent);
}
/* Flat pastel alternative (Tweaks → Farm photo off) */
body.no-photo {
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 2.4px, transparent 2.8px);
  background-size: 26px 26px;
}
body.no-photo::before { display: none; }

/* ---------- Ambient background motion (subtle, sits behind everything) ---------- */
.bg-anim { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
body.no-photo .bg-anim, body.no-motion .bg-anim { display: none; }
.cloud, .cloud::before { background: rgba(255,255,255,.85); }
.cloud { position: absolute; width: 92px; height: 22px; left: -160px; }
.cloud::before { content: ""; position: absolute; width: 54%; height: 100%; top: -86%; left: 23%; }
.cloud.c1 { top: 5%;  transform: scale(1);    animation: cloud-drift 95s  linear infinite; }
.cloud.c2 { top: 11%; transform: scale(0.7);  animation: cloud-drift 140s linear infinite; animation-delay: -60s; }
.cloud.c3 { top: 2%;  transform: scale(1.35); opacity: .75; animation: cloud-drift 170s linear infinite; animation-delay: -115s; }
@keyframes cloud-drift { to { translate: calc(100vw + 320px) 0; } }
.twinkle { position: absolute; width: 6px; height: 6px; background: #fffbe6; opacity: 0; animation: twinkle 4.5s ease-in-out infinite; }
.twinkle.t1 { left: 7%;  bottom: 14%; }
.twinkle.t2 { right: 9%; bottom: 26%; animation-delay: 1.6s; }
.twinkle.t3 { left: 13%; top: 38%;  animation-delay: 3.1s; }
@keyframes twinkle { 0%, 100% { opacity: 0; scale: .6; } 50% { opacity: .9; scale: 1; } }
.butterfly { position: absolute; left: 5%; top: 58%; width: 3px; height: 3px; animation: flutter 34s ease-in-out infinite alternate; }
.butterfly .px { display: block; width: 3px; height: 3px; animation: flap .5s steps(1, end) infinite; }
@keyframes flap {
  0%, 100% { box-shadow:
    3px 0 #e2849f, 6px 0 #e2849f, 12px 0 #e2849f, 15px 0 #e2849f,
    0 3px #e2849f, 3px 3px #f5b8c8, 6px 3px #f5b8c8, 9px 3px #52422f, 12px 3px #f5b8c8, 15px 3px #f5b8c8, 18px 3px #e2849f,
    3px 6px #f5b8c8, 6px 6px #f5b8c8, 9px 6px #52422f, 12px 6px #f5b8c8, 15px 6px #f5b8c8,
    3px 9px #e2849f, 6px 9px #f5b8c8, 9px 9px #52422f, 12px 9px #f5b8c8, 15px 9px #e2849f; }
  50% { box-shadow:
    6px 0 #e2849f, 12px 0 #e2849f,
    6px 3px #f5b8c8, 9px 3px #52422f, 12px 3px #f5b8c8,
    6px 6px #f5b8c8, 9px 6px #52422f, 12px 6px #f5b8c8,
    6px 9px #e2849f, 9px 9px #52422f, 12px 9px #e2849f; }
}
@keyframes flutter {
  0%   { translate: 0 0; }
  25%  { translate: 6vw -10vh; }
  50%  { translate: 2vw -4vh; }
  75%  { translate: 9vw -14vh; }
  100% { translate: 4vw -2vh; }
}
@media (prefers-reduced-motion: reduce) { .bg-anim { display: none; } }

/* ---------- Farm photo + grazing animals (one fixed layer, one geometry) ---------- */
.farm-anim {
  position: fixed; inset: 0; z-index: -2; overflow: hidden; pointer-events: none;
  background: url('background.jpg') center center / cover no-repeat;
}
body.no-photo .farm-anim { display: none; }
.farm-animal { position: absolute; transform-origin: 50% 88%; }
.farm-animal.grazing { animation: graze 1.9s steps(1, end); }
@keyframes graze {
  0%, 100%      { transform: none; }
  12%, 38%, 64% { transform: translateY(3%) scaleY(.93); }
  25%, 50%, 78% { transform: none; }
}
/* Loose text needs lift when it sits on the photo */
body:not(.no-photo) h1 { color: #ffffff; text-shadow: 0 2px 0 rgba(0,0,0,.22), 0 5px 16px rgba(0,0,0,.38); }
body:not(.no-photo) h1 .chomp { color: var(--accent); }
body:not(.no-photo) .hint {
  background: rgba(255,255,255,.86);
  padding: 5px 14px; border-radius: 999px;
}
body:not(.no-photo) .hint { color: var(--ink); }

/* ---------- Direction A · Pastel Picnic (warm cream + strawberry) ---------- */
body[data-theme="picnic"] {
  --bg:#fdf1e3; --dot:#f5dfc6;
  --card:#fffdf9; --card-edge:#f0dcc4;
  --ink:#5c4636; --ink-soft:#9b8470;
  --accent:#ef8aa4; --accent-deep:#d6688a; --accent-ink:#ffffff;
  --frame:#f0a9bb;
  --maze-bg:#fff8ec;
  --maze-wall:#f7b3c2; --maze-wall-edge:#e2899f; --maze-wall-hi:rgba(255,255,255,.55);
  --maze-gate:#d9a05b; --maze-accent:#d6688a; --maze-ready-stroke:rgba(255,255,255,.92);
  --maze-treat:#e8a64b; --maze-power:#e0784f;
  --photo-tint: rgba(255,205,190,.22);
}

/* ---------- Direction B · Minty Sundae (cool mint + lilac) ---------- */
body[data-theme="mint"] {
  --bg:#e8f4ee; --dot:#d6e9df;
  --card:#fbfdfb; --card-edge:#cfe5da;
  --ink:#2e5147; --ink-soft:#7a9c91;
  --accent:#9d8fe0; --accent-deep:#7d6cc9; --accent-ink:#ffffff;
  --frame:#79bda7;
  --maze-bg:#f3faf6;
  --maze-wall:#8fd2bd; --maze-wall-edge:#65b29b; --maze-wall-hi:rgba(255,255,255,.5);
  --maze-gate:#c69d63; --maze-accent:#7d6cc9; --maze-ready-stroke:rgba(255,255,255,.92);
  --maze-treat:#eaa64d; --maze-power:#e07b54;
  --photo-tint: rgba(170,225,205,.26);
}

/* ---------- Direction C · Garden Classic (your green, polished) ---------- */
body[data-theme="garden"] {
  --bg:#f5f3e4; --dot:#e9e5cd;
  --card:#fffef6; --card-edge:#e3dec2;
  --ink:#3a4632; --ink-soft:#84907a;
  --accent:#f2c043; --accent-deep:#cf9a1d; --accent-ink:#3a2a00;
  --frame:#8a623b;
  --maze-bg:#edf1dc;
  --maze-wall:#4f8551; --maze-wall-edge:#3a6340; --maze-wall-hi:rgba(190,220,130,.45);
  --maze-gate:#8a5a2b; --maze-accent:#b97f10; --maze-ready-stroke:rgba(255,255,255,.92);
  --maze-treat:#c98f3a; --maze-power:#cc5b35;
  --photo-tint: rgba(245,235,180,.10);
}

/* ---------- Layout ---------- */
.wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 12px;
}
.masthead { text-align: center; }
h1 {
  margin: 0; font-family: 'Baloo 2', sans-serif; font-weight: 800;
  font-size: clamp(26px, 5.5vw, 42px); line-height: 1.05;
  color: var(--ink); letter-spacing: .5px;
}
h1 .chomp { color: var(--accent-deep); }
.tagline {
  display: inline-block; margin-top: 7px;
  font-size: 10.5px; font-weight: 800; letter-spacing: 3px;
  color: var(--accent-deep);
  background: var(--card); border: 2px solid var(--card-edge);
  padding: 4px 14px; border-radius: 999px;
}

/* ---------- HUD ---------- */
.hud {
  width: 100%; max-width: 608px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.stat {
  background: var(--card); border: 2px solid var(--card-edge);
  border-radius: calc(var(--radius) * 0.72);
  padding: 6px 8px 7px;
  display: flex; flex-direction: column; align-items: center;
}
.stat-label {
  font-size: 9.5px; font-weight: 800; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--ink-soft);
}
.stat b { font-family: 'Baloo 2', sans-serif; font-size: 21px; line-height: 1.15; color: var(--ink); }
.stat b#lives { font-size: 15px; letter-spacing: 1px; }

/* ---------- Stage ---------- */
.play-area { display: flex; gap: 18px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.stage { position: relative; }
canvas {
  display: block;
  background: var(--maze-bg);
  border: 4px solid var(--frame); border-radius: var(--radius);
  box-shadow: 0 10px 26px rgba(0,0,0,.12), 0 2px 0 rgba(0,0,0,.04);
  max-width: 92vw; max-height: 78vh; width: auto; height: auto; touch-action: none;
}
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 12px; overflow-y: auto;
  background: rgba(255,255,255,.92);
  border-radius: calc(var(--radius) - 4px);
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.ov-head { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
#ov-img { width: clamp(96px, 30vmin, 158px); height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
.overlay h2 { margin: 0; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 30px; color: var(--ink); }
.overlay p { margin: 0; max-width: 360px; line-height: 1.55; font-size: 14px; color: var(--ink); opacity: .88; text-wrap: pretty; }
.overlay p b { color: var(--accent-deep); }

.btn {
  margin-top: 4px; border: none; cursor: pointer;
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 30px; border-radius: 999px;
  box-shadow: 0 4px 0 var(--accent-deep), 0 10px 18px rgba(0,0,0,.12);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-deep), 0 4px 10px rgba(0,0,0,.10); }

/* ---------- Side panel ---------- */
.panel {
  background: var(--card); border: 2px solid var(--card-edge);
  border-radius: var(--radius); padding: 14px; width: 190px;
  box-shadow: 0 6px 16px rgba(0,0,0,.06);
}
.panel-title {
  font-size: 10.5px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 10px; text-align: center;
}
.diff-btn {
  display: block; width: 100%; margin: 6px 0; padding: 9px 12px;
  border-radius: calc(var(--radius) * 0.6); border: 2px solid var(--card-edge);
  background: var(--bg); color: var(--ink);
  font-family: 'Nunito', sans-serif; font-size: 14px; font-weight: 800;
  cursor: pointer; text-align: left; transition: all .12s;
}
.diff-btn:hover { border-color: var(--accent); }
.diff-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent-deep); }
.diff-btn small { display: block; font-weight: 600; font-size: 11px; opacity: .65; }
.diff-btn.util { text-align: center; }
.panel-note { font-size: 11px; color: var(--ink-soft); text-align: center; margin-top: 8px; }

/* ---------- Footer ---------- */
.hint { font-size: 12.5px; max-width: 608px; text-align: center; color: var(--ink-soft); text-wrap: pretty; }

/* ---------- D-pad (touch / small screens) ---------- */
.dpad { display: none; }
.dbtn {
  border: 2px solid var(--card-edge); border-radius: 50%;
  background: var(--card); color: var(--ink);
  font-size: 22px; font-weight: 700;
  box-shadow: 0 3px 0 var(--card-edge);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
}
.dbtn:active { background: var(--accent); color: var(--accent-ink); transform: translateY(2px); box-shadow: none; }
.dbtn.up{grid-column:2;grid-row:1;} .dbtn.left{grid-column:1;grid-row:2;}
.dbtn.right{grid-column:3;grid-row:2;} .dbtn.down{grid-column:2;grid-row:3;}

@media (max-width:560px){
  .panel { width: 92vw; max-width: 456px; }
  #diffButtons { display: flex; flex-wrap: wrap; gap: 6px; }
  .diff-btn { flex: 1 1 28%; margin: 0; text-align: center; padding: 8px 4px; }
  .diff-btn small { display: none; }
}
@media (pointer:coarse), (max-width:760px){
  .wrap { justify-content: flex-start; }
  canvas { max-height: 50vh; }
  .play-area { flex-direction: column; align-items: center; gap: 12px; }
  .dpad {
    display: grid; margin: 2px auto;
    grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); gap: 8px;
    touch-action: none; user-select: none;
  }
}
