/* Paint: visual "Caderno de adesivos" (tokens copiados de site/style.css, para o app ser independente) */
:root {
  --y: #ffd43b;
  --y-dot: #f5bf0a;
  --ink: #3a2a17;
  --paper: #fffdf5;
  --pink: #ff6f91;
  --sky: #4cc3ff;
  --leaf: #4ccf7a;
  --orange: #ff9f1c;
  --display: "Gluten", "Comic Sans MS", cursive;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --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);
  --cor: #ffd43b; /* cor escolhida (o main.js troca) */
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--y);
  background-image: radial-gradient(var(--y-dot) 2.2px, transparent 2.6px);
  background-size: 26px 26px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
h1, h2 { font-family: var(--display); font-weight: 800; margin: 0; line-height: 1.1; }

/* ---------- Início (só na galeria) ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center;
  padding: calc(14px + var(--safe-t)) 16px 22px calc(16px + var(--safe-l));
  /* o mesmo fundo de bolinhas da página (alinhado, porque a faixa é fixa no canto e a página não rola),
     sumindo embaixo para os cards passarem por trás */
  background: var(--y);
  background-image: radial-gradient(var(--y-dot) 2.2px, transparent 2.6px);
  background-size: 26px 26px;
  background-position: 0 0;
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
  pointer-events: none;
}
.topbar .home-link { pointer-events: auto; }
.home-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 16px 6px 10px;
  font-family: var(--display); font-weight: 800; font-size: 20px;
  color: var(--ink); text-decoration: none;
  background: var(--y); border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.home-link svg { width: 22px; height: 22px; }
.home-link:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* ---------- galeria ---------- */
.galeria {
  position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(70px + var(--safe-t)) calc(18px + var(--safe-r)) calc(36px + var(--safe-b)) calc(18px + var(--safe-l));
}
.galeria h1 {
  text-align: center; font-size: clamp(44px, 9vw, 68px); margin: 0 0 22px;
  text-shadow: 3px 3px 0 var(--paper);
}
.grade {
  display: grid; gap: 26px; max-width: 1100px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(min(40vw, 230px), 1fr));
}
.card {
  position: relative; aspect-ratio: 4 / 3; padding: 0;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: 5px 5px 0 var(--ink);
  transform: rotate(var(--rot, -1.2deg));
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:nth-child(2n) { --rot: 1.4deg; }
.card:nth-child(3n) { --rot: -.5deg; }
.card:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.novo {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--pink); color: var(--paper);
  font-family: var(--display); font-weight: 800; font-size: clamp(24px, 4vw, 32px);
  text-shadow: 2px 2px 0 var(--ink);
}
.novo .mais {
  display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%;
  background: var(--y); color: var(--ink); border: 4px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  font-size: 1.5em; line-height: 1; text-shadow: none; padding-top: .08em;
}
.desenho .abrir {
  display: block; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  background: #f1e9d6;
}
.desenho .abrir svg { display: block; width: 100%; height: 100%; }
.lixo {
  position: absolute; top: -16px; right: -16px;
  display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
}
.lixo svg { width: 24px; height: 24px; }
.lixo:active { transform: translate(2px, 2px); box-shadow: none; }

/* ---------- folha ---------- */
.editor {
  position: fixed; inset: 0;
  display: grid; gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  /* deitado: ferramentas à esquerda, cores à direita */
  grid-template-columns: auto minmax(0, 1fr) auto;
  /* os botões de cima à direita ocupam 2 fileiras pequenas sem empurrar as ferramentas da esquerda */
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "nav palco acts" "tools palco acts" "tools palco paleta";
  --b: clamp(42px, calc((100dvh - 70px) / 7.3), 66px);
  --sw: calc(var(--b) * .74);
}
.nav { grid-area: nav; display: flex; justify-content: center; }
.acts { grid-area: acts; display: grid; grid-template-columns: repeat(3, var(--b)); gap: 8px; justify-content: end; align-content: start; }
.tools { grid-area: tools; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.palco { grid-area: palco; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.paleta { grid-area: paleta; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.cores { display: grid; grid-template-columns: repeat(3, var(--sw)); gap: 9px; }
.tamanhos { display: flex; gap: 8px; }
.tamanhos.apagado { visibility: hidden; } /* esconde sem mexer no tamanho da folha */

@media (orientation: portrait) {
  /* de pé: botões em cima, folha no meio, ferramentas e cores embaixo */
  .editor {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "nav acts" "palco palco" "tools tools" "paleta paleta";
    --b: clamp(42px, calc((100vw - 90px) / 6), 66px);
    --sw: clamp(32px, calc((100vw - 100px) / 7), 46px);
  }
  .acts { display: flex; justify-content: flex-end; }
  .tools { flex-direction: row; justify-content: center; }
  .paleta { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 10px 14px; }
  .cores { grid-template-columns: repeat(6, var(--sw)); }
}
@media (orientation: portrait) and (min-width: 720px) {
  .cores { grid-template-columns: repeat(12, var(--sw)); }
}

.rb {
  display: grid; place-items: center; width: var(--b); height: var(--b); padding: 0;
  border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.rb svg { width: 60%; height: 60%; overflow: visible; }
.rb:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.rb:disabled { opacity: .35; cursor: default; }
.tool[aria-pressed="true"], #btnFormas[aria-expanded="true"] {
  background: #bfe9ff; transform: scale(1.1); box-shadow: 4px 4px 0 var(--ink);
}
#btnMudo .off { display: none; }
#btnMudo[aria-pressed="true"] { background: #ffd6de; }
#btnMudo[aria-pressed="true"] .on { display: none; }
#btnMudo[aria-pressed="true"] .off { display: inline; }
.cor-fill { fill: var(--cor); }
.cor-stroke { stroke: var(--cor); }

.cor, .tam {
  width: var(--sw); height: var(--sw); padding: 0; border-radius: 50%;
  border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
  transition: transform .12s ease;
}
.cor { background: var(--c); }
.cor[aria-pressed="true"] { transform: scale(1.2); box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
.tam { display: grid; place-items: center; background: var(--paper); }
.tam span {
  display: block; width: var(--t); height: var(--t); border-radius: 50%;
  background: var(--cor); border: 2px solid var(--ink);
}
.tam[aria-pressed="true"] { background: #bfe9ff; transform: scale(1.12); }

.folha {
  display: block; width: 300px; height: 200px;
  background: #fff; border-radius: 4px;
  box-shadow: 0 0 0 4px var(--ink), 7px 7px 0 4px var(--ink);
  touch-action: none;
}
.folha[data-tool="mao"] { cursor: grab; }
.folha[data-tool="tinta"] { cursor: pointer; }
.folha[data-tool="lapis"], .folha[data-tool="linha"] { cursor: crosshair; }
.folha[data-tool="apagador"] { cursor: none; }

.ui, .fx { pointer-events: none; }
.ui .sel { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: 9 7; }
.ui .alca { pointer-events: auto; cursor: nwse-resize; }
.alca circle { fill: var(--y); stroke: var(--ink); stroke-width: 4; }
.alca .alca-toque { fill: transparent; stroke: none; }
.alca-seta { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.borracha { fill: rgba(255, 255, 255, .55); stroke: var(--ink); stroke-width: 3; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; }

.corpo.nasce { transform-box: fill-box; transform-origin: center; animation: nasce .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes nasce { from { transform: scale(.2); } }
.respingo { transform-box: fill-box; transform-origin: center; animation: respingo .5s ease-out forwards; }
@keyframes respingo { from { transform: scale(.15); opacity: .7; } to { transform: scale(1); opacity: 0; } }
.poeira { transform-box: fill-box; transform-origin: center; fill: #d9cfbd; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; animation: poeira .6s ease-out forwards; }
@keyframes poeira { to { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; } }

/* gaveta de formas */
.gaveta {
  position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%);
  --fb: clamp(52px, min(15vw, 14dvh), 88px);
  display: grid; grid-template-columns: repeat(4, var(--fb)); gap: 8px; padding: 14px;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 24px; box-shadow: 6px 6px 0 var(--ink);
  animation: abre .18s ease-out;
}
@keyframes abre { from { transform: translate(-50%, -46%) scale(.94); opacity: 0; } }
.gaveta button {
  width: var(--fb); height: var(--fb); padding: 6px; border: 0; border-radius: 16px; background: transparent;
  touch-action: none; cursor: grab;
}
.gaveta button:active { background: #fff1bf; }
.gaveta svg { display: block; width: 100%; height: 100%; }

/* ---------- diálogo e aviso ---------- */
.dlg {
  width: min(92vw, 420px); padding: 22px; text-align: center;
  background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 24px;
  box-shadow: 7px 7px 0 var(--ink);
}
.dlg::backdrop { background: rgba(58, 42, 23, .45); }
.dlg h2 { font-size: 28px; margin: 14px 0 18px; }
.dlg-miniatura { width: 70%; margin: 0 auto; aspect-ratio: 4 / 3; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; background: #f1e9d6; }
.dlg-miniatura svg { display: block; width: 100%; height: 100%; }
.dlg-botoes { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn {
  min-width: 130px; padding: 10px 22px; border-radius: 999px;
  font-family: var(--display); font-weight: 800; font-size: 22px;
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
.btn.nao { background: var(--leaf); }
.btn.sim { background: var(--paper); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.aviso {
  position: fixed; z-index: 60; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px);
  max-width: 90vw; padding: 10px 18px; border-radius: 16px;
  background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  font-weight: 800; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.aviso.show { opacity: 1; transform: translate(-50%, 0); }

@media (hover: hover) {
  .card:hover { transform: rotate(0) translateY(-3px); box-shadow: 6px 8px 0 var(--ink); }
  .home-link:hover, .home-link:focus-visible { transform: translate(-1px, -2px); box-shadow: 4px 5px 0 var(--ink); outline: none; }
  .rb:not(:disabled):hover { transform: translateY(-2px); }
  .tool[aria-pressed="true"]:hover { transform: scale(1.1) translateY(-2px); }
  .gaveta button:hover { background: #fff6d6; }
}

/* ---------- impressão: só o desenho, centralizado na folha A4 (o @page é posto pelo main.js) ---------- */
.impressao { display: none; }
@media print {
  html, body { height: auto; overflow: visible; background: none; }
  body > *:not(.impressao) { display: none !important; }
  .impressao {
    display: flex; align-items: center; justify-content: center;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .impressao svg { display: block; }
}

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