/* ============================================================
   Kids Arcade — shared styles
   Big, bright, touch-friendly. No scrolling, no tiny targets.
   ============================================================ */
:root {
  --bg1: #6a5cff;
  --bg2: #ff6ad5;
  --tile: #ffffff;
  --ink: #2b2350;
  --good: #35d07f;
  --warn: #ff6b6b;
  --sun: #ffd23f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI Rounded", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
}
body { position: fixed; inset: 0; }

/* ---------- generic layout ---------- */
.aa-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px; text-align: center;
}
.aa-title {
  font-size: clamp(28px, 6vw, 56px);
  font-weight: 800; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,.15);
  margin: 0 0 8px;
}
.aa-prompt {
  font-size: clamp(22px, 5vw, 40px);
  font-weight: 800; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.15);
  margin: 6px 0 18px;
  min-height: 1.2em;
}

/* ---------- big buttons / choices ---------- */
.aa-choices {
  display: flex; flex-wrap: wrap; gap: 18px;
  align-items: center; justify-content: center;
  max-width: 900px;
}
.aa-btn {
  font-family: inherit;
  border: none; cursor: pointer;
  background: var(--tile); color: var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 rgba(0,0,0,.15), 0 12px 22px rgba(0,0,0,.18);
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  transition: transform .07s ease;
  -webkit-user-select: none; user-select: none;
}
.aa-btn:active { transform: translateY(4px) scale(.97); box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.aa-choice {
  width: clamp(110px, 26vw, 170px);
  height: clamp(110px, 26vw, 170px);
  font-size: clamp(48px, 12vw, 90px);
}
.aa-choice.small { width: clamp(84px,20vw,120px); height: clamp(84px,20vw,120px); font-size: clamp(38px,9vw,64px); }

.aa-correct { animation: aa-correct .5s ease; }
.aa-wrong { animation: aa-shake .4s ease; }
@keyframes aa-correct { 0%{transform:scale(1)} 40%{transform:scale(1.18)} 100%{transform:scale(1)} }
@keyframes aa-shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }

/* ---------- home button (always tappable, sits above game-over overlays) ----------
   Sits BELOW the iPad status bar (clock/date overlays the top edge in
   standalone web-app mode) via safe-area inset + extra offset. */
.aa-home {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(14px + env(safe-area-inset-left, 0px));
  z-index: 200;
  width: 72px; height: 72px; border: none; cursor: pointer;
  border-radius: 50%; background: rgba(255,255,255,.95);
  font-size: 38px; line-height: 72px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.aa-home:active { transform: scale(.92); }
.aa-back-world {
  position:fixed; top:calc(16px + env(safe-area-inset-top,0px)); left:calc(14px + env(safe-area-inset-left,0px));
  z-index:201; width:72px; height:72px; border:0; border-radius:50%; cursor:pointer;
  background:rgba(255,255,255,.95); color:#2b2350; font:900 34px/1 system-ui;
  box-shadow:0 4px 12px rgba(0,0,0,.25);
}
.aa-home.aa-home-with-back { left:calc(96px + env(safe-area-inset-left,0px)); }
.aa-back-world:active { transform:scale(.92); }

/* ---------- star jar ---------- */
.aa-stars {
  position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); right: 14px; z-index: 50;
  background: rgba(255,255,255,.92); border-radius: 30px;
  padding: 8px 18px 8px 14px;
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 28px; color: var(--ink);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.aa-star-icon { font-size: 28px; }

/* coin counter (permanent currency) */
.aa-coins {
  position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 50;
  background: rgba(255,255,255,.92); border-radius: 30px;
  padding: 8px 18px 8px 14px;
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 28px; color: var(--ink);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}

/* big screens (iPads): chunkier shared UI */
@media (min-width: 1020px) {
  .aa-home { width: 84px; height: 84px; font-size: 46px; line-height: 84px; }
  .aa-back-world { width:84px; height:84px; font-size:42px; }
  .aa-home.aa-home-with-back { left:calc(112px + env(safe-area-inset-left,0px)); }
  .aa-stars, .aa-coins { font-size: 34px; padding: 10px 22px 10px 16px; }
  .aa-star-icon { font-size: 34px; }
  .aa-pick { font-size: clamp(26px, 3.2vw, 38px) !important; padding: 20px 30px !important; }
}
.aa-pop { animation: aa-pop .4s ease; }
@keyframes aa-pop { 0%{transform:scale(1)} 50%{transform:scale(1.25)} 100%{transform:scale(1)} }
.aa-flystar {
  position: fixed; z-index: 60; left: 50%; top: 50%;
  font-size: 44px; pointer-events: none;
  animation: aa-fly 0.9s ease forwards;
}
@keyframes aa-fly {
  0% { transform: translate(-50%,-50%) scale(.4); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(40vw,-42vh) scale(1); opacity: 0; }
}

/* ---------- confetti ---------- */
.aa-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.aa-confetti span {
  position: absolute; top: -40px;
  animation: aa-fall 2.4s ease-in forwards;
}
@keyframes aa-fall {
  0% { transform: translateY(-40px) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 1; }
}

/* ---------- D-pad ---------- */
.aa-dpad {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 40;
  display: grid; grid-template-columns: repeat(3, 66px); grid-template-rows: repeat(3, 66px);
  gap: 6px;
}
.aa-dbtn {
  border: none; cursor: pointer; font-size: 30px;
  background: rgba(255,255,255,.9); border-radius: 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,.2);
}
.aa-dbtn:active { transform: scale(.9); }
.aa-d-up { grid-column: 2; grid-row: 1; }
.aa-d-left { grid-column: 1; grid-row: 2; }
.aa-d-right { grid-column: 3; grid-row: 2; }
.aa-d-down { grid-column: 2; grid-row: 3; }

/* ---------- level / theme pickers ---------- */
.aa-pickrow { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 10px; }
.aa-pick {
  font-family: inherit; border: none; cursor: pointer;
  background: var(--tile); color: var(--ink); font-weight: 800;
  border-radius: 20px; padding: 16px 22px; font-size: clamp(20px,4vw,30px);
  box-shadow: 0 6px 0 rgba(0,0,0,.15);
  display: flex; align-items: center; gap: 10px;
}
.aa-pick:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.aa-pick .emj { font-size: 1.4em; }

/* ---------- canvas games ---------- */
.aa-gamewrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.aa-canvas { background: rgba(255,255,255,.14); border-radius: 18px; touch-action: none; }

/* small helper */
.aa-hidden { display: none !important; }
.aa-sub { color: #fff; font-size: clamp(16px,3.5vw,24px); font-weight: 700; opacity: .95; margin-top: 8px; }

/* ---------- NEW RECORD banner (Arcade.reportScore) ---------- */
.aa-record {
  position: fixed; top: 38%; left: 50%; z-index: 300; pointer-events: none;
  background: linear-gradient(#ffd23f, #ffab2e); color: #5a3d1e;
  font-weight: 900; font-size: clamp(24px,6.5vw,42px); text-align: center; white-space: nowrap;
  padding: 16px 34px; border-radius: 26px; border: 4px solid #fff6b0;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  animation: aaRecord 2.6s ease forwards;
}
.aa-record .aa-record-n { font-size: 1.5em; text-shadow: 0 2px 0 #fff6b0; }
@keyframes aaRecord {
  0%   { transform: translate(-50%,-50%) scale(.2); opacity: 0; }
  12%  { transform: translate(-50%,-50%) scale(1.15); opacity: 1; }
  22%  { transform: translate(-50%,-50%) scale(1); }
  80%  { opacity: 1; }
  100% { transform: translate(-50%,-62%) scale(1); opacity: 0; }
}

/* ---------- monster buddy (the kid's own monster, along for every game) ---------- */
.aa-buddy {
  position: fixed; z-index: 45; pointer-events: none;
  left: calc(14px + env(safe-area-inset-left, 0px));
  top: calc(100px + env(safe-area-inset-top, 0px));
  width: 74px; text-align: center;
  filter: drop-shadow(0 5px 7px rgba(0,0,0,.28));
  animation: aaBuddyIdle 2.8s ease-in-out infinite;
  transform-origin: bottom center;
}
.aa-buddy img { width: 100%; height: auto; display: block; }
.aa-buddy .aa-buddy-emj { font-size: 56px; line-height: 1; display: block; }
@keyframes aaBuddyIdle { 0%,100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-6px) rotate(1.5deg); } }
.aa-buddy.aa-buddy-cheer { animation: aaBuddyCheer .7s ease; }
@keyframes aaBuddyCheer {
  0%,100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-20px) scale(1.15) rotate(-6deg); }
  60% { transform: translateY(-4px) scale(1.05) rotate(5deg); }
}
.aa-buddy-heart {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  font-size: 24px; animation: aaBuddyHeart .9s ease forwards;
}
@keyframes aaBuddyHeart {
  0% { opacity: 0; transform: translateX(-50%) translateY(0) scale(.5); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-34px) scale(1.25); }
}
@media (min-width: 1020px) {
  .aa-buddy { width: 104px; top: calc(116px + env(safe-area-inset-top, 0px)); }
  .aa-buddy .aa-buddy-emj { font-size: 80px; }
}

.aa-buddy.aa-buddy-tickle { animation: aaBuddyTickle .6s ease; }
/* The buddy belongs on the island/monster screens; floating over game playfields obscures touch targets. */
.aa-buddy{display:none!important}
@keyframes aaBuddyTickle {
  0%,100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-10deg) scale(1.12); }
  40% { transform: rotate(9deg) scale(1.05); }
  60% { transform: rotate(-7deg) scale(1.1); }
  80% { transform: rotate(5deg) scale(1.02); }
}

/* Calm end-of-round feedback: celebrates mastery without blocking play. */
.aa-round-recap {
  position: fixed; z-index: 920; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 18px); min-width: min(360px, calc(100vw - 32px));
  padding: 14px 22px; border: 4px solid rgba(255,255,255,.94); border-radius: 22px;
  background: linear-gradient(145deg,#463991,#2c226e); color: #fff; text-align: center;
  font: 800 18px/1.25 system-ui, sans-serif; box-shadow: 0 12px 30px rgba(28,20,70,.34);
  pointer-events: none; animation: aaRoundRecap 2.5s ease both;
}
.aa-round-recap strong { display:block; margin-bottom:3px; color:#ffe66a; font-size:22px; }
.aa-round-recap small { display:block; margin-top:3px; opacity:.86; font-size:14px; }
@keyframes aaRoundRecap {
  0% { opacity:0; transform:translate(-50%,18px) scale(.94); }
  12%,82% { opacity:1; transform:translate(-50%,0) scale(1); }
  100% { opacity:0; transform:translate(-50%,-8px) scale(.98); }
}

/* ---------- iPad safety + accessibility ---------- */
button, a, [role="button"] { min-width: 44px; min-height: 44px; }
button, a, [role="button"] { transition:transform .1s cubic-bezier(.2,.8,.3,1),filter .14s ease,box-shadow .14s ease; }
button:active, a:active, [role="button"]:active { filter:brightness(1.06) saturate(1.08); }
.aa-page-enter { animation:aaPageEnter .48s cubic-bezier(.18,.82,.28,1) both; }
@keyframes aaPageEnter { from { opacity:0; transform:scale(.985); } to { opacity:1; transform:scale(1); } }
.aa-tap-ripple { position:fixed; z-index:9999; width:18px; height:18px; margin:-9px 0 0 -9px; border:4px solid rgba(255,255,255,.9);
  border-radius:50%; pointer-events:none; box-shadow:0 0 0 2px rgba(63,43,120,.18); animation:aaTapRipple .48s ease-out forwards; }
@keyframes aaTapRipple { to { transform:scale(4.2); opacity:0; } }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 5px solid #15103f; outline-offset: 4px;
}
.aa-parent-button {
  position: fixed; z-index: 240; right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px)); width: 52px; height: 52px;
  border: 3px solid rgba(43,35,80,.35); border-radius: 50%; background: rgba(255,255,255,.94);
  color: #2b2350; font: 800 28px/1 system-ui; box-shadow: 0 5px 14px rgba(0,0,0,.25); cursor: pointer;
}
.aa-parent-panel {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px)) calc(18px + env(safe-area-inset-left, 0px));
  background: rgba(25,20,58,.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.aa-parent-card {
  position: relative; width: min(620px, 100%); max-height: 100%; overflow: auto; user-select: text;
  border: 5px solid #fff; border-radius: 28px; background: #f8f7ff; color: #2b2350;
  padding: 26px; box-shadow: 0 24px 70px rgba(0,0,0,.38); text-align: left;
}
.aa-parent-card h2 { margin: 0; padding-right: 48px; font-size: clamp(28px,5vw,42px); }
.aa-parent-intro { margin: 4px 0 18px; font-size: 18px; }
.aa-parent-close { position: absolute; right: 14px; top: 14px; width: 48px; height: 48px; border: 0; border-radius: 50%; background: #e8e5ff; font-size: 24px; }
.aa-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 4px; border-top: 2px solid #e3e0f2; }
.aa-setting span { display: grid; gap: 2px; }
.aa-setting strong { font-size: 20px; }
.aa-setting small { font-size: 15px; opacity: .78; }
.aa-setting input { position: absolute; opacity: 0; }
.aa-setting i { width: 64px; height: 36px; flex: 0 0 auto; border-radius: 22px; padding: 4px; background: #aaa5bf; transition: .18s; }
.aa-setting i::after { content: ""; display: block; width: 28px; height: 28px; border-radius: 50%; background: white; transition: .18s; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.aa-setting input:checked + i { background: #35b878; }
.aa-setting input:checked + i::after { transform: translateX(28px); }
.aa-time-setting select { font: 800 18px/1 system-ui; border: 3px solid #766bd0; border-radius: 13px; padding: 10px; background: white; color: #2b2350; }
.aa-reset-progress { width: 100%; margin-top: 18px; border: 3px solid #c53f53; border-radius: 16px; padding: 13px; background: #fff0f2; color: #9b2435; font: 800 18px/1.2 inherit; }
.aa-version { text-align: center; opacity: .55; font-size: 13px; }
.aa-gate { text-align: center; max-width: 460px; }
.aa-gate p { font-size: 24px; }
.aa-gate-row { display: flex; gap: 10px; }
.aa-gate-row input { width: 110px; flex: 1; border: 4px solid #766bd0; border-radius: 16px; padding: 12px; font: 800 28px/1 inherit; text-align: center; }
.aa-gate-go { flex: 2; border: 0; border-radius: 16px; background: #35b878; color: white; font: 800 20px/1 inherit; }
.aa-gate-error { min-height: 1.3em; color: #a42136; font-size: 16px !important; }
.aa-break-screen { position: fixed; inset: 0; z-index: 1100; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg,#6a5cff,#2f246e); color: white; text-align: center; }
.aa-break-screen > div { max-width: 600px; }
.aa-break-emoji { font-size: 100px; }
.aa-break-screen h2 { font-size: clamp(36px,7vw,62px); margin: 10px; }
.aa-break-screen p { font-size: clamp(22px,4vw,32px); }
.aa-break-screen button { border: 0; border-radius: 18px; background: white; color: #2b2350; padding: 16px 24px; font: 800 18px/1 inherit; }
.aa-large-text { font-size: 112.5%; }
.aa-large-text .aa-prompt, .aa-large-text .aa-sub { font-size: clamp(26px,5.4vw,44px); }
.aa-high-contrast button, .aa-high-contrast a { box-shadow: 0 0 0 4px #15103f, 0 8px 0 rgba(0,0,0,.25) !important; }
.aa-reduce-motion *, .aa-reduce-motion *::before, .aa-reduce-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
@media (max-width: 760px) {
  .aa-home { width: 60px; height: 60px; line-height: 60px; font-size: 32px; }
  .aa-back-world { width:60px; height:60px; font-size:30px; }
  .aa-home.aa-home-with-back { left:calc(82px + env(safe-area-inset-left,0px)); }
  .aa-stars { right: calc(10px + env(safe-area-inset-right,0px)); font-size: 22px; padding: 7px 13px; }
  .aa-coins { font-size: 22px; padding: 7px 13px; }
  .aa-parent-button { width: 48px; height: 48px; font-size: 24px; }
}
