/* Sprout Arcade — reset + shared components. Loaded by the hub and every game. */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--ink);
  min-height: 100dvh;

  /* Sunlight through the canopy: a sky-to-leaf wash with foliage scattered on top. */
  background-color: var(--bg);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='170' viewBox='0 0 170 170'%3E%3Cg fill='%23C4E7A8' fill-opacity='0.6'%3E%3Cg transform='translate(32 36) rotate(-24)'%3E%3Cpath d='M0,-19 C10,-8 10,10 0,19 C-10,10 -10,-8 0,-19 Z'/%3E%3C/g%3E%3Cg transform='translate(120 84) rotate(40)'%3E%3Cpath d='M0,-23 C12,-10 12,12 0,23 C-12,12 -12,-10 0,-23 Z'/%3E%3C/g%3E%3Cg transform='translate(68 134) rotate(158)'%3E%3Cpath d='M0,-16 C9,-7 9,9 0,16 C-9,9 -9,-7 0,-16 Z'/%3E%3C/g%3E%3Cg transform='translate(152 20) rotate(72)'%3E%3Cpath d='M0,-13 C7,-6 7,7 0,13 C-7,7 -7,-6 0,-13 Z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--bg-sky) 0%, var(--bg) 46%);
  background-repeat: repeat, no-repeat;
  background-size: 170px 170px, 100% 100%;
  background-attachment: fixed, fixed;

  -webkit-font-smoothing: antialiased;
  /* Kids drag and double-tap constantly; none of it should select or zoom. */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body {
    background-image:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='170' viewBox='0 0 170 170'%3E%3Cg fill='%2317405A' fill-opacity='0.9'%3E%3Cg transform='translate(32 36) rotate(-24)'%3E%3Cpath d='M0,-19 C10,-8 10,10 0,19 C-10,10 -10,-8 0,-19 Z'/%3E%3C/g%3E%3Cg transform='translate(120 84) rotate(40)'%3E%3Cpath d='M0,-23 C12,-10 12,12 0,23 C-12,12 -12,-10 0,-23 Z'/%3E%3C/g%3E%3Cg transform='translate(68 134) rotate(158)'%3E%3Cpath d='M0,-16 C9,-7 9,9 0,16 C-9,9 -9,-7 0,-16 Z'/%3E%3C/g%3E%3Cg transform='translate(152 20) rotate(72)'%3E%3Cpath d='M0,-13 C7,-6 7,7 0,13 C-7,7 -7,-6 0,-13 Z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
      linear-gradient(180deg, var(--bg-sky) 0%, var(--bg) 46%);
  }
}
:root[data-theme="dark"] body {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='170' viewBox='0 0 170 170'%3E%3Cg fill='%2317405A' fill-opacity='0.9'%3E%3Cg transform='translate(32 36) rotate(-24)'%3E%3Cpath d='M0,-19 C10,-8 10,10 0,19 C-10,10 -10,-8 0,-19 Z'/%3E%3C/g%3E%3Cg transform='translate(120 84) rotate(40)'%3E%3Cpath d='M0,-23 C12,-10 12,12 0,23 C-12,12 -12,-10 0,-23 Z'/%3E%3C/g%3E%3Cg transform='translate(68 134) rotate(158)'%3E%3Cpath d='M0,-16 C9,-7 9,9 0,16 C-9,9 -9,-7 0,-16 Z'/%3E%3C/g%3E%3Cg transform='translate(152 20) rotate(72)'%3E%3Cpath d='M0,-13 C7,-6 7,7 0,13 C-7,7 -7,-6 0,-13 Z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--bg-sky) 0%, var(--bg) 46%);
}

img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 4px solid var(--go); outline-offset: 3px; border-radius: var(--r-sm); }
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--primary);
  --btn-edge: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: var(--s3) var(--s5);
  font-size: var(--t-md); font-weight: 800; letter-spacing: .01em;
  color: var(--on-color);
  background: var(--btn-bg);
  border: var(--bd) solid var(--stroke);
  border-radius: var(--r-pill);
  box-shadow: var(--ring), 0 var(--lift) 0 var(--stroke), var(--shadow-sm);
  transform: translateY(0);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), filter var(--dur);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(var(--lift)); box-shadow: var(--ring), 0 0 0 var(--stroke), var(--shadow-sm); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn--lg { min-height: 68px; padding: var(--s4) var(--s7); font-size: var(--t-lg); }

/* Mango. The button a child is meant to press. */
.btn--go { --btn-bg: var(--go); --btn-edge: var(--go-dark); }

.btn--ghost { --btn-bg: var(--surface); --btn-edge: var(--line-strong); color: var(--ink); }
.btn--quiet {
  min-height: 44px; padding: var(--s2) var(--s4);
  color: var(--ink-soft); background: none; border: 0; box-shadow: none; font-weight: 700;
}
.btn--quiet { box-shadow: none; }
.btn--quiet:hover { color: var(--ink); background: var(--surface-2); }

/* ---------- Game shell ---------- */

.shell { display: flex; flex-direction: column; min-height: 100dvh; }

.hud {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  padding-top: max(var(--s3), env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: var(--bd) solid var(--stroke);
  position: sticky; top: 0; z-index: 20;
}
.hud__back { flex: none; }
.hud__title {
  font-size: var(--t-md); font-weight: 800; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.hud__spacer { flex: 1; }

.stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 62px; padding: var(--s1) var(--s3);
  background: var(--surface-2); border: 2px solid var(--stroke); border-radius: var(--r-md);
}
.stat__label {
  font-size: 10px; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-mute);
}
.stat__value { font-size: var(--t-lg); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat--warn .stat__value { color: var(--bad); }

.progressbar { height: 10px; background: var(--line); overflow: hidden; }
.progressbar__fill {
  height: 100%; width: 0%;
  background: var(--game-accent, var(--primary));
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  transition: width 320ms var(--ease);
}

.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s5);
  width: 100%; max-width: 880px; margin: 0 auto;
  padding: var(--s5) var(--s4);
  padding-bottom: max(var(--s5), env(safe-area-inset-bottom));
  text-align: center;
}

.prompt { display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.prompt__label { font-size: var(--t-sm); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-mute); }
.prompt__main { font-size: var(--t-3xl); font-weight: 900; line-height: 1.1; }
.prompt__emoji { font-size: var(--t-4xl); line-height: 1; }

/* ---------- Choice tiles ---------- */

.choices {
  display: grid; gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  width: 100%;
}
.choices--2 { grid-template-columns: repeat(2, 1fr); }
.choices--tight { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); }

.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s1);
  min-height: 96px; padding: var(--s4);
  font-size: var(--t-xl); font-weight: 900;
  color: var(--ink);
  background: var(--surface);
  border: var(--bd) solid var(--stroke);
  border-radius: var(--r-lg);
  box-shadow: 0 5px 0 var(--stroke), var(--shadow-sm);
  transition: transform var(--dur) var(--ease), border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.tile:hover:not([disabled]) {
  transform: translateY(-3px);
  background: var(--game-accent, var(--primary));
  color: var(--on-color);
  box-shadow: 0 8px 0 var(--stroke), var(--shadow-md);
}
.tile:active:not([disabled]) { transform: translateY(3px); box-shadow: 0 2px 0 var(--stroke), var(--shadow-sm); }
.tile[disabled] { pointer-events: none; }
.tile__sub { font-size: var(--t-xs); font-weight: 700; color: var(--ink-mute); }
.tile--emoji { font-size: var(--t-2xl); }

/* Right/wrong never rely on colour alone — the tile also gets a ✓ / ✗ badge and motion,
   which matters because roughly 1 in 12 boys is colour-blind. */
.tile.is-right,
.tile.is-wrong { position: relative; }
.tile.is-right::after,
.tile.is-wrong::after {
  content: '✓';
  position: absolute; top: -10px; right: -10px;
  display: grid; place-items: center;
  width: 30px; height: 30px;
  font-size: 17px; font-weight: 900; line-height: 1;
  color: #fff; background: var(--good);
  border: var(--bd) solid var(--stroke); border-radius: 50%;
}
.tile.is-wrong::after { content: '✗'; background: var(--bad); }

.tile.is-right { background: var(--good-soft); border-color: var(--good); color: var(--good); box-shadow: 0 5px 0 var(--stroke); animation: pop 380ms var(--ease); }
.tile.is-wrong { background: var(--bad-soft);  border-color: var(--bad);  color: var(--bad);  box-shadow: 0 5px 0 var(--stroke);  animation: shake 380ms ease; }
.tile.is-faded { opacity: .35; }

@keyframes pop   { 0%{transform:scale(1)} 45%{transform:scale(1.12)} 100%{transform:scale(1)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(3px)} }
@keyframes floatUp { from{opacity:0; transform:translate(-50%,0) scale(.7)} 25%{opacity:1} to{opacity:0; transform:translate(-50%,-90px) scale(1.15)} }
@keyframes fadeUp  { from{opacity:0; transform:translateY(14px)} to{opacity:1; transform:translateY(0)} }
@keyframes sway    { 0%,100%{transform:rotate(-4deg)} 50%{transform:rotate(4deg)} }

.fade-in { animation: fadeUp 280ms var(--ease) both; }

/* ---------- Feedback ---------- */

.flash {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  opacity: 0; transition: opacity 140ms;
}
.flash.is-on { opacity: 1; }
.flash--good { background: radial-gradient(circle at 50% 55%, transparent 40%, var(--good-soft) 100%); }
.flash--bad  { background: radial-gradient(circle at 50% 55%, transparent 40%, var(--bad-soft)  100%); }

.floater {
  position: fixed; left: 50%; top: 42%; z-index: 41; pointer-events: none;
  font-size: var(--t-2xl); font-weight: 900;
  animation: floatUp 900ms var(--ease) forwards;
}

.confetti-piece {
  position: fixed; top: -20px; z-index: 45; pointer-events: none;
  width: 10px; height: 16px; border-radius: 2px;
}

/* ---------- Overlays: level picker, results ---------- */

.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s4);
  background: rgba(10, 39, 84, .62);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeUp 200ms ease both;
}
.sheet__panel {
  position: relative;
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: var(--s4);
  padding: var(--s6) var(--s5);
  padding-bottom: max(var(--s6), env(safe-area-inset-bottom));
  text-align: center;
  background: var(--surface);
  border: 4px solid var(--stroke);
  border-radius: var(--r-xl);
  box-shadow: var(--ring), var(--shadow-lg);
}
.sheet__emoji { font-size: var(--t-3xl); line-height: 1; }
.sheet__title { font-size: var(--t-xl); font-weight: 900; }
.sheet__note  { font-size: var(--t-sm); color: var(--ink-soft); max-width: 40ch; }
.sheet__actions { display: flex; flex-wrap: wrap; gap: var(--s3); justify-content: center; width: 100%; }
.sheet__actions .btn { flex: 1 1 auto; }

.levels { display: grid; gap: var(--s3); width: 100%; }
.level {
  display: flex; align-items: center; gap: var(--s4);
  min-height: var(--tap); padding: var(--s4);
  text-align: left;
  background: var(--surface-2);
  border: var(--bd) solid var(--stroke);
  border-radius: var(--r-lg);
  box-shadow: 0 4px 0 var(--stroke);
  transition: transform var(--dur) var(--ease), border-color var(--dur);
}
.level:hover { transform: translateY(-2px); background: var(--game-accent, var(--primary)); color: var(--on-color); }
.level__badge {
  flex: none;
  display: grid; place-items: center;
  width: 46px; height: 46px;
  font-size: var(--t-md); font-weight: 900;
  color: var(--on-color);
  background: var(--game-accent, var(--primary));
  border: 2px solid var(--stroke);
  border-radius: var(--r-md);
}
.level__name { font-weight: 800; }
.level__hint { font-size: var(--t-xs); color: var(--ink-soft); }
.level__best { margin-left: auto; font-size: var(--t-xs); font-weight: 800; color: var(--ink-mute); white-space: nowrap; }

.stars { display: flex; gap: var(--s2); font-size: var(--t-2xl); line-height: 1; }
.star--off { opacity: .22; filter: grayscale(1); }

.scoreline { display: flex; gap: var(--s5); justify-content: center; flex-wrap: wrap; }
.scoreline .stat { min-width: 88px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .confetti-piece { display: none; }
}

/* A little leafy vine, used as a divider under sheet titles. */
.vine {
  width: 128px; height: 14px; flex: none;
  background: no-repeat center/contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='14' viewBox='0 0 128 14'%3E%3Cpath d='M2 7h124' stroke='%230A2754' stroke-width='2.5' stroke-linecap='round' fill='none'/%3E%3Cg fill='%234FBF12'%3E%3Cpath d='M30 7c0-5 5-7 9-6-1 5-5 7-9 6z'/%3E%3Cpath d='M52 7c0 5 5 7 9 6-1-5-5-7-9-6z'/%3E%3Cpath d='M74 7c0-5 5-7 9-6-1 5-5 7-9 6z'/%3E%3Cpath d='M96 7c0 5 5 7 9 6-1-5-5-7-9-6z'/%3E%3C/g%3E%3Ccircle cx='64' cy='7' r='4' fill='%23FF8A1E'/%3E%3C/svg%3E");
}
