/* Rabisco Mágico — 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; }
.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);
}
@media (min-width: 700px) {
  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);
  }
  .phone::after {
    content: "Feito para celular";
    position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
    color: var(--ink); background: #fff; font-weight: 600;
    padding: 6px 14px; border-radius: 999px;
  }
}
.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; }
.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 four icon buttons. */
.screen-draw .topbar { padding: 10px 8px; }
/* One tool row under the board: colours (scrollable) + brush-size cycle + eraser. */
.tools { display: flex; gap: 8px; align-items: center; padding: 10px 8px 12px; }
.tools .palette { flex: 1; min-width: 0; }
.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: 4px 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. */
.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;
}
.swatch.active { outline: 3px solid var(--sun); }
/* Transform floats over the board's bottom-right corner: a 64px-tall
 * yellow pill, always under the thumb, never over the centre of the
 * drawing. The label still comes from the transform i18n key. */
.transform-btn {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  height: 64px; min-width: 64px; padding: 0 20px; border: none; border-radius: 999px;
  background: var(--sun); color: var(--ink);
  font-family: inherit; font-size: 20px; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.transform-btn:active { transform: translateY(2px); box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.transform-btn:disabled { opacity: .6; }
/* 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;
}
/* 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; }
.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 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; }

/* 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; }
.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-in, #parent-signed-out { display: flex; flex-direction: column; gap: 12px; }
#parent-signed-in[hidden], #parent-signed-out[hidden] { display: none; }
