/* Paint World — light, round, and forgiving.
   Layout rules that matter for toddlers:
   • No tap target under 56px (48px only on very small phones).
   • Nothing important within 12px of a screen edge (thumbs live there).
   • No red, no X, no timers, no locks anywhere in this file. */

:root {
  --ink: #4a4260;
  --ink-soft: #7d7392;
  --paper: #fffdf9;
  --sky-1: #d9f2ff;
  --sky-2: #ffeaf4;
  --sky-3: #fff6d9;
  --accent: #ff8fb8;
  --accent-2: #7fd8ff;
  --sun: #ffd93d;
  --shadow: 0 8px 0 rgba(74, 66, 96, 0.14), 0 14px 28px rgba(74, 66, 96, 0.14);
  --round: 26px;
  --font: 'Baloo 2', 'Chalkboard SE', 'Comic Sans MS', 'Marker Felt', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: var(--sky-1);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* The 2D colouring view sits ABOVE the 3D canvas but never takes input:
   #scene stays the one owner of every pointer event and its NDC space. */
#scene2d {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  pointer-events: none;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------------ top bar */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

.round {
  width: 60px; height: 60px; flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 5px 0 rgba(74, 66, 96, 0.16), 0 8px 18px rgba(74, 66, 96, 0.12);
  font-size: 30px; line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.round:active { transform: translateY(4px) scale(0.96); box-shadow: 0 1px 0 rgba(74, 66, 96, 0.16); }

#stage-title {
  flex: 1 1 auto; min-width: 0;
  font-size: clamp(20px, 4.6vw, 30px); font-weight: 700;
  text-align: center;
  color: var(--ink);
  text-shadow: 0 2px 0 #fff, 0 0 14px rgba(255, 255, 255, 0.85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#progress {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  width: min(46vw, 260px); height: 16px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 2px 5px rgba(74, 66, 96, 0.14);
  overflow: hidden;
}
#progress-fill {
  height: 100%; width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ffd93d, #ff9a3c 35%, #ff7bc5 65%, #a86be8);
  transition: width 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* ------------------------------------------------------------- speech bubble */
#toast {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(0);
  top: calc(max(12px, env(safe-area-inset-top)) + 88px);
  max-width: min(84vw, 460px);
  padding: 12px 22px;
  background: var(--paper);
  border-radius: 99px;
  box-shadow: var(--shadow);
  font-size: clamp(17px, 3.6vw, 22px); font-weight: 600;
  text-align: center;
  animation: bubble-in 0.42s cubic-bezier(0.2, 1.5, 0.5, 1) both;
  pointer-events: none;
  z-index: 6;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ----------------------------------------------------------------- paint bar */
#bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 12px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255, 253, 249, 0) 0%, rgba(255, 253, 249, 0.92) 42%, #fffdf9 100%);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

#tools { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.tool {
  width: 64px; height: 64px;
  border: 4px solid transparent; border-radius: 22px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(74, 66, 96, 0.14), 0 8px 16px rgba(74, 66, 96, 0.1);
  font-size: 30px; line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.14s ease, border-color 0.14s ease;
}
.tool:active { transform: translateY(4px) scale(0.95); }
.tool.on {
  border-color: var(--accent);
  background: #fff4f9;
  transform: translateY(-3px) scale(1.06);
}

#colors {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  max-width: 780px;
}

.swatch {
  width: 58px; height: 58px;
  border: 5px solid #fff; border-radius: 50%;
  box-shadow: 0 5px 0 rgba(74, 66, 96, 0.18), 0 8px 16px rgba(74, 66, 96, 0.12);
  cursor: pointer;
  padding: 0;
  transition: transform 0.14s cubic-bezier(0.34, 1.5, 0.64, 1), border-color 0.14s ease;
}
.swatch:active { transform: translateY(4px) scale(0.94); }
.swatch.on {
  transform: translateY(-6px) scale(1.16);
  border-color: var(--ink);
}

/* ------------------------------------------------------------------- screens */
.screen {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 90% at 50% 0%, var(--sky-3) 0%, var(--sky-2) 45%, var(--sky-1) 100%);
  overflow: hidden;
}
.screen.see-through {
  background: none;
  justify-content: space-between;
  pointer-events: none;
}
.screen.see-through > * { pointer-events: auto; }

.logo {
  margin: 0;
  font-size: clamp(52px, 15vw, 116px);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: -1px;
  text-align: center;
  color: var(--accent);
  text-shadow: 0 6px 0 #fff, 0 10px 0 rgba(74, 66, 96, 0.12);
  animation: bob 3.4s ease-in-out infinite;
}
.logo span { display: block; color: var(--accent-2); }
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50% { transform: translateY(-14px) rotate(1.2deg); }
}

.sub { margin: 0; font-size: clamp(18px, 4.4vw, 26px); color: var(--ink-soft); font-weight: 600; }

.big {
  border: none; cursor: pointer;
  padding: 20px 44px;
  min-height: 72px;
  border-radius: 99px;
  font-family: var(--font);
  font-size: clamp(21px, 5vw, 30px); font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ffa5c6, #ff7bb0);
  box-shadow: 0 8px 0 #e05e93, 0 16px 26px rgba(224, 94, 147, 0.32);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  animation: pulse 2.6s ease-in-out infinite;
}
.big:active { transform: translateY(7px); box-shadow: 0 1px 0 #e05e93; }
.big.soft {
  background: linear-gradient(180deg, #ffffff, #f2f6ff);
  color: var(--ink);
  box-shadow: 0 8px 0 #cdd7ea, 0 14px 22px rgba(74, 66, 96, 0.16);
  animation: none;
}
.big.soft:active { box-shadow: 0 1px 0 #cdd7ea; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.screen-title {
  margin: 0;
  font-size: clamp(28px, 6.6vw, 46px); font-weight: 800;
  color: var(--ink);
  text-shadow: 0 3px 0 #fff;
}

/* soft floating blobs behind the title screen */
.blobs { position: absolute; inset: 0; z-index: -1; }
.blobs::before, .blobs::after {
  content: ''; position: absolute; border-radius: 50%; filter: blur(2px); opacity: 0.55;
}
.blobs::before {
  width: 44vmin; height: 44vmin; left: -12vmin; top: 8vmin;
  background: #ffe08a; animation: drift 15s ease-in-out infinite;
}
.blobs::after {
  width: 52vmin; height: 52vmin; right: -14vmin; bottom: -8vmin;
  background: #a8e6ff; animation: drift 19s ease-in-out infinite reverse;
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(6vmin, -5vmin) scale(1.12); }
}

/* ------------------------------------------------------------- stage picker */
#mode-toggle {
  display: flex; gap: 8px;
  padding: 7px;
  background: rgba(255, 255, 255, 0.62);
  border-radius: 99px;
  box-shadow: inset 0 2px 6px rgba(74, 66, 96, 0.12);
}

.mode-btn {
  min-width: 116px; min-height: 60px;
  border: 4px solid transparent; border-radius: 99px;
  background: transparent;
  font-family: var(--font);
  font-size: clamp(19px, 4vw, 24px); font-weight: 800;
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.34, 1.5, 0.64, 1), background 0.14s ease;
}
.mode-btn.on {
  background: #fff;
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(74, 66, 96, 0.14), 0 8px 16px rgba(74, 66, 96, 0.1);
  transform: translateY(-2px);
}
.mode-btn:active { transform: translateY(3px) scale(0.96); }

/* 2D cards show the actual line art on a little paper tile. */
.card .thumb {
  width: 100%; height: clamp(66px, 13vw, 96px);
  background-color: #fff;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px rgba(74, 66, 96, 0.08);
}

#stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 16px;
  width: min(94vw, 880px);
  max-height: 72vh;
  overflow-y: auto;
  padding: 6px;
  touch-action: pan-y;
}

.card {
  border: none; cursor: pointer;
  background: var(--paper);
  border-radius: var(--round);
  padding: 18px 12px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 7px 0 rgba(74, 66, 96, 0.14), 0 12px 22px rgba(74, 66, 96, 0.12);
  transition: transform 0.14s cubic-bezier(0.34, 1.5, 0.64, 1);
  font-family: var(--font);
}
.card:active { transform: translateY(6px) scale(0.97); }
.card .emoji { font-size: clamp(46px, 9vw, 66px); line-height: 1; }
.card .name { font-size: clamp(15px, 3.2vw, 19px); font-weight: 700; color: var(--ink); }
.card .card-stars { font-size: 17px; letter-spacing: 2px; min-height: 22px; color: var(--sun); }

/* --------------------------------------------------------------- celebration */
.done-banner {
  margin-top: max(10px, env(safe-area-inset-top));
  background: rgba(255, 253, 249, 0.94);
  border-radius: var(--round);
  padding: 14px 34px 18px;
  text-align: center;
  box-shadow: var(--shadow);
  /* NOT bubble-in: that keyframe carries translateX(-50%) for the absolutely
     positioned toast, which drags this flex-centred banner half its own width
     to the left. */
  animation: pop-in 0.5s cubic-bezier(0.2, 1.5, 0.5, 1) both;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.8); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.done-title { font-size: clamp(26px, 6vw, 40px); font-weight: 800; }
.stars { font-size: clamp(34px, 8vw, 52px); letter-spacing: 6px; line-height: 1.1; }
.stars span {
  display: inline-block;
  animation: star-pop 0.6s cubic-bezier(0.2, 1.7, 0.5, 1) both;
}
.stars span:nth-child(2) { animation-delay: 0.18s; }
.stars span:nth-child(3) { animation-delay: 0.36s; }
@keyframes star-pop {
  from { opacity: 0; transform: scale(0.2) rotate(-40deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.done-buttons {
  margin-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
}
.done-buttons .big { padding: 18px 30px; min-height: 68px; }

/* ------------------------------------------------------------- boot watchdog */
#boot-error {
  position: absolute; inset: 0; z-index: 99;
  background: #fffdf9; color: var(--ink);
  padding: 28px; overflow: auto;
  font-family: var(--font);
}
#boot-error pre {
  white-space: pre-wrap; background: #fff0f4; padding: 14px;
  border-radius: 14px; font-size: 14px; font-family: ui-monospace, monospace;
}
#boot-error .hint { color: var(--ink-soft); font-size: 16px; line-height: 1.5; }
#boot-error code { background: #eef4ff; padding: 2px 7px; border-radius: 7px; }

/* --------------------------------------------------------------- small phones */
@media (max-width: 430px) {
  .swatch { width: 46px; height: 46px; border-width: 4px; }
  .tool { width: 56px; height: 56px; font-size: 26px; border-radius: 18px; }
  #colors { gap: 8px; }
  .round { width: 52px; height: 52px; font-size: 26px; }
  #bottom { gap: 9px; padding-top: 10px; }
}

@media (max-height: 560px) {
  #progress { display: none; }
  .logo { font-size: clamp(40px, 11vw, 64px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
