:root {
  --bg: #fff6e6;
  --ink: #2d2a32;
  --soft: #6b6573;
  --paper: #ffffff;
  --accent: #ff6a2b;
  --go: #2fb344;
  --card: #ffffff;
  --shadow: 0 6px 0 rgba(45, 42, 50, .12), 0 10px 24px rgba(45, 42, 50, .10);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  font-weight: 500;
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(rgba(255, 166, 77, .18) 2px, transparent 2.5px);
  background-size: 28px 28px;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }
h1, h2, h3 { margin: 0; font-weight: 700; }

.screen { display: none; min-height: 100dvh; padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l)); }
.screen.active { display: block; }

/* ---------- Top bars ---------- */
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.top h2 { font-size: clamp(24px, 4vw, 34px); flex: 1; text-align: center; }
.spacer { width: 52px; }
.logo { font-size: clamp(32px, 6vw, 48px); flex: 1; letter-spacing: .5px; }
.logo span { color: var(--accent); }
.round { width: 52px; height: 52px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 24px; display: grid; place-items: center; flex: none; }
.round:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(45, 42, 50, .12); }
.round.on { background: #ffe8d9; outline: 3px solid var(--accent); }
.round.light { background: rgba(255, 255, 255, .92); }
.pill { padding: 12px 20px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 19px; font-weight: 600; white-space: nowrap; }
.pill:active { transform: translateY(3px); }
.pill.big { font-size: 22px; padding: 16px 26px; }
.pill.camera { background: #ffd43b; }
.pill.go { background: var(--go); color: #fff; }
.pill.danger { background: #ffe3e3; color: #c92a2a; }

.gear { position: relative; width: 52px; height: 52px; border-radius: 50%; font-size: 26px; color: var(--soft); background: rgba(255, 255, 255, .6); }
.gear .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.gear .ring circle { fill: none; stroke: var(--accent); stroke-width: 4; stroke-dasharray: 132; stroke-dashoffset: 132; }
.gear.holding .ring circle { transition: stroke-dashoffset 1.5s linear; stroke-dashoffset: 0; }

/* ---------- Pip and speech bubbles ---------- */
.pip-slot { width: 96px; flex: none; cursor: pointer; }
.pip { width: 100%; display: block; overflow: visible; }
.pip .arm path { fill: none; stroke: #2d2a32; stroke-width: 5; stroke-linecap: round; }
.pip .arm circle { fill: #ffd8be; stroke: #2d2a32; stroke-width: 3; }
.pip-body { transform-origin: 70px 200px; animation: bob 3s ease-in-out infinite; }
.pip .arm-r { transform-origin: 106px 112px; animation: wave 2.4s ease-in-out infinite; }
.pip .eyes { transform-origin: 70px 92px; animation: blink 4.5s infinite; }
.pip .mouth { display: none; transform-origin: 70px 116px; }
.pip.talking .smile { display: none; }
.pip.talking .mouth { display: block; animation: chatter .26s ease-in-out infinite alternate; }
.pip.hop .pip-body { animation: hop .45s ease-out, bob 3s ease-in-out .45s infinite; }
.pip.cheer .pip-body { animation: cheer .6s ease-in-out 3; }
.pip.cheer .arm-l { transform-origin: 34px 112px; animation: cheerArm .3s ease-in-out infinite alternate; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(1.5deg); } }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 70%, 90% { transform: rotate(-18deg); } 80% { transform: rotate(10deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes chatter { from { transform: scaleY(.35); } to { transform: scaleY(1); } }
@keyframes hop { 40% { transform: translateY(-22px) rotate(-4deg); } 70% { transform: translateY(0) scaleY(.94); } }
@keyframes cheer { 30% { transform: translateY(-26px) rotate(-8deg); } 60% { transform: translateY(0); } 80% { transform: translateY(-10px) rotate(6deg); } }
@keyframes cheerArm { to { transform: rotate(60deg); } }

.bubble { position: relative; background: var(--card); border-radius: 22px; padding: 14px 18px; font-size: clamp(18px, 2.4vw, 23px); line-height: 1.35; box-shadow: var(--shadow); }
.bubble::before { content: ''; position: absolute; left: -12px; top: 26px; border: 12px solid transparent; border-right-color: var(--card); border-left: 0; }

/* ---------- Home ---------- */
.hello { display: flex; align-items: center; gap: 18px; max-width: 760px; margin: 0 auto 14px; }
.hello .pip-slot { width: 104px; }
.hello .bubble { flex: 1; }
.home-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.gallery-btn { background: #ffd43b; }
.surprise-btn { background: #d0bfff; }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 200px), 1fr)); gap: 16px; max-width: 1100px; margin: 0 auto; }
.cat { position: relative; background: var(--card); border-radius: 26px; padding: 12px 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; border-top: 10px solid var(--c); transition: transform .15s; }
.cat:active { transform: scale(.96); }
.cat-art { width: 78%; aspect-ratio: 1; display: block; }
.cat-art svg { width: 100%; height: 100%; }
.cat-emoji { position: absolute; top: 6px; left: 10px; font-size: 30px; }
.cat-name { font-size: 22px; font-weight: 700; text-align: center; line-height: 1.1; }
.cat-count { font-size: 15px; color: var(--soft); margin-top: 4px; }

/* ---------- Category ---------- */
.blurb { text-align: center; color: var(--soft); font-size: 19px; margin: -4px 0 4px; grid-column: 1 / -1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 190px), 1fr)); gap: 16px; max-width: 1100px; margin: 0 auto; }
.card { position: relative; background: var(--card); border-radius: 24px; padding: 10px 10px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; border-bottom: 8px solid var(--c); }
.card:active { transform: scale(.96); }
.card-art { width: 100%; aspect-ratio: 1; display: block; }
.card-art svg { width: 100%; height: 100%; }
.card-name { font-size: 20px; font-weight: 700; text-align: center; line-height: 1.1; }
.card-meta { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.lvl { font-size: 14px; letter-spacing: -2px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #f1f3f5; color: var(--soft); }
.tag.colour { background: linear-gradient(90deg, #ffe3e3, #fff3bf, #d3f9d8, #d0ebff); color: #5f3dc4; }
.tag.shade { background: #e9ecef; color: #495057; }
.star { position: absolute; top: 8px; right: 10px; font-size: 26px; }

/* ---------- Drawing art ---------- */
.art { display: block; }
.art .ln { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.art .ln.thin { stroke-width: 3; }
.art .ln.bold { stroke-width: 11; }
.art .ln.solid { fill: var(--ink); stroke-width: 2; }
.art .ln.new { stroke: var(--accent); stroke-width: 6.5; }
.art .ln.new.thin { stroke-width: 4.5; }
.art .ln.new.bold { stroke-width: 12; }
.art .ln.new.solid { fill: var(--accent); }
.art.anim .ln.new { stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: draw .9s ease-in-out forwards; }
.art.anim .ln.new.solid { stroke-dasharray: none; stroke-dashoffset: 0; opacity: 0; transform-box: fill-box; transform-origin: center; animation: pop .35s ease-out forwards; }
.art.anim .nf { animation: fadein 1.1s ease forwards; }
@keyframes draw { 0% { stroke-dashoffset: 1; opacity: 0; } 3% { opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: scale(1); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Lesson ---------- */
#screen-lesson { padding: 0; height: 100dvh; overflow: hidden; }
#screen-lesson.active { display: block; }
.lesson { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 34vw, 400px); gap: 16px; padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l)); }
.stage-wrap { min-width: 0; min-height: 0; display: grid; place-items: center; }
.stage { position: relative; width: 300px; height: 300px; background: var(--paper); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.stage::after { content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: 18px; box-shadow: inset 0 0 0 2px rgba(45, 42, 50, .06); }
.paper { position: absolute; inset: 3%; transition: opacity .3s; }
.paper svg { width: 100%; height: 100%; }
.paper .preview { animation: fadein .6s; }
.paper-tag { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); background: #fff3bf; padding: 4px 14px; border-radius: 99px; font-size: 16px; color: var(--soft); white-space: nowrap; }
.paper.ghost { opacity: .28; }
#sketch { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
#sketch.on { pointer-events: auto; cursor: crosshair; }
.drawing .stage { outline: 4px dashed rgba(255, 106, 43, .5); outline-offset: 4px; }

.panel { min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.lesson-top { display: flex; align-items: center; gap: 10px; }
.lesson-top h2 { flex: 1; text-align: center; font-size: clamp(22px, 2.8vw, 30px); line-height: 1.1; }
.talk { display: flex; gap: 14px; align-items: flex-start; flex: 1; min-height: 0; overflow: auto; padding: 4px 4px 10px; }
.talk .pip-slot { width: clamp(70px, 9vw, 104px); margin-top: 4px; }
.talk .bubble { flex: 1; }
.tools { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.sw { aspect-ratio: 1; border-radius: 50%; background: var(--sw); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .15); }
.sw.on { outline: 4px solid var(--ink); outline-offset: 2px; }
.tool-row { display: flex; gap: 6px; justify-content: space-between; }
.tool { flex: 1; height: 44px; border-radius: 14px; background: #f1f3f5; font-size: 22px; display: grid; place-items: center; }
.tool.on { background: #ffe8d9; outline: 3px solid var(--accent); }
.tool i { display: block; border-radius: 50%; background: var(--ink); }
.steps-bar { display: flex; justify-content: center; }
.dots { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: #e9ecef; box-shadow: inset 0 0 0 2px #dee2e6; transition: all .25s; }
.dots i.past { background: #ffc9a8; box-shadow: none; }
.dots i.now { background: var(--accent); box-shadow: none; transform: scale(1.35); }
.controls { display: grid; grid-template-columns: 64px 64px 1fr; gap: 10px; }
.ctl { height: 72px; border-radius: 22px; background: var(--card); box-shadow: var(--shadow); font-size: 26px; }
.ctl:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(45, 42, 50, .12); }
.ctl.next { background: var(--go); color: #fff; font-size: 28px; font-weight: 700; box-shadow: 0 6px 0 #1f8a31, 0 10px 20px rgba(47, 179, 68, .3); animation: nudge 2.8s ease-in-out 3s infinite; }
.ctl.next.finish { background: #ff922b; box-shadow: 0 6px 0 #d9480f, 0 10px 20px rgba(255, 146, 43, .3); }
@keyframes nudge { 0%, 90%, 100% { transform: none; } 94% { transform: scale(1.05); } }

/* Portrait: drawing on top, Pip and buttons below */
@media (orientation: portrait), (max-width: 760px) {
  .lesson { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; }
  .panel { display: contents; }
  .lesson-top { order: -1; grid-row: 1; }
  .stage-wrap { grid-row: 2; }
  .talk { grid-row: 3; flex: none; max-height: 30vh; padding-bottom: 4px; }
  .tools { grid-row: 4; }
  .steps-bar { grid-row: 5; }
  .controls { grid-row: 6; }
  .lesson { grid-template-rows: auto minmax(0, 1fr) auto auto auto auto; }
}
/* Short landscape phones */
@media (orientation: landscape) and (max-height: 500px) {
  .ctl { height: 56px; }
  .talk .bubble { font-size: 17px; padding: 10px 14px; }
  .lesson-top .round { width: 44px; height: 44px; font-size: 20px; }
}

/* Finished overlay */
.done { position: fixed; inset: 0; background: rgba(255, 246, 230, .9); display: grid; place-items: center; z-index: 20; padding: 20px; overflow: hidden; }
.done[hidden] { display: none; }
.done-card { background: var(--card); border-radius: 30px; padding: 22px 26px 26px; box-shadow: var(--shadow); text-align: center; max-width: 520px; width: 100%; animation: popIn .5s cubic-bezier(.2, 1.6, .5, 1); position: relative; z-index: 2; }
.done-art { width: min(240px, 50vw); margin: 0 auto; }
.done-art svg { width: 100%; }
.done-card h2 { font-size: 36px; margin: 6px 0 16px; }
.done-buttons { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
@keyframes popIn { from { transform: scale(.6); opacity: 0; } }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall 3s linear forwards; }
@keyframes fall { to { top: 110%; transform: translateX(40px) rotate(720deg); } }

/* ---------- Gallery ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 220px), 1fr)); gap: 16px; max-width: 1100px; margin: 0 auto; }
.photo { background: #fff; padding: 10px 10px 8px; border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.photo:nth-child(odd) { transform: rotate(-1.5deg); }
.photo:nth-child(even) { transform: rotate(1.2deg); }
.photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; background: #f1f3f5; }
.photo span { font-size: 17px; }
.empty { text-align: center; font-size: 22px; color: var(--soft); max-width: 520px; margin: 40px auto; line-height: 1.5; }

.viewer { position: fixed; inset: 0; background: rgba(20, 18, 24, .92); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); gap: 12px; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100%; min-height: 0; flex: 1; object-fit: contain; border-radius: 8px; }
.viewer-cap { color: #fff; font-size: 20px; }
.viewer-bar { display: flex; gap: 14px; }

/* ---------- Camera ---------- */
.camera-ui { position: fixed; inset: 0; background: #111; z-index: 40; }
.camera-ui[hidden] { display: none; }
.camera-ui video, .camera-ui img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-frame { position: absolute; inset: 8% 10% 22%; border: 4px dashed rgba(255, 255, 255, .55); border-radius: 22px; pointer-events: none; }
.camera-ui img:not([hidden]) ~ .cam-frame { display: none; }
.cam-msg { position: absolute; top: calc(20px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: #fff; padding: 12px 20px; border-radius: 99px; font-size: 20px; text-align: center; width: max-content; max-width: 90%; box-shadow: var(--shadow); }
.cam-bar { position: absolute; left: 0; right: 0; bottom: calc(24px + var(--safe-b)); display: flex; justify-content: center; align-items: center; gap: 40px; }
.cam-bar[hidden] { display: none; }
.cam-bar.keep { gap: 16px; }
.shutter { width: 92px; height: 92px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 6px rgba(255, 255, 255, .4), inset 0 0 0 5px #111; }
.shutter:active { transform: scale(.92); }
.camera-ui.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: flash .3s forwards; }
@keyframes flash { to { opacity: 0; } }

/* ---------- Grown-ups ---------- */
.parents { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; font-size: 19px; }
.parents .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--card); padding: 12px 16px; border-radius: 16px; box-shadow: var(--shadow); }
.parents input[type=text], .parents select { font: inherit; font-size: 18px; padding: 8px 10px; border-radius: 10px; border: 2px solid #dee2e6; max-width: 60%; min-width: 0; }
.parents input[type=checkbox] { width: 28px; height: 28px; accent-color: var(--go); }
.parents input[type=range] { width: 50%; accent-color: var(--accent); }
.row-buttons { display: flex; gap: 12px; flex-wrap: wrap; }
.note { background: #fff9db; border-radius: 16px; padding: 4px 18px; line-height: 1.45; font-size: 17px; }
.note h3 { margin-top: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(30px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 99px; font-size: 19px; z-index: 50; }
.toast[hidden] { display: none; }
.toast.show { animation: popIn .3s; }

/* Pencil-style (realistic) drawings and guidelines */
.art.pencil .ln { stroke: #34313a; stroke-width: 3.4; }
.art.pencil .ln.thin { stroke-width: 1.9; }
.art.pencil .ln.bold { stroke-width: 6; }
.art.pencil .ln.solid { fill: #34313a; stroke-width: 1.2; }
.art.pencil .ln.new { stroke: var(--accent); stroke-width: 4.2; }
.art.pencil .ln.new.thin { stroke-width: 2.6; }
.art.pencil .ln.new.solid { fill: var(--accent); }
.art .ln.guide { stroke: #8db4f0; stroke-width: 2.4; stroke-dasharray: 7 6; fill: none; }
.art .ln.guide.new { stroke: #4c8be8; stroke-width: 3; }
.art.anim .ln.guide.new { stroke-dasharray: 7 6; stroke-dashoffset: 0; animation: fadein .8s ease forwards; }
.tag.real { background: #343a40; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .pip-body, .pip .arm-r, .ctl.next { animation: none !important; }
}
