/* Rabisco — styles. Mobile portrait first; desktop gets a phone frame.
 * Contrast (Batch 5 audit, WCAG 2.2 AA): white text sits on --sky-deep
 * (#1770a8, 5.36:1), never on the bright --sky (#2b9be0, 3.06:1 — large
 * text only). White text sits on --coral-deep (#c93a2c, 5.09:1), never
 * on bright coral (2.8:1). Error/parent notes are ink text on a pale
 * yellow banner (10.32:1), never yellow text on blue (2.37:1). The hint
 * on white is #54616d (6.35:1), not #7a8a96 (3.56:1). */
:root {
  --sky: #2b9be0;
  --sky-deep: #1770a8;
  --sun: #ffc93c;
  --coral: #ff6b5b;
  --coral-deep: #c93a2c;
  --ink: #10324a;
  --hint: #54616d;
  --radius: 24px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* Keyboard focus must always be visible: ink ring + sun halo reads on
 * both the white canvas and the deep-sky background. */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--sun);
}
/* Skip link: hidden until keyboard focus, jumps to the Transform button. */
.skip-link {
  position: absolute; left: 16px; top: -100px; z-index: 10;
  background: #fff; color: var(--ink); font-weight: 700;
  padding: 12px 16px; border-radius: 12px;
}
.skip-link:focus { top: 12px; }
html, body { height: 100%; overflow-x: hidden; }
body {
  font-family: "Fredoka", system-ui, sans-serif;
  background: var(--sky);
  color: var(--ink);
  overscroll-behavior: none;
}
.phone { height: 100dvh; display: flex; justify-content: center; min-width: 0; }
/* Desktop/tablet "made for mobile" notice: a real element (not a CSS
   ::after) so applyLanguage() can translate it; hidden on phones. */
.desktop-note { display: none; }
.app {
  width: 100%; max-width: 480px; height: 100dvh; min-width: 0;
  background: var(--sky-deep);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* Phone frame is desktop-only: a wide viewport AND a fine pointer
   (mouse/trackpad). Tablets are touch (coarse pointer) and get the full
   screen instead — drawing on a tablet in a phone-sized frame wastes
   the screen the app is mostly used on. */
@media (min-width: 700px) and (pointer: fine) {
  body { display: flex; align-items: center; justify-content: center; }
  .phone { height: auto; }
  .app {
    height: min(880px, 96vh);
    border: 12px solid #0b2536; border-radius: 48px;
    overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,.35);
  }
  .desktop-note {
    display: block; position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
    color: var(--ink); background: #fff; font-weight: 600;
    padding: 6px 14px; border-radius: 999px; margin: 0;
  }
}
/* Tablets (and any touch screen wider than a phone): the app uses the
   whole width, so the drawing board is as big as the screen. */
@media (min-width: 500px) and (pointer: coarse) {
  .app { max-width: none; }
}
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.screen[hidden] { display: none; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 8px; flex-wrap: wrap;
}
.topbar h1 { color: #fff; font-size: 26px; font-weight: 700; min-width: 0; overflow-wrap: break-word; }
.topbar h1::first-letter { color: var(--sun); }
.top-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; min-width: 0; }
/* Draw topbar groups: kid actions (undo / clear / gallery) and parent
   actions (lock / parents) are separate groups with a divider between
   them, so the bar never reads as one mixed row. */
.action-group { display: flex; gap: 8px; align-items: center; min-width: 0; }
.action-divider { width: 1px; align-self: stretch; margin: 6px 2px; background: rgba(255,255,255,.45); }
.top-actions [hidden] { display: none; }
.icon-btn, #lang-picker, #lang-picker-welcome {
  min-width: 44px; min-height: 44px; border: none; border-radius: 14px;
  background: #fff; font-size: 20px; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.icon-btn:active, #lang-picker:active, #lang-picker-welcome:active { transform: translateY(2px); box-shadow: none; }
#lang-picker, #lang-picker-welcome { font-family: inherit; font-weight: 700; color: var(--ink); padding: 0 6px; }

.board-wrap { flex: 1; position: relative; margin: 0 8px; min-height: 0; }
#board {
  width: 100%; height: 100%; display: block;
  background: #fff; border-radius: var(--radius);
  touch-action: none; /* the browser must not scroll or zoom while drawing */
}
.hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 0 32px; color: var(--hint); font-size: 20px; font-weight: 600;
  pointer-events: none;
}
.hint[hidden] { display: none; }

/* Draw screen topbar: no title, just the quota pill and grouped action buttons. */
.screen-draw .topbar { padding: 10px 8px; }
/* One tool row under the board: colours (scrollable) + brush picker + eraser. */
.tools { display: flex; gap: 8px; align-items: center; padding: 10px 8px 12px; }
.tools .palette { flex: 1; min-width: 0; }
/* Brush size is one compact picker button, not three buttons: the
   control is rarely reached for, so it stays out of the palette's way.
   The button shows the current size as a short line in the current
   colour (its thickness IS the brush size — set by renderBrushPicker).
   The panel pops up above the tools row, over the board edge, and is
   absolutely positioned so opening it never shifts the palette or the
   other tools. The selected line is highlighted like the eraser. */
.brush-picker { position: relative; flex-shrink: 0; }
.brush-picker-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px; }
.brush-line { display: block; width: 30px; border-radius: 999px; }
.brush-chevron { font-size: 11px; line-height: 1; opacity: .6; }
.brush-panel {
  position: absolute; bottom: calc(100% + 10px); right: 0; z-index: 5;
  display: flex; flex-direction: column; gap: 6px;
  background: #fff; border-radius: 14px; padding: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.brush-panel[hidden] { display: none; }
.brush-option {
  display: flex; align-items: center; justify-content: center;
  min-width: 72px; min-height: 44px; border: none; border-radius: 10px;
  background: #f2f2f2; cursor: pointer;
}
.brush-option:active { transform: translateY(1px); }
.brush-option.active { background: var(--sun); }
.brush-option .brush-line { width: 44px; }
.tool-btn {
  flex: 0 0 auto; min-width: 44px; min-height: 44px; border: none; border-radius: 14px;
  background: #fff; color: var(--ink); font-size: 20px; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.tool-btn:active { transform: translateY(2px); box-shadow: none; }
.tool-btn.active { background: var(--sun); }
.palette { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px; scrollbar-width: none; touch-action: pan-x; -webkit-overflow-scrolling: touch; }
.palette::-webkit-scrollbar { display: none; }
/* 36px colour disc inside a 44px tap target: the button is 44px, 4px of
 * padding leaves a 36px content box, and the white ring is a box-shadow.
 * The selected swatch has to be unmistakable for a small child, so it
 * pops (scale + thick yellow ring) and carries a white ✓ — the old
 * 3px outline alone was too easy to miss. The 6px vertical padding on
 * .palette leaves room for the scaled swatch. */
.swatch {
  flex: 0 0 auto; width: 44px; height: 44px; padding: 4px; border-radius: 50%;
  border: none; cursor: pointer;
  box-shadow: 0 0 0 3px #fff, 0 2px 0 rgba(0,0,0,.15);
  background-clip: content-box;
  position: relative;
  transition: transform .15s ease;
}
.swatch.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--sun), 0 2px 0 rgba(0,0,0,.15);
  z-index: 1;
}
.swatch.active::after {
  content: "✓";
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 800; line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,.7), 0 0 2px rgba(0,0,0,.5);
}
/* Colour-pick toast: a small pill over the board's bottom-left corner
 * (the Transform pill owns the bottom-right). It fades in on a pick and
 * out after about a second; pointer-events none so it never blocks a
 * stroke. The [hidden] rule is explicit: the display:flex above would
 * otherwise beat the browser's built-in hidden handling. */
.color-toast {
  position: absolute; left: 12px; bottom: 12px; z-index: 3;
  display: flex; align-items: center; gap: 8px;
  background: #fff; color: var(--ink); font-weight: 700; font-size: 16px;
  border-radius: 999px; padding: 8px 14px; margin: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.color-toast.visible { opacity: 1; }
.color-toast[hidden] { display: none; }
.color-toast .toast-dot {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.12);
}
/* Transform floats over the board's bottom-right corner: a 56px round
 * yellow icon button showing the same 🪄 wand as the loading screen,
 * always under the thumb, never over the centre of the drawing.
 * Icon-only, like the rest of the board — the accessible name comes
 * from the transformLabel i18n key, set by applyLanguage(). */
.transform-btn {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  width: 56px; height: 56px; padding: 0; border: none; border-radius: 50%;
  background: var(--sun); color: var(--ink);
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
.transform-btn:active { transform: translateY(2px); box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.transform-btn:disabled { opacity: .6; }
.transform-icon { display: block; }
/* While a transform runs the wand waves — the same animation as the
 * loading screen — so busy never looks like idle. */
.transform-btn[aria-busy="true"] .transform-icon { animation: wave 1.2s ease-in-out infinite; }
/* Free-transforms-left pill in the draw topbar, e.g. "3/5". */
.quota {
  min-height: 44px; display: flex; align-items: center;
  background: #fff; color: var(--ink); font-weight: 700; font-size: 15px;
  border-radius: 999px; padding: 0 12px;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.quota:empty { display: none; }
.app-footer { text-align: center; padding: 0 16px 14px; }
.app-footer a { color: #fff; font-weight: 600; }
/* The Parents button carries a word, not just a lock, so a parent can find sign-in. */
.parents-btn { font-size: 16px; font-weight: 700; padding: 0 10px; }
.clear-warn { text-align: center; color: #fff; font-weight: 600; padding-bottom: 12px; }

.screen-loading { align-items: center; justify-content: center; gap: 20px; padding: 32px; text-align: center; }
.screen-loading p { color: #fff; font-size: 22px; font-weight: 600; }
.wand { font-size: 72px; animation: wave 1.2s ease-in-out infinite; }
@keyframes wave { 0%,100% { transform: rotate(-12deg); } 50% { transform: rotate(14deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .wand { animation: none; }
}

.screen-result { padding: 16px; gap: 12px; overflow-y: auto; }
.screen-result h2 { color: #fff; font-size: 26px; text-align: center; }
.screen-result p { color: #fff; text-align: center; font-size: 18px; }
.result-image-wrap { position: relative; }
.result-image-wrap img#result-image { width: 100%; border-radius: var(--radius); display: block; background: #fff; }
.thumb {
  position: absolute; right: 12px; bottom: 12px; width: 84px; height: 84px;
  object-fit: contain; background: #fff; border: 4px solid #fff; border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,.35); transform: rotate(4deg);
}
.result-actions { display: flex; gap: 10px; }
.result-actions.secondary { justify-content: center; }
.btn {
  flex: 1; min-height: 52px; border: none; border-radius: 18px; cursor: pointer;
  font-family: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.2);
  max-width: 100%; white-space: normal; line-height: 1.3;
  /* Buttons had no horizontal padding, so long labels touched the
     edges when the button shrank to its content. */
  padding: 10px 18px;
}
/* In the single-column welcome/upgrade screens the buttons must not
 * stretch vertically to fill the screen. */
.welcome-body .btn, .upgrade-body .btn { flex: 0 0 auto; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn-primary { background: var(--sun); }
.btn-share { background: var(--coral-deep); color: #fff; }
.error {
  color: var(--ink); background: #ffe08a; font-weight: 600;
  padding: 8px 12px; border-radius: 12px;
}

.gallery-tools { display: flex; gap: 10px; padding: 0 16px 12px; }
.gallery-search { flex: 1; }
.gallery-fav-filter { flex: 0 0 auto; min-height: 52px; font-size: 16px; padding: 0 14px; }
.gallery-fav-filter.active { background: var(--sun); }
.gallery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px 16px; overflow-y: auto; grid-auto-rows: max-content; }
.gallery-grid figure { background: #fff; border-radius: 16px; overflow: hidden; cursor: pointer; position: relative; }
.gallery-grid figure.favourite { outline: 3px solid var(--sun); }
.gallery-grid .fav-btn {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px;
  border: none; border-radius: 50%; background: rgba(255,255,255,.92);
  font-size: 22px; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.gallery-grid .del-btn {
  position: absolute; top: 8px; left: 8px; width: 44px; height: 44px;
  border: none; border-radius: 50%; background: rgba(255,255,255,.92);
  font-size: 20px; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.gallery-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-grid figcaption { padding: 8px; font-weight: 600; font-size: 14px; text-align: center; }
.gallery-empty { color: #fff; text-align: center; padding: 32px; font-size: 18px; }
.gallery-more { margin: 0 16px 24px; }
.gallery-more[hidden] { display: none; }

/* Parental gate + parent panel (adults only), welcome screen and upgrade gate. */
.gate-body, .parent-panel, .welcome-body, .upgrade-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.gate-body p, .parent-panel p, .welcome-body p, .upgrade-body p { color: #fff; font-size: 18px; }
.upgrade-body h2 { color: #fff; font-size: 24px; text-align: center; margin: 8px 0 0; }
.gate-question { font-size: 40px; font-weight: 700; text-align: center; color: var(--sun); }
.gate-answers { display: flex; gap: 10px; justify-content: center; }
.gate-answer { flex: 0 0 84px; }
/* Lock screen (parent PIN) + code entry. Big tap targets: the PIN pad
   is used by a parent holding the tablet for the child. */
.lock-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; align-items: center; text-align: center; }
.lock-body p { color: #fff; font-size: 18px; }
.lock-body .btn { flex: 0 0 auto; }
.lock-emoji { font-size: 64px; }
.pin-dots { font-size: 32px; font-weight: 700; color: #fff; letter-spacing: 8px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 84px); gap: 12px; justify-content: center; }
.pin-key { min-width: 84px; min-height: 72px; border: none; border-radius: 18px; cursor: pointer; font-family: inherit; font-size: 28px; font-weight: 700; color: var(--ink); background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.pin-key:active { transform: translateY(3px); box-shadow: none; }
.pin-field { letter-spacing: 6px; font-size: 24px; font-weight: 700; text-align: center; }
#code-box { display: flex; flex-direction: column; gap: 14px; }
.field-label { color: #fff; font-weight: 600; font-size: 16px; }
.field {
  min-height: 52px; border: none; border-radius: 14px; padding: 0 14px;
  font-family: inherit; font-size: 17px; color: var(--ink); width: 100%;
}
.parent-status { font-weight: 700; }
.parent-note { color: var(--ink); background: #ffe08a; font-weight: 600; padding: 8px 12px; border-radius: 12px; }
.btn-danger { background: var(--coral-deep); color: #fff; }
#parent-signed-out { display: flex; flex-direction: column; gap: 12px; }
#parent-signed-in { display: flex; flex-direction: column; gap: 16px; }
#parent-signed-in[hidden], #parent-signed-out[hidden] { display: none; }
/* Parent area: the back button sits in the header, before the title,
   instead of floating top-right as a lone white square. */
.topbar-parents { justify-content: flex-start; gap: 12px; }
.topbar-parents h1 { flex: 1; }
.back-btn { border-radius: 50%; font-size: 24px; font-weight: 700; }
/* Parent panel: even section rhythm, and room at the bottom so the last
   button is never clipped by the screen edge or the safe area. */
.parent-panel { gap: 16px; padding-bottom: 32px; }
/* Account summary card: one line per fact (email / plan / turns left)
   so nothing wraps mid-phrase. The plan reads as a yellow pill. */
.account-card {
  background: #fff; border-radius: 20px; padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.account-email { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.account-plan {
  align-self: flex-start; background: var(--sun); border-radius: 999px;
  padding: 4px 12px; font-weight: 700; font-size: 16px;
}
.account-turns { font-size: 15px; color: var(--hint); font-weight: 600; }
/* Plans card: the three plan options live in one white card. Monthly
   stays the yellow primary; yearly and pack are quiet secondary rows. */
.plans-card {
  background: #fff; border-radius: 20px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.btn-plan { background: #eef6fb; box-shadow: none; border: 2px solid #d8e8f2; }
/* PIN card: same white card as the plans, so the PIN form reads as one
   section; its buttons stack full-width with real padding. Inputs get
   a light fill so they read on the white card. */
.pin-card {
  background: #fff; border-radius: 20px; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.parent-panel .pin-card p { color: var(--ink); }
.pin-card .field-label { color: var(--ink); }
.pin-card .parent-status { font-size: 19px; }
.pin-card .field { background: #eef6fb; border: 2px solid #d8e8f2; }
/* Marketing consent: a plain checkbox row, not a toggle — the choice
   must read as a choice, not a setting that was already on. On the
   sign-in screen it sits on the blue background (white text); inside
   a white card the text is ink. */
.consent-label { display: flex; gap: 10px; align-items: flex-start; color: #fff; font-size: 16px; line-height: 1.4; margin: 12px 0; cursor: pointer; }
.consent-label input { width: 22px; height: 22px; flex: none; margin-top: 2px; accent-color: var(--sun); cursor: pointer; }
.pin-card .consent-label { color: var(--ink); margin: 0; }
.consent-title { font-size: 18px; font-weight: 700; color: var(--ink); margin: 0; }
/* PIN card header: a plain row (status + chevron), not a button
   shape — tapping it expands or collapses the form below. The form
   is collapsed by default once a PIN exists, so the card takes one
   line until the parent wants to change the PIN. */
.pin-toggle {
  background: none; border: 0; box-shadow: none; padding: 0; margin: 0;
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; cursor: pointer; font: inherit; color: var(--ink); text-align: left;
}
.pin-chevron { font-size: 22px; font-weight: 700; color: var(--hint); flex: none; }
#pin-form { display: flex; flex-direction: column; gap: 12px; }
#pin-form[hidden], #pin-current-row[hidden] { display: none; }
#pin-current-row { display: flex; flex-direction: column; gap: 12px; }

/* Style picker: a bottom sheet over the board, opened only from the
   Transform button (tap when no default is stored, long-press when one
   is). Four fixed tile images — the same small house in each style —
   so the child sees what each style looks like before picking. */
.style-picker { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(16,50,74,.55); }
.style-picker[hidden] { display: none; }
.style-sheet { position: relative; width: 100%; max-width: 480px; background: #fff; border-radius: 24px 24px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); color: var(--ink); box-shadow: 0 -8px 32px rgba(0,0,0,.3); }
.style-sheet h2 { font-size: 24px; text-align: center; }
.style-sub { text-align: center; color: var(--hint); margin: 4px 0 16px; font-size: 15px; }
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.style-tile { position: relative; border: 3px solid transparent; border-radius: 16px; overflow: hidden; padding: 0; background: #eef4f8; text-align: center; font-family: inherit; cursor: pointer; }
.style-tile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.style-tile span { display: block; padding: 8px; font-weight: 700; font-size: 16px; color: var(--ink); }
.style-tile.selected { border-color: var(--sun); }
.style-check { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; background: var(--sun); color: var(--ink); display: flex; align-items: center; justify-content: center; font-style: normal; font-weight: 800; font-size: 16px; }
.style-check[hidden] { display: none; }
.style-remember { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; font-weight: 700; font-size: 15px; background: none; border: none; padding: 0; color: var(--ink); font-family: inherit; cursor: pointer; text-align: left; }
.style-toggle { width: 52px; height: 30px; border-radius: 999px; background: var(--sun); position: relative; flex: none; }
.style-toggle::after { content: ''; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; }
.style-remember[aria-pressed="false"] .style-toggle { background: #cbd5db; }
.style-remember[aria-pressed="false"] .style-toggle::after { right: auto; left: 3px; }
.style-note { color: var(--hint); font-size: 14px; margin: 0 0 16px; }
.style-go { width: 100%; padding: 14px; border: none; border-radius: 999px; background: var(--sun); color: var(--ink); font-size: 18px; font-weight: 800; font-family: inherit; cursor: pointer; }
.style-go:disabled { background: #d7e0e6; color: #7a8a96; cursor: default; }
.style-close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: none; background: #eef4f8; color: var(--ink); font-size: 16px; cursor: pointer; }
