/* ==========================================================================
   Ateliê de pintura
   ========================================================================== */

.studio {
  position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
  background: linear-gradient(180deg, #e4f5ff 0%, #fff3d6 100%);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

/* ----- topo ----- */
.st-top {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; z-index: 5;
  padding: calc(8px + var(--safe-t)) max(10px, var(--safe-r)) 8px max(10px, var(--safe-l));
  background: var(--paper); border-bottom: 3px solid var(--ink);
}
.st-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 1.2rem; }
.st-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-cat { font-size: 1.6rem; }
.st-actions { display: flex; align-items: center; gap: 8px; }
.st-top .btn-round { width: 50px; height: 50px; }
.st-top .btn { min-height: 50px; }
.st-save { padding: .4em 1.2em .4em 1em; font-size: 1.1rem; }
.st-save .ico { width: 1.4em; height: 1.4em; }

/* ----- corpo ----- */
.st-body {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: 'stage' 'tools' 'colors';
}
.st-stage { grid-area: stage; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }

/* ----- papel ----- */
.paper-wrap {
  position: relative; background: #fff; border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 7px 0 var(--ink); overflow: hidden;
  transform: translateY(-3px);
}
.paper { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
.paper .layer-paint, .paper .layer-lines { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.paper .layer-lines { mix-blend-mode: multiply; pointer-events: none; -webkit-user-drag: none; }
.st-loading { position: absolute; inset: 0; z-index: 8; display: grid; place-content: center; gap: 14px; text-align: center; background: var(--cream); font-weight: 700; transition: opacity .35s; }
.st-loading.off { opacity: 0; pointer-events: none; }
.cursor-ring {
  position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; opacity: 0; border-radius: 50%;
  border: 2px solid var(--ink); box-shadow: 0 0 0 2px rgba(255, 255, 255, .9); will-change: transform;
}
.studio[data-ferr=balde] .cursor-ring { border-radius: 4px; }

/* ----- balão do mascote ----- */
.st-bubble {
  position: absolute; left: 8px; top: 8px; z-index: 6; display: flex; align-items: flex-end; gap: 6px; max-width: min(94%, 440px);
  opacity: 0; transform: translateY(-14px) scale(.92); transform-origin: top left; pointer-events: none; transition: opacity .25s, transform .35s var(--ease-pop);
}
.st-bubble.on { opacity: 1; transform: none; pointer-events: auto; cursor: pointer; }
.sb-mascote { flex: 0 0 auto; width: 46px; margin-bottom: -4px; }
.sb-mascote .mascote { width: 100%; }
.sb-mascote .mascote-braco { animation: wave 1.6s ease-in-out infinite; }
.st-bubble p { margin: 0; padding: 10px 14px; font-weight: 600; font-size: 1rem; line-height: 1.25; color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 18px 18px 18px 4px; box-shadow: 0 4px 0 var(--ink); }

/* ----- ferramentas ----- */
.st-tools { grid-area: tools; background: var(--paper); border-top: 3px solid var(--ink); }
.tools-grid { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 4px; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tools-grid::-webkit-scrollbar { display: none; }
.tool {
  position: relative; flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px;
  width: 66px; height: 72px; padding-top: 5px; font-size: .7rem; font-weight: 700; line-height: 1; color: var(--ink);
  border: 3px solid transparent; border-radius: 18px; scroll-snap-align: center; transition: transform .14s var(--ease-pop), background .15s;
}
.tool .ico-tool { width: 42px; height: 42px; }
.tool .ico { width: 36px; height: 36px; margin-top: 3px; }
.tool.on { background: #fff; border-color: var(--ink); box-shadow: 0 4px 0 var(--ink); transform: translateY(-3px); }
.tool:active { transform: scale(.92); }
.tools-extra { display: flex; align-items: center; gap: 12px; padding: 2px 10px 8px; }
.sizes { display: flex; gap: 4px; padding: 3px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; }
.size { width: 44px; height: 38px; display: grid; place-items: center; border-radius: 999px; transition: background .15s; }
.size i { display: block; width: var(--s); height: var(--s); border-radius: 50%; background: var(--ink); background-image: none; }
.size.on { background: #ffe58a; box-shadow: inset 0 0 0 2.5px var(--ink); }
.st-tools .tool-ima { flex: 0 0 auto; white-space: nowrap; flex-direction: row; justify-content: center; width: auto; height: 46px; padding: 0 14px 0 10px; gap: 6px; font-size: .85rem; background: #fff; border: 3px solid var(--ink); border-radius: 999px; }
.st-tools .tool-ima .ico { width: 24px; height: 24px; margin: 0; }
.st-tools .tool-ima.on { background: var(--green); transform: none; box-shadow: 0 3px 0 var(--ink); }

/* ----- cores ----- */
.st-colors { grid-area: colors; background: #fff6df; border-top: 3px solid var(--ink); padding-bottom: var(--safe-b); }
.pal { display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, 44px); grid-auto-columns: 44px; gap: 8px; padding: 8px 12px 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.pal::-webkit-scrollbar { display: none; }
.pal-sep { grid-row: 1 / span 2; align-self: center; justify-self: center; font-size: 1.4rem; }
.sw {
  position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--sw); border: 3px solid var(--ink);
  box-shadow: 0 3px 0 rgba(47, 36, 64, .85); transition: transform .14s var(--ease-pop), box-shadow .14s;
}
.sw:active { transform: scale(.88); }
.sw.on { transform: scale(1.16); box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink); z-index: 2; }
.sw.on::after {
  content: ''; position: absolute; left: 50%; top: 46%; width: 11px; height: 19px; margin: -10px 0 0 -5px;
  border: solid var(--ink); border-width: 0 4px 4px 0; transform: rotate(45deg); filter: drop-shadow(0 0 1px #fff);
}
.sw-magic { border-style: solid; }
.sw-magic::before { content: '✨'; position: absolute; right: -6px; top: -8px; font-size: .75rem; filter: drop-shadow(0 1px 0 #fff); }
.sw-branco.on::after { border-color: var(--ink); }

/* ----- menus flutuantes ----- */
.flyout { position: absolute; z-index: 30; width: max-content; max-width: calc(100vw - 16px); padding: 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink); animation: pop .25s var(--ease-pop); }
.fly-title { margin: 0 0 8px; font-weight: 700; text-align: center; font-size: .95rem; }
.stamps { display: grid; grid-template-columns: repeat(5, 56px); gap: 6px; }
.stamp { width: 56px; height: 56px; border-radius: 14px; border: 3px solid transparent; background: #fff; display: grid; place-items: center; transition: transform .12s var(--ease-pop); }
.stamp img { display: block; }
.stamp.on { border-color: var(--ink); background: #fff3b8; }
.stamp:active { transform: scale(.88); }
@media (max-width: 360px) { .stamps { grid-template-columns: repeat(5, 48px); } .stamp { width: 48px; height: 48px; } .stamp img { width: 40px; height: 40px; } }
.fly-menu { padding: 8px; min-width: 260px; max-width: calc(100vw - 16px); }
.menu { display: grid; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; font-weight: 600; border-radius: 14px; }
@media (hover: hover) { .menu button:hover { background: #ffe9a8; } }
.menu button:active { background: #ffe9a8; }
.menu .ico { width: 24px; height: 24px; }

/* ----- tablet / computador (deitado): laterais ----- */
@media (min-width: 560px) and (orientation: landscape) {
  .st-body { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr); grid-template-areas: 'tools stage colors'; }
  .st-tools { display: flex; flex-direction: column; gap: 10px; width: 168px; padding: 10px 8px; overflow-y: auto; border-top: 0; border-right: 3px solid var(--ink); scrollbar-width: thin; }
  .tools-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 0; overflow: visible; }
  .tool { width: 100%; height: 76px; }
  .tool .ico-tool { width: 44px; height: 44px; }
  .tools-extra { flex-direction: column; align-items: stretch; padding: 4px 0 0; gap: 10px; }
  .sizes { justify-content: space-between; }
  .size { width: 36px; }
  .st-colors { width: 210px; overflow-y: auto; border-top: 0; border-left: 3px solid var(--ink); scrollbar-width: thin; }
  .pal { grid-auto-flow: row; grid-template-rows: none; grid-template-columns: repeat(4, 1fr); grid-auto-columns: auto; gap: 10px 8px; padding: 12px; overflow: visible; justify-items: center; }
  .pal-sep { grid-column: 1 / -1; grid-row: auto; font-size: 1rem; padding: 2px 0; }
  .sw { width: 100%; max-width: 44px; height: auto; aspect-ratio: 1; }
}
@media (min-width: 1100px) and (orientation: landscape) {
  .st-tools { width: 190px; }
  .st-colors { width: 250px; }
  .pal { gap: 12px 10px; }
  .sw { max-width: 50px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .st-top { padding-top: calc(4px + var(--safe-t)); padding-bottom: 4px; }
  .st-top .btn-round { width: 42px; height: 42px; } .st-top .btn { min-height: 42px; }
  .st-top .st-save { padding: .2em 1em .2em .8em; }
  .st-tools { width: 140px; padding: 6px; gap: 6px; }
  .tools-grid { gap: 4px; }
  .tool { height: 60px; padding-top: 3px; font-size: .64rem; }
  .tool .ico-tool { width: 34px; height: 34px; }
  .sizes { padding: 2px; gap: 0; }
  .size { width: 30px; height: 30px; }
  .st-tools .tool-ima { height: 40px; font-size: .78rem; }
  .st-colors { width: 156px; }
  .pal { grid-template-columns: repeat(3, 1fr); padding: 8px; gap: 8px 6px; }
  .sw { max-width: 38px; }
  .st-bubble p { font-size: .9rem; padding: 7px 11px; }
}

/* ----- telas estreitas ----- */
@media (max-width: 559px) {
  .st-music { display: none; }
}
@media (max-width: 560px) {
  .st-title { display: none; }
  .st-actions { width: 100%; justify-content: flex-end; }
  .st-top { gap: 6px; }
  .st-top .btn-round { width: 46px; height: 46px; }
  .st-top #st-back { margin-right: auto; }
  .st-save span { display: none; }
  .st-save { padding: 0; width: 56px; height: 56px; min-height: 0; border-radius: 50%; }
  .tool { width: 60px; height: 68px; }
  .tool .ico-tool { width: 38px; height: 38px; }
}
@media (max-width: 380px) { .st-redo { display: none; } }
