/* ======================================================================
   هيا نلعب ونتعلم — premium kids arcade, ages 3-6, Arabic-first RTL.
   One coherent world: deep twilight sky + aurora, glass cards, candy
   accents. CSS-only atmosphere; sprite art pops on the dark ground.
   ====================================================================== */
:root {
  --sky-top: #241b52;
  --sky-mid: #4a2f8f;
  --sky-glow: #b465d8;
  --dawn: #ff9e7d;
  --ink: #2b2d42;
  --white: #ffffff;
  --warm: #ffe8c9;
  --glass: rgba(255, 255, 255, 0.13);
  --glass-brd: rgba(255, 255, 255, 0.32);
  --shadow-deep: 0 18px 40px -12px rgba(15, 8, 52, 0.55);
  --shadow-soft: 0 8px 22px -8px rgba(15, 8, 52, 0.45);
  --r-lg: 30px;
  --r-md: 22px;
  --grad-letters: linear-gradient(135deg, #ff6b6b, #ff9e7d);
  --grad-memory: linear-gradient(135deg, #4cc9f0, #7c5cff);
  --grad-counting: linear-gradient(135deg, #ffd166, #ff9e7d);
  --grad-coloring: linear-gradient(135deg, #ff7ac6, #c77dff);
  --grad-shapes: linear-gradient(135deg, #06d6a0, #4cc9f0);
  --grad-maze: linear-gradient(135deg, #f9c74f, #90be6d);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: "Baloo Bhaijaan 2", "Baloo 2", "Segoe UI", sans-serif;
  color: var(--white);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 52%, var(--sky-glow) 82%, var(--dawn) 130%);
}
img { -webkit-user-drag: none; }

/* ------- the world: aurora blobs + drifting stars (CSS only) ------- */
body::before, body::after {
  content: ""; position: fixed; inset: -20%; z-index: 0; pointer-events: none;
}
body::before {
  background:
    radial-gradient(38% 30% at 18% 22%, rgba(124, 92, 255, 0.45), transparent 70%),
    radial-gradient(34% 28% at 84% 14%, rgba(76, 201, 240, 0.35), transparent 70%),
    radial-gradient(40% 34% at 70% 78%, rgba(255, 122, 198, 0.30), transparent 72%),
    radial-gradient(30% 26% at 24% 82%, rgba(255, 209, 102, 0.22), transparent 70%);
  filter: blur(10px);
  animation: aurora 26s ease-in-out infinite alternate;
}
body::after {
  background-image:
    radial-gradient(2.5px 2.5px at 12% 18%, #fff9, transparent 60%),
    radial-gradient(2px 2px at 32% 8%, #fff7, transparent 60%),
    radial-gradient(2px 2px at 55% 22%, #fff8, transparent 60%),
    radial-gradient(2.5px 2.5px at 76% 12%, #fff9, transparent 60%),
    radial-gradient(2px 2px at 90% 30%, #fff6, transparent 60%),
    radial-gradient(2px 2px at 44% 38%, #fff5, transparent 60%),
    radial-gradient(2.5px 2.5px at 8% 52%, #fff6, transparent 60%),
    radial-gradient(2px 2px at 68% 48%, #fff5, transparent 60%);
  animation: twinkle 7s ease-in-out infinite alternate;
}
@keyframes aurora { to { transform: translate3d(3%, 4%, 0) rotate(4deg) scale(1.08); } }
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.screen { position: fixed; inset: 0; display: none; flex-direction: column; z-index: 1; }
.screen.active { display: flex; }
.layer { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%; }

/* ---------------- top bar ---------------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; }
.btn-round {
  width: 68px; height: 68px; border-radius: 24px; border: 1px solid var(--glass-brd);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft); font-size: 30px; cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-round:active { transform: scale(0.9); }
.stars-chip {
  border: 1px solid var(--glass-brd); background: var(--glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 40px; box-shadow: var(--shadow-soft);
  padding: 8px 22px; font-size: 27px; font-weight: 700; color: var(--warm);
  display: flex; align-items: center; gap: 10px;
}
.game-title { font-size: 30px; font-weight: 800; color: var(--white); text-shadow: 0 2px 14px rgba(0,0,0,0.35); }

/* ---------------- hub ---------------- */
#hub .layer { align-items: center; }
.hub-head { display: flex; align-items: center; gap: 12px; margin-top: 0; }
.mascot { width: min(84px, 11vw); filter: drop-shadow(0 0 26px rgba(255, 214, 102, 0.55)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }
.hub-title {
  font-size: clamp(20px, 3vw, 32px); font-weight: 800;
  background: linear-gradient(90deg, #ffe8c9, #ffd166, #ffe8c9);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: none; filter: drop-shadow(0 3px 10px rgba(0,0,0,0.3));
}
.tiles {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(12px, 1.6vw, 20px);
  padding: 10px 24px 20px; width: 100%; max-width: 1240px; flex: 1;
  align-content: start; min-height: 0; overflow-y: auto;
}
@media (max-aspect-ratio: 1/1) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  border: 1px solid var(--glass-brd); border-radius: var(--r-lg);
  background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-deep); cursor: pointer; position: relative;
  padding: clamp(8px, 1.2vw, 14px) 12px 12px; min-height: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: rise 0.5s backwards;
}
.tile:nth-child(1) { animation-delay: 0.03s; } .tile:nth-child(2) { animation-delay: 0.09s; }
.tile:nth-child(3) { animation-delay: 0.15s; } .tile:nth-child(4) { animation-delay: 0.21s; }
.tile:nth-child(5) { animation-delay: 0.27s; } .tile:nth-child(6) { animation-delay: 0.33s; }
@keyframes rise { from { transform: translateY(26px); opacity: 0; } }
.tile:active { transform: scale(0.94); }
.tile-art {
  width: clamp(60px, min(8.5vw, 13vh), 96px); height: clamp(60px, min(8.5vw, 13vh), 96px);
  display: grid; place-items: center; position: relative; margin-top: -6px;
}
.tile-art::before {
  content: ""; position: absolute; inset: 6%; border-radius: 50%;
  background: var(--acc, var(--grad-letters)); opacity: 0.55; filter: blur(20px);
}
.tile-art img, .tile-art .glyph {
  position: relative; animation: bob 3.4s ease-in-out infinite;
}
.tile:nth-child(2) .tile-art img { animation-delay: 0.4s; }
.tile:nth-child(3) .tile-art img { animation-delay: 0.8s; }
.tile-art img { width: 92%; height: 92%; object-fit: contain; filter: drop-shadow(0 10px 14px rgba(10, 5, 40, 0.45)); }
.tile-art .glyph {
  font-size: clamp(38px, 5vw, 56px); font-weight: 800; color: #fff;
  line-height: 1; text-shadow: 0 8px 18px rgba(10, 5, 40, 0.5);
}
.tile-art svg { filter: drop-shadow(0 10px 14px rgba(10, 5, 40, 0.45)); animation: bob 3.4s ease-in-out infinite; }
.tile .name { font-size: clamp(18px, 2vw, 24px); font-weight: 800; color: var(--white); line-height: 1.05; }
.tile .hint { font-size: clamp(11px, 1.2vw, 13px); font-weight: 600; color: rgba(255, 255, 255, 0.75); }
.tile .chip {
  position: absolute; top: 12px; inset-inline-start: 12px; width: 34px; height: 10px;
  border-radius: 8px; background: var(--acc, var(--grad-letters));
}

/* ---------------- letter pop ---------------- */
#field { position: relative; flex: 1; }
.bubble {
  position: absolute; border: none; border-radius: 50%;
  transform: translate(-50%, -50%);
  width: clamp(112px, 16vw, 172px); height: clamp(112px, 16vw, 172px);
  font-family: inherit; font-size: clamp(48px, 8vw, 84px); font-weight: 800;
  color: #fff; cursor: pointer;
  background:
    radial-gradient(35% 35% at 30% 25%, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0) 70%),
    var(--bub, var(--grad-letters));
  box-shadow: inset 0 -10px 22px rgba(0, 0, 0, 0.18), var(--shadow-deep);
  display: grid; place-items: center; padding-bottom: 8px;
}
.bubble > span {
  display: block;
  animation: rise-in 0.45s calc(var(--i, 0) * 0.09s) backwards,
             floaty 3.2s ease-in-out calc(var(--i, 0) * 0.4s + 0.5s) infinite;
}
@keyframes rise-in { from { transform: scale(0.2); opacity: 0; } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
.bubble.pop { animation: popc 0.4s forwards; }
@keyframes popc { to { transform: translate(-50%, -50%) scale(1.7); opacity: 0; } }
.bubble.wrong { animation: wobblec 0.45s; }
@keyframes wobblec {
  0%,100% { transform: translate(-50%, -50%); }
  25% { transform: translate(calc(-50% - 10px), -50%); }
  75% { transform: translate(calc(-50% + 10px), -50%); }
}
.mode-toggle {
  border: 1px solid var(--glass-brd); border-radius: 40px; padding: 10px 24px;
  font-family: inherit; font-size: 22px; font-weight: 800; color: var(--white);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft); cursor: pointer;
}

/* ---------------- memory ---------------- */
#memgrid { flex: 1; display: grid; gap: 16px; padding: 14px 22px 26px; place-content: center; }
.mcard { perspective: 700px; border: none; background: none; padding: 0; cursor: pointer;
  width: var(--msize, 150px); height: var(--msize, 150px); }
.mcard-inner { position: relative; width: 100%; height: 100%;
  transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1); transform-style: preserve-3d; }
.mcard.flipped .mcard-inner { transform: rotateY(180deg); }
.mface { position: absolute; inset: 0; border-radius: 24px; backface-visibility: hidden;
  display: grid; place-items: center; box-shadow: var(--shadow-soft); }
.mface.front {
  background: radial-gradient(40% 40% at 30% 25%, rgba(255,255,255,0.35), transparent 70%), var(--grad-memory);
  font-size: 52px; color: #fff; font-weight: 800;
  border: 1px solid var(--glass-brd);
}
.mface.back { background: #fffdf7; transform: rotateY(180deg); padding: 12px; }
.mface.back img { width: 100%; height: 100%; object-fit: contain; }
.mcard.matched { animation: matched 0.5s; pointer-events: none; }
.mcard.matched .mface.back { box-shadow: 0 0 0 4px #ffd166, var(--shadow-soft); }
@keyframes matched { 50% { transform: scale(1.15); } }

/* ---------------- counting ---------------- */
#countfield { position: relative; flex: 1; }
.countable { position: absolute; border: none; background: none; padding: 0; cursor: pointer;
  width: clamp(92px, 13vw, 150px); height: clamp(92px, 13vw, 150px); }
.countable img { width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(10, 5, 40, 0.5)); }
.countable.counted { pointer-events: none; }
.countable.counted img { animation: matched 0.4s; }
.count-badge {
  position: absolute; top: -10px; inset-inline-start: -10px; width: 46px; height: 46px;
  background: var(--grad-counting); color: var(--ink); border-radius: 50%;
  display: grid; place-items: center; font-size: 25px; font-weight: 800;
  box-shadow: var(--shadow-soft);
}
#numchoices { display: flex; justify-content: center; gap: 24px; padding: 12px 0 28px; min-height: 132px; }
.numchoice {
  width: 106px; height: 106px; border-radius: 50%;
  border: 1px solid var(--glass-brd);
  background: radial-gradient(38% 38% at 30% 25%, rgba(255,255,255,0.5), transparent 70%), var(--grad-counting);
  box-shadow: var(--shadow-deep); font-family: inherit;
  font-size: 50px; font-weight: 800; color: var(--ink); cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.numchoice:active { transform: scale(0.9); }

/* ---------------- coloring ---------------- */
#colwrap { flex: 1; display: flex; gap: 14px; padding: 0 16px 16px; min-height: 0; }
#colcanvas-box {
  flex: 1; background: #fffdf7; border-radius: var(--r-lg);
  box-shadow: var(--shadow-deep); display: grid; place-items: center; min-width: 0;
}
#colcanvas { max-width: 100%; max-height: 100%; border-radius: var(--r-lg); cursor: pointer; }
#palette { display: flex; flex-direction: column; flex-wrap: wrap; gap: 12px;
  justify-content: center; align-content: center; padding: 6px; }
.swatch { width: 60px; height: 60px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.85);
  box-shadow: var(--shadow-soft); cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1); }
.swatch.sel { border-color: #ffd166; transform: scale(1.16); }
#colpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 14px; padding: 14px 22px 24px; overflow-y: auto; flex: 1; }
#colpick button {
  border: 1px solid var(--glass-brd); background: rgba(255, 253, 247, 0.92);
  border-radius: var(--r-md); box-shadow: var(--shadow-soft); padding: 10px; cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#colpick button:active { transform: scale(0.93); }
#colpick img { width: 100%; aspect-ratio: 1; object-fit: contain; }

/* ---------------- shapes ---------------- */
#shapeboard { position: relative; flex: 1; }
.socket { position: absolute; opacity: 0.95; }
.piece { position: absolute; cursor: grab; touch-action: none;
  filter: drop-shadow(0 10px 12px rgba(10, 5, 40, 0.5)); z-index: 3; }
.piece.placed { cursor: default; filter: none; z-index: 1; }

/* ---------------- maze ---------------- */
#mazebox { flex: 1; display: grid; place-items: center; padding: 6px 16px 20px; min-height: 0; }
#mazecanvas { background: #fffdf7; border-radius: 24px; box-shadow: var(--shadow-deep);
  touch-action: none; max-width: 100%; max-height: 100%; }

/* ---------------- overlays ---------------- */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#bigstar { position: fixed; inset: 0; display: none; place-items: center; z-index: 40;
  font-size: 130px; pointer-events: none; }
#bigstar.show { display: grid; animation: starfly 1s forwards; }
@keyframes starfly {
  0% { transform: scale(0.2); opacity: 0; }
  40% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.6) translateY(-38vh); opacity: 0; }
}
.celebrate-img { position: fixed; inset: 0; margin: auto; width: min(70vmin, 480px);
  z-index: 30; display: none; pointer-events: none; }
.celebrate-img.show { display: block; animation: matched 0.8s; }

/* ---------------- v2: gradients ---------------- */
:root {
  --grad-colors: linear-gradient(135deg, #e63946, #ffd60a 45%, #3a86ff);
  --grad-feelings: linear-gradient(135deg, #ffd166, #ff7ac6);
  --grad-tidy: linear-gradient(135deg, #06d6a0, #90be6d);
  --grad-routine: linear-gradient(135deg, #4cc9f0, #3a86ff);
}

/* ---------------- colors game ---------------- */
#colorfield { position: relative; flex: 1; }
.splat {
  position: absolute; border: none; background: none; padding: 0; cursor: pointer;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 10px 14px rgba(10, 5, 40, 0.45));
}
.splat svg {
  display: block;
  animation: rise-in 0.45s calc(var(--i, 0) * 0.09s) backwards,
             floaty 3.4s ease-in-out calc(var(--i, 0) * 0.4s + 0.5s) infinite;
}
.splat.pop { animation: popc 0.4s forwards; }
.splat.wrong { animation: wobblec 0.45s; }

/* ---------------- feelings ---------------- */
#feelfield {
  flex: 1; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: clamp(12px, 2vw, 26px); padding: 16px 26px 26px; place-content: center;
}
@media (max-aspect-ratio: 1/1) { #feelfield { grid-template-columns: repeat(2, 1fr); } }
.feel-card {
  border: 1px solid var(--glass-brd); border-radius: var(--r-lg);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-deep); cursor: pointer; padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: inherit; color: var(--white);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.feel-card:active { transform: scale(0.93); }
.feel-card img { width: clamp(90px, 14vw, 170px); height: clamp(90px, 14vw, 170px); object-fit: contain; }
.feel-card span { font-size: clamp(20px, 2.4vw, 28px); font-weight: 800; }
.feel-card small { font-size: clamp(12px, 1.4vw, 16px); color: rgba(255,255,255,0.75); font-weight: 600; }
.feel-card.win { animation: matched 0.5s; box-shadow: 0 0 0 4px #ffd166, var(--shadow-deep); }
.feel-card.wrong { animation: wobble 0.45s; }

/* ---------------- tidy up ---------------- */
#tidyboard { position: relative; flex: 1; }
.home {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 10px 8px 8px; border-radius: var(--r-md);
  border: 2px dashed rgba(255, 255, 255, 0.45); background: rgba(255, 255, 255, 0.07);
}
.home img { width: 72%; aspect-ratio: 1; object-fit: contain; }
.home span { font-size: clamp(13px, 1.5vw, 17px); font-weight: 700; color: var(--white); }
.home.glow { border-color: #ffd166; box-shadow: 0 0 26px rgba(255, 209, 102, 0.6); }
.tidy-item {
  position: absolute; cursor: grab; touch-action: none; z-index: 3;
  filter: drop-shadow(0 10px 12px rgba(10, 5, 40, 0.5));
}
.tidy-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.tidy-item.done { cursor: default; filter: none; }

/* ---------------- routine ---------------- */
#routine-title {
  text-align: center; font-size: clamp(22px, 3vw, 32px); font-weight: 800;
  color: var(--warm); padding: 2px 0 6px;
}
#routinefield {
  flex: 1; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: clamp(12px, 2vw, 26px); padding: 6px 26px 26px; place-content: center;
}
@media (max-aspect-ratio: 1/1) { #routinefield { grid-template-columns: repeat(2, 1fr); } }
.routine-card {
  position: relative;
  border: 1px solid var(--glass-brd); border-radius: var(--r-lg);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-deep); cursor: pointer; padding: 16px 10px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: inherit; color: var(--white);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.routine-card:active { transform: scale(0.93); }
.routine-card img { width: clamp(80px, 12vw, 150px); height: clamp(80px, 12vw, 150px); object-fit: contain; }
.routine-card span:not(.badge) { font-size: clamp(17px, 2vw, 24px); font-weight: 800; }
.routine-card .badge {
  position: absolute; top: -14px; inset-inline-start: -14px; width: 52px; height: 52px;
  border-radius: 50%; background: var(--grad-counting); color: var(--ink);
  display: grid; place-items: center; font-size: 26px; font-weight: 800;
  box-shadow: var(--shadow-soft); opacity: 0; transform: scale(0.4);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.routine-card.done { box-shadow: 0 0 0 4px #ffd166, var(--shadow-deep); }
.routine-card.done .badge { opacity: 1; transform: scale(1); }
.routine-card.wrong { animation: wobble 0.45s; }

/* ================= PREMIUM GAME CHROME (v3 polish) ================= */
.topbar { position: relative; min-height: 88px; z-index: 2; }
.game-title {
  position: absolute; inset-inline: 0; top: 50%; transform: translateY(-50%);
  text-align: center; pointer-events: none;
}
.game-title::after {
  content: ""; display: block; width: 64px; height: 6px; border-radius: 6px;
  margin: 3px auto 0; background: var(--acc, var(--grad-letters));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* framed glass stage for every play area */
#field, #colorfield, #countfield, #shapeboard, #tidyboard {
  position: relative; flex: 1; min-height: 0;
  margin: 0 18px 16px; border-radius: var(--r-lg);
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.055);
  box-shadow: inset 0 2px 22px rgba(10, 5, 40, 0.28);
}
#memgrid, #feelfield, #routinefield, #colpick { margin: 0 18px 16px; }
#countfield.dim { opacity: 0.4; filter: saturate(0.6); transition: opacity 0.4s, filter 0.4s; }

/* memory: mascot-watermarked identical backs + richer flip */
.mface.front { overflow: hidden; }
.mface.front::before {
  content: ""; position: absolute; inset: 7px; border-radius: 16px;
  border: 2px dashed rgba(255, 255, 255, 0.4);
}
.mface.front::after {
  content: ""; position: absolute; inset: 16%;
  background: url("../assets/art/mascot.png") center/contain no-repeat;
  opacity: 0.3; filter: saturate(0.4) brightness(1.5);
}
.mface.front { font-size: 0; }              /* watermark replaces the ؟ */
.mface.back { border: 4px solid #fff; }

/* board + tray zones for drag games (inserted by JS) */
.zone {
  position: absolute; inset-inline: 12px; border-radius: 20px;
  border: 1.5px dashed rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.045); pointer-events: none;
}

/* counting choices: glass dock */
#numchoices {
  margin: 0 auto 18px; padding: 12px 26px; border-radius: 60px; width: max-content;
  border: 1px solid var(--glass-brd); background: var(--glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-deep); min-height: 0;
}
#numchoices:empty { display: none; }

/* coloring: warm canvas + tactile palette + lifted picker */
#colcanvas-box { background: #fffaf4; box-shadow: inset 0 2px 16px rgba(90, 60, 20, 0.12), var(--shadow-deep); }
#colcanvas { background: #fffaf4; }
.swatch { position: relative; transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.15s; }
.swatch.sel { border-color: #ffd166; box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.45), var(--shadow-soft); }
#colpick button { background: rgba(255, 253, 247, 0.95); }
#colpick button:hover { transform: translateY(-3px); box-shadow: 0 12px 26px -10px rgba(10, 5, 40, 0.6); }

/* maze: warm parchment board */
#mazecanvas { background: #fffaf4; border: 1px solid rgba(255, 255, 255, 0.4); }

/* card entrances for feelings/routine */
.feel-card, .routine-card { animation: rise 0.45s backwards; }
.feel-card:nth-child(1), .routine-card:nth-child(1) { animation-delay: 0.03s; }
.feel-card:nth-child(2), .routine-card:nth-child(2) { animation-delay: 0.1s; }
.feel-card:nth-child(3), .routine-card:nth-child(3) { animation-delay: 0.17s; }
.feel-card:nth-child(4), .routine-card:nth-child(4) { animation-delay: 0.24s; }

/* countables get a soft entrance too */
.countable img { animation: rise-in 0.4s calc(var(--i, 0) * 0.07s) backwards; }

/* ================= MOBILE (phones & small tablets) ================= */
.layer { padding-bottom: env(safe-area-inset-bottom, 0px); }

@media (max-width: 700px) {
  /* chrome: compact glass bar; the title joins the flex row so nothing collides */
  .topbar { min-height: 58px; padding: 8px 10px; gap: 8px; }
  .btn-round { width: 50px; height: 50px; border-radius: 17px; font-size: 22px; }
  .stars-chip { padding: 4px 12px; font-size: 17px; gap: 6px; border-radius: 30px; }
  .game-title { position: static; transform: none; flex: 1 1 auto; min-width: 0; font-size: 18px; line-height: 1.1; }
  .game-title::after { width: 40px; height: 4px; margin-top: 2px; }
  .mode-toggle { padding: 6px 12px; font-size: 15px; border-radius: 30px; }

  /* hub */
  .hub-head { gap: 8px; }
  .mascot { width: 48px; }
  .hub-title { font-size: 22px; }
  .tiles { gap: 10px; padding: 8px 12px 18px; }
  .tile { border-radius: 24px; padding: 12px 8px; gap: 3px; }
  .tile-art { width: 62px; height: 62px; margin-top: 0; }
  .tile-art .glyph { font-size: 34px; }
  .tile .name { font-size: 19px; }
  .tile .hint { font-size: 11px; line-height: 1.25; }
  .tile .chip { top: 10px; inset-inline-start: 12px; width: 26px; height: 8px; }

  /* stages hug the phone edges */
  #field, #colorfield, #countfield, #shapeboard, #tidyboard { margin: 0 10px 12px; border-radius: 24px; }
  #memgrid, #feelfield, #routinefield, #colpick { margin: 0 10px 12px; }
  .zone { inset-inline: 8px; }

  /* letters */
  .bubble {
    width: clamp(92px, 25vw, 172px); height: clamp(92px, 25vw, 172px);
    font-size: clamp(40px, 11vw, 84px);
  }

  /* counting */
  .countable { width: clamp(74px, 19vw, 150px); height: clamp(74px, 19vw, 150px); }
  .count-badge { width: 34px; height: 34px; font-size: 18px; top: -8px; inset-inline-start: -8px; }
  #numchoices { gap: 14px; padding: 10px 16px; margin-bottom: 12px; max-width: calc(100% - 20px); }
  .numchoice { width: clamp(68px, 20vw, 106px); height: clamp(68px, 20vw, 106px); font-size: clamp(32px, 9vw, 50px); }

  /* memory */
  #memgrid { gap: 10px; padding: 10px 12px 16px; }

  /* coloring */
  .swatch { width: 44px; height: 44px; border-width: 3px; }
  #colpick { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; padding: 10px 12px 18px; }

  /* feelings / routine / tidy */
  #feelfield, #routinefield { gap: 10px; padding: 10px 4px 14px; }
  .feel-card img { width: clamp(76px, 22vw, 170px); height: clamp(76px, 22vw, 170px); }
  .routine-card img { width: clamp(70px, 20vw, 150px); height: clamp(70px, 20vw, 150px); }
  .routine-card .badge { width: 42px; height: 42px; font-size: 21px; top: -10px; inset-inline-start: -10px; }
  #routine-title { font-size: 20px; }
  .home span { font-size: 14px; }

  #bigstar { font-size: 96px; }
}

/* portrait tablets: the centered-absolute title collides with the toggle row —
   let it join the flex row there too (phones already do this above) */
@media (min-width: 701px) and (max-width: 1080px) and (max-aspect-ratio: 1/1) {
  .game-title { position: static; transform: none; flex: 1 1 auto; min-width: 0; font-size: 26px; line-height: 1.1; }
}

/* portrait: the coloring palette moves under the canvas as a tap row */
@media (max-aspect-ratio: 1/1) {
  #colwrap { flex-direction: column; gap: 10px; padding: 0 10px 12px; }
  #palette { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 2px 0 0; gap: 10px; }
}
