:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --line: #e4e4ea;
  --ink: #17171c;
  --muted: #6b6b78;
  --brand: #5b3cff;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); height: 100vh; display: flex; flex-direction: column; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 18px; display: flex; gap: 8px; align-items: center; }
.logo { color: var(--brand); font-size: 22px; }
.top-actions { display: flex; gap: 14px; align-items: center; }
.count { color: var(--muted); font-size: 14px; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn:hover { border-color: #c9c9d3; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }

.layout { flex: 1; display: grid; grid-template-columns: 400px 1fr; min-height: 0; }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 0 20px 24px; }
.tabs { display: flex; gap: 4px; position: sticky; top: 0; background: var(--panel); padding: 14px 0 12px; z-index: 2; }
.tabs button { flex: 1; border: 0; background: var(--bg); padding: 9px; border-radius: 9px; font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--ink); color: #fff; }

.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 6px; }
.lbl input[type=text] { display: block; width: 100%; margin-top: 6px; }
input[type=text], select, textarea { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 46vh; resize: vertical; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; }
textarea:focus, input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }

.help { margin: 12px 0; font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 10px 14px; }
.help summary { font-weight: 600; color: var(--ink); cursor: pointer; }
.help ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.7; }
.help code { background: #fff; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); color: var(--ink); }
.row { display: flex; gap: 8px; }

h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tpl { border: 2px solid transparent; border-radius: 10px; padding: 0; background: none; cursor: pointer; text-align: center; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); }
.tpl canvas { width: 100%; display: block; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tpl span { display: block; padding: 6px 0 4px; }
.tpl.active { border-color: var(--brand); color: var(--ink); }

.seg { display: flex; gap: 6px; }
.seg button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 4px; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }
.seg button small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.seg button.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, #fff); }

.colors, .fonts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fonts { grid-template-columns: 1fr 1fr; }
.colors label, .fonts label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
input[type=color] { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: #fff; cursor: pointer; }
.palettes { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.pal { display: flex; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; padding: 0; background: none; }
.pal i { width: 16px; height: 26px; display: block; }
.checks { display: flex; flex-direction: column; gap: 9px; font-size: 14px; }
.checks input { accent-color: var(--brand); width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }

.avatar-row { display: flex; gap: 14px; align-items: center; }
.avatar-row > div:last-child { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.avatar-preview { width: 72px; height: 72px; border-radius: 50%; background: var(--bg) center/cover; border: 1px solid var(--line); flex-shrink: 0; }
.logo-preview { width: 110px; height: 80px; border-radius: 10px; background: #020D2E center/contain no-repeat; border: 1px solid var(--line); flex-shrink: 0; }
.note { font-size: 13px; color: var(--muted); margin-top: 18px; }

.stage { overflow: auto; padding: 28px; display: flex; flex-direction: column; min-width: 0; }
.strip { display: flex; gap: 18px; overflow-x: auto; padding-bottom: 16px; align-items: flex-start; scroll-snap-type: x proximity; }
.slide { flex: 0 0 auto; width: 340px; scroll-snap-align: start; }
.slide canvas { width: 100%; display: block; border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 12px 32px rgba(0,0,0,.08); background: #fff; }
.slide-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 13px; color: var(--muted); }
.slide-meta b { color: var(--ink); }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 60px 0; }

@media (max-width: 860px) {
  body { height: auto; }
  .layout { display: flex; flex-direction: column; }
  /* no telemóvel os slides aparecem primeiro, o editor por baixo */
  .stage { order: -1; padding: 16px 16px 4px; }
  .panel { border-right: 0; border-top: 1px solid var(--line); }
  .slide { width: 72vw; max-width: 340px; }
  textarea { min-height: 260px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .top-actions { flex-wrap: wrap; gap: 8px; width: 100%; }
  .top-actions .btn { flex: 1 1 auto; padding: 9px 10px; font-size: 13px; }
  #btn-zip { flex-basis: 100%; }
  .count { font-size: 12px; }
  .hint { font-size: 12px; margin: 6px 0 0; }
}

textarea.prompt { min-height: 30vh; font-family: inherit; font-size: 15px; line-height: 1.5; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.opts label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.btn.big { width: 100%; padding: 13px; font-size: 15px; }
.status { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 10px 0; }
.status.erro { color: #b42318; }
.status.ok { color: #067647; }
.legenda textarea { width: 100%; min-height: 180px; font-family: inherit; font-size: 14px; margin-bottom: 8px; }
.btn.loading { position: relative; color: transparent; }
.btn.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #17171c; color: #fff; padding: 12px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 10; max-width: calc(100vw - 32px); }
.toast[hidden] { display: none; }
.toast .btn { background: #fff; color: #17171c; border-color: #fff; }
