:root {
  --sun: #ffd166;
  --sun-2: #ffe8a8;
  --berry: #ef476f;
  --sea: #118ab2;
  --mint: #06d6a0;
  --ink: #2b2d42;
  --paper: #fffaf0;
  --soft: rgba(43, 45, 66, 0.65);
  --shadow: 0 6px 0 rgba(43, 45, 66, 0.18);
  --font: 'Baloo 2', ui-rounded, 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--sun-2);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.55) 0 22px, transparent 23px),
    radial-gradient(circle at 82% 8%, rgba(255,255,255,.45) 0 34px, transparent 35px),
    radial-gradient(circle at 70% 88%, rgba(239,71,111,.12) 0 60px, transparent 61px),
    linear-gradient(160deg, var(--sun-2), var(--sun));
  background-attachment: fixed;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; }
[hidden] { display: none !important; }

/* ---------- screens ---------- */
.screen { display: none; min-height: 100%; padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b)); max-width: 620px; margin: 0 auto; }
body[data-screen="home"] #home,
body[data-screen="draw"] #draw,
body[data-screen="review"] #review { display: block; }
#stage, #cam, #hud { display: none; }
body[data-screen="play"] { overflow: hidden; background: #a9d6e5; }
body[data-screen="play"] #stage { display: block; }
body[data-screen="play"] #hud { display: block; }
body[data-screen="play"][data-mode="camera"] #cam:not([hidden]) { display: block; }
#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; z-index: 1; }
#cam { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; object-fit: cover; z-index: 0; background: #000; }
body[data-screen="play"][data-mode="room"] { background: linear-gradient(#cdeaf5, #a9d6e5); }

/* ---------- home ---------- */
.hero { text-align: center; margin: 8px 0 18px; }
.hero h1 { margin: 0; font-size: clamp(54px, 15vw, 84px); line-height: .9; font-weight: 800; letter-spacing: -1px; }
.hero h1 .d { color: var(--berry); display: inline-block; transform: rotate(-4deg); text-shadow: 0 5px 0 rgba(43,45,66,.15); }
.hero h1 .z { color: var(--sea); display: inline-block; transform: rotate(3deg) translateY(4px); margin-left: 6px; text-shadow: 0 5px 0 rgba(43,45,66,.15); }
.hero p { margin: 10px 0 0; font-size: 20px; font-weight: 700; color: var(--soft); }

.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-btn {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  padding: 18px 10px 16px; border-radius: 26px; background: #fff; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .12s; font-size: 16px; user-select: none;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(43,45,66,.18); }
.big-btn .ico { font-size: 48px; line-height: 1.1; }
.big-btn b { font-size: 21px; line-height: 1.1; }
.big-btn small { color: var(--soft); font-size: 14px; line-height: 1.2; font-weight: 500; }
.big-btn.scan b { color: var(--berry); }
.big-btn.draw b { color: var(--sea); }

.samples { margin: 18px 0 8px; text-align: center; font-weight: 700; color: var(--soft); }
#sample-row { display: flex; justify-content: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
#sample-row button { width: 58px; height: 58px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); font-size: 30px; }
#sample-row button:active { transform: translateY(3px); }

.zoo-list { margin-top: 22px; background: rgba(255,255,255,.6); border-radius: 26px; padding: 14px; }
.zoo-list h2 { margin: 0 0 8px; font-size: 24px; }
.zoo-list h2 small { color: var(--soft); font-size: 16px; }
#zoo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 12px; }
.zoo-card { position: relative; background: #fff; border-radius: 18px; padding: 8px 6px 6px; text-align: center; box-shadow: 0 3px 0 rgba(43,45,66,.12); }
.zoo-card img { width: 100%; height: 72px; object-fit: contain; display: block; }
.zoo-card b { display: block; font-size: 14px; line-height: 1.1; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoo-card small { font-size: 12px; color: var(--soft); }
.zoo-card .del { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; line-height: 26px; padding: 0; }

.parents { margin-top: 22px; background: rgba(255,255,255,.55); border-radius: 20px; padding: 10px 16px; font-size: 15px; line-height: 1.4; }
.parents summary { font-weight: 800; cursor: pointer; }
.parents ol { padding-left: 20px; }
.parents li { margin-bottom: 6px; }

.go-btn {
  display: block; width: 100%; margin-top: 14px; padding: 14px; border-radius: 22px;
  background: var(--berry); color: #fff; font-size: 23px; font-weight: 800; box-shadow: 0 6px 0 #b8304f;
}
.go-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8304f; }
.go-btn.small { font-size: 18px; padding: 10px; }
.icon-btn { width: 46px; height: 46px; border-radius: 16px; background: #fff; font-size: 22px; box-shadow: 0 4px 0 rgba(43,45,66,.18); flex-shrink: 0; }
.pill-btn { padding: 8px 14px; border-radius: 999px; background: #fff; font-size: 16px; font-weight: 700; box-shadow: 0 4px 0 rgba(43,45,66,.15); }
.pill-btn.on { background: var(--mint); color: #fff; }

/* ---------- draw ---------- */
.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; font-weight: 800; font-size: 18px; line-height: 1.2; }
.pad-wrap { background: #fff; border-radius: 22px; padding: 6px; box-shadow: var(--shadow); }
#pad { display: block; width: 100%; aspect-ratio: 4 / 3; border-radius: 16px; touch-action: none; background: #fff; }
.tools { margin-top: 12px; }
#swatches, .swatches { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#swatches button, .swatches button { width: 38px; height: 38px; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), 0 2px 0 rgba(0,0,0,.15); border: 3px solid #fff; }
#swatches button.on, .swatches button.on { transform: scale(1.18); outline: 3px solid var(--ink); }
.tool-row { display: flex; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tool { width: 46px; height: 46px; border-radius: 14px; background: #fff; font-size: 22px; box-shadow: 0 3px 0 rgba(43,45,66,.15); display: grid; place-items: center; }
.tool.on { background: var(--sea); }
.tool.size i { display: block; width: var(--s); height: var(--s); border-radius: 50%; background: var(--ink); }
.tool.size.on i { background: #fff; }

/* ---------- review ---------- */
.review-card { background: #fff; border-radius: 26px; padding: 8px; box-shadow: var(--shadow); }
#review-canvas { display: block; width: 100%; border-radius: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.chip { padding: 4px 12px; border-radius: 999px; background: #fff; font-weight: 700; font-size: 15px; box-shadow: 0 2px 0 rgba(43,45,66,.12); }
.moves { text-align: center; font-size: 20px; font-weight: 800; margin: 10px 0 0; }
.review-opts { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.sens { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 12px; font-weight: 700; color: var(--soft); font-size: 14px; }
.sens input { flex: 1; max-width: 220px; }

/* ---------- play HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; font-family: var(--font); }
#hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: flex-start; }
#hud-names { flex: 1; justify-content: flex-start; margin: 0; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 6px; }
#hud-names .chip { white-space: nowrap; cursor: pointer; }
.hud-bottom {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b));
  display: flex; gap: 6px; background: rgba(255,255,255,.88); padding: 6px; border-radius: 24px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: calc(100vw - 16px);
}
.hud-bottom button { display: flex; flex-direction: column; align-items: center; min-width: 56px; padding: 6px 4px 4px; border-radius: 18px; background: transparent; }
.hud-bottom button i { font-style: normal; font-size: 26px; line-height: 1; }
.hud-bottom button span { font-size: 12px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.hud-bottom button.on { background: var(--sun); }
.hud-bottom .cam-only { display: none; }
body[data-mode="camera"] .hud-bottom .cam-only { display: flex; }
.status { position: absolute; top: calc(70px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: rgba(43,45,66,.82); color: #fff; padding: 8px 16px; border-radius: 16px; font-weight: 700; font-size: 17px; text-align: center; max-width: 90vw; }
.status:empty { display: none; }
#toast { position: absolute; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%) scale(.9); opacity: 0; transition: .25s; background: #fff; padding: 10px 18px; border-radius: 18px; font-weight: 800; font-size: 19px; box-shadow: 0 6px 20px rgba(0,0,0,.2); pointer-events: none; text-align: center; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }
.panel { position: absolute; left: 50%; transform: translateX(-50%); background: #fff; border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 12px; }
.tray { bottom: calc(96px + var(--safe-b)); display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; width: min(360px, 92vw); }
.tray button { font-size: 34px; width: 54px; height: 54px; border-radius: 16px; background: var(--sun-2); }
.tray button:active { transform: scale(.9); }
#name-card { top: 22%; width: min(340px, 90vw); text-align: center; }
#name-card .hello { margin: 0; font-weight: 700; color: var(--soft); font-size: 18px; }
.name-row { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
#name-input { flex: 1; min-width: 0; font-family: inherit; font-size: 28px; font-weight: 800; text-align: center; border: 3px dashed var(--sun); border-radius: 16px; padding: 2px 6px; color: var(--berry); }
.trait { margin: 6px 0 0; font-weight: 700; }
#hint-arrow { position: absolute; top: 50%; left: 50%; font-size: 64px; margin: -40px 0 0 -32px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); transition: transform .2s; pointer-events: none; animation: nudge 1s infinite; }
@keyframes nudge { 50% { opacity: .55; } }

@media (max-width: 400px) {
  .hud-bottom button { min-width: 48px; }
  .hud-bottom button span { font-size: 11px; }
  .big-btn b { font-size: 19px; }
}

/* ---------- drawing straight onto the zoo ---------- */
.hud-bottom .draw-act { background: var(--sun); }
#scribble {
  position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 3;
  transition: transform .5s cubic-bezier(.5, -0.3, .7, 1), opacity .5s;
}
#scribble.peel { transform: scale(.15) rotate(-8deg); opacity: 0; }
body.scribbling .hud-bottom, body.scribbling .hud-top, body.scribbling #hint-arrow { display: none; }
body.scribbling #hud-status { top: calc(12px + var(--safe-t)); }
.scribble-bar { bottom: calc(10px + var(--safe-b)); width: min(400px, 96vw); z-index: 4; padding: 10px 8px; }
.scribble-bar .swatches button { width: 32px; height: 32px; }
.scribble-bar .tool-row { margin-top: 8px; gap: 6px; }
.scribble-bar .tool { width: 42px; height: 42px; }
.scribble-bar .tool.done { background: var(--mint); color: #fff; font-weight: 800; }
.tool.sz i { display: block; width: var(--s); height: var(--s); border-radius: 50%; background: var(--ink); }
.tool.sz.on { background: var(--sea); }
.tool.sz.on i { background: #fff; }
#what-panel { bottom: calc(24px + var(--safe-b)); width: min(360px, 94vw); text-align: center; z-index: 5; }
#what-panel .hello { margin: 0 0 8px; font-weight: 800; font-size: 20px; }
.what-row { display: flex; gap: 8px; }
.what-row button { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 10px 4px; border-radius: 18px; background: var(--sun-2); font-weight: 800; font-size: 15px; }
.what-row button i { font-style: normal; font-size: 36px; line-height: 1.1; }
.what-row button:active { transform: scale(.94); }

/* ================= polish ================= */
/* screens slide in */
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { opacity: 0; transform: translateX(-50%) scale(.7); } 70% { transform: translateX(-50%) scale(1.04); } 100% { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes chipIn { from { opacity: 0; transform: translateY(8px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes float { 50% { transform: translateY(-7px) rotate(var(--r, 0deg)); } }
@keyframes wobble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(-1deg) translateY(-3px); } }
@keyframes wobble2 { 0%, 100% { transform: rotate(3deg) translateY(4px); } 50% { transform: rotate(6deg) translateY(1px); } }
@keyframes spin { to { transform: rotate(360deg); } }
body[data-screen="home"] #home, body[data-screen="draw"] #draw, body[data-screen="review"] #review { animation: screenIn .35s ease-out; }

/* hero: wobbly title with crayon doodles floating around it */
.hero { position: relative; }
.hero h1 .d { animation: wobble 3.2s ease-in-out infinite; }
.hero h1 .z { animation: wobble2 3.6s ease-in-out infinite; }
.doodle { position: absolute; width: 34px; height: 34px; animation: float 3s ease-in-out infinite; pointer-events: none; }
/* kept in the outer margins so they never cover the words */
.doodle.s1 { left: -6px; top: -10px; width: 28px; --r: 12deg; }
.doodle.s2 { right: -4px; top: -12px; width: 42px; animation-delay: -1s; }
.doodle.s3 { right: -2px; top: 104px; width: 22px; animation-delay: -2s; --r: -10deg; }
.doodle.s4 { left: -2px; top: 106px; width: 20px; animation-delay: -.5s; }
.hero { margin-top: 18px; }

.big-btn { border: 3px solid rgba(255,255,255,.9); background: linear-gradient(#fff, #fffaf0); transition: transform .12s, box-shadow .12s; }
.big-btn .ico { filter: drop-shadow(0 4px 2px rgba(0,0,0,.12)); }
.big-btn:hover .ico { animation: float 1.2s ease-in-out infinite; }

#sample-row button { width: 60px; height: 70px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; font-size: 30px; line-height: 1; transition: transform .12s; }
#sample-row button span { font-size: 11px; font-weight: 800; color: var(--soft); margin-top: 4px; }
#sample-row button:hover { transform: translateY(-3px) rotate(-3deg); }

.zoo-card { animation: chipIn .3s ease-out backwards; transition: transform .12s; }
.zoo-card:hover { transform: translateY(-3px) rotate(-1.5deg); }
.zoo-card img { filter: drop-shadow(0 4px 3px rgba(0,0,0,.18)); }

/* review */
.review-card { animation: screenIn .45s ease-out; }
.chips .chip { animation: chipIn .35s ease-out backwards; }
.chips .chip:nth-child(2) { animation-delay: .06s; } .chips .chip:nth-child(3) { animation-delay: .12s; }
.chips .chip:nth-child(4) { animation-delay: .18s; } .chips .chip:nth-child(5) { animation-delay: .24s; }
.chips .chip:nth-child(6) { animation-delay: .3s; }
.go-btn { transition: transform .1s, box-shadow .1s; }
.go-btn:hover { filter: brightness(1.05); }

/* busy overlay while a drawing is being scanned */
#busy { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; background: rgba(255, 232, 168, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
body.busy #busy { display: grid; }
.busy-card { background: #fff; border-radius: 26px; padding: 18px 26px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.15); font-weight: 800; font-size: 18px; }
.busy-card p { margin: 6px 0 0; }
.crayon-spin { font-size: 42px; display: inline-block; animation: spin 1s linear infinite; transform-origin: 50% 60%; }

/* play HUD: frosted glass, springy panels, smaller toasts */
.hud-bottom { background: rgba(255,255,255,.78); backdrop-filter: blur(12px) saturate(1.4); -webkit-backdrop-filter: blur(12px) saturate(1.4); border: 1px solid rgba(255,255,255,.7); }
.hud-bottom button { transition: transform .12s, background .2s; }
.hud-bottom button:active { transform: scale(.9); }
.hud-bottom button i { filter: drop-shadow(0 2px 1px rgba(0,0,0,.12)); }
.icon-btn { background: rgba(255,255,255,.9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: transform .12s; }
.icon-btn:active { transform: scale(.9); }
#hud-names .chip { background: rgba(255,255,255,.9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: transform .12s; }
#hud-names .chip:active { transform: scale(.94); }
.panel:not([hidden]) { animation: pop .32s cubic-bezier(.3, 1.4, .5, 1) both; }
.status { background: rgba(43,45,66,.75); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 999px; font-size: 16px; padding: 7px 16px; }
#toast { font-size: 16px; padding: 9px 16px; border-radius: 999px; bottom: calc(96px + var(--safe-b)); background: rgba(255,255,255,.95); transition: opacity .25s, transform .3s cubic-bezier(.3, 1.4, .5, 1); }
#name-input { transition: font-size .15s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* install to home screen */
.install-btn { display: block; width: 100%; margin-top: 18px; padding: 12px; border-radius: 20px; background: #fff; font-size: 17px; font-weight: 800; color: var(--sea); box-shadow: var(--shadow); }
.install-btn:active { transform: translateY(3px); }
.install-tip { margin: 18px 0 0; padding: 10px 14px; border-radius: 18px; background: rgba(255,255,255,.65); font-size: 15px; font-weight: 600; text-align: center; }

/* AI helper */
.says { text-align: center; font-size: 17px; font-weight: 700; font-style: italic; color: var(--soft); margin: 4px 0 0; min-height: 0; }
.says:empty { display: none; }
#name-trait { white-space: pre-line; }
.ai-toggle { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; padding: 10px 12px; background: rgba(255,255,255,.7); border-radius: 14px; cursor: pointer; }
.ai-toggle input { width: 22px; height: 22px; flex-shrink: 0; margin-top: 2px; accent-color: var(--berry); }
