/* GameForKidz shared player shell — one consistent frame every game runs inside.
   Fixes the ad-hoc per-game layouts that caused HUD/canvas overlaps: a fixed header
   bar + a flex "stage" that owns exactly the remaining space (min-height:0 is what
   makes flex stop overflowing). Games size their canvas to .gfk-stage, never to the
   raw viewport. Works identically on the web and in the bundled app.
   Fonts self-hosted per game; this file only lays out the frame + chrome. */

/* Adaptive sizing, the CSS half of the policy in player.js — same threshold,
   same shares. On a phone both variables are 0, so a game's own ceiling wins
   through max(): `min(420px, 90vw)` becomes `min(max(420px, var(--gfk-strip)),
   90vw)` and is byte-for-byte the old layout. Above the threshold the viewport's
   short side (vmin) takes over. Keep in step with TABLET_MIN in player.js. */
:root{--gfk-board:0px;--gfk-strip:0px}
@media (min-width:540px) and (min-height:540px){
  :root{--gfk-board:78vmin;--gfk-strip:62vmin}
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;overflow:hidden;user-select:none;color:#fff;
  font-family:'Baloo 2','Nunito',system-ui,-apple-system,sans-serif;touch-action:none}

.gfk-player{position:fixed;inset:0;display:flex;flex-direction:column;overflow:hidden;
  background:var(--gfk-bg,#05060f)}

/* header / chrome bar */
.gfk-bar{flex:0 0 auto;display:flex;align-items:center;gap:8px;
  padding:calc(env(safe-area-inset-top,0px) + 8px) 12px 6px;min-height:46px}
.gfk-title{flex:1;text-align:center;font-weight:800;font-size:1.02rem;opacity:.96;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  text-shadow:0 0 14px var(--gfk-glow,rgba(75,229,255,.5))}
.gfk-actions{display:flex;gap:6px}
/* Chrome buttons hold the 44px minimum touch target — small hands need at
   least that, and the bar is the one thing every game shares. */
.gfk-btn{border:0;border-radius:12px;background:rgba(255,255,255,.13);color:#fff;font-weight:800;
  font-family:inherit;font-size:.92rem;padding:8px 14px;min-height:44px;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:5px;line-height:1;transition:transform .06s,background .12s;
  -webkit-tap-highlight-color:transparent;touch-action:manipulation}
.gfk-btn:active{transform:scale(.93)}
.gfk-btn.icon{width:44px;min-width:44px;height:44px;padding:0;font-size:1.08rem}
/* 44px is the phone MINIMUM, not a target — on a tablet the same controls are
   further from the eye and held at arm's length. */
@media (min-width:540px) and (min-height:540px){
  /* Content shorter than the stage is centred rather than pinned to the top:
     on a tablet a phone-sized board otherwise sits high with a band of empty
     space beneath it. Games whose arena is flex:1 already fill the stage and
     are unaffected. */
  .gfk-stage{justify-content:center}
  .gfk-bar{gap:12px;padding:calc(env(safe-area-inset-top,0px) + 12px) 20px 8px;min-height:58px}
  .gfk-btn{font-size:1.05rem;padding:10px 18px;min-height:54px;border-radius:15px}
  .gfk-btn.icon{width:54px;min-width:54px;height:54px;font-size:1.25rem}
  .gfk-title{font-size:1.3rem}
  .gfk-hud .k{font-size:.72rem}
  .gfk-hud .v{font-size:1.7rem}
  .gfk-stage{padding:0 18px calc(env(safe-area-inset-bottom,0px) + 12px)}
}
.gfk-back-hidden{display:none}

/* the play area — the only thing games draw into. Never overflows the frame. */
.gfk-stage{flex:1 1 auto;min-height:0;position:relative;width:100%;
  display:flex;flex-direction:column;align-items:center;justify-content:flex-start;
  overflow:hidden;padding:0 10px calc(env(safe-area-inset-bottom,0px) + 8px)}

/* a small in-stage HUD row games can drop their score/lives into */
.gfk-hud{flex:0 0 auto;display:flex;justify-content:space-between;align-items:center;gap:10px;
  width:100%;max-width:max(560px,var(--gfk-board));padding:6px 4px 8px;font-weight:800}
.gfk-hud .g{display:flex;flex-direction:column;line-height:1}
.gfk-hud .g.r{align-items:flex-end}
.gfk-hud .k{font-size:.58rem;letter-spacing:.14em;opacity:.7;text-transform:uppercase}
.gfk-hud .v{font-size:1.35rem}

/* consistent overlays (start / pause / game-over) */
.gfk-overlay{position:absolute;inset:0;display:none;flex-direction:column;align-items:center;
  justify-content:center;gap:16px;text-align:center;padding:22px;z-index:9;
  background:rgba(4,6,15,.86);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}
.gfk-overlay.show{display:flex}
.gfk-overlay h1{font-size:2.5rem;margin:0;color:var(--gfk-accent,#4be5ff);
  text-shadow:0 0 22px var(--gfk-glow,rgba(75,229,255,.7))}
.gfk-overlay p{margin:0;opacity:.85;font-size:1rem;max-width:22em}
@media (min-width:540px) and (min-height:540px){
  .gfk-overlay h1{font-size:min(7vmin,3.6rem)}
  .gfk-overlay h2{font-size:min(5.4vmin,2.6rem)}
  .gfk-overlay p{font-size:min(2.6vmin,1.3rem)}
  .gfk-play{font-size:min(3vmin,1.6rem);padding:18px 46px;border-radius:20px}
}
.gfk-play{border:0;border-radius:16px;padding:14px 36px;font-weight:800;font-family:inherit;
  font-size:1.3rem;cursor:pointer;color:#05060f;background:var(--gfk-btn,linear-gradient(180deg,#7bf0ff,#2ec8ff));
  box-shadow:0 0 24px var(--gfk-glow,rgba(75,229,255,.55)),0 6px 0 var(--gfk-btn-sh,#1a92c0);transition:transform .08s}
.gfk-play:active{transform:translateY(3px)}
.gfk-hint{font-size:.85rem;opacity:.75;margin:0}

/* Shared answer feedback. Across the learning games a choice is marked
   .right/.correct or .wrong and, until now, only changed colour. Putting the
   motion here means every one of them answers the child the same way: a warm
   little pop for right, a short head-shake for wrong — never a punishing one. */
.right,.correct{animation:gfk-yes .34s cubic-bezier(.2,1.5,.4,1)}
@keyframes gfk-yes{0%{transform:scale(1)}42%{transform:scale(1.16)}100%{transform:scale(1)}}
.wrong{animation:gfk-no .3s ease}
@keyframes gfk-no{0%,100%{transform:translateX(0)}25%{transform:translateX(-5px)}75%{transform:translateX(5px)}}
@media (prefers-reduced-motion:reduce){.right,.correct,.wrong{animation:none}}

/* Pause overlay (injected by player.js, so every game has one). Sits above the
   board but below a game's own win/lose overlays. */
.gfk-overlay.gfk-pause{z-index:8;background:rgba(6,8,20,.72);-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px)}
.gfk-play.gfk-ghost{background:rgba(255,255,255,.14);color:#fff;box-shadow:none;font-size:1.05rem;padding:11px 26px}

/* ---- Shared game controller -------------------------------------------
   One pad for every game that needs steering, instead of each game rolling
   its own. It reads as a single cross-shaped object rather than four loose
   squares, and it tints itself from the host game's palette (--gfk-accent /
   --gfk-glow), so one component serves 53 different colour schemes.
   Built by GFKPlayer.mountPad(). */
.gfk-pad{flex:0 0 auto;display:grid;justify-content:center;align-content:center;
  gap:5px;padding:6px 0 2px;touch-action:none;-webkit-user-select:none;user-select:none}
.gfk-pad.dpad{grid-template-columns:repeat(3,var(--pad-cell,62px));
  grid-template-rows:repeat(3,var(--pad-row,50px))}
.gfk-pad.lr{grid-template-columns:repeat(2,var(--pad-wide,116px));
  grid-template-rows:var(--pad-row,56px)}
.gfk-pad.actions{grid-auto-flow:column;grid-auto-columns:var(--pad-wide,96px);
  grid-template-rows:var(--pad-row,52px)}
.gfk-pad .sp{visibility:hidden;pointer-events:none}
.gfk-pad button{
  border:0;cursor:pointer;font:inherit;font-weight:800;font-size:1.35rem;line-height:1;
  color:var(--gfk-accent,#7be7ff);
  background:
    linear-gradient(180deg,rgba(255,255,255,.16),rgba(255,255,255,.05));
  border-radius:14px;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.28), 0 2px 0 rgba(0,0,0,.35);
  display:flex;align-items:center;justify-content:center;
  transition:transform .06s ease, box-shadow .06s ease, background .12s ease;
  -webkit-tap-highlight-color:transparent;touch-action:manipulation}
/* The cross: square off the edges that meet the hub so the four keys read as
   one piece, and round the outer corners. */
.gfk-pad.dpad .du{border-bottom-left-radius:6px;border-bottom-right-radius:6px}
.gfk-pad.dpad .dd{border-top-left-radius:6px;border-top-right-radius:6px}
.gfk-pad.dpad .dl{border-top-right-radius:6px;border-bottom-right-radius:6px}
.gfk-pad.dpad .dr{border-top-left-radius:6px;border-bottom-left-radius:6px}
.gfk-pad button.is-down,.gfk-pad button:active{
  transform:translateY(2px) scale(.97);
  background:linear-gradient(180deg,rgba(255,255,255,.26),rgba(255,255,255,.12));
  box-shadow:inset 0 1px 0 rgba(255,255,255,.2), 0 0 18px var(--gfk-glow,rgba(255,255,255,.35))}
.gfk-pad button.wide{font-size:1.05rem;letter-spacing:.02em}
/* Roomier keys where there's space; tighter on short screens so the pad never
   eats the play area. */
@media (min-height:760px){.gfk-pad.dpad{--pad-cell:70px;--pad-row:56px}}
@media (max-height:600px){.gfk-pad.dpad{--pad-cell:56px;--pad-row:46px;gap:4px}.gfk-pad button{font-size:1.15rem}}
/* On a tablet the pad is held by a bigger hand at a longer reach, so the keys
   grow with the short side rather than staying at their phone size. */
@media (min-width:540px) and (min-height:540px){
  .gfk-pad{gap:7px}
  /* Measured: the first tablet sizing (11vmin cells) took a third of the height
     and squeezed Maze's board down to 429px inside a 760px stage. The pad grows,
     but modestly — the board has first claim on the height. */
  .gfk-pad.dpad{--pad-cell:clamp(70px,8.5vmin,92px);--pad-row:clamp(56px,7vmin,76px)}
  .gfk-pad.lr{--pad-wide:clamp(116px,16vmin,168px);--pad-row:clamp(56px,7.5vmin,80px)}
  .gfk-pad.actions{--pad-wide:clamp(96px,14vmin,148px);--pad-row:clamp(52px,7vmin,74px)}
  .gfk-pad button{font-size:min(2.8vmin,1.7rem);border-radius:16px}
}

/* ---- Landscape: put the pad BESIDE the board, not under it ----------------
   Stacked vertically on a short screen the pad and the HUD leave almost nothing
   for the game: measured on a landscape phone, Maze's board came out 108x108 in
   a 335px-tall stage. Moving the pad to the side gives the height back to the
   board. Only applies when a pad is actually mounted (player.js adds the class),
   so games without one are untouched. */
@media (orientation:landscape) and (max-height:620px){
  .gfk-has-pad .gfk-stage{padding-right:calc(3 * var(--pad-cell,56px) + 26px)}
  .gfk-has-pad .gfk-pad{position:absolute;right:10px;bottom:14px;padding:0;z-index:3}
  .gfk-has-pad .gfk-pad.lr,.gfk-has-pad .gfk-pad.actions{right:50%;transform:translateX(50%);bottom:8px}
  .gfk-has-pad .gfk-stage .gfk-hud{max-width:100%}
}

/* Control hints adapt to the device: on a touch screen (the app + mobile web) we
   never mention arrow keys / WASD; on a mouse/desktop we hide the touch wording.
   Games wrap the relevant text in <span class="touch-only"> / <span class="kbd-only">. */
@media (pointer:coarse){.kbd-only{display:none!important}}
@media (pointer:fine){.touch-only{display:none!important}}
