/* ============ Página de pintura ============ */
.app-body { overflow: hidden; height: 100dvh; background: var(--bg); }
.app {
  height: 100dvh; display: grid;
  grid-template-columns: 116px minmax(0, 1fr) 290px;
  grid-template-rows: 66px minmax(0, 1fr);
  grid-template-areas: "top top top" "tools stage colors";
}

/* --- barra de cima --- */
.app-top {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: #fff; border-bottom: 2px solid var(--line); position: relative; z-index: 5;
}
.top-btn {
  height: 44px; min-width: 44px; padding: 0 10px; border-radius: 14px; border: 0;
  background: transparent; color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 .95rem var(--font-head); text-decoration: none;
}
.top-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.top-btn:hover { background: var(--bg-soft); }
.top-btn:disabled { opacity: .3; pointer-events: none; }
.top-btn.labeled { background: var(--bg-soft); padding: 0 14px; }
.top-btn.primary { background: var(--purple); color: #fff; box-shadow: 0 3px 0 #6648d8; }
.top-btn.primary:hover { filter: brightness(1.06); background: var(--purple); }
.top-btn.back { background: var(--bg-soft); }
.sep { width: 2px; height: 26px; background: var(--line); border-radius: 2px; margin: 0 2px; }
.show-sm { display: none !important; }

.page-nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.page-pill {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0; min-width: 0;
  border: 0; background: var(--bg-soft); border-radius: 14px; padding: 5px 16px; cursor: pointer; color: var(--ink);
  text-align: left;
}
.page-pill:hover { background: #FFE3CC; }
.book-name { font: 600 .98rem var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.page-num { font-size: .8rem; font-weight: 800; color: var(--ink-soft); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; padding: 8px;
  background: #fff; border-radius: 18px; box-shadow: 0 20px 50px -12px rgba(42,33,64,.35), 0 0 0 1px var(--line);
}
.menu button {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: none;
  border-radius: 12px; cursor: pointer; font: 700 .97rem var(--font-body); color: var(--ink); text-align: left;
}
.menu button:hover { background: var(--bg-soft); }
.menu svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.menu hr { border: 0; border-top: 2px solid var(--line); margin: 6px 4px; }
.menu .danger { color: #C9184A; }

/* --- ferramentas --- */
.app-tools {
  grid-area: tools; background: #fff; border-right: 2px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; gap: 18px; padding: 16px 12px; overflow-y: auto;
}
.tool-group { display: flex; flex-direction: column; gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px;
  border: 0; border-radius: 18px; background: var(--bg-soft); color: var(--ink); cursor: pointer;
  font: 600 .82rem var(--font-head); transition: transform .12s, background .12s;
}
.tool svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: #FFE3CC; }
.tool[aria-checked="true"] { background: var(--purple); color: #fff; box-shadow: 0 4px 0 #6648d8; transform: translateY(-2px); }

.contour-tip {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
  width: max-content; max-width: calc(100% - 24px); margin: 0; padding: 8px 14px;
  border-radius: 999px; background: #FFF4D6; border: 2px solid #F3C74F; color: var(--ink);
  font-size: .85rem; line-height: 1.3; text-align: center; pointer-events: none;
  box-shadow: 0 6px 16px -8px rgba(42,33,64,.35);
}
.contour-tip b { font-family: var(--font-head); font-weight: 600; }
.contour-tip[hidden] { display: none; }
.brush-opts { display: flex; flex-direction: column; gap: 16px; }
.brush-opts[hidden] { display: none; }
.size { display: grid; gap: 8px; justify-items: center; font: 600 .8rem var(--font-head); }
.size input { width: 100%; accent-color: var(--purple); }
.size i { display: block; border-radius: 50%; background: var(--ink); width: 12px; height: 12px; }
.switch { display: grid; justify-items: center; gap: 6px; cursor: pointer; font: 600 .78rem var(--font-head); text-align: center; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 46px; height: 26px; border-radius: 999px; background: #D9D2E6; position: relative; transition: .2s; }
.switch .track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--purple); outline-offset: 2px; }

/* --- desenho --- */
.app-stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; }
.painter { position: absolute; inset: 0; }
.locked {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgba(255, 248, 238, .75); backdrop-filter: blur(6px); z-index: 3;
}
.locked[hidden] { display: none; }
.locked-card { background: #fff; border-radius: 28px; padding: 34px 30px; max-width: 440px; text-align: center; box-shadow: var(--shadow); }
.locked-card h2 { font-size: 1.5rem; }
.lock-ico { width: 70px; height: 70px; margin: 0 auto 14px; border-radius: 22px; display: grid; place-items: center; background: #EDE7FF; }
.lock-ico svg { width: 36px; height: 36px; fill: none; stroke: var(--purple); stroke-width: 2.2; stroke-linecap: round; }
.locked-actions { display: flex; flex-direction: column; gap: 12px; margin: 20px 0 8px; }
.small { font-size: .9rem; }
.locked-card a:not(.btn) { color: var(--purple); font-weight: 800; }

/* --- cores --- */
.app-colors {
  grid-area: colors; background: #fff; border-left: 2px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.current { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 2px solid var(--line); }
.current strong { display: block; font-family: var(--font-head); font-weight: 600; }
.current small { color: var(--ink-soft); font-size: .8rem; line-height: 1.2; display: block; }
.current-swatch { position: relative; flex: none; cursor: pointer; }
.current-swatch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.current-swatch span {
  display: block; width: 56px; height: 56px; border-radius: 50%; background: #F2711C;
  box-shadow: 0 0 0 4px #fff, 0 0 0 6px var(--line), inset 0 -6px 0 rgba(0,0,0,.15);
}
.current-swatch::after {
  content: '+'; position: absolute; right: -4px; bottom: -4px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); color: #fff; display: grid; place-items: center; font: 700 15px/1 var(--font-head);
}
.colors-scroll { overflow-y: auto; padding: 14px 18px 24px; }
.colors-scroll h4 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); margin: 10px 0 10px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px; margin-bottom: 8px; }
.swatches button {
  aspect-ratio: 1; width: 100%; border-radius: 50%; border: 0; cursor: pointer; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), inset 0 -4px 0 rgba(0,0,0,.14);
  transition: transform .1s;
}
.swatches button:hover { transform: scale(1.1); }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); transform: scale(1.05); }
.swatches.book button { border-radius: 14px; }

/* --- diálogos --- */
.sheet {
  border: 0; padding: 0; border-radius: 28px; width: min(980px, 100% - 24px); max-height: min(86dvh, 900px);
  background: var(--bg); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(42,33,64,.5);
}
.sheet::backdrop { background: rgba(42, 33, 64, .45); backdrop-filter: blur(3px); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px 26px; }
.sheet-head h2 { margin: 0; font-size: 1.4rem; }
.sheet .thumbs { padding: 10px 24px 26px; overflow-y: auto; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.thumb.current { box-shadow: 0 0 0 4px var(--purple); }
.thumb .done { position: absolute; right: 14px; bottom: 14px; width: 26px; height: 26px; border-radius: 50%; background: var(--purple); display: grid; place-items: center; }
.thumb .done svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.ref .ref-body { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; padding: 6px 26px 28px; overflow-y: auto; }
.ref-figure { margin: 0; background: #fff; border-radius: 20px; padding: 10px; box-shadow: 0 0 0 2px var(--line); }
.ref-figure img { border-radius: 12px; width: 100%; }
.ref-figure figcaption { font-weight: 700; color: var(--ink-soft); font-size: .9rem; padding: 8px 4px 2px; text-align: center; }
.ref-figure[hidden] { display: none; }
.ref-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ref-chips button {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 14px; border: 0;
  background: #fff; cursor: pointer; font: 700 .9rem var(--font-body); color: var(--ink); text-align: left;
  box-shadow: 0 0 0 2px var(--line);
}
.ref-chips button:hover { box-shadow: 0 0 0 2px var(--purple); }
.ref-chips i { width: 30px; height: 30px; border-radius: 10px; background: var(--c); flex: none; box-shadow: inset 0 -4px 0 rgba(0,0,0,.14), inset 0 0 0 1px rgba(0,0,0,.08); }

/* ===================== celular / tablet em pé ===================== */
@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 58px minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "stage" "tools" "colors";
  }
  .app > * { min-width: 0; }
  .app-top { padding: 0 8px; gap: 4px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
  .tool-extra { margin-left: auto; display: flex; gap: 2px; }
  .top-btn.labeled span { display: none; }
  .top-btn.labeled { padding: 0 10px; }
  .sep { display: none; }
  .page-nav { flex: 1; }
  .page-pill { flex: 1; padding: 4px 10px; }
  .book-name { max-width: 100%; font-size: .88rem; }
  .page-nav .top-btn { min-width: 36px; padding: 0 4px; }

  .app-tools {
    flex-direction: row; align-items: center; gap: 10px; padding: 8px 10px; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-top: 2px solid var(--line);
  }
  .tool-group { flex-direction: row; gap: 6px; }
  .tool { flex-direction: row; padding: 8px 12px; font-size: .85rem; border-radius: 14px; }
  .tool svg { width: 22px; height: 22px; }
  .tool span { display: none; }
  .tool[aria-checked="true"] span { display: inline; }
  .brush-opts { flex-direction: row; align-items: center; gap: 12px; }
  .size { grid-auto-flow: column; align-items: center; }
  .size span { display: none; }
  .size input { width: 90px; }
  .switch { grid-auto-flow: column; align-items: center; font-size: .75rem; text-align: left; }
  .switch .lbl { max-width: 70px; line-height: 1.1; }
  .contour-tip { top: 8px; border-radius: 16px; font-size: .78rem; }

  .app-colors { flex-direction: row; align-items: center; border-left: 0; border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .current { padding: 10px 6px 10px 12px; border-bottom: 0; }
  .current div { display: none; }
  .current-swatch span { width: 46px; height: 46px; }
  .colors-scroll { display: flex; align-items: center; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 10px 12px; }
  .colors-scroll .swatches { display: flex; gap: 8px; margin: 0; flex: none; }
  .colors-scroll .swatches button { width: 40px; height: 40px; flex: none; }
  .swatches.book { padding-right: 10px; border-right: 2px solid var(--line); }
  .ref .ref-body { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .tool { padding: 8px 10px; }
  .tool[aria-checked="true"] span { display: none; }
  .switch .lbl { display: none; }
}
