/* Visually hidden but present for screen readers and SEO. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  /* Colors matching the landing page — default fallbacks; theme.js overrides
     these live via inline custom properties using the studio's saved theme. */
  --bg-body: #f4f5f7;
  --text-main: #111827;
  --text-muted: #4b5563;
  --text-light: #6b7280;
  --brand-orange: #f97316;
  --brand-orange-light: #fff7ed;
  --border-color: #e5e7eb;
  --card-bg: #ffffff;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.15);

  /* Studio Specific */
  --panel-border: #d1d5db;
  --btn-bg-light: #eef0f2;
  --btn-bg-hover: #e2e5e9;
  --skeleton-base: #dde1e7;
  --skeleton-shine: #f6f8fa;
  --accent-soft: #fff7ed;
  --accent-soft-2: #ffedd5;
  --btn-primary-bg: #111111;
  --btn-primary-fg: #ffffff;
  --btn-primary-hover: #000000;
  --cta-bg: #ffffff;
  --cta-text: #111827;
  --cta-glow: rgba(249, 115, 22, 0.25);
  --step-line: #e5e7eb;
  --trim-dim: rgba(17, 24, 39, 0.12);
  --logo-bg: #111111;
  --logo-fg: #ffffff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 0 24px 24px;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }

.hidden { display: none !important; }

.app-container {
  max-width: 1400px;
  margin: 24px auto 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* --- Header (matches landing page: full-width, sticky, glass) --- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: 0 -24px;
  background: color-mix(in srgb, var(--bg-body) 30%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  backdrop-filter: blur(14px) saturate(1.5);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.03);
}

.header-inner {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-link { display: flex; }

.logo-icon {
  width: 36px;
  height: 36px;
  background-color: var(--logo-bg, #111);
  background-image: var(--insta-gradient, linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--logo-fg, var(--brand-orange)); /* Waveform inside the circle */
}
.logo-icon svg { width: 20px; height: 20px; }

.logo-text {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

/* "mr.velosofy" — pink italic (matches the brand accent) with a soft glow. */
.grad-text {
  font-style: italic;
  font-weight: 600;
  font-size: 1em;
  background-image: var(--insta-gradient, linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5));
  background-size: 400% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: grad-breathe 8s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 12px rgba(214, 41, 118, 0.35));
  padding: 0 3px;
  margin: 0 -3px;
}

@keyframes grad-breathe {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Light / dark mode toggle (top-right, left of Reset Project). Same shape and
   proportions as the Reset Project button so they sit side by side. */
.ui-mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: color-mix(in srgb, var(--card-bg) 30%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid color-mix(in srgb, var(--panel-border) 75%, transparent);
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  transition: background-color 0.2s;
}
.ui-mode-btn:hover { background-color: color-mix(in srgb, var(--btn-bg-light) 40%, transparent); }
.ui-mode-btn svg { width: 18px; height: 18px; }
.ui-mode-btn .icon-sun { display: none; }
html[data-ui-mode="dark"] .ui-mode-btn .icon-sun { display: block; }
html[data-ui-mode="dark"] .ui-mode-btn .icon-moon { display: none; }

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--card-bg) 30%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid color-mix(in srgb, var(--panel-border) 75%, transparent);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  transition: background-color 0.2s;
}
.btn-outline:hover { background-color: color-mix(in srgb, var(--btn-bg-light) 40%, transparent); }
.btn-outline svg { width: 16px; height: 16px; }

/* --- Workspace Layout ---
   Desktop: Avatar | Audio on row 1, Live Preview | Generate on row 2,
   then a full-width Trim row and the privacy notice at the bottom. */
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: stretch;
}
.workspace > * {
  min-width: 0;
  max-width: 100%;
}
.panel-avatar { grid-column: 1; grid-row: 1; }
.panel-audio { grid-column: 2; grid-row: 1; }
.panel-trim { grid-column: 1 / -1; grid-row: 2; }
.panel-preview { grid-column: 1 / -1; grid-row: 3; }
.privacy-notice { grid-column: 1 / -1; grid-row: 4; }

:focus-visible {
  outline: 2px solid var(--brand-orange);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Step completion checks in panel headers */
.step-check {
  display: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--accent-soft, #dcfce7);
  color: var(--btn-primary-bg, #16a34a);
  font-size: 0.75rem;
  font-weight: 800;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
}
.panel-header.done .step-check,
.trim-panel-header.done .step-check {
  display: inline-flex;
}

/* --- Common Panel Styles --- */
.panel {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
}

.panel-header {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* --- 1. Avatar & Theme Panel --- */
.panel-avatar {
  display: flex;
  flex-direction: column;
}
.avatar-theme-section {
  display: flex;
  align-items: center;
  gap: 24px;
}
.panel-avatar > .avatar-theme-section {
  flex: 1;
}

.avatar-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #312e81; /* Indigo base */
  position: relative;
  border: 2px solid var(--card-bg);
  box-shadow: 0 0 0 2px var(--panel-border, #e5e7eb);
  cursor: pointer;
  transition: box-shadow 0.2s;
  flex-shrink: 0;
}
.avatar-preview:hover { box-shadow: 0 0 0 2px var(--brand-orange); }
.avatar-preview.locked { opacity: 0.5; pointer-events: none; }

#avatar-preview {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-label {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: color 0.2s, background-color 0.2s;
}
.avatar-label:hover {
  color: var(--brand-orange);
  background-color: var(--accent-soft, rgba(249, 115, 22, 0.12));
}

/* Pencil overlay on the avatar circle — straddles the edge, slightly above
   and to the left of the bottom-right corner. */
.avatar-edit-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  z-index: 6;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--brand-orange);
  color: var(--btn-primary-fg, #fff);
  border: 2px solid var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.avatar-edit-badge svg { width: 12px; height: 12px; }

.theme-selector {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.theme-label { font-size: 0.875rem; color: var(--text-muted); }

/* Theme dropdown (native-free custom dropdown with color preview) */
.theme-dropdown {
  position: relative;
  width: 100%;
}

.theme-current {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--card-bg);
  color: var(--text-main);
  cursor: pointer;
  min-height: 44px;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.theme-current:hover { background-color: var(--btn-bg-light); }
.theme-current[aria-expanded="true"] {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(249, 115, 22, 0.15));
}

.th-preview {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.th-preview i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  display: block;
}

.theme-name { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Side chevron on the trigger — rotates when the menu is open. */
.theme-caret {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1;
  transition: transform 0.25s ease;
}
.theme-current[aria-expanded="true"] .theme-caret { transform: rotate(180deg); }

.theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-lg, 0 14px 40px rgba(0, 0, 0, 0.12));
  transform-origin: top center;
}
.theme-menu:not(.hidden) {
  animation: themeMenuIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes themeMenuIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.theme-option:hover { background-color: var(--btn-bg-light); }
.theme-option .theme-check {
  margin-left: auto;
  color: var(--brand-orange);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.theme-option:hover .theme-check { transform: scale(1.15); }

.theme-dropdown.locked { opacity: 0.5; pointer-events: none; }

/* Custom theme editor — three color slots (background, bubble, accent).
   Collapses via grid-template-rows so the avatar panel height animates
   smoothly instead of snapping when the editor appears/disappears. */
.theme-custom {
  display: grid;
  grid-template-rows: 0fr;
  --tc-pad-y: 12px;
  --tc-pad-x: 14px;
  margin-top: 0;
  padding: 0 var(--tc-pad-x);
  border: 1px solid var(--panel-border);
  border-width: 0;
  border-radius: 12px;
  background: var(--btn-bg-light);
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows 0.35s ease, opacity 0.35s ease,
              margin-top 0.35s ease, padding-top 0.35s ease, padding-bottom 0.35s ease,
              border-width 0.35s ease, visibility 0s linear 0.35s;
}
.theme-custom.open {
  grid-template-rows: 1fr;
  margin-top: 10px;
  padding-top: var(--tc-pad-y);
  padding-bottom: var(--tc-pad-y);
  border-width: 1px;
  opacity: 1;
  visibility: visible;
  transition: grid-template-rows 0.35s ease, opacity 0.35s ease,
              margin-top 0.35s ease, padding-top 0.35s ease, padding-bottom 0.35s ease,
              border-width 0.35s ease, visibility 0s;
}
.theme-custom > .theme-custom-slots {
  overflow: hidden;
  min-height: 0;
  display: flex;
  gap: 12px;
}
.custom-slot {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.custom-slot-name {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.color-swatch {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background-color: var(--swatch, #888);
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 45%);
  cursor: pointer;
  box-shadow: var(--shadow-sm), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.color-swatch:hover { transform: scale(1.07); box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(0, 0, 0, 0.1); }
.color-swatch:active { transform: scale(0.97); }
.color-swatch:focus-visible { outline: 2px solid var(--brand-orange); outline-offset: 2px; }
.custom-slot-hex {
  font-size: 0.625rem;
  color: var(--text-light);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Custom color picker popover — rendered into <body>, follows the UI theme. */
.color-picker {
  position: fixed;
  z-index: 1000;
  width: 264px;
  padding: 12px;
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  user-select: none;
}
.cp-sv {
  position: relative;
  height: 140px;
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
  margin-bottom: 12px;
}
.cp-hue {
  position: relative;
  height: 14px;
  border-radius: 7px;
  cursor: pointer;
  touch-action: none;
  margin-bottom: 12px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.cp-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cp-preview {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.cp-hex {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--input-bg, var(--card-bg));
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875rem;
  text-transform: uppercase;
}
.cp-hex:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* --- 2. Audio Panel --- */
.audio-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.action-btn {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background-color: var(--card-bg);
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.action-btn:hover {
  border-color: var(--text-main);
  background-color: var(--btn-bg-light);
}
.action-btn svg { width: 24px; height: 24px; color: var(--text-main); transition: color 0.25s ease; }
.action-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  transition: color 0.25s ease;
}
.action-desc {
  font-size: 0.75rem;
  color: var(--text-light);
  min-width: 104px;
  text-align: center;
  transition: color 0.25s ease;
}

/* Fade the swapped title/description text in on state changes. */
.action-btn .action-title,
.action-btn .action-desc {
  animation: actionSwap 0.28s ease;
}

.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Recording state — clearly distinct from idle (red ring + pulsing dot +
   red title) so "start" vs "stop" is obvious. */
.action-btn.recording {
  border-color: #ef4444;
  background-color: rgba(239, 68, 68, 0.08);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}
.action-btn.recording .action-title { color: #ef4444; }
.action-btn.recording .action-desc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #ef4444;
}
.action-btn.recording .action-desc::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ef4444;
  animation: recPulse 1s ease-in-out infinite;
}
.action-btn.recording svg { color: #ef4444; }

@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* Short fade-up used when the record card text swaps states. */
@keyframes actionSwap {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.active-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--btn-bg-light);
  border: 1px solid var(--panel-border);
  padding: 12px 16px;
  border-radius: 12px;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.file-info { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 0; overflow: hidden; }
.file-icon { color: var(--text-muted); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.file-icon svg { width: 20px; height: 20px; display: block; }
.file-name {
  font-size: 0.875rem;
  font-weight: 500;
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.file-meta { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 0.875rem; flex-shrink: 0; }
.btn-icon { color: var(--text-light); transition: color 0.2s; display: flex; align-items: center; }
.btn-icon:hover { color: var(--text-main); }
.btn-icon svg { width: 18px; height: 18px; }

/* The active-file row is disabled while previewing, recording or rendering. */
.active-file.locked {
  opacity: 0.5;
  pointer-events: none;
}

/* --- Local Privacy Notice --- */
.privacy-notice {
  background-color: var(--accent-soft, #fff7ed);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  border: 1px solid var(--border-color);
}
.privacy-icon { color: var(--text-main); flex-shrink: 0; }
.privacy-icon svg { width: 24px; height: 24px; }
.privacy-text h4 { font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }
.privacy-text p { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.4; }

/* --- Footer --- */
.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 0 24px;
  font-size: 0.875rem;
  color: var(--text-light);
  text-align: center;
}
.footer .heart-svg {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  display: inline-block;
}

.footer-links {
  display: flex;
  gap: 24px;
  width: 100%;
  justify-content: center;
}
.footer-links a { transition: color 0.2s; }
.footer-links a:hover { color: var(--text-main); }
/* --- Live Preview Panel --- */
.preview-container {
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

#scene {
  width: 100%;
  max-width: 800px;
  height: auto;
  display: block;
  border-radius: 12px;
}

/* Preview + Generate buttons sit side-by-side in a centered row. */
.action-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}
.btn-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 220px;
  background-color: var(--btn-bg-light);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  padding: 14px 40px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  transition: background-color 0.2s, transform 0.2s;
}
.btn-preview:hover:not(:disabled) { background-color: var(--btn-bg-hover); transform: translateY(-1px); }
.btn-preview svg { width: 18px; height: 18px; }
.btn-preview:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cancel (X) button shown next to Generate while rendering. Width/opacity
   are animated so the row reflows smoothly when it appears and disappears. */
.btn-cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 0;
  align-self: stretch;
  flex-shrink: 0;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.7);
  pointer-events: none;
  background-color: var(--btn-bg-light);
  color: var(--text-light);
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition:
    width 0.3s ease,
    opacity 0.25s ease,
    transform 0.25s ease,
    border-color 0.3s ease,
    color 0.2s,
    background-color 0.2s;
}
.btn-cancel.show {
  width: 48px;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  border-color: var(--panel-border);
}
.btn-cancel.show:hover {
  color: #ef4444;
  border-color: #ef4444;
  background-color: color-mix(in srgb, #ef4444 8%, var(--btn-bg-light));
  transform: scale(1.04);
}
.btn-cancel svg { width: 20px; height: 20px; }

/* Undo mode (cached MP4 available after a scene change): the same slot shows
   the undo icon instead of the X, with a green hover. */
.btn-cancel .icon-undo { display: none; }
.btn-cancel.undo .icon-x { display: none; }
.btn-cancel.undo .icon-undo { display: block; }
.btn-cancel.undo.show:hover {
  color: #22c55e;
  border-color: #22c55e;
  background-color: color-mix(in srgb, #22c55e 8%, var(--btn-bg-light));
}

/* --- Trim Audio Panel --- */
.trim-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.trim-title { font-size: 1rem; font-weight: 700; }

.trimmer-container {
  position: relative;
  height: 80px;
  background-color: var(--btn-bg-light);
  border-radius: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.trim-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 20px;
}

#trim-wave {
  width: 100%;
  height: 72px;
  cursor: ew-resize;
  touch-action: none;
  transition: opacity 0.25s ease;
}
#trim-wave.trim-wave-loading { opacity: 0; }
#trim-wave.locked { opacity: 0.5; pointer-events: none; }

/* Skeleton shown while the audio decodes / is restored from cache. Bars are
   absolutely positioned by JS at the exact same coordinates as the trim wave
   bars, so the shimmer overlays the real bars pixel-for-pixel. */
.trim-skeleton {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  pointer-events: none;
}
.trim-skeleton[hidden] { display: none; }
.trim-skeleton i {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 36px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--skeleton-base) 25%,
    var(--skeleton-shine) 37%,
    var(--skeleton-base) 63%
  );
  background-size: 400% 100%;
  animation: skeletonShimmer 1.4s ease infinite;
}

@keyframes skeletonShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.trim-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-group-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.input-items {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.input-item {
  display: flex;
  align-items: center;
  gap: 12px;
}
.input-item label { font-size: 0.875rem; font-weight: 500; }
.time-input {
  width: 90px;
  padding: 8px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  text-align: center;
  background: var(--card-bg);
  color: var(--text-main);
}
.time-input:disabled { opacity: 0.5; cursor: not-allowed; }

.duration-display { font-size: 0.875rem; font-weight: 500; display: flex; gap: 8px; }
.duration-display span { font-weight: 400; color: var(--text-muted); }

.trim-reset-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-left: auto;
  padding: 8px 14px;
  white-space: nowrap;
  background-color: var(--btn-bg-light);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  transition: background-color 0.2s, color 0.2s;
}
.trim-reset-icon:hover:not(:disabled) { background-color: var(--btn-bg-hover); color: var(--brand-orange); }
.trim-reset-icon:disabled { opacity: 0.5; cursor: not-allowed; }
.trim-reset-icon svg { width: 16px; height: 16px; }

.btn-secondary {
  padding: 8px 16px;
  background-color: var(--btn-bg-light);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  transition: background-color 0.2s;
}
.btn-secondary:hover:not(:disabled) { background-color: var(--btn-bg-hover); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Generate Button (inside the Live Preview panel) --- */
.btn-generate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 220px;
  overflow: hidden;
  background-color: var(--btn-primary-bg, #111);
  background-image: var(--insta-gradient, linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5));
  color: var(--btn-primary-fg, white);
  padding: 14px 40px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  transition: background-color 0.2s, transform 0.2s, filter 0.2s;
}
/* Rotating brand-color blob behind the button content. */
.btn-generate::before {
  content: "";
  position: absolute;
  inset: -60%;
  background: conic-gradient(from 0deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5, #feda75);
  filter: blur(18px);
  animation: btnGradSpin 16s linear infinite;
  pointer-events: none;
}
@keyframes btnGradSpin { to { transform: rotate(360deg); } }
.btn-generate.ready::before { animation: none; opacity: 0; }
.btn-generate > * { position: relative; z-index: 1; }
.btn-generate:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-generate svg { width: 20px; height: 20px; }
.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; }

/* State icons — shown via the button's data-icon attribute. */
#preparing-icon, #recording-icon, #converting-icon, #download-icon { display: none; }
.btn-generate[data-icon]:not([data-icon="generate"]) #generate-icon { display: none; }
.btn-generate[data-icon="preparing"] #preparing-icon,
.btn-generate[data-icon="recording"] #recording-icon,
.btn-generate[data-icon="converting"] #converting-icon,
.btn-generate[data-icon="download"] #download-icon { display: block; }
.btn-generate[data-icon="preparing"] #preparing-icon,
.btn-generate[data-icon="converting"] #converting-icon { animation: genSpin 1.1s linear infinite; }
@keyframes genSpin { to { transform: rotate(360deg); } }

/* Progress fills the button itself with color. The button base is the theme's
   accent color, so the fill uses the button's text color as a translucent
   wash — a same-color gradient would be invisible against it. */
.generate-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  z-index: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.55));
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--btn-primary-fg, #fff) 22%, transparent),
    color-mix(in srgb, var(--btn-primary-fg, #fff) 48%, transparent));
  transition: width 0.2s linear;
  pointer-events: none;
}
.generate-fill.indeterminate {
  width: 30%;
  animation: genSweep 1.1s ease-in-out infinite;
}
@keyframes genSweep {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(350%); }
}

/* Ready = Download state. */
.btn-generate.ready {
  background-color: var(--success, #16a34a);
  background-image: linear-gradient(135deg, #34d399, #16a34a 55%, #15803d);
  box-shadow: 0 8px 24px -8px rgba(22, 163, 74, 0.6);
}
.btn-generate.ready:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Warning shown while generating/converting — red, readable in light & dark.
   Collapses via a grid-template-rows 0fr->1fr transition so the panel height
   animates smoothly instead of snapping when it appears/disappears. */
.busy-warning {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows 0.35s ease, opacity 0.35s ease, margin-top 0.35s ease, visibility 0s linear 0.35s;
}
.busy-warning.busy-warning-visible {
  grid-template-rows: 1fr;
  margin-top: 12px;
  opacity: 1;
  visibility: visible;
  transition: grid-template-rows 0.35s ease, opacity 0.35s ease, margin-top 0.35s ease, visibility 0s;
}
.busy-warning-track {
  overflow: hidden;
  min-height: 0;
}
.busy-warning-inner {
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 10px;
  text-align: center;
}
.busy-warning-inner svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
@media (prefers-reduced-motion: reduce) {
  .busy-warning { transition: none; }
  .trim-skeleton i { animation: none; }
  .action-btn .action-title,
  .action-btn .action-desc { animation: none; }
}

#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-light);
  flex-shrink: 0;
}
#status-dot.recording {
  background-color: #ef4444;
  animation: pulse 1s ease-in-out infinite;
}
#status-dot.recording.exported {
  background-color: var(--brand-orange, #22c55e);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Debug metrics (hidden unless ?debug=1) --- */
.debug-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 340px;
  max-height: 50vh;
  overflow: auto;
  z-index: 50;
}

.panel-collapse {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-main);
  padding: 4px 0 12px;
}

.debug-panel[data-collapsed="true"] ul#metrics-list { display: none; }

#metrics-list {
  list-style: none;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
#metrics-list li { padding: 3px 0; }

/* --- Unsupported overlay --- */
#unsupported {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, 0.85);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
}

/* --- Responsive Design --- */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr; }
  /* Mobile stack order: Avatar, Audio, Trim, Preview, Privacy. */
  .panel-avatar { grid-column: 1; grid-row: 1; }
  .panel-audio { grid-column: 1; grid-row: 2; }
  .panel-trim { grid-column: 1; grid-row: 3; }
  .panel-preview { grid-column: 1; grid-row: 4; }
  .privacy-notice { grid-column: 1; grid-row: 5; }
}
@media (max-width: 768px) {
  body { padding: 0 12px 12px; overflow-x: hidden; }
  .app-container { margin-top: 16px; }
  .trim-inputs { flex-direction: column; gap: 16px; align-items: flex-start; }
  .input-group-row { flex-wrap: wrap; width: 100%; }
  .header { margin: 0 -12px; }
  .header-inner { gap: 12px; padding: 12px; }
  #reset-btn { padding: 8px 10px; }
  .reset-text { display: none; }

  /* Compact, always-expanded layout (no collapsible panels on mobile) with
     smaller controls so everything fits without scrolling gymnastics. */
  .panel { padding: 16px; border-radius: 14px; }
  .panel-header { font-size: 0.9375rem; margin-bottom: 14px; }
  .workspace { gap: 14px; }
  .app-container { gap: 14px; }
  .avatar-theme-section { gap: 16px; }
  .avatar-preview { width: 64px; height: 64px; }
  .avatar-edit-badge { width: 20px; height: 20px; bottom: -4px; right: -4px; }
  .avatar-edit-badge svg { width: 11px; height: 11px; }
  .avatar-label { font-size: 0.6875rem; }

  .action-btn { padding: 12px 10px; gap: 6px; border-radius: 10px; }
  .action-btn svg { width: 20px; height: 20px; }
  .action-title { font-size: 0.8125rem; }
  .active-file { padding: 10px 12px; }

  .privacy-notice { padding: 12px 14px; gap: 10px; border-radius: 12px; }
  .privacy-icon svg { width: 18px; height: 18px; }
  .privacy-text h4 { font-size: 0.8125rem; margin-bottom: 2px; }
  .privacy-text p { font-size: 0.75rem; line-height: 1.35; }

  .preview-container { padding: 12px; min-height: 150px; }
  .action-row { gap: 10px; margin-top: 12px; }
  .btn-preview, .btn-generate { flex: 1; min-width: 0; padding: 13px 16px; font-size: 0.9375rem; }
  .btn-preview svg { width: 18px; height: 18px; }

  .trim-panel-header { margin-bottom: 14px; }
  .trimmer-container { height: 64px; padding: 0 12px; }
  .time-input { width: 76px; padding: 6px 10px; font-size: 0.8125rem; }
  .trim-inputs { gap: 14px; }
  .input-group-row { flex-wrap: nowrap; gap: 10px; }
  .input-items { flex: 1; min-width: 0; gap: 16px; }
  .trim-reset-icon { flex-shrink: 0; padding: 8px 10px; }

  /* Custom theme editor — compact so the three slots fit beside the avatar. */
  .theme-custom { --tc-pad-y: 10px; --tc-pad-x: 12px; }
  .theme-custom > .theme-custom-slots { gap: 8px; }
  .custom-slot { gap: 6px; }
  .color-swatch { width: 38px; height: 38px; border-radius: 12px; }
  .custom-slot-name { font-size: 0.625rem; }
  .custom-slot-hex { font-size: 0.5625rem; }

  /* Footer — side padding on mobile. */
  .footer { padding: 8px 16px 24px; }
}

/* Transient warning toast (auto-dismissed by app.js) — glassy amber so it
   reads as a warning while staying readable over any theme.
   Mobile: 80% width, centered at the bottom. Desktop: bottom-right, sliding
   in from the right and out to the right again. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  width: 80%;
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 18px;
  background: color-mix(in srgb, #fbbf24 18%, transparent);
  border: 1px solid rgba(245, 158, 11, 0.6);
  border-radius: 12px;
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  box-shadow: 0 8px 32px rgba(245, 158, 11, 0.25);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.3s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 768px) {
  .toast {
    left: auto;
    right: 28px;
    bottom: 28px;
    width: auto;
    max-width: min(420px, calc(100vw - 56px));
    transform: translateX(calc(100% + 40px));
  }
  .toast.show {
    transform: translateX(0);
  }
}
