/* Ateliê — interface neutra (cinza médio) para que as cores do desenho sejam julgadas sem viés. */
:root {
  --bg: #2b2d31;
  --bg-raised: #34363b;
  --bg-sunken: #232427;
  --work: #3c3e43;
  --line: #45474d;
  --text: #ebe8e1;
  --dim: #a4a7ae;
  --accent: #4a5ff0;
  --accent-hi: #98a4ff;
  --accent-soft: rgba(74, 95, 240, .2);
  --cadmium: #f2b705;
  --danger: #e0584c;
  --ok: #7ccf9a;
  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Ubuntu, Cantarell, sans-serif;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; }
#app { height: 100%; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent-hi); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }
::selection { background: var(--accent-soft); }

/* ---------- botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-raised); text-decoration: none; transition: background .12s, border-color .12s; }
.btn:hover { background: #3d3f45; border-color: #5a5d65; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #5b6ef5; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[aria-pressed="true"] { border-color: var(--accent-hi); background: var(--accent-soft); }
.btn:disabled { opacity: .45; cursor: default; }
.btn .ic svg { width: 18px; height: 18px; display: block; }
.ibtn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text); }
.ibtn:hover:not(:disabled) { background: rgba(255, 255, 255, .08); }
.ibtn:disabled { opacity: .3; cursor: default; }
.ibtn.on, .ibtn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-hi); }
.ibtn.accent { color: var(--accent-hi); }
.ibtn.danger:hover:not(:disabled) { color: var(--danger); }
.ibtn.sm { width: 32px; height: 32px; }
.ibtn.sm svg { width: 18px; height: 18px; }
.group { display: flex; align-items: center; gap: 2px; }
.spacer { flex: 1; }

/* ---------- campos ---------- */
input[type=text], input:not([type]), input[type=number], select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-sunken); font-size: 16px; }
textarea { resize: vertical; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-sunken); }
.field { display: grid; grid-template-columns: 96px 1fr 48px; align-items: center; gap: 8px; min-height: 34px; font-size: 13px; }
.field.col { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.field:has(> .segmented), .field:has(> select) { grid-template-columns: 96px 1fr; }
.flabel { color: var(--dim); }
.readout { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 10px; min-height: 34px; font-size: 13px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { color: var(--dim); font-size: 13px; }
.hint.err, .err { color: #ff8f84; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { flex: 1; min-height: 32px; padding: 0 10px; border: 0; background: transparent; font-size: 13px; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-hi); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; --fill: 50%; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent-hi) var(--fill), #55575e var(--fill)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #55575e; }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent-hi); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--text); border: 2px solid var(--bg); box-shadow: 0 0 0 1px #00000066; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 2px solid var(--bg); }
input[type=range].hue::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
input[type=range].hue::-moz-range-track { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
input[type=range].hue::-webkit-slider-thumb { margin-top: -4px; background: var(--thumb, #fff); }

/* ---------- avisos e janelas ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: 10px; background: #17181a; border: 1px solid var(--line); box-shadow: 0 8px 24px #0006; font-size: 14px; transition: opacity .4s; }
.toast.err { border-color: var(--danger); }
.toast.out { opacity: 0; }
.modal-back { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(10, 10, 12, .6); }
.modal { width: min(100%, 460px); max-height: 92dvh; overflow: auto; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); box-shadow: 0 24px 60px #000a; display: grid; gap: 16px; }
.modal h2 { font: 600 20px/1.2 var(--serif); }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.newform { display: grid; gap: 10px; }
.presetgrid, .bgrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dims { display: flex; align-items: end; gap: 8px; }
.dims .field { flex: 1; }
.times { padding-bottom: 10px; color: var(--dim); }
.exportbody { display: grid; gap: 10px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; align-content: center; padding: max(24px, var(--safe-t)) 24px 24px; }
.login-card { width: min(100%, 460px); margin-inline: max(0px, calc((100vw - 460px) / 2 - 8vw)); display: grid; gap: 20px; }
.wordmark { font: italic 400 clamp(56px, 12vw, 92px)/.95 var(--serif); letter-spacing: -.02em; }
.wordmark.sm { font-size: 30px; }
.flourish { width: min(320px, 70%); margin-top: -6px; overflow: visible; }
.flourish path { fill: none; stroke: var(--cadmium); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.3s .2s cubic-bezier(.5, 0, .2, 1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .flourish path { animation: none; stroke-dashoffset: 0; } }
.login-lead { font-size: 17px; color: #d3d0c9; max-width: 38ch; }
.wallets { display: grid; gap: 10px; }
.wallet { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-raised); text-decoration: none; color: var(--text); font-weight: 600; text-align: left; }
.wallet:hover { border-color: var(--accent-hi); background: #3a3d47; }
.wallet[aria-busy="true"] { opacity: .6; pointer-events: none; }
.wallet img, .wicon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; }
.wicon svg { width: 24px; height: 24px; }
.login-help { display: grid; gap: 12px; font-size: 14px; }
.login-status { min-height: 1.4em; color: var(--dim); font-size: 14px; }
.fineprint { color: var(--dim); font-size: 13px; max-width: 48ch; }

/* ---------- galeria ---------- */
.gallery { min-height: 100%; display: flex; flex-direction: column; }
.gal-top { display: flex; align-items: center; gap: 12px; padding: calc(12px + var(--safe-t)) 24px 12px; border-bottom: 1px solid var(--line); }
.chip-user { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-raised); font-variant-numeric: tabular-nums; }
.chip-user .ic svg { width: 18px; height: 18px; display: block; }
.gal-main { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }
.gal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.gal-head h2 { font: 600 24px/1.2 var(--serif); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.card { position: relative; display: grid; gap: 8px; }
.thumb { display: grid; place-items: center; aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: conic-gradient(#d4d4d4 25%, #f2f2f2 0 50%, #d4d4d4 0 75%, #f2f2f2 0) 0 0 / 16px 16px; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb:hover { border-color: var(--accent-hi); }
.noimg { color: #666; font-size: 13px; }
.cardinfo { display: grid; }
.cname { color: var(--text); text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmeta { color: var(--dim); font-size: 13px; }
.card .del { position: absolute; top: 6px; right: 6px; background: rgba(20, 20, 22, .75); opacity: 0; transition: opacity .12s; }
.card:hover .del, .card:focus-within .del { opacity: 1; }
@media (hover: none) { .card .del { opacity: 1; } }
.empty { display: grid; gap: 14px; justify-items: start; padding: 40px 0; color: var(--dim); }
.loading { height: 100%; display: grid; place-items: center; color: var(--dim); }

/* ---------- editor ---------- */
.editor-root, .editor { height: 100%; }
.editor { position: relative; display: grid; grid-template-columns: 56px minmax(0, 1fr) 312px; grid-template-rows: 48px minmax(0, 1fr); grid-template-areas: "top top top" "rail stage panel"; background: var(--bg); overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 4px; padding: var(--safe-t) 8px 0; height: calc(48px + var(--safe-t)); border-bottom: 1px solid var(--line); background: var(--bg); }
.editor { grid-template-rows: calc(48px + var(--safe-t)) minmax(0, 1fr); }
.docinfo { display: grid; gap: 0; min-width: 0; width: min(280px, 40vw); line-height: 1.15; }
.docinfo .docname { min-height: 24px; height: 24px; padding: 0 6px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-size: 15px; font-weight: 600; text-overflow: ellipsis; }
.docinfo .docname:hover { border-color: var(--line); }
.docinfo .docname:focus { background: var(--bg-sunken); border-color: var(--line); }
.save-status { padding: 0 6px; font-size: 11.5px; color: var(--dim); min-height: 14px; }
.save-status[data-s="saving"], .save-status[data-s="dirty"] { color: var(--cadmium); }
.save-status[data-s="error"], .save-status[data-s="conflict"], .save-status[data-s="offline"] { color: #ff8f84; }
.save-status[data-s="saved"] { color: var(--ok); }
.zoomlabel { min-width: 56px; height: 32px; border: 0; border-radius: 6px; background: transparent; font-variant-numeric: tabular-nums; font-size: 13px; }
.zoomlabel:hover { background: rgba(255, 255, 255, .08); }

.rail { grid-area: rail; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; }
.tool { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent; color: var(--text); }
.tool:hover { background: rgba(255, 255, 255, .08); }
.tool[aria-pressed="true"] { background: var(--accent); color: #fff; }
.rail-sep { width: 28px; height: 1px; margin: 6px 0; background: var(--line); }
.swatch-btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2px solid var(--text); background: var(--c, #000); box-shadow: 0 0 0 2px var(--bg); cursor: pointer; }

.stage { grid-area: stage; position: relative; background: var(--work); overflow: hidden; touch-action: none; cursor: crosshair; outline: none; }
.stage[data-tool="mao"], .stage.panning { cursor: grab; }
.stage[data-tool="mover"] { cursor: move; }
.stage[data-tool="gotas"] { cursor: copy; }
.stage[data-tool="texto"] { cursor: text; }
.stage .view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.zoomhud { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); padding: 4px 10px; border-radius: 999px; background: #17181acc; font-size: 13px; font-variant-numeric: tabular-nums; pointer-events: none; }
.selbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; border-radius: 12px; background: #17181af0; border: 1px solid var(--line); }
.quick { display: none; }

.panel { grid-area: panel; display: flex; flex-direction: column; overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg); }
.grab { display: none; }
.sec { padding: 14px 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; align-content: start; }
.sec h3 { font: 600 14px/1.2 var(--sans); }
.sec h4 { font-size: 12px; font-weight: 500; color: var(--dim); margin-top: 4px; }
.sechead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sechead .group { flex-wrap: wrap; justify-content: flex-end; }
.sechead .ibtn { width: 30px; height: 30px; }
.sechead .ibtn svg { width: 18px; height: 18px; }

.sv { width: 100%; height: auto; aspect-ratio: 220 / 160; border-radius: 8px; touch-action: none; cursor: crosshair; }
.colorrow { display: flex; align-items: center; gap: 10px; }
.swpair { position: relative; width: 48px; height: 40px; flex: none; }
.sw { position: absolute; width: 30px; height: 30px; border-radius: 6px; border: 2px solid var(--text); padding: 0; }
.sw.primary { left: 0; top: 0; z-index: 1; }
.sw.secondary { right: 0; bottom: 0; border-color: var(--dim); }
.hex { width: 100%; font-variant-numeric: tabular-nums; text-transform: lowercase; }
.swatches { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.swatches.recent { grid-template-columns: repeat(14, 1fr); }
.swatches.recent:empty, .recent-h:has(+ .swatches.recent:empty) { display: none; }
.chip { aspect-ratio: 1; min-width: 0; padding: 0; border: 1px solid #0006; border-radius: 4px; }
.chip:hover { outline: 2px solid var(--text); outline-offset: 1px; }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset { display: grid; gap: 2px; justify-items: start; padding: 6px 8px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-raised); font-size: 12px; text-align: left; }
.preset:hover { border-color: #5a5d65; }
.preset[aria-pressed="true"] { border-color: var(--accent-hi); background: var(--accent-soft); }
.bprev { width: 100%; height: 22px; display: block; object-fit: contain; }
.brushblock, .tooloptions, .togglegroup { display: grid; gap: 4px; }

.layerlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 40vh; overflow-y: auto; }
.layer { display: grid; grid-template-columns: 32px minmax(0, 1fr) 32px; align-items: center; min-height: 46px; padding: 2px 4px; border: 1px solid transparent; border-radius: 8px; background: var(--bg-raised); }
.layer.active { border-color: var(--accent-hi); background: var(--accent-soft); }
.layer.hidden .lbody { opacity: .5; }
.lbody { display: flex; align-items: center; gap: 8px; min-width: 0; height: 100%; cursor: pointer; }
.lthumb { width: 44px; height: 34px; border-radius: 4px; border: 1px solid #0008; flex: none; }
.lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.rename { min-height: 30px !important; font-size: 14px !important; }
.layermeta { display: grid; gap: 4px; }

/* ---------- celular e telas estreitas ---------- */
@media (max-width: 820px) {
  .editor { grid-template-columns: minmax(0, 1fr); grid-template-rows: calc(48px + var(--safe-t)) minmax(0, 1fr) 52px calc(50px + var(--safe-b)); grid-template-areas: "top" "stage" "rail" "dock"; }
  .hide-m { display: none !important; }
  .docinfo { width: auto; flex: 1; }
  .rail { flex-direction: row; justify-content: flex-start; padding: 5px 8px; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; gap: 4px; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .tool { flex: none; width: 44px; height: 42px; }
  .rail-sep { width: 1px; height: 28px; margin: 0 6px; flex: none; }
  .swatch-btn { flex: none; }
  .dock { grid-area: dock; display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: var(--safe-b); border-top: 1px solid var(--line); background: var(--bg); }
  .dock button { display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: transparent; font-size: 14px; }
  .dock button svg { width: 20px; height: 20px; }
  .dock button[aria-pressed="true"] { color: var(--accent-hi); background: var(--accent-soft); }
  .dock .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--c, #000); border: 2px solid var(--text); }
  .panel { position: absolute; left: 0; right: 0; bottom: calc(102px + var(--safe-b)); max-height: min(58dvh, 520px); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px #0008; z-index: 20; display: none; }
  .editor[data-sheet] .panel .sec { display: none; border-bottom: 0; }
  .editor[data-sheet="color"] .panel, .editor[data-sheet="tool"] .panel, .editor[data-sheet="layers"] .panel { display: flex; }
  .editor[data-sheet="color"] .panel .sec-color, .editor[data-sheet="tool"] .panel .sec-tool, .editor[data-sheet="layers"] .panel .sec-layers { display: grid; }
  .grab { display: grid; place-items: center; height: 22px; flex: none; cursor: pointer; }
  .grab span { width: 40px; height: 4px; border-radius: 2px; background: #666; }
  .sec { padding-top: 4px; }
  .layerlist { max-height: 26dvh; }
  .quick { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); display: flex; gap: 10px; padding: 8px 4px; border-radius: 22px; background: #17181acc; }
  .qcol { position: relative; width: 30px; height: 130px; display: grid; place-items: end center; }
  .qcol input { position: absolute; width: 130px; height: 30px; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-90deg); }
  .qcol span { position: absolute; bottom: -18px; font-size: 11px; color: var(--dim); }
  .qcol { margin-bottom: 20px; }
  .quick { padding-bottom: 6px; }
  .qtip { position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); padding: 4px 8px; border-radius: 8px; background: #17181af0; font-size: 12px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s; }
  .qtip.on { opacity: 1; }
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -10px; }
  .field { grid-template-columns: 88px 1fr 44px; }
  .selbar { bottom: 10px; }
  .swatches { grid-template-columns: repeat(11, 1fr); }
  .gal-top, .gal-main { padding-inline: 16px; }
}
@media (min-width: 821px) { .dock { display: none; } }
@media (max-width: 380px) { .dock button span:not(.dot) { display: none; } }

/* voltar ao site */
.back-site { display: inline-flex; align-items: center; gap: 4px; justify-self: start; color: var(--dim); text-decoration: none; font-size: 14px; padding: 6px 10px 6px 4px; margin-left: -4px; border-radius: 8px; }
.back-site:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.back-site .ic { display: inline-grid; }
.back-site svg { width: 18px; height: 18px; }
