:root {
  --sky1: #8fd3fb; --sky2: #c9ecff; --grass: #b8ec9a;
  --panel: rgba(255, 255, 255, 0.72); --ink: #e53935;
  --text: #2b2340; --shadow: 0 6px 0 rgba(43, 35, 64, 0.12), 0 10px 24px rgba(43, 35, 64, 0.12);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", "Varela Round", system-ui, sans-serif;
  color-scheme: light;                       /* a colouring book is always a white page */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  font-family: var(--font); color: var(--text);
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 70%, var(--grass) 100%);
}
body { position: fixed; inset: 0; touch-action: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { display: block; }
img { -webkit-user-drag: none; user-select: none; }
.scroll { touch-action: pan-x pan-y; overflow: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }

.screen { position: absolute; inset: 0; display: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen.active { display: flex; animation: screen-in 0.35s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- start */
#start { flex-direction: column; align-items: center; justify-content: center; gap: 3vh; overflow: hidden; }
.title { margin: 0; font-size: clamp(48px, 11vw, 120px); font-weight: 900; letter-spacing: 0.02em; text-align: center; line-height: 1; }
.title span { display: inline-block; -webkit-text-stroke: 3px #fff; paint-order: stroke fill; text-shadow: 0 6px 0 rgba(43, 35, 64, 0.15); animation: bob 2.4s ease-in-out infinite; }
.title span:nth-child(1) { color: #e53935; animation-delay: 0s; } .title span:nth-child(2) { color: #ff7a1a; animation-delay: 0.1s; }
.title span:nth-child(3) { color: #f2b705; animation-delay: 0.2s; } .title span:nth-child(4) { color: #2db34a; animation-delay: 0.3s; }
.title span:nth-child(5) { color: #14b8a6; animation-delay: 0.4s; } .title span:nth-child(6) { color: #1e5fd9; animation-delay: 0.5s; }
.title span:nth-child(7) { color: #7b3fd1; animation-delay: 0.6s; } .title span:nth-child(8) { color: #f25aa8; animation-delay: 0.7s; }
.title span:nth-child(9) { color: #e8197f; animation-delay: 0.8s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-10px) rotate(-3deg); } }
#parade { display: flex; gap: 2vw; }
#parade img { width: clamp(64px, 12vw, 140px); height: auto; background: #fff; border-radius: 28%; padding: 6px; box-shadow: var(--shadow); animation: bob 2.8s ease-in-out infinite; }
#parade img:nth-child(2) { animation-delay: 0.4s; } #parade img:nth-child(3) { animation-delay: 0.8s; } #parade img:nth-child(4) { animation-delay: 1.2s; } #parade img:nth-child(5) { animation-delay: 1.6s; }
.play { width: clamp(140px, 24vw, 220px); aspect-ratio: 1; filter: drop-shadow(0 10px 0 rgba(20, 110, 40, 0.25)); animation: pulse 1.6s ease-in-out infinite; }
.play-bg { fill: #2db34a; stroke: #fff; stroke-width: 6; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.sky-deco i { position: absolute; width: 22vmin; height: 8vmin; background: #fff; border-radius: 99px; opacity: 0.8; animation: drift 40s linear infinite; }
.sky-deco i::before { content: ""; position: absolute; width: 50%; height: 140%; left: 18%; bottom: 30%; background: #fff; border-radius: 50%; }
.sky-deco i:nth-child(1) { top: 8%; left: -25%; } .sky-deco i:nth-child(2) { top: 22%; left: -25%; animation-delay: -12s; animation-duration: 55s; }
.sky-deco i:nth-child(3) { top: 70%; left: -25%; animation-delay: -25s; } .sky-deco i:nth-child(4) { top: 45%; left: -25%; animation-delay: -6s; animation-duration: 60s; }
.sky-deco i:nth-child(5) { top: 85%; left: -25%; animation-delay: -33s; animation-duration: 48s; }
@keyframes drift { to { transform: translateX(160vw); } }

/* ---------------------------------------------------------------- picker */
#picker { flex-direction: column; }
.picker-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; }
.cats { flex: 1; display: flex; gap: clamp(8px, 1.6vw, 18px); justify-content: center; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
.cat { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 10px 6px; border-radius: 26px; background: var(--panel); box-shadow: var(--shadow); transition: transform 0.15s, background 0.15s; }
.cat img { width: clamp(52px, 8vw, 84px); height: clamp(52px, 8vw, 84px); }
.cat span { font-size: clamp(12px, 1.5vw, 16px); font-weight: 800; opacity: 0.75; }
.cat.on { background: #fff; transform: translateY(-4px) scale(1.06); outline: 5px solid #ffd21f; }
.grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(130px, 21vw, 230px), 1fr)); gap: clamp(12px, 2vw, 24px); padding: 12px clamp(14px, 3vw, 36px) 40px; align-content: start; }
.card { aspect-ratio: 1; background: #fff; border-radius: 30px; box-shadow: var(--shadow); padding: 6%; transition: transform 0.15s; animation: card-in 0.4s backwards; }
.card img { width: 100%; height: 100%; object-fit: contain; border-radius: 18px; pointer-events: none; }
.card:active { transform: scale(0.94); }
@keyframes card-in { from { opacity: 0; transform: translateY(16px) scale(0.9); } }

/* ---------------------------------------------------------------- the grown-ups cog (hold to open) */
.gear { width: 52px; height: 52px; flex: 0 0 auto; opacity: 0.55; }
.gear .cog { fill: #fff; stroke: rgba(43, 35, 64, 0.35); stroke-width: 1.5; }
.gear .ring { fill: none; stroke: #2b2340; stroke-width: 3; stroke-dasharray: 132; stroke-dashoffset: 132; transform: rotate(-90deg); transform-origin: center; }
.gear.holding { opacity: 1; }
.gear.holding .ring { transition: stroke-dashoffset 1.2s linear; stroke-dashoffset: 0; }

/* ---------------------------------------------------------------- colouring */
#paint { flex-direction: row; }
.side { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 10px; min-height: 0; }
.side-left { width: clamp(132px, 13vw, 176px); }
.side-right { width: clamp(176px, 19vw, 264px); }
.btn-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex: 0 0 auto; }
.round-btn { width: 60px; height: 60px; border-radius: 50%; background: #5b8def; box-shadow: 0 5px 0 #3a63b8; padding: 10px; transition: transform 0.1s; }
#undo { background: #ff9f43; box-shadow: 0 5px 0 #d97b1c; }
.round-btn:active, .done-btn:active { transform: translateY(4px); box-shadow: none; }
.done-btn { width: 76px; height: 76px; filter: drop-shadow(0 5px 0 rgba(200, 140, 0, 0.35)); animation: pulse 2.2s ease-in-out infinite; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; flex: 1 1 auto; min-height: 0; align-content: start; padding: 4px; }
.tool { aspect-ratio: 1; border-radius: 20px; background: var(--panel); box-shadow: 0 4px 0 rgba(43, 35, 64, 0.1); padding: 7px; transition: transform 0.15s, background 0.15s; }
.tool.on { background: #fff; transform: scale(1.1); outline: 4px solid var(--ink); z-index: 1; }
.tool svg { width: 100%; height: 100%; }
.tool .ink { fill: var(--ink); }
.tool .ink-s { stroke: var(--ink); }
.sizes { display: flex; gap: 6px; align-items: center; justify-content: center; background: var(--panel); border-radius: 26px; padding: 6px; flex: 0 0 auto; }
.size { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.size i { display: block; border-radius: 50%; background: var(--ink); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12); }
.size.on { background: #fff; outline: 3px solid var(--ink); }
.stage { flex: 1; min-width: 0; display: grid; place-items: center; padding: 10px 4px; }
.board { position: relative; background: #fff; border-radius: 26px; box-shadow: 0 10px 0 rgba(43, 35, 64, 0.1), 0 18px 40px rgba(43, 35, 64, 0.18); overflow: hidden; touch-action: none; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#c-lines { pointer-events: none; }
#c-live { pointer-events: none; }
.board.pop { animation: board-pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes board-pop { from { transform: scale(0.85); opacity: 0.3; } }
.paltabs { display: flex; gap: 8px; justify-content: center; flex: 0 0 auto; }
.paltab { width: 44px; height: 44px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 3px 0 rgba(43, 35, 64, 0.15); transition: transform 0.15s; }
.paltab.on { transform: scale(1.18); outline: 3px solid #2b2340; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; flex: 1 1 auto; min-height: 0; align-content: start; padding: 8px; }
.swatch { aspect-ratio: 1; border-radius: 46% 54% 48% 52% / 52% 46% 54% 48%; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.15), inset 0 5px 0 rgba(255, 255, 255, 0.35), 0 4px 0 rgba(43, 35, 64, 0.12); transition: transform 0.15s; border: 3px solid rgba(255, 255, 255, 0.9); }
.swatch.light { border-color: #d9d4e4; }
.swatch.on { transform: scale(1.18) rotate(-6deg); outline: 4px solid #2b2340; outline-offset: 2px; z-index: 1; }
.swatch:active { transform: scale(0.92); }

/* portrait: a strip of tools on top, the page, colours underneath */
@media (orientation: portrait) {
  #paint { flex-direction: column; }
  .side { flex-direction: row; width: 100% !important; padding: 8px 12px; }
  .side-left { order: 1; } .stage { order: 2; } .side-right { order: 3; flex-wrap: wrap; justify-content: center; }
  .tools { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; overflow: visible; flex: 1; gap: 6px; max-width: 320px; }
  .tool { flex: 0 0 56px; height: 56px; padding: 5px; }
  .sizes { flex-direction: column; padding: 4px; border-radius: 20px; }
  .size { width: 30px; height: 30px; }
  .side-right .btn-row { order: 3; }
  .paltabs { order: 1; width: 100%; }
  .swatches { order: 2; display: flex; flex-wrap: wrap; justify-content: center; overflow: visible; flex: 1; gap: 8px; padding: 8px 4px; }
  .swatch { flex: 0 0 52px; height: 52px; }
  .round-btn { width: 54px; height: 54px; }
  .done-btn { width: 64px; height: 64px; }
}

/* ---------------------------------------------------------------- effects + grown-up sheet */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(43, 35, 64, 0.45); display: grid; place-items: center; padding: 16px; touch-action: pan-y; }
.sheet[hidden] { display: none; }
.sheet-card { width: min(560px, 100%); max-height: 92vh; background: #fff; border-radius: 28px; padding: 22px 24px; box-shadow: var(--shadow); -webkit-user-select: text; user-select: text; }
.sheet h2 { margin: 0 0 10px; font-size: 24px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid #eee8f5; font-size: 17px; font-weight: 700; }
.row input[type=checkbox] { width: 28px; height: 28px; accent-color: #2db34a; }
.row input[type=range] { width: 180px; accent-color: #5b8def; }
.row input[type=text] { font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 12px; border: 2px solid #d9d4e4; width: 180px; -webkit-user-select: text; user-select: text; }
.seg { display: flex; gap: 6px; }
.pill { background: #eef3ff; color: #2b4aa0; padding: 10px 16px; border-radius: 99px; font-weight: 800; }
.pill.on { background: #5b8def; color: #fff; }
.pill.warn { background: #fff0ee; color: #c0392b; }
.pill.warn.armed { background: #c0392b; color: #fff; }
.pill.big { display: block; width: 100%; margin-top: 16px; padding: 16px; font-size: 19px; background: #2db34a; color: #fff; }
.note { font-size: 14px; line-height: 1.45; color: #5d5670; margin: 12px 0 0; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
