:root {
  --bg: #0f1115;
  --surface: #161a21;
  --surface-2: #1d222b;
  --surface-3: #262c37;
  --border: #2a303b;
  --text: #e8eaee;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent-ink: #0b1220;
  --rec: #ef4444;
  --radius: 10px;
  --topbar-h: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
}

.sprite { position: absolute; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sprite .fill { fill: currentColor; stroke: none; }

/* ---------- barra de topo ---------- */
.topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: #00b140; box-shadow: inset 0 0 0 5px #e9e9eb, inset 0 0 0 11px #00b140; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.actions::-webkit-scrollbar { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #7aa2ff; }
.btn.rec .ico { color: var(--rec); }
.btn.icon-only { width: 36px; padding: 0; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ---------- área de trabalho ---------- */
.workspace { flex: 1; min-height: 0; display: flex; position: relative; }
.stage-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #0b0d11;
  overflow: hidden;
}
.stage-frame { display: block; line-height: 0; border-radius: 6px; overflow: hidden; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.stage-frame.checker {
  background: repeating-conic-gradient(#3a3f48 0% 25%, #2b2f37 0% 50%) 0 0 / 24px 24px;
}
#stage { display: block; }

/* escrita ao vivo: textarea invisível que recebe o teclado */
.live-input { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; font-size: 16px; pointer-events: none; }
.live-hint { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); margin: 0; padding: 8px 14px; max-width: calc(100% - 24px); border-radius: 10px; background: rgba(15, 17, 21, 0.85); border: 1px solid var(--border); color: var(--muted); font-size: 13px; text-align: center; pointer-events: none; z-index: 4; }
.live-hint b { color: var(--text); }
body.live #btnLive { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
body.clean .live-hint { display: none; }

/* contagem 3-2-1 */
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: min(32vw, 32vh);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 6px 40px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 5;
}
.countdown span { animation: pop 0.9s ease-out both; }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 25% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); opacity: 0.85; } }

/* barra do modo limpo: aparece ao mexer o rato/tocar e desaparece sozinha */
.clean-bar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  display: none;
  gap: 8px;
  padding: 8px;
  background: rgba(15, 17, 21, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 6;
}
body.clean .clean-bar { display: flex; pointer-events: none; }
body.clean.bar-visible .clean-bar { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
body.recording .clean-bar { display: none; }

/* modo limpo e gravação: só o palco */
body.clean .topbar, body.clean .panel, body.clean .panel-backdrop, body.clean .privacy { display: none; }
body.clean .stage-wrap { position: fixed; inset: 0; padding: 0; background: #000; z-index: 50; }
body.clean .stage-frame { border-radius: 0; box-shadow: none; }
body.clean.hide-cursor:not(.bar-visible) .stage-wrap { cursor: none; }

/* ---------- painel de configurações ---------- */
.panel {
  flex: none;
  width: 348px;
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
body.panel-open .panel { display: flex; }
.panel-head { display: none; align-items: center; justify-content: space-between; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.panel-body { overflow-y: auto; padding: 4px 0 24px; flex: 1; overscroll-behavior: contain; }
.panel-backdrop { display: none; }

.sec { border-bottom: 1px solid var(--border); }
.sec > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.15s; margin-right: 4px; }
.sec[open] > summary::after { transform: rotate(-135deg); }
.sec-body { padding: 0 16px 14px; display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field label, .field .label { color: var(--text); }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field .note { margin: 0; color: var(--muted); font-size: 12px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="color"] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; }
select, input[type="text"], textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input[type="checkbox"] {
  appearance: none;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
input[type="checkbox"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #c8cedb; transition: transform 0.15s, background 0.15s; }
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after { transform: translateX(16px); background: #fff; }

.presets { display: grid; gap: 6px; }
.preset { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.preset:has(input:checked) { border-color: var(--accent); background: #1b2740; }
.preset label { flex: 1; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.preset input[type="radio"] { accent-color: var(--accent); }
.rec-info { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.rec-info b { color: var(--text); }

.file-btn { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn input[type="file"] { display: none; }

/* ---------- rodapé de privacidade ---------- */
.privacy {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12.5px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.privacy .ico { width: 14px; height: 14px; }

/* ---------- modais ---------- */
.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-wide { width: min(760px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(5, 7, 10, 0.7); backdrop-filter: blur(3px); }
.modal-inner { display: grid; gap: 14px; padding: 18px 20px 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal h3 { margin: 4px 0 0; font-size: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint.warn { color: #fbbf24; }
.hint code, .syntax code { padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text); font-size: 12.5px; }
kbd { padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-3); font: inherit; font-size: 12px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.script-text { min-height: min(46dvh, 360px); resize: vertical; font: 15px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 12px; }
.syntax summary { cursor: pointer; color: var(--muted); }
.syntax p { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.9; }
.store-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.store-row input[type="text"] { flex: 1 1 160px; width: auto; }
.store-row select { flex: 1 1 160px; width: auto; }
.preview-video { width: 100%; max-height: 52dvh; background: #000; border-radius: 10px; }

/* ---------- avisos ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 10px 16px; border-radius: 10px; background: #0b0d11; border: 1px solid var(--border); color: var(--text); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); animation: toast-in 0.2s ease-out; transition: opacity 0.3s; }
.toast.out { opacity: 0; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- móvel ---------- */
@media (max-width: 860px) {
  .panel {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 74dvh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    transition: transform 0.25s ease;
    z-index: 30;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.panel-open .panel { transform: none; }
  .panel-head { display: flex; }
  .panel-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 20; }
  body.panel-open .panel-backdrop { opacity: 1; pointer-events: auto; }
  .stage-wrap { padding: 10px; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 10px; }
  .brand { font-size: 0; gap: 0; }
  .actions .btn { padding: 0; width: 38px; }
  .actions .btn span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .actions { gap: 6px; }
  .actions .btn.primary { width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
