/* Shell, tokens and shared controls. Room layouts live in rooms.css. */
/* Self-hosted Baloo 2 (display) and Nunito (text); relative URLs work at both / and /games/. */
@font-face {
  font-family: "Baloo 2";
  font-style: normal;
  font-weight: 700 800;
  font-display: swap;
  src: url("../assets/fonts/baloo-2-vn.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Baloo 2";
  font-style: normal;
  font-weight: 700 800;
  font-display: swap;
  src: url("../assets/fonts/baloo-2-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 900;
  font-display: swap;
  src: url("../assets/fonts/nunito-vn.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 900;
  font-display: swap;
  src: url("../assets/fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #FFFDF7;
  --ink: #1F2937;
  --ink-soft: #4B5563;
  --paper: #FFFFFF;
  --line: #E5E7EB;
  --night: #1E293B;
  --red: #EF4444;
  --yellow: #FACC15;
  --blue: #3B82F6;
  --green: #22C55E;
  --orange: #F97316;
  --purple: #A855F7;
  /* Fruit & vegetable world: wooden board, wicker, soil and leaves. */
  --wood: #E8B77A;
  --wood-dark: #92400E;
  --wicker: #F59E0B;
  --soil: #A16207;
  --leaf: #BBF7D0;

  /* Mirrors TUNING.edgeSafePx / targetGapPx / brickMinPx / brickMaxPx. */
  --edge-top: max(24px, env(safe-area-inset-top));
  --edge-right: max(24px, env(safe-area-inset-right));
  --edge-bottom: max(24px, env(safe-area-inset-bottom));
  --edge-left: max(24px, env(safe-area-inset-left));
  --touch-gap: 24px;
  --brick-min: 96px;
  --brick-max: 160px;
  --brick: clamp(var(--brick-min), 13vmin, var(--brick-max));
  --bar: 72px;
  --round: 24px;
  --hold-ms: 3000ms;
  --font-display: "Baloo 2", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Tablet: short side >= TUNING.tabletMinShortSidePx. */
@media (min-width: 600px) and (min-height: 600px) {
  :root { --brick-min: 128px; --bar: 80px; }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Parent gate and panel headings use the display face (their layout lives in rooms.css). */
.gate-title, .panel-title { font-family: var(--font-display); }

img, svg { display: block; -webkit-user-drag: none; }

button {
  font: inherit;
  color: inherit;
  margin: 0;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: none;
}

button:focus-visible { outline: 4px solid var(--blue); outline-offset: 4px; }

/* Press feedback on the first frame: onTap acts on pointerup, so :active is the
   only response at pointerdown. Instant (no transition); tray bricks keep their shadow. */
button[data-hit]:not(.piece):not(.food):active { filter: brightness(.92); }

[hidden] { display: none !important; }

.app { position: fixed; inset: 0; overflow: hidden; }
.stage { position: absolute; inset: 0; }

.room {
  position: absolute;
  inset: 0;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  overflow: hidden;
}

/* Round kid-sized icon button (home, shelf, next). */
.icon-btn {
  display: grid;
  place-items: center;
  width: var(--bar);
  height: var(--bar);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
}
.icon-btn svg { width: 58%; height: 58%; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }

/* Adult gate: a quiet lock that needs a 3 s hold, top-right inside the safe band. */
.lock {
  position: absolute;
  top: calc(var(--edge-top) + (var(--bar) - 56px) / 2);
  right: var(--edge-right);
  z-index: 20;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  color: #9CA3AF;
}
.lock > svg:first-child { width: 26px; height: 26px; }
.lock-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.lock-ring circle {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 3;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  stroke-linecap: round;
}
.lock.is-holding .lock-ring circle { stroke-dashoffset: 0; transition: stroke-dashoffset var(--hold-ms) linear; }
.app[data-room="rest"] .lock { background: rgba(255, 255, 255, .12); color: #94A3B8; }

.gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  background: rgba(31, 41, 55, .6);
}

/* Adult surfaces (gate card, Parent Panel) share these controls. */
.card {
  width: min(100%, 560px);
  max-height: 100%;
  overflow: auto;
  padding: 24px;
  border-radius: var(--round);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}

.btn {
  min-height: 52px;
  min-width: 52px;
  padding: 12px 20px;
  border-radius: 16px;
  background: #F3F4F6;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  touch-action: manipulation;
}
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn-primary { background: var(--blue); color: var(--paper); }
.btn-danger { background: #FEE2E2; color: #991B1B; }
.btn-danger.is-armed { background: #B91C1C; color: var(--paper); }

/* Time cue (last 5 minutes): wordless night cloud in the top band, between the kid
   button and the lock (≥ --touch-gap from both). Never takes a touch. Big for 6 s
   (.is-featured), then a badge (.is-badge) whose lit stars count the minutes left. */
.cue {
  position: absolute;
  z-index: 15;
  top: calc(var(--edge-top) + (var(--bar) - 52px) / 2);
  left: calc(var(--edge-left) + var(--bar) + var(--touch-gap));
  right: calc(var(--edge-right) + 56px + var(--touch-gap));
  width: 160px;
  height: 52px;
  margin-inline: auto;
  pointer-events: none;
  transform-origin: 50% 0;
  transition: transform .6s ease, opacity .6s ease;
}
.cue.is-featured { transform: translateY(var(--bar)) scale(1.7); animation: cue-in .5s ease-out 1; }
.cue-cloud { position: absolute; inset: 0; width: 100%; height: 100%; fill: var(--night); opacity: .92; }
.cue-row {
  position: absolute;
  inset: 12px 10px 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.cue-moon { flex: none; width: 28px; height: 28px; }
.cue-moon-body { fill: var(--yellow); }
.cue-moon-face { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.cue-stars { display: flex; gap: 2px; }
.cue-star { width: 12px; height: 12px; fill: #475569; stroke: #475569; stroke-width: 1.5; stroke-linejoin: round; transition: fill .6s ease, stroke .6s ease; }
.cue-star.is-lit { fill: var(--yellow); stroke: var(--yellow); }
/* The yawning pet joins at the 2-minute mark. */
.cue-pet { flex: none; width: 0; height: 26px; opacity: 0; transition: width .6s ease, opacity .6s ease; }
.cue[data-mark="2"] .cue-pet { width: 26px; opacity: 1; animation: cue-yawn 4s ease-in-out infinite; }
/* Sound has a second bar button (listen): where there is room, the badge starts after it. */
@media (min-width: 480px) {
  .app[data-room="sound"] .cue { left: calc(var(--edge-left) + 2 * var(--bar) + 2 * var(--touch-gap)); }
}
/* Home, the phone Zoo and narrow Sound have no free top band: the badge fades out there (the big cue still shows). */
.app[data-room="home"] .cue.is-badge { opacity: 0; }
@media not all and (min-width: 600px) and (min-height: 600px) {
  .app[data-room="zoo"] .cue.is-badge { opacity: 0; }
}
@media (max-width: 479px) {
  .app[data-room="sound"] .cue.is-badge { opacity: 0; }
}
/* Fruit & vegetable rooms: the badge starts after the bar buttons (3 in slice, harvest and market,
   2 in basket). Phones have no free top band there, so the badge fades out (the big cue still shows). */
.app[data-room="slice"] .cue, .app[data-room="harvest"] .cue, .app[data-room="market"] .cue {
  left: calc(var(--edge-left) + 3 * var(--bar) + 3 * var(--touch-gap));
}
.app[data-room="basket"] .cue { left: calc(var(--edge-left) + 2 * var(--bar) + 2 * var(--touch-gap)); }
@media not all and (min-width: 600px) and (min-height: 600px) {
  .app[data-room="slice"] .cue.is-badge, .app[data-room="harvest"] .cue.is-badge,
  .app[data-room="market"] .cue.is-badge, .app[data-room="basket"] .cue.is-badge { opacity: 0; }
}
@keyframes cue-in { from { opacity: 0; transform: translateY(var(--bar)) scale(1.2); } }
@keyframes cue-yawn { 0%, 80%, 100% { transform: scale(1); } 88% { transform: scale(1.06, .92); } }

/* Bar buttons in Home and the fruit & vegetable rooms meet the brick minimum (96 phone / 128 tablet). */
.app[data-room="slice"], .app[data-room="harvest"], .app[data-room="market"], .app[data-room="basket"] { --bar: var(--brick-min); }

/* Narrow phones: three --brick-min bar buttons and the lock do not fit in one row, so the
   "next" button docks in the bottom-right corner and the room keeps a band free for it. */
@media (max-width: 479px) {
  .room-slice, .room-harvest, .room-market { padding-bottom: calc(var(--edge-bottom) + var(--bar) + var(--touch-gap)); }
  .room-slice .bar-next, .room-harvest .bar-next, .room-market .bar-next {
    position: absolute;
    right: var(--edge-right);
    bottom: var(--edge-bottom);
  }
}

/* ?dev=1 → H shows hit areas and snap radii. */
.app.dev-hit [data-hit] { outline: 3px dashed var(--red); outline-offset: 0; }
.app.dev-hit .slot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--snap-r, 80px) * 2);
  height: calc(var(--snap-r, 80px) * 2);
  border: 2px dashed var(--purple);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.dev-badge {
  position: absolute;
  left: 50%;
  bottom: 4px;
  z-index: 40;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  transform: translateX(-50%);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
  /* Cue: big → badge and star changes switch at once. */
  .cue, .cue * { animation: none !important; transition: none !important; }
  /* Fruit & vegetable world: states switch at once (scripted flights are skipped in JS too). */
  .room-home .world-card, .room-home .world-card *, .room-home .games-produce, .room-home .games-produce *,
  .room-slice, .room-slice *, .room-harvest, .room-harvest *,
  .room-market, .room-market *, .room-basket, .room-basket * { animation: none !important; transition: none !important; }
}
