:root {
  --bg: #0b141a;
  --surface: #111b21;
  --surface-2: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --danger: #f15c6d;
  --warn: #f59e0b;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-text { min-width: 0; }
.session-account { display: block; color: var(--muted); font-size: 12px; font-weight: 400; overflow-wrap: anywhere; }
.brand-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--accent); display: inline-block; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.view { padding: 14px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.view[hidden], [hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.center-card { margin-top: 12vh; }

h1 { margin: 0; font-size: 20px; }
h2 { margin: 0; font-size: 16px; }
h3 { margin: 0; font-size: 17px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-xs { display: flex; flex-direction: column; gap: 4px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wrap-row { flex-wrap: wrap; }

.step-header { display: flex; align-items: center; justify-content: space-between; }
.step-pill { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }

input[type="text"], input[type="url"], input[type="password"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }

button, a.btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0b141a; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-whatsapp { background: #25d366; color: #0b141a; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }
.btn-danger { background: rgba(241, 92, 109, 0.15); color: var(--danger); }

.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.status-pill {
  background: rgba(0, 168, 132, 0.14);
  color: var(--accent-hover);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.error-text { color: var(--danger); font-size: 13px; }
.hint-text { color: var(--warn); font-size: 13px; }
.badge { background: var(--surface-2); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge.warn { background: rgba(245, 158, 11, 0.2); color: var(--warn); }

/* Clip preview and waveform */
#trim-video {
  display: block;
  width: 100%;
  height: clamp(160px, 31vh, 300px);
  object-fit: contain;
  border-radius: 12px;
  background: #000;
}
.waveform-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}
#waveform-canvas { width: 100%; height: 120px; display: block; }
.nudge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nudge-group { display: flex; flex-direction: column; gap: 6px; }
.btn-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* Segmented controls */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  gap: 4px;
}
.segmented.compact { width: auto; }
.seg-btn {
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
}
.seg-btn.active { background: var(--surface-2); color: var(--text); }

/* Sticker Canvas */
.canvas-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#sticker-canvas {
  width: min(100%, 320px);
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background-image:
    linear-gradient(45deg, #1b2830 25%, transparent 25%),
    linear-gradient(-45deg, #1b2830 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1b2830 75%),
    linear-gradient(-45deg, transparent 75%, #1b2830 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  touch-action: none;
}
.canvas-tip { font-size: 12px; color: var(--muted); }

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  color: var(--accent-hover);
  font-weight: 600;
  cursor: pointer;
}
.file-drop input { display: none; }

.swatches { display: flex; gap: 6px; align-items: center; }
.swatch {
  width: 28px; height: 28px; min-height: 28px; padding: 0;
  border-radius: 50%; border: 2px solid var(--border);
}
.swatch.active { border-color: var(--accent); transform: scale(1.12); }
.toggle-inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.emoji-input { width: 64px !important; text-align: center; padding: 6px !important; font-size: 18px !important; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.emoji-btn {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 0;
  min-height: 38px;
  font-size: 20px;
}
.emoji-btn.active { outline: 2px solid var(--accent); }

/* WhatsApp Preview */
.wa-preview {
  background: #0d1c23;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.wa-sticker-wrap { position: relative; width: min(100%, 220px); aspect-ratio: 1; }
.wa-sticker-wrap :is(img, video) { width: 100%; height: 100%; object-fit: contain; }
.wa-sticker-wrap.playing img { animation: pulse-sticker 1.1s ease-in-out infinite; }
@keyframes pulse-sticker {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.emoji-badge {
  position: absolute; right: 4px; bottom: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 8px; font-size: 18px;
}
.wa-audio-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 12px;
}
.btn-play-circle {
  width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: var(--accent); color: #0b141a; flex-shrink: 0;
}
.wa-audio-meta { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.history-item img { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: var(--surface-2); flex-shrink: 0; }
.history-info { flex: 1; min-width: 0; }
.history-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal-card {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
}
.modal-preview-row { display: flex; align-items: center; gap: 12px; }
.modal-preview-row img { width: 72px; height: 72px; object-fit: contain; border-radius: 10px; background: var(--surface-2); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
}
