/* ============ temas ============ */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --bg-2: #f5f6f8;
  --bg-3: #eceef2;
  --line: #e3e6eb;
  --line-2: #d0d5dd;
  --text: #111318;
  --text-2: #5e6573;
  --text-3: #8a909c;
  --accent: #5b3df5;
  --accent-hover: #4b2fe0;
  --accent-ink: #ffffff;
  --accent-soft: #efecff;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --ok: #12a150;
  --overlay: rgba(17, 19, 24, 0.45);
  --shadow: 0 1px 2px rgba(17, 19, 24, 0.06), 0 8px 24px -12px rgba(17, 19, 24, 0.18);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #000000;
  --bg-2: #111214;
  --bg-3: #1b1d21;
  --line: #24262b;
  --line-2: #33363d;
  --text: #f2f3f5;
  --text-2: #a1a7b3;
  --text-3: #6e7480;
  --accent: #8b7bff;
  --accent-hover: #9d8fff;
  --accent-ink: #0b0820;
  --accent-soft: #1d1938;
  --danger: #ff6b5e;
  --danger-soft: #2a1210;
  --ok: #3ccf7f;
  --overlay: rgba(0, 0, 0, 0.7);
  --shadow: 0 0 0 1px var(--line), 0 12px 32px -12px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

:root {
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --bar-h: 72px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  font-feature-settings: "tnum" 1;
  transition: background-color 0.2s, color 0.2s;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { letter-spacing: -0.015em; }

/* visões */
body[data-view="loading"] main, body[data-view="loading"] .action-bar { visibility: hidden; }
body:not([data-view="login"]) .only-login { display: none !important; }
body:not([data-view="app"]) .only-app { display: none !important; }
body[data-view="app"] { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 20px); }

/* ============ topo ============ */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.05rem; }
.brand-mark { width: 28px; height: 28px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; }
[data-theme="light"] .i-sun, [data-theme="dark"] .i-moon { display: none; }

/* ============ botões ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 600; font-size: 0.95rem; text-decoration: none; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.88rem; border-radius: 10px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--bg-2); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { border-color: var(--line-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--bg-2); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.link-btn:disabled { color: var(--text-3); cursor: default; }
.link-left { justify-self: start; }

/* ============ login ============ */
.login {
  max-width: 420px; margin: 0 auto; padding: 32px 20px 40px;
  min-height: calc(100dvh - 70px); display: flex; flex-direction: column; justify-content: center;
}
.login-step { display: grid; gap: 16px; }
.login h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; font-weight: 650; }
.lead { margin: -6px 0 6px; color: var(--text-2); }
.field { display: grid; gap: 6px; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.field input, .phone {
  min-height: 50px; width: 100%; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--bg); padding: 0 14px; font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .phone:focus-within {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[aria-invalid="true"], .phone[aria-invalid="true"] { border-color: var(--danger); }
.phone { display: flex; align-items: stretch; padding: 0; overflow: hidden; }
.phone-country {
  display: flex; align-items: center; gap: 6px; padding: 0 10px 0 14px; border: 0;
  border-right: 1px solid var(--line); background: var(--bg-2); font-weight: 600; flex-shrink: 0;
}
.phone-country svg { width: 16px; height: 16px; color: var(--text-3); }
.phone input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 14px; font-size: 1.05rem; letter-spacing: 0.01em; }
.phone input:focus { outline: none; }
.code-input { font-size: 1.6rem !important; letter-spacing: 0.5em; text-align: center; font-weight: 600; padding-left: calc(14px + 0.5em) !important; }
.form-error { margin: -4px 0 0; color: var(--danger); font-size: 0.88rem; font-weight: 500; min-height: 0; }
.form-error:empty { display: none; }
.fine { margin: 0; font-size: 0.8rem; color: var(--text-3); text-align: center; }
.code-links { display: flex; justify-content: space-between; }

/* lista de países */
.search {
  width: 100%; min-height: 44px; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--bg-2); padding: 0 14px; margin-bottom: 8px;
}
.country-list { list-style: none; margin: 0; padding: 0; max-height: 55dvh; overflow: auto; }
.country-list button {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 6px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left;
}
.country-list button[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.country-list .c-flag { font-size: 1.3rem; }
.country-list .c-name { flex: 1; }
.country-list .c-dial { color: var(--text-2); }

/* ============ app ============ */
.layout { padding: 8px 16px 0; max-width: 1080px; margin: 0 auto; }

.stage-wrap { display: flex; flex-direction: column; align-items: center; padding: 12px 0 4px; }
.stage {
  position: relative; width: min(84vw, 360px); aspect-ratio: 1;
  border-radius: 20px; background: var(--stage-bg, #fff);
  box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden;
}
.stage-media { position: absolute; inset: 0; overflow: hidden; }
.stage-media > * { position: absolute; display: block; max-width: none; pointer-events: none; }
.stage[data-empty="true"] { background: var(--bg-2); box-shadow: none; border: 1.5px dashed var(--line-2); }
.stage-empty {
  position: absolute; inset: 0; border: 0; background: transparent; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 24px; text-align: center;
}
.stage[data-empty="false"] .stage-empty { display: none; }
.stage-empty svg {
  width: 48px; height: 48px; padding: 12px; margin-bottom: 10px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink);
}
.stage-empty-title { font-weight: 600; font-size: 1.05rem; }
.stage-empty-sub { color: var(--text-2); font-size: 0.9rem; }
.sound-badge {
  position: absolute; top: 10px; right: 10px; display: flex; align-items: center; gap: 4px;
  padding: 4px 9px 4px 7px; border-radius: 999px; background: rgba(0, 0, 0, 0.62); color: #fff;
  font-size: 0.78rem; font-weight: 600; pointer-events: none;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.sound-badge svg { width: 15px; height: 15px; }
.stage-hint { margin: 12px 0 0; font-size: 0.82rem; color: var(--text-3); }

.panels { display: grid; gap: 12px; margin-top: 16px; }
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.panel h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.file-name { margin: 0; color: var(--text-2); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.note { color: var(--text-2); font-size: 0.84rem; margin: 8px 0 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.ctl-label { font-size: 0.88rem; font-weight: 500; color: var(--text-2); min-width: 56px; }

.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 7px 14px; font-weight: 600; font-size: 0.88rem; color: var(--text-2); min-height: 34px; }
.seg button[aria-checked="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--line); }
[data-theme="dark"] .seg button[aria-checked="true"] { background: var(--bg-3); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.seg-wide { display: flex; width: 100%; margin: 8px 0 12px; }
.seg-wide button { flex: 1; padding: 7px 4px; }
.seg-small button { padding: 4px 12px; min-height: 30px; }

.frame-controls { display: grid; gap: 14px; margin-top: 14px; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row output { min-width: 44px; text-align: right; color: var(--text-2); font-size: 0.88rem; }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; }
.swatches { display: flex; align-items: center; gap: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; padding: 0; background: var(--c); border: 1px solid var(--line-2); position: relative; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.swatch-custom { background: conic-gradient(#ff5a5a, #ffce3a, #19c27a, #2fa4ff, #5b3df5, #ff5ad0, #ff5a5a); overflow: hidden; cursor: pointer; }
.swatch-custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* seletor de trecho */
.trim-block { margin-top: 16px; }
.trim-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 0.92rem; margin-bottom: 8px; }
.trim-len { font-size: 0.88rem; color: var(--accent); }
.trim { position: relative; height: 68px; border-radius: 10px; background: var(--bg-2); touch-action: none; user-select: none; -webkit-user-select: none; }
.trim.trim-video { height: 60px; background: #111; }
.trim-bg { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 10px; }
.trim-shade { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--bg) 70%, transparent); pointer-events: none; }
.trim-video .trim-shade { background: rgba(0, 0, 0, 0.6); }
.trim-shade-l { left: 0; border-radius: 10px 0 0 10px; }
.trim-shade-r { right: 0; border-radius: 0 10px 10px 0; }
.trim-sel { position: absolute; top: -3px; bottom: -3px; border: 2px solid var(--accent); border-radius: 9px; cursor: grab; }
.trim.is-dragging .trim-sel { cursor: grabbing; }
.trim-handle {
  position: absolute; top: 50%; width: 16px; height: 40px; margin-top: -20px; padding: 0;
  border: 0; border-radius: 6px; background: var(--accent); touch-action: none;
}
.trim-handle::after { content: ""; position: absolute; left: 50%; top: 12px; bottom: 12px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--accent-ink); opacity: 0.8; }
.trim-handle::before { content: ""; position: absolute; inset: -14px -14px; }
.trim-h-start { left: -9px; }
.trim-h-end { right: -9px; }
.trim.is-window .trim-handle { display: none; }
.trim-playhead { position: absolute; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; pointer-events: none; }

.nudges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.nudge { display: flex; flex-direction: column; gap: 6px; background: var(--bg-2); border-radius: var(--r-md); padding: 8px 10px; }
.nudge-label { font-size: 0.82rem; color: var(--text-2); }
.nudge-label b { color: var(--text); font-weight: 600; font-size: 0.9rem; }
.nudge-btns { display: flex; gap: 6px; }
.nudge-btns button { flex: 1; min-height: 36px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; font-weight: 600; font-size: 1.1rem; line-height: 1; }
.nudge-btns button:active { background: var(--accent-soft); border-color: var(--accent); }
.trim-block.is-window [data-only-range] { display: none; }
.trim-block.is-window .nudges { grid-template-columns: 1fr; }

/* barra de ação */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.play-btn {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--text); display: grid; place-items: center;
}
.play-btn svg { width: 20px; height: 20px; }
.play-btn .i-stop { display: none; }
.play-btn.is-playing .i-play { display: none; }
.play-btn.is-playing .i-stop { display: block; }
.play-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.action-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.action-dur { font-weight: 650; font-size: 1.05rem; }
.action-sub { font-size: 0.78rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* folhas (dialogs) */
.sheet {
  border: 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 480px; margin: auto auto 0; border-radius: 20px 20px 0 0;
  background: var(--bg); color: var(--text); max-height: 92dvh; overflow: auto;
  box-shadow: 0 -1px 0 var(--line);
}
.sheet::backdrop { background: var(--overlay); }
.sheet[open] { animation: sheet-up 0.2s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.5; } }
.sheet h3 { margin: 0 0 6px; font-size: 1.15rem; font-weight: 650; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; }
.sheet-head form { margin: 0; }
.sheet-text { margin: 0 0 14px; color: var(--text-2); }
.sheet-actions { display: grid; gap: 8px; margin-top: 12px; }
.sheet form { margin: 0; }
.center { text-align: center; }
.help-list { padding-left: 20px; margin: 10px 0 16px; color: var(--text-2); }
.help-list li { margin-bottom: 8px; }
.help-list b { color: var(--text); }
.account-info { margin: 0; display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--r-md); }
.account-info div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.account-info div:last-child { border-bottom: 0; }
.account-info dt { color: var(--text-2); }
.account-info dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.result-check { width: 52px; height: 52px; margin: 4px auto 12px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.result-check svg { width: 28px; height: 28px; }
.result-sticker { width: min(56vw, 220px); aspect-ratio: 1; margin: 6px auto 8px; border-radius: 16px; overflow: hidden; background: #000; box-shadow: var(--shadow); }
.result-sticker video { width: 100%; height: 100%; display: block; object-fit: cover; }
.result-meta { text-align: center; font-size: 0.82rem; color: var(--text-3); margin: 0; }

/* tela de envio (bloqueia toques) */
.busy {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
  background: var(--overlay); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  touch-action: none; overscroll-behavior: contain;
}
.busy-card { width: 100%; max-width: 380px; background: var(--bg); border-radius: 20px; padding: 22px 20px; box-shadow: var(--shadow); }
.busy-card h3 { margin: 0 0 16px; font-size: 1.1rem; font-weight: 650; }
.steps { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.steps li { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 0.95rem; }
.step-text { flex: 1; }
.step-pct { font-size: 0.85rem; color: var(--text-2); }
.step-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); flex-shrink: 0; position: relative; }
.steps li[data-state="active"] { color: var(--text); font-weight: 600; }
.steps li[data-state="active"] .step-dot { border-color: var(--accent); border-right-color: transparent; animation: spin 0.8s linear infinite; }
.steps li[data-state="done"] { color: var(--text-2); }
.steps li[data-state="done"] .step-dot { border-color: var(--ok); background: var(--ok); }
.steps li[data-state="done"] .step-dot::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid var(--bg); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.steps li[data-state="error"] { color: var(--danger); font-weight: 600; }
.steps li[data-state="error"] .step-dot { border-color: var(--danger); background: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 999px; background: var(--bg-3); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.2s; }
.busy-hint { margin: 12px 0 0; font-size: 0.84rem; color: var(--text-2); text-align: center; }
.busy-error p { color: var(--danger); font-weight: 500; margin: 12px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  z-index: 120; max-width: min(92vw, 440px); padding: 11px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 500; font-size: 0.9rem; box-shadow: var(--shadow);
}
.toast.is-error { background: var(--danger); color: #fff; }
body[data-view="login"] .toast { bottom: calc(24px + env(safe-area-inset-bottom)); }

@media (min-width: 860px) {
  .layout { display: grid; grid-template-columns: 420px 1fr; gap: 32px; align-items: start; padding-top: 20px; }
  .stage-wrap { position: sticky; top: 80px; }
  .stage { width: 380px; }
  .panels { margin-top: 0; }
  .action-bar { left: 50%; right: auto; transform: translateX(-50%); width: min(1040px, 96vw); bottom: 16px; border: 1px solid var(--line); border-radius: 16px; padding-bottom: 10px; box-shadow: var(--shadow); }
  .sheet { margin: auto; border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .steps li[data-state="active"] .step-dot { animation: none; }
  body, .progress-bar { transition: none; }
}
