/* Editor — usa os tokens de site.css. Desktop: 3 colunas + timeline; celular: palco no topo, painéis empilhados. */
.page:has(.editor) {
  height: 100dvh;
  overflow: hidden;
}
.page:has(.editor)::before {
  display: none;
}
.editor {
  height: 100dvh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  grid-template-areas: 'top top top' 'media center insp' 'tl tl tl';
  background: var(--paper);
}
.editor-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 12px;
  border-bottom: var(--border);
  background: var(--paper);
}
.editor-top .logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--ink);
  color: var(--chroma);
  font-size: 1.3rem;
  border-radius: var(--radius);
}
.project-name {
  border: 0;
  background: transparent;
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 0;
  width: 100%;
  max-width: 280px;
  padding: 6px;
}
.project-name:focus {
  background: var(--card);
  outline: 2px solid var(--ink);
}
.grow-end {
  margin-left: auto;
  flex-wrap: nowrap;
}
.menu {
  position: relative;
}
.menu summary {
  list-style: none;
}
.menu-list {
  position: absolute;
  right: 0;
  top: 110%;
  z-index: 30;
  display: grid;
  min-width: 220px;
  background: var(--card);
  border: var(--border);
  box-shadow: var(--shadow);
}
.menu-list button {
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: 0;
  cursor: pointer;
  font-weight: 600;
}
.menu-list button:hover {
  background: var(--paper-2);
}

.media-panel,
.inspector {
  overflow-y: auto;
  background: var(--card);
}
.media-panel {
  grid-area: media;
  border-right: var(--border);
}
.inspector {
  grid-area: insp;
  border-left: var(--border);
}
.editor-center {
  grid-area: center;
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px;
  min-height: 0;
  background: #e3ded2;
  overflow: hidden;
}
.timeline {
  grid-area: tl;
  border-top: var(--border);
  background: var(--card);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 2;
}
.tabs button {
  padding: 10px 4px;
  background: none;
  border: 0;
  border-right: 1.5px solid var(--ink);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.88rem;
}
.tabs button:last-child {
  border-right: 0;
}
.tabs button.on {
  background: var(--ink);
  color: var(--paper);
}
.panel-body {
  padding: 14px;
  display: grid;
  gap: 0.8rem;
}
.panel-title {
  font-size: 1rem;
  font-stretch: 85%;
  margin-top: 0.4rem;
}
.upload {
  width: 100%;
}
.hint {
  font-size: 0.86rem;
  color: var(--muted);
}
.add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.add-grid button {
  padding: 12px 8px;
  border: var(--border);
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius);
}
.add-grid button:hover {
  background: var(--paper-2);
}
.add-grid .chroma {
  background: var(--chroma);
  color: var(--chroma-ink);
}
.mini-grid,
.sticker-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mini-grid button {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  background: var(--paper);
  border: var(--border);
  padding: 6px;
  cursor: pointer;
}
.mini-grid img {
  width: 100%;
  aspect-ratio: 9 / 12;
  object-fit: cover;
  background: var(--paper-2);
}
.mini-grid span {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.2;
}
.mini-grid small {
  color: var(--muted);
  font-size: 0.75rem;
}
.sticker-grid {
  grid-template-columns: repeat(3, 1fr);
}
.sticker-grid button {
  width: 100%;
  aspect-ratio: 1;
  padding: 6px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  cursor: pointer;
}
.sticker-grid button:hover {
  background: var(--paper-2);
  transform: translate(-1px, -1px);
}
.sticker-grid img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chips button {
  padding: 4px 10px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  border-radius: 99px;
  font-size: 0.82rem;
  cursor: pointer;
}
.chips button.on {
  background: var(--ink);
  color: var(--paper);
}

.seg {
  display: flex;
  border: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  flex: 1;
  padding: 8px 6px;
  background: var(--paper);
  border: 0;
  border-right: 1.5px solid var(--ink);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}
.seg button:last-child {
  border-right: 0;
}
.seg button.on {
  background: var(--ink);
  color: var(--paper);
}
.seg-wrap {
  flex-wrap: wrap;
}

.insp-head {
  padding: 12px;
  border-bottom: var(--border);
  display: grid;
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 2;
}
.insp-head input {
  font-weight: 800;
}
.insp-section {
  border-bottom: 1.5px solid var(--ink);
}
.insp-section summary {
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
}
.insp-body {
  padding: 0 12px 14px;
  display: grid;
  gap: 0.7rem;
}
.ctl {
  font-weight: 600;
  font-size: 0.9rem;
}
.ctl > span {
  display: flex;
  justify-content: space-between;
}
.ctl output {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.8rem;
}
.ctl input[type='range'] {
  width: 100%;
  accent-color: var(--ink);
}
.ctl-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}
input[type='color'] {
  width: 40px;
  height: 32px;
  padding: 0;
  border: var(--border);
  background: none;
  cursor: pointer;
}

/* palco */
.stage {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  align-content: center;
}
.stage-frame {
  position: relative;
  max-width: 100%;
  max-height: calc(100dvh - 56px - 260px);
  box-shadow: var(--shadow-lg);
  border: var(--border);
  background: var(--ink);
}
.stage-frame.aspect-9x16 {
  aspect-ratio: 9 / 16;
  height: calc(100dvh - 56px - 280px);
}
.stage-frame.aspect-1x1 {
  aspect-ratio: 1;
  height: min(calc(100dvh - 56px - 280px), 100%);
}
.stage-frame.aspect-16x9 {
  aspect-ratio: 16 / 9;
  width: min(100%, 900px);
}
.stage-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.stage-overlay {
  position: absolute;
  inset: 0;
  touch-action: none;
}
.stage-overlay.tool-eyedropper {
  cursor: crosshair;
}
.stage-overlay[class*='tool-mask'] {
  cursor: crosshair;
}
.layer-handle {
  position: absolute;
  touch-action: none;
  outline: 1px dashed rgba(0, 224, 90, 0.9);
  transform-origin: center;
}
.mask-draft {
  position: absolute;
  overflow: visible;
  pointer-events: none;
  transform-origin: center;
}
.mask-draft * {
  fill: rgba(0, 224, 90, 0.18);
  stroke: var(--chroma);
  stroke-width: 2;
}
.stage-hint {
  font-size: 0.9rem;
  background: var(--card);
  border: var(--border);
  padding: 6px 10px;
}
.empty-hint {
  position: absolute;
  inset: auto 16px 24px;
  margin: auto;
  max-width: 420px;
  text-align: center;
  background: var(--card);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 14px;
}
.mobile-note {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  padding: 6px 10px;
}

/* timeline */
.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1.5px solid var(--ink);
}
.time {
  min-width: 110px;
}
.zoom {
  margin-left: auto;
  width: 140px;
}
.zoom input {
  width: 100%;
  accent-color: var(--ink);
}
.timeline-empty {
  padding: 14px;
}
.timeline .timeline-editor {
  background: var(--card) !important;
  font-family: var(--font-body);
}
.timeline .timeline-editor-edit-row {
  background: transparent !important;
  border-bottom: 1px solid rgba(17, 17, 16, 0.12) !important;
}
.timeline .timeline-editor-action {
  border-radius: 3px;
}
.timeline .timeline-editor-cursor {
  border-color: var(--danger) !important;
}
.clip {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  color: var(--ink);
}
.clip-video {
  background: #ffe08a;
}
.clip-image {
  background: #b8e1ff;
}
.clip-text {
  background: #fff;
}
.clip-solid {
  background: var(--chroma);
}
.clip-audio {
  background: #e2c6ff;
}

/* diálogo de download */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 16, 0.55);
  z-index: 40;
}
.dialog {
  position: fixed;
  z-index: 41;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  border: var(--border);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  display: grid;
  gap: 1rem;
}
.dialog h2 {
  font-size: 2rem;
}
.dialog-close {
  position: absolute;
  right: 10px;
  top: 8px;
  background: none;
  border: 0;
  font-size: 1.6rem;
  cursor: pointer;
}
.pay-options {
  display: grid;
  gap: 0.3rem;
}
.pay-options .btn {
  width: 100%;
}
.pay-options .trigger {
  margin: 0 0 0.7rem;
}
progress {
  width: 100%;
  height: 18px;
  accent-color: var(--chroma);
}
.celebrate {
  font-size: 1.25rem;
  font-weight: 800;
}
.link {
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  font-weight: 700;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--chroma);
  max-width: calc(100% - 32px);
}
.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  background: rgba(0, 224, 90, 0.25);
  border: 6px dashed var(--ink);
  font-size: 2rem;
  font-weight: 900;
  pointer-events: none;
}
.editor-boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 1rem;
  text-align: center;
  padding: 16px;
}
.skeleton {
  width: min(360px, 80vw);
  aspect-ratio: 9 / 16;
  max-height: 60vh;
  background: linear-gradient(90deg, var(--paper-2), var(--card), var(--paper-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border: var(--border);
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* Barra inferior e textos só do celular: escondidos no desktop. */
.mobile-tabs,
.mobile-only {
  display: none;
}

/*
 * Celular (e tablet em pé): app de uma tela, estilo CapCut simplificado.
 * Palco em cima ocupando o que sobrar; transporte (play/tempo) fixo; uma
 * folha inferior com o painel escolhido na barra de abas (Mídia, Stickers,
 * Templates, Ajustes, Tempo). Tocar na aba aberta fecha a folha.
 */
@media (max-width: 900px), (max-height: 500px) and (pointer: coarse) {
  .page:has(.editor) {
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    font-size: 16px;
  }
  .editor {
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: 'top' 'center' 'tl' 'sheet' 'tabs';
  }
  .mobile-only {
    display: revert;
  }
  .desktop-only {
    display: none;
  }

  /* topo: só ícones em desfazer/refazer, Baixar sempre visível */
  .editor-top {
    gap: 6px;
    padding: calc(6px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px
      max(8px, env(safe-area-inset-left));
  }
  .editor-top .grow-end {
    gap: 6px;
  }
  .editor-top .btn-sm {
    min-height: 44px;
    padding: 0 12px;
  }
  .editor-top .btn-ghost {
    min-width: 44px;
    padding: 0 8px;
    font-size: 1.2rem;
  }
  .editor-top .menu .btn-ghost {
    font-size: 0.95rem;
  }
  .editor-top .btn-pay {
    padding: 0 18px;
    font-size: 1rem;
  }
  .btn-label,
  .project-name {
    display: none;
  }
  .menu-list button {
    min-height: 48px;
  }

  /* palco: cabe na célula que sobra (container query), sem rolar */
  .editor-center {
    container-type: size;
    padding: 10px;
  }
  .stage-frame {
    max-height: none;
    box-shadow: var(--shadow);
  }
  .stage-frame.aspect-9x16 {
    height: auto;
    width: min(100%, calc(100cqh * 9 / 16));
  }
  .stage-frame.aspect-1x1 {
    height: auto;
    width: min(100%, 100cqh);
  }
  .stage-frame.aspect-16x9 {
    width: min(100%, calc(100cqh * 16 / 9));
  }
  .empty-hint {
    inset: auto 12px 12px;
    padding: 12px;
    font-size: 0.95rem;
  }
  .empty-hint .hint {
    margin-top: 0.3rem;
  }

  /* folha inferior: só o painel escolhido; rola por dentro */
  .media-panel,
  .inspector {
    grid-area: sheet;
    display: none;
    border: 0;
    border-top: var(--border);
    max-height: 42dvh;
    overscroll-behavior: contain;
  }
  .editor.m-media .media-panel,
  .editor.m-ajustes .inspector {
    display: block;
  }
  .media-panel .tabs {
    display: none;
  }
  .panel-body {
    padding: 12px max(12px, env(safe-area-inset-left));
  }
  .add-grid button {
    min-height: 48px;
  }
  .mini-grid,
  .sticker-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }
  .sticker-grid {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  }

  /* inspector: alvos de toque de 44px, sem zoom do iOS em campos (≥16px) */
  .insp-head .row {
    gap: 6px;
  }
  .insp-head .btn-sm,
  .insp-body .btn-sm {
    min-height: 44px;
  }
  .insp-section summary {
    padding: 13px 12px;
  }
  .seg button,
  .tabs button {
    min-height: 44px;
  }
  .chips button {
    min-height: 36px;
    padding: 6px 12px;
  }
  .ctl input[type='range'],
  .zoom input {
    height: 32px;
  }
  input[type='color'] {
    width: 48px;
    height: 40px;
  }
  .editor input:not([type='range'], [type='checkbox'], [type='color'], [type='file']),
  .editor textarea,
  .editor select {
    font-size: 16px;
  }

  /* linha do tempo: transporte sempre; trilhas só na aba Tempo */
  .timeline .transport {
    border-bottom: 0;
    padding: 4px max(10px, env(safe-area-inset-left));
  }
  .timeline .transport .btn-sm {
    min-height: 44px;
    min-width: 52px;
  }
  .editor:not(.m-tempo) .timeline :is(.zoom, .timeline-editor, .timeline-empty) {
    display: none;
  }
  .editor.m-tempo .timeline .zoom {
    width: 120px;
  }
  .editor.m-tempo .timeline .transport {
    border-bottom: 1.5px solid var(--ink);
  }

  .mobile-tabs {
    grid-area: tabs;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    border-top: var(--border);
    background: var(--ink);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .mobile-tabs button {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 6px 2px;
    background: none;
    border: 0;
    color: var(--paper);
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-tabs button.on {
    color: var(--ink);
    background: var(--chroma);
  }
  @media (max-width: 380px) {
    .mobile-tabs button {
      font-size: 0.66rem;
      letter-spacing: -0.01em;
    }
  }
  .mobile-tabs span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* alças do Moveable maiores para o dedo */
  .stage-overlay .moveable-control {
    width: 22px !important;
    height: 22px !important;
    margin-top: -11px !important;
    margin-left: -11px !important;
  }
  .stage-overlay .moveable-rotation-control {
    width: 28px !important;
    height: 28px !important;
    margin-left: -14px !important;
    margin-top: -14px !important;
  }

  /* diálogos viram folha de baixo, com a área segura do aparelho */
  .dialog {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    transform: none;
    width: 100%;
    max-height: 92dvh;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    border-width: 2px 0 0;
    box-shadow: 0 -4px 0 var(--ink);
  }
  .dialog h2 {
    font-size: 1.7rem;
    padding-right: 36px;
  }
  .dialog-close {
    width: 44px;
    height: 44px;
    right: 6px;
    top: 6px;
  }
  .dialog .btn-sm {
    min-height: 44px;
  }
  .toast {
    bottom: auto;
    top: calc(64px + env(safe-area-inset-top));
  }
}

/* Celular deitado: folha à direita do palco para não espremer a altura. */
@media (max-height: 500px) and (orientation: landscape) and (pointer: coarse),
  (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .editor {
    grid-template-columns: minmax(0, 1fr) min(360px, 45vw);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: 'top top' 'center sheet' 'tl tl' 'tabs tabs';
  }
  .media-panel,
  .inspector {
    max-height: none;
    border-top: 0;
    border-left: var(--border);
  }
  .mobile-tabs button {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 44px;
    gap: 6px;
    font-size: 0.8rem;
  }
  .editor-top {
    padding-block: 4px;
  }
  /* sem folha aberta o palco fica com a largura toda */
  .editor.m-none {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'top' 'center' 'tl' 'tabs';
  }
  /* aba Tempo: a linha do tempo ocupa a coluna da direita */
  .editor.m-tempo {
    grid-template-columns: minmax(0, 1fr) min(440px, 52vw);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: 'top top' 'center tl' 'tabs tabs';
  }
  .editor.m-tempo .timeline {
    border-top: 0;
    border-left: var(--border);
    overflow-y: auto;
  }
}
.ideas {
  border: var(--border);
  padding: 10px;
  background: var(--paper);
}
.ideas-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}
.ideas-list button {
  width: 100%;
  text-align: left;
  border: 1.5px solid var(--ink);
  background: var(--card, #fff);
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
}
.ideas-list button:hover,
.ideas-list button:focus-visible {
  background: var(--chroma);
}

/* meus projetos */
.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  max-height: 50dvh;
  overflow: auto;
}
.project-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(17, 17, 16, 0.12);
}
.project-list .grow {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
