:root {
  color-scheme: dark;
  /* Ardosia com viés violeta: nao e preto neutro nem roxo saturado. O matiz
     fica em ~250deg com saturacao baixa, entao o fundo respira sem puxar cor. */
  --bg: #191922;
  --panel: #24242f;
  --panel-soft: #2d2d3a;
  --line: #3a3a47;
  --line-soft: #31313d;
  --text: #f2f2f7;
  --muted: #9c9cb0;
  --accent: #7c5cff;
  --accent-hover: #8f73ff;
  --good: #4ade80;
  --warn: #fbbf24;
  --error: #fb7185;
  --r: 10px;
  --gap: 10px;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: .875rem; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2, p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip-link { position: fixed; z-index: 100; left: 10px; top: 10px; padding: 8px 11px; border-radius: 8px; background: #fff; color: #111; font-weight: 700; text-decoration: none; transform: translateY(-200%); }
.skip-link:focus { transform: translateY(0); }

.studio { display: flex; flex-direction: column; height: 100%; }

/* Topo */
.studio-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px clamp(20px, 7vw, 110px); border-bottom: 1px solid var(--line); background: var(--panel); }
.head-left, .head-right { display: flex; align-items: center; gap: 7px; }
.head-left select { min-width: 165px; max-width: 230px; }
.chip-label { color: var(--muted); font-size: .66rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.ghost-button { min-height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: .72rem; font-weight: 600; transition: border-color .15s, color .15s; }
.ghost-button:hover { border-color: var(--accent); color: var(--text); }
.balance-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-soft); }
.balance-chip strong { font-size: .78rem; font-variant-numeric: tabular-nums; }
.balance-chip.is-low strong { color: var(--warn); }
.balance-chip.is-off strong { color: var(--muted); font-size: .68rem; font-weight: 500; }
.icon-button { padding: 1px; border: 0; background: transparent; color: var(--muted); font-size: .78rem; line-height: 1; }
.icon-button:hover { color: var(--text); }
.icon-button.is-busy { opacity: .4; }
.connection { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .68rem; }
.connection span:first-child { width: 6px; height: 6px; border-radius: 50%; background: #64646f; }
.connection.is-ready span:first-child { background: var(--good); }
.connection.is-error span:first-child { background: var(--error); }

/* Palco */
/* Respiro lateral generoso: o palco encolhe o video antes de encostar nas bordas. */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) clamp(230px, 19vw, 280px); gap: clamp(14px, 1.8vw, 26px); min-height: 0; flex: 1; padding: clamp(12px, 1.8vh, 20px) clamp(20px, 7vw, 110px) clamp(14px, 2vh, 22px); }
.player-pane { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; min-height: 0; }

/* O box ocupa a altura livre; o stack dentro dele respeita o aspect ratio do video
   e nunca estoura — object-fit:contain garante o video inteiro, sem corte. */
.player-box { position: relative; display: grid; place-items: center; flex: 1 1 0; min-height: 0; padding: clamp(10px, 1.6vw, 20px); overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #12121a; }
.player-stack { position: relative; height: 100%; max-height: 100%; aspect-ratio: var(--ar, 9 / 16); max-width: 100%; border-radius: 8px; overflow: hidden; background: #000; }
.player-stack:empty { display: none; }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.layer.is-front { opacity: 1; }
.player-empty { position: absolute; display: grid; gap: 5px; max-width: 300px; padding: 20px; color: var(--muted); font-size: .8rem; line-height: 1.5; text-align: center; }
.player-empty strong { color: var(--text); font-size: .85rem; }
.player-badge { position: absolute; top: 14px; left: 14px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: rgba(6,6,10,.8); font-size: .72rem; font-weight: 600; backdrop-filter: blur(8px); }
.player-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.player-badge.is-live .dot { background: var(--good); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* Controles */
.player-bar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.icon-action { display: grid; place-content: center; width: 28px; height: 28px; flex: none; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-soft); color: var(--text); font-size: .7rem; transition: border-color .15s; }
.icon-action:hover { border-color: var(--accent); }
.scrubber { display: flex; gap: 3px; flex: 1; min-width: 110px; height: 6px; }
.seg { position: relative; flex: var(--w, 1); overflow: hidden; border-radius: 999px; background: #363644; cursor: pointer; transition: transform .15s; }
.seg:hover { transform: scaleY(1.5); }
.seg span { position: absolute; inset: 0; width: 0; border-radius: inherit; background: var(--accent); }
.seg.is-done span { width: 100%; }
.seg.is-pending { background: repeating-linear-gradient(90deg, #363644 0 5px, #43435c 5px 10px); cursor: default; }
.seg.is-pending:hover { transform: none; }
.time-code { color: var(--muted); font-size: .68rem; font-variant-numeric: tabular-nums; }
.switch { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .68rem; cursor: pointer; }
.switch input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }

/* Refazer */
.redo-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border: 1px solid #4a3d7a; border-radius: 8px; background: #1d1836; }
.redo-text { color: #cbbcff; font-size: .72rem; font-weight: 600; }
.scene-row[data-stitched] .scene-thumb { outline: 1px solid var(--accent); outline-offset: -1px; }

/* Composer */
.composer { display: grid; gap: 7px; padding: 9px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
textarea, input, select { width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; background: #2b2b38; color: var(--text); font-size: .82rem; line-height: 1.5; transition: border-color .15s; }
textarea { min-height: 48px; resize: vertical; }
textarea::placeholder, input::placeholder { color: #62626f; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); outline: none; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 9px; flex-wrap: wrap; }
.composer-options { display: flex; gap: 5px; flex-wrap: wrap; }
.composer-options select { width: auto; min-width: 76px; padding: 5px 7px; font-size: .72rem; }
.composer-actions { display: flex; align-items: center; gap: 9px; }
.cost-inline { color: var(--good); font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.primary-button, .secondary-button { min-height: 34px; padding: 0 14px; border-radius: 8px; font-size: .78rem; font-weight: 650; transition: background .15s, border-color .15s; }
.primary-button { border: 0; background: var(--accent); color: #fff; }
.primary-button:hover:not(:disabled) { background: var(--accent-hover); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: .4; }
.secondary-button { border: 1px solid var(--line); background: transparent; color: var(--muted); }
.secondary-button:hover:not(:disabled) { border-color: #4d4d60; color: var(--text); }
.form-error { min-height: 13px; color: var(--error); font-size: .72rem; }

/* Fila */
.queue-pane { display: flex; flex-direction: column; gap: var(--gap); min-height: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 9px 7px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); text-align: center; }
.stat strong { display: block; font-size: .95rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .62rem; }
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.visual-bible { padding: 8px 9px; border-left: 2px solid var(--accent); border-radius: 0 7px 7px 0; background: var(--panel-soft); color: var(--muted); font-size: .7rem; line-height: 1.5; white-space: pre-wrap; }
.queue { display: grid; gap: 6px; align-content: start; overflow-y: auto; flex: 1; min-height: 70px; padding-right: 2px; scrollbar-width: thin; }
.queue-empty { padding: 12px 2px; color: var(--muted); font-size: .75rem; line-height: 1.55; }
.scene-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 8px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--panel); text-align: left; color: var(--text); transition: border-color .15s, background .15s; }
.scene-row:hover { border-color: #3c3c4c; }
.scene-row.is-active { border-color: var(--accent); background: #1b1730; }
.scene-thumb { width: 28px; height: 42px; border-radius: 4px; background: #000; object-fit: cover; }
.scene-thumb.placeholder { display: grid; place-content: center; background: var(--panel-soft); color: var(--muted); font-size: .62rem; }
.scene-body { min-width: 0; display: grid; gap: 2px; cursor: pointer; }
.scene-body strong { overflow: hidden; font-size: .7rem; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.scene-meta { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: .62rem; }
.tag { padding: 1px 4px; border-radius: 3px; font-size: .58rem; font-weight: 700; text-transform: uppercase; }
.tag.ok { background: #14361f; color: var(--good); }
.tag.run { background: #2c2748; color: #b9a8ff; }
.tag.err { background: #3a1922; color: var(--error); }
.scene-actions { display: grid; gap: 3px; opacity: .5; transition: opacity .15s; }
.scene-row:hover .scene-actions, .scene-row.is-active .scene-actions { opacity: 1; }
.mini-button { width: 20px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--muted); font-size: .6rem; line-height: 1; }
.mini-button:hover { border-color: var(--accent); color: var(--text); }
.export-button { width: 100%; }
.export-note { min-height: 13px; color: var(--muted); font-size: .68rem; line-height: 1.4; text-align: center; }
.export-note a { color: var(--accent); }

/* Modais */
.modal { width: min(420px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,.74); }
.modal form { display: grid; gap: 11px; padding: 18px; }
.modal h2 { font-size: 1rem; }
label { display: block; margin-bottom: 4px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.optional { font-weight: 400; }
.confirm-price { display: grid; gap: 1px; padding: 11px; border: 1px solid #313d63; border-radius: 9px; background: #161a2b; }
.confirm-price strong { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cost-breakdown { color: var(--muted); font-size: .72rem; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--line); }
.summary div { padding: 7px 9px; background: var(--panel); }
.summary dt { color: var(--muted); font-size: .6rem; text-transform: uppercase; }
.summary dd { margin: 2px 0 0; font-size: .72rem; overflow-wrap: anywhere; }
.prompt-details summary { cursor: pointer; color: var(--muted); font-size: .72rem; }
.prompt-details pre { max-height: 120px; overflow: auto; margin-top: 7px; padding: 9px; border-radius: 7px; background: #2b2b38; color: var(--muted); font-size: .68rem; line-height: 1.5; white-space: pre-wrap; }
.confirm-check { display: flex; align-items: flex-start; gap: 7px; margin: 0; color: var(--text); font-size: .72rem; font-weight: 400; line-height: 1.45; }
.confirm-check input { flex: none; width: 15px; height: 15px; accent-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 7px; }

.toast { position: fixed; z-index: 30; bottom: 14px; left: 50%; max-width: calc(100vw - 28px); padding: 9px 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-soft); font-size: .78rem; opacity: 0; transform: translate(-50%, 130%); transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Telas menores: a fila vai para baixo do player */
@media (max-width: 940px) {
  body { height: auto; }
  .studio { height: auto; min-height: 100%; }
  .stage { grid-template-columns: 1fr; }
  .player-box { min-height: 52vh; }
  .queue { max-height: 260px; }
}
@media (max-width: 560px) {
  .head-left, .head-right { width: 100%; justify-content: space-between; }
  .head-left select { flex: 1; }
  .composer-bar { align-items: stretch; flex-direction: column; }
  .composer-actions { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Imagem inicial escolhida pelo usuario */
.start-image { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border: 1px solid #3a4a6b; border-radius: 8px; background: #161c2b; }
.start-image img { width: 30px; height: 44px; border-radius: 5px; object-fit: cover; background: #000; }
.start-image-info { display: grid; gap: 1px; flex: 1; min-width: 0; }
.start-image-info strong { color: #bcd0ff; font-size: .72rem; }
.start-image-info span { color: var(--muted); font-size: .66rem; }
.ghost-button.is-active { border-color: var(--accent); color: #cbbcff; background: #1d1836; }
.player-pane.is-dropping .player-box { border-color: var(--accent); background: #12101f; }

/* Armazenamento */
.storage-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.storage-info { color: var(--muted); font-size: .66rem; }

/* Aviso da promocao / trava de custo */
.promo-alert { position: relative; margin: 0 clamp(20px, 7vw, 110px); padding: 9px 34px 9px 13px; border: 1px solid #2f3f5c; border-radius: 9px; background: #151b28; color: #b9cbe8; font-size: .74rem; line-height: 1.5; }
.promo-close { position: absolute; top: 5px; right: 6px; display: grid; place-content: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; font-size: 1.05rem; line-height: 1; opacity: .55; transition: opacity .15s, background .15s; }
.promo-close:hover { opacity: 1; background: rgba(255,255,255,.1); }
.promo-alert strong { color: #dbe7f7; }
.promo-alert.is-warning { border-color: #5a4718; background: #241d0d; color: #f0d59a; }
.promo-alert.is-warning strong { color: var(--warn); }
.promo-alert.is-locked { border-color: #5e2532; background: #2a1119; color: #f4c2cc; }
.promo-alert.is-locked strong { color: var(--error); }
.promo-alert code { padding: 1px 4px; border-radius: 3px; background: rgba(255,255,255,.08); font-size: .92em; }

/* ============================================================
   TELA INICIAL (home)
   Mobile-first: no celular ocupa a tela toda como na referencia;
   no desktop o carrossel vira grade centralizada.
   ============================================================ */

body[data-view="home"], body:not([data-mode="advanced"]) { height: 100%; }
body[data-view="home"] .studio { display: none; }
body[data-view="studio"] .home { display: none; }

.home {
  --home-accent: #f4b47a;
  --home-accent-2: #c9a3f5;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vh, 30px);
  height: 100%;
  overflow-y: auto;
  /* Espaco no rodape para a tab bar, que e fixa e flutua por cima. */
  padding: max(18px, env(safe-area-inset-top)) 0 calc(96px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 55% at 50% -8%, rgba(201, 163, 245, .12), transparent 62%),
    radial-gradient(90% 45% at 88% 4%, rgba(244, 180, 122, .09), transparent 60%),
    var(--bg);
}
.home > * { width: min(520px, 100%); margin-inline: auto; padding-inline: clamp(18px, 5vw, 26px); }

/* --- topo: marca + saldo --- */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { display: block; width: 42px; height: 42px; flex: none; }
.brand-mark svg { width: 100%; height: 100%; overflow: visible; }
.brand-name { display: grid; line-height: 1.05; min-width: 0; }
.brand-name strong { font-size: 1.32rem; font-weight: 800; letter-spacing: -.02em; }
.brand-name span { color: var(--muted); font-size: .82rem; font-weight: 600; }

.coin-pill {
  display: inline-flex; align-items: center; gap: 9px; flex: none;
  padding: 7px 12px 7px 8px;
  border: 1px solid rgba(201, 163, 245, .38);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.02));
  color: var(--text);
  transition: border-color .18s, transform .18s;
}
.coin-pill:hover { border-color: var(--home-accent); }
.coin-pill:active { transform: scale(.97); }
.coin-pill.is-busy { opacity: .5; }
.coin {
  display: grid; place-content: center; width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffd77a, #e8a13c 62%, #c8801f);
  color: #6b3f05; font-size: .86rem; font-weight: 800;
  box-shadow: 0 2px 7px rgba(232, 161, 60, .34);
}
.coin-text { display: grid; line-height: 1.15; text-align: left; }
.coin-text strong { font-size: .96rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.coin-text span { color: var(--muted); font-size: .64rem; font-weight: 600; }
.coin-arrow { color: var(--muted); font-size: 1.05rem; line-height: 1; }

/* --- titulo da secao --- */
.home-section { display: flex; flex-direction: column; justify-content: center; gap: 14px; flex: 1 1 auto; min-height: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head h2 { font-size: clamp(1.5rem, 5.5vw, 1.85rem); font-weight: 800; letter-spacing: -.025em; }
.round-arrow {
  display: grid; place-content: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(255,255,255,.04); color: var(--text);
  font-size: 1.25rem; line-height: 1;
  transition: border-color .18s, background .18s;
}
.round-arrow:hover { border-color: var(--home-accent); background: rgba(244,180,122,.1); }

/* --- carrossel de historias --- */
/* No celular e um scroll horizontal com snap e o card do meio fica maior,
   como na referencia. No desktop vira grade e os cards ficam todos iguais. */
.rail {
  display: flex; gap: 14px;
  padding: 6px 0 4px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  /* Sangra ate a borda da tela e recompoe o respiro com padding, para o
     primeiro e o ultimo card poderem centralizar no snap. */
  margin-inline: calc(-1 * clamp(18px, 5vw, 26px));
  padding-inline: max(clamp(18px, 5vw, 26px), calc(50% - 100px - 7px));
}
.rail::-webkit-scrollbar { display: none; }

.story-card {
  position: relative;
  display: grid; gap: 12px; align-content: start;
  width: 46vw; max-width: 200px; min-width: 150px; flex: none;
  padding: 10px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.035);
  color: inherit; text-align: left;
  scroll-snap-align: center;
  transition: transform .28s cubic-bezier(.22,.9,.3,1), border-color .22s, background .22s;
}
.story-card:hover { border-color: rgba(244,180,122,.5); background: rgba(255,255,255,.06); }
.story-card:active { transform: scale(.98); }

/* O card ativo cresce e ganha o contorno quente da referencia. */
.story-card.is-active {
  border-color: var(--home-accent);
  background: rgba(255,255,255,.07);
  box-shadow: 0 0 0 1px rgba(244,180,122,.32), 0 14px 40px -18px rgba(244,180,122,.55);
  transform: scale(1.075);
  z-index: 1;
}

.story-cover {
  position: relative;
  aspect-ratio: 3 / 4.35;
  border-radius: 15px;
  overflow: hidden;
  background: linear-gradient(160deg, #2e2e42, #1d1d29);
}
.story-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback { display: grid; place-content: center; height: 100%; font-size: 1.9rem; opacity: .5; }
.story-count {
  position: absolute; left: 8px; bottom: 8px;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(6,6,10,.72); backdrop-filter: blur(6px);
  font-size: .6rem; font-weight: 700; letter-spacing: .02em;
}
.story-name {
  padding-inline: 4px;
  font-size: .95rem; font-weight: 650; line-height: 1.3;
  /* No maximo duas linhas, como na referencia. */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.rail-empty {
  display: grid; gap: 6px; align-content: center;
  width: 100%; min-height: 190px; padding: 22px;
  border: 1px dashed var(--line); border-radius: 22px;
  color: var(--muted); font-size: .82rem; line-height: 1.55; text-align: center;
}
.rail-empty strong { color: var(--text); font-size: .9rem; }

/* --- pontinhos --- */
.dots { display: flex; justify-content: center; gap: 6px; }
.dot {
  width: 22px; height: 4px; border-radius: 999px;
  background: #3d3d4c; border: 0; padding: 0;
  transition: background .22s, width .22s;
}
.dot.is-active { width: 34px; background: linear-gradient(90deg, var(--home-accent), var(--home-accent-2)); }

/* --- botao principal --- */
.home-cta { display: grid; place-items: center; flex: none; padding-bottom: clamp(8px, 2vh, 22px); }
.big-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  width: min(360px, 100%); min-height: 56px;
  border: 0; border-radius: 999px;
  background: linear-gradient(95deg, #f6bd83, #d9aeee 55%, #c3a6f7);
  color: #1a1020; font-size: 1.06rem; font-weight: 750; letter-spacing: -.01em;
  box-shadow: 0 12px 34px -12px rgba(226, 173, 208, .6);
  transition: transform .18s, box-shadow .18s, filter .18s;
}
.big-button:hover { filter: brightness(1.05); box-shadow: 0 16px 40px -12px rgba(226, 173, 208, .75); }
.big-button:active { transform: scale(.97); }

/* --- tab bar --- */
.tabbar {
  position: fixed; left: 50%; bottom: 0; z-index: 20;
  transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  width: min(520px, 100%);
  padding: 10px clamp(10px, 4vw, 20px) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  background: rgba(30,30,42,.92);
  backdrop-filter: blur(18px);
}
.tab {
  display: grid; justify-items: center; gap: 4px;
  padding: 6px 2px; border: 0; border-radius: 14px;
  background: transparent; color: var(--muted);
  transition: color .18s;
}
.tab:hover { color: var(--text); }
.tab-icon { display: grid; place-content: center; width: 26px; height: 26px; }
.tab-icon svg { width: 21px; height: 21px; fill: currentColor; }
.tab-label { font-size: .62rem; font-weight: 600; }
.tab.is-active { color: var(--text); }
.tab.is-active .tab-icon { width: 40px; border-radius: 12px; background: rgba(255,255,255,.09); }

/* O botao central sobe acima da barra, como na referencia. */
.tab-center { padding: 0; align-self: center; }
.center-orb {
  display: grid; place-content: center;
  width: 54px; height: 54px; margin-top: -22px;
  border-radius: 50%;
  background: linear-gradient(140deg, #f6bd83, #c3a6f7);
  color: #1a1020; font-size: 1.25rem;
  box-shadow: 0 10px 26px -8px rgba(198, 165, 240, .8);
  transition: transform .18s;
}
.tab-center:hover .center-orb { transform: translateY(-2px) scale(1.04); }
.tab-center:active .center-orb { transform: scale(.95); }

/* Botao de voltar dentro do estudio. */
.back-home { font-size: 1.3rem; line-height: 1; padding: 0 6px; }

/* --- desktop: carrossel vira grade --- */
@media (min-width: 760px) {
  .home > * { width: min(920px, 100%); }
  .tabbar { width: min(920px, 100%); }
  .rail {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
    gap: 18px;
    overflow: visible;
    margin-inline: 0;
    padding-inline: 0;
  }
  .story-card { width: auto; max-width: none; min-width: 0; }
  /* Sem carrossel nao ha card "do meio": o destaque viraria ruido. */
  .story-card.is-active { transform: none; }
  .dots { display: none; }
}

/* ============================================================
   MODOS DE VISUALIZACAO
   Os tres modos reaproveitam os MESMOS elementos (player, composer,
   cenas). Nada e duplicado: so o arranjo muda, via data-mode no <body>.
   Assim custo, confirmacao de gasto e jobs em andamento continuam
   valendo igual nos tres.
   ============================================================ */

/* Peças que só existem fora do avançado. */
.lite-head, .scene-strip { display: none; }
body[data-mode="advanced"] .lite-head { display: none; }

/* --- o que o modo avançado mostra e os simples escondem --- */
body:not([data-mode="advanced"]) .studio-head,
body:not([data-mode="advanced"]) .queue-pane,
body:not([data-mode="advanced"]) .player-bar .switch { display: none; }

body:not([data-mode="advanced"]) .lite-head { display: flex; }
body:not([data-mode="advanced"]) .scene-strip { display: flex; }
body:not([data-mode="advanced"]) .stage { grid-template-columns: minmax(0, 1fr); }

/* Nos modos simples o composer some as opcoes: elas migram para o dialogo
   do botao de ajustes. O custo continua visivel — e dinheiro real. */
body:not([data-mode="advanced"]) .composer-options { display: none; }

/* ============================================================
   MODO SIMPLES — retrato empilhado (refs 1, 3 e 4)
   ============================================================ */
.lite-head {
  align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 4vw, 22px) 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.round-icon {
  display: grid; place-content: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(255,255,255,.04); color: var(--text);
  font-size: 1rem; line-height: 1;
  transition: border-color .18s, background .18s;
}
.round-icon:hover { border-color: var(--home-accent, #f4b47a); background: rgba(244,180,122,.1); }
.lite-title { display: grid; gap: 6px; flex: 1; min-width: 0; justify-items: center; }
.lite-title strong {
  font-size: .98rem; font-weight: 700; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Progresso em tracinhos, como nas referencias. */
.lite-steps { display: flex; gap: 4px; }
.lite-steps i { width: 20px; height: 3px; border-radius: 999px; background: #3d3d4c; }
.lite-steps i.is-done { background: linear-gradient(90deg, #f4b47a, #c9a3f5); }
.coin-pill.is-compact { padding: 5px 10px 5px 5px; gap: 7px; }
.coin-pill.is-compact .coin { width: 24px; height: 24px; font-size: .72rem; }
.coin-pill.is-compact strong { font-size: .82rem; font-variant-numeric: tabular-nums; }

body[data-mode="simple"] .stage {
  padding: clamp(12px, 2vh, 18px) clamp(18px, 5vw, 26px) clamp(14px, 2vh, 20px);
  gap: 14px;
}
/* O modo simples nasceu para celular: no desktop ele se mantem numa coluna
   estreita e centralizada, senao o video vertical boia num vazio enorme. */
body[data-mode="simple"] .lite-head,
body[data-mode="simple"] .stage,
body[data-mode="simple"] #promo-alert { width: min(560px, 100%); margin-inline: auto; }
/* A coluna nao rola e a fita fica ancorada no rodape: os capitulos ficam
   sempre a vista, como na referencia, em vez de sumirem no fim do scroll. */
body[data-mode="simple"] .player-pane { gap: 14px; overflow: hidden; }
body[data-mode="simple"] .player-bar { margin-top: auto; }
/* O video manda no espaco; composer e fita ficam com o que precisam. */
/* O box acompanha o formato do video em vez de deixar barras pretas ao redor,
   como nas referencias em que a cena ocupa a largura toda. */
body[data-mode="simple"] .player-box {
  padding: 0; border-radius: 18px; border: 0;
  background: transparent;
  flex: 0 1 auto; min-height: 120px;
  height: min(46vh, 100%);
}
/* A ALTURA manda: o box entrega a folga que sobrou depois do campo e da fita,
   e o video se ajusta a ela. Se a largura mandasse, um video 9:16 ficaria mais
   alto que a tela e empurraria composer e fita para fora. */
body[data-mode="simple"] .player-stack {
  border-radius: 18px; margin-inline: auto;
  height: 100%; width: auto; max-width: 100%;
  aspect-ratio: var(--ar, 9 / 16);
}
body[data-mode="simple"] .layer { object-fit: contain; }
body[data-mode="simple"] .player-empty { position: static; margin-inline: auto; }
/* A fita nao pode ser espremida pelo video: ela reserva a propria altura. */
body[data-mode="simple"] .scene-strip {
  flex: 0 0 auto;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
body[data-mode="simple"] .player-bar {
  order: 2; padding: 4px 2px; gap: 7px;
  background: transparent; border-color: transparent;
}
body[data-mode="simple"] .composer { order: 3; border-radius: 16px; padding: 12px; }
body[data-mode="simple"] .scene-strip { order: 4; }
body[data-mode="simple"] .composer textarea { min-height: 62px; font-size: .9rem; }
body[data-mode="simple"] .primary-button { min-height: 42px; padding: 0 20px; border-radius: 999px; }
body[data-mode="simple"] .primary-button {
  background: linear-gradient(95deg, #f6bd83, #c3a6f7);
  color: #1a1020; font-weight: 750;
}

/* --- fita de cenas --- */
.scene-strip {
  gap: 9px; flex: none;
  padding: 2px 0 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.scene-strip::-webkit-scrollbar { display: none; }
.strip-item {
  position: relative;
  width: 74px; height: 100px; flex: none;
  padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 12px;
  background: #1c1c26;
  transition: border-color .18s, transform .18s;
}
.strip-item:hover { transform: translateY(-2px); }
.strip-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.strip-item.is-active { border-color: var(--home-accent, #f4b47a); box-shadow: 0 0 0 1px rgba(244,180,122,.4); }
.strip-num {
  position: absolute; left: 5px; bottom: 5px;
  display: grid; place-content: center;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: rgba(6,6,10,.8);
  font-size: .58rem; font-weight: 700;
}
.strip-item.is-pending { display: grid; place-content: center; color: var(--muted); font-size: .58rem; text-align: center; }
.strip-item.is-pending .spin { font-size: .9rem; animation: strip-spin 1.4s linear infinite; }
@keyframes strip-spin { to { transform: rotate(360deg); } }
.strip-add {
  display: grid; place-content: center;
  width: 74px; height: 100px; flex: none;
  border: 1px dashed var(--line); border-radius: 12px;
  background: transparent; color: var(--muted); font-size: 1.3rem;
}
.strip-add:hover { border-color: var(--home-accent, #f4b47a); color: var(--text); }

/* ============================================================
   MODO IMERSIVO — video ocupa tudo, campo flutua (refs 2 e 5)
   ============================================================ */
body[data-mode="immersive"] .stage { padding: 0; gap: 0; }
body[data-mode="immersive"] #promo-alert:not([hidden]) {
  position: absolute; z-index: 8; inset: 62px clamp(12px, 3vw, 26px) auto;
  border-radius: 12px;
}
body[data-mode="immersive"] .lite-head {
  position: absolute; z-index: 6; inset: 0 0 auto 0;
  border: 0; background: linear-gradient(180deg, rgba(20,20,28,.86), transparent);
  backdrop-filter: blur(6px);
}
body[data-mode="immersive"] .player-pane { position: relative; }
body[data-mode="immersive"] .player-box { padding: 0; border: 0; border-radius: 0; }
body[data-mode="immersive"] .player-stack { border-radius: 0; height: 100%; width: 100%; aspect-ratio: auto; }
body[data-mode="immersive"] .layer { object-fit: contain; }

/* O composer vira um cartao flutuante no canto, sobre o video. */
body[data-mode="immersive"] .composer {
  position: absolute; z-index: 7;
  right: clamp(12px, 3vw, 26px); bottom: clamp(84px, 12vh, 110px);
  width: min(370px, calc(100% - 2 * clamp(12px, 3vw, 26px)));
  padding: 13px;
  border-radius: 16px;
  background: rgba(32,32,45,.93);
  backdrop-filter: blur(16px);
  box-shadow: 0 22px 50px -18px rgba(0,0,0,.85);
}
body[data-mode="immersive"] .composer textarea { min-height: 56px; background: rgba(0,0,0,.32); }
body[data-mode="immersive"] .primary-button {
  min-height: 40px; border-radius: 999px;
  background: linear-gradient(95deg, #f6bd83, #c3a6f7); color: #1a1020; font-weight: 750;
}
body[data-mode="immersive"] .player-bar {
  position: absolute; z-index: 6; left: clamp(12px, 3vw, 26px); bottom: clamp(84px, 12vh, 110px);
  width: auto; padding: 6px 10px;
  border-radius: 999px;
  background: rgba(32,32,45,.9); backdrop-filter: blur(14px);
}
body[data-mode="immersive"] .scrubber { display: none; }
/* A fita flutua no rodape, como a faixa de cenas das referencias. */
body[data-mode="immersive"] .scene-strip {
  position: absolute; z-index: 6; inset: auto 0 0 0;
  padding: 10px clamp(12px, 3vw, 26px) calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(20,20,28,.92), transparent);
}
body[data-mode="immersive"] .strip-item,
body[data-mode="immersive"] .strip-add { width: 62px; height: 84px; }

/* ============================================================
   Dialogo de modo
   ============================================================ */
.mode-list { display: grid; gap: 8px; margin: 4px 0 14px; }
.mode-option {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-soft);
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.mode-option:hover { border-color: #4d4d60; }
.mode-option:has(input:checked) { border-color: var(--accent); background: #1b1730; }
.mode-option input { width: 15px; height: 15px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.mode-copy { display: grid; gap: 3px; }
.mode-copy strong { font-size: .84rem; }
.mode-copy span { color: var(--muted); font-size: .72rem; line-height: 1.45; }
.mode-settings { display: grid; gap: 7px; padding-top: 12px; border-top: 1px solid var(--line); }
.mode-fields { display: flex; gap: 7px; flex-wrap: wrap; }
.mode-fields select { width: auto; flex: 1; min-width: 118px; }
.mode-hint { color: var(--muted); font-size: .68rem; }

/* ============================================================
   Celular: nos dois modos simples o layout ja e vertical.
   ============================================================ */
@media (max-width: 700px) {
  /* Imersivo em tela estreita: o cartao ocupa a largura toda no rodape. */
  body[data-mode="immersive"] .composer {
    right: clamp(12px, 3vw, 26px); left: clamp(12px, 3vw, 26px);
    bottom: calc(104px + env(safe-area-inset-bottom));
    width: auto;
  }
  body[data-mode="immersive"] .player-bar { bottom: calc(104px + env(safe-area-inset-bottom)); display: none; }
}

/* ============ TELA DE ENTRADA ============ */
/* Vira mais uma view: o <body data-view> decide o que aparece. */
body[data-view="auth"] .home,
body[data-view="auth"] .studio,
body[data-view="auth"] .tabbar { display: none; }
body[data-view="loading"] .home,
body[data-view="loading"] .studio,
body[data-view="loading"] .tabbar,
body[data-view="loading"] .auth { display: none; }
body:not([data-view="auth"]) .auth { display: none; }
body:not([data-view="loading"]) .boot { display: none; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 60; }
.boot-spin { width: 30px; height: 30px; border: 2px solid #3a3a4c; border-top-color: var(--accent); border-radius: 50%; animation: boot-spin .8s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }

.auth { position: fixed; inset: 0; display: grid; place-items: center; overflow-y: auto; padding: 24px 18px; background: radial-gradient(120% 80% at 50% -10%, #2a2440 0%, var(--bg) 60%); z-index: 50; }
.auth-card { width: min(390px, 100%); display: grid; gap: 15px; padding: clamp(22px, 5vw, 32px); border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: 0 24px 60px rgba(0,0,0,.4); }
.auth-brand { justify-content: center; margin-bottom: 2px; }
.auth-title { margin: 0; font-size: 1.05rem; font-weight: 650; line-height: 1.35; text-align: center; }

.google-button { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #1f1f28; font-size: .88rem; font-weight: 600; transition: filter .15s; }
.google-button:hover:not(:disabled) { filter: brightness(.95); }
.google-button:disabled { opacity: .55; cursor: not-allowed; }
.google-mark { width: 17px; height: 17px; flex: none; }

.auth-sep { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; color: var(--muted); font-size: .72rem; }
.auth-sep::before, .auth-sep::after { content: ""; height: 1px; background: var(--line); }

.auth-form { display: grid; gap: 6px; }
.auth-form label { margin: 6px 0 0; color: var(--muted); font-size: .74rem; font-weight: 600; }
.auth-form input { min-height: 46px; border-radius: 11px; }
.auth-error { min-height: 16px; margin: 4px 0 0; color: var(--error); font-size: .76rem; line-height: 1.4; }
.auth-note { min-height: 0; margin: 0; color: var(--good); font-size: .76rem; line-height: 1.4; }
.auth-submit { min-height: 46px; margin-top: 6px; border-radius: 999px; background: linear-gradient(95deg, #f6bd83, #d9aeee 55%, #c3a6f7); color: #241b33; font-weight: 700; }
.auth-submit:hover:not(:disabled) { filter: brightness(1.05); background: linear-gradient(95deg, #f6bd83, #d9aeee 55%, #c3a6f7); }

.auth-switch { margin: 2px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }
.auth-switch .link-button { padding: 0 4px; font-size: .78rem; }

.profile-body { display: grid; gap: 14px; padding: 22px; }
.profile-email { margin: 0; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
