/* ============================================================
   CTHULHUAI — Main Stylesheet
   Design: Abyssal black & charcoal, blood-red accent, mono type
   ============================================================ */

:root {
  --bg: #0A0A0B;
  --bg-2: #111113;
  --bg-3: #18181B;
  --surface: #1C1C20;
  --surface-2: #26262B;
  --border: #303036;
  --border-2: #3A3A42;
  --accent: #C81E2C;
  --accent-2: #E8434F;
  --accent-glow: rgba(200, 30, 44, 0.32);
  --cyan: #6E7480;
  --text: #F1F1F3;
  --text-2: #9C9CA8;
  --text-3: #61616E;
  --success: #3ECA7F;
  --error: #FF5E6C;
  --warning: #E8A23D;
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius: 12px;
  --radius-lg: 20px;
  --transition: 0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---- UTILS ---- */
.hidden { display: none !important; }
.page { min-height: 100vh; }
.page.active { display: block; }
.container { max-width: 1160px; margin: 0 auto; padding: 0 24px; }
.gradient-text {
  background: linear-gradient(135deg, var(--accent-2), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 20px; border-radius: var(--radius);
  font-family: var(--font-display); font-size: 15px; font-weight: 600;
  cursor: pointer; border: none; transition: all var(--transition);
  white-space: nowrap; text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 0 20px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-2); box-shadow: 0 0 30px var(--accent-glow); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn-outline { background: transparent; color: var(--accent-2); border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--accent-glow); }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-google {
  background: #fff; color: #1f1f1f;
  border: 1px solid var(--border-2);
}
.btn-google:hover { background: #f3f3f3; transform: translateY(-1px); }
.btn-google .google-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---- AUTH DIVIDER ---- */
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--text-2); font-size: 13px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ---- NAV ---- */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(8, 11, 20, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1160px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; height: 64px;
}
.logo { font-size: 22px; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.5px; display: inline-flex; align-items: center; gap: 8px; }
.logo span { color: var(--accent-2); }
.logo-mark { height: 28px; width: auto; display: block; }
.nav-links { display: flex; align-items: center; gap: 12px; }
.nav-links a { color: var(--text-2); text-decoration: none; font-size: 15px; transition: color var(--transition); }
.nav-links a:hover { color: var(--text); }

/* ---- HERO ---- */
.hero {
  position: relative; overflow: hidden;
  min-height: calc(100vh - 64px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 24px;
}
.hero-bg { position: absolute; inset: 0; pointer-events: none; }
.hero-orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.35;
}
.orb-1 { width: 600px; height: 600px; background: radial-gradient(circle, var(--accent), transparent); top: -200px; left: -100px; animation: pulse 8s ease-in-out infinite; }
.orb-2 { width: 400px; height: 400px; background: radial-gradient(circle, var(--cyan), transparent); bottom: -100px; right: 100px; animation: pulse 10s ease-in-out infinite reverse; }
.orb-3 { width: 300px; height: 300px; background: radial-gradient(circle, #FC5CBA, transparent); top: 50%; right: -50px; animation: pulse 12s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.hero-content { position: relative; z-index: 1; text-align: center; max-width: 760px; }
.hero-badge {
  display: inline-block; padding: 6px 16px; margin-bottom: 24px;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 100px; font-size: 13px; color: var(--text-2);
  font-family: var(--font-mono);
}
.hero-title { font-size: clamp(44px, 7vw, 80px); font-weight: 700; line-height: 1.05; letter-spacing: -2px; margin-bottom: 24px; }
.hero-sub { font-size: 20px; color: var(--text-2); max-width: 540px; margin: 0 auto 40px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 60px; }
.hero-stats { display: flex; gap: 48px; justify-content: center; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-num { font-family: var(--font-mono); font-size: 28px; font-weight: 700; color: var(--accent-2); }
.stat-label { font-size: 13px; color: var(--text-3); }

.hero-gallery { display: none; } /* decorative, hidden for simplicity */

/* ---- SECTIONS ---- */
.section { padding: 100px 0; }
.section-dark { background: var(--bg-2); }
.section-header { text-align: center; margin-bottom: 60px; }
.eyebrow { font-family: var(--font-mono); font-size: 22px; color: var(--accent-2); letter-spacing: 2px; text-transform: uppercase; margin-bottom: 12px; }
.section-header h2 { font-size: clamp(32px, 4vw, 48px); font-weight: 700; letter-spacing: -1px; margin-bottom: 16px; }
.section-sub { font-size: 18px; color: var(--text-2); max-width: 520px; margin: 0 auto; }

/* ---- MODELS GRID ---- */
.models-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.model-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  transition: all var(--transition); position: relative;
}
.model-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 30px var(--accent-glow); }
.model-card.featured { border-color: var(--accent); background: linear-gradient(135deg, var(--surface), rgba(200,30,44,0.1)); }
.model-badge, .plan-badge, .pkg-badge {
  position: absolute; top: -12px; left: 20px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 10px;
  border-radius: 100px; letter-spacing: 0.5px;
}
.model-icon { font-size: 28px; margin-bottom: 12px; }
.model-card h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.model-card p { font-size: 14px; color: var(--text-2); margin-bottom: 16px; }
.model-meta { display: flex; gap: 12px; }
.model-meta span { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); background: var(--bg-3); padding: 4px 8px; border-radius: 6px; }

/* ---- PRICING ---- */
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; max-width: 900px; margin: 0 auto; }
.pricing-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 28px;
  position: relative; transition: all var(--transition);
}
.pricing-card:hover { transform: translateY(-3px); }
.pricing-card.featured {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--surface-2), rgba(200,30,44,0.08));
  box-shadow: 0 0 40px var(--accent-glow);
}
.plan-name { font-size: 14px; font-weight: 600; color: var(--text-2); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 12px; }
.plan-price { font-size: 48px; font-weight: 700; letter-spacing: -2px; margin-bottom: 4px; }
.plan-price span { font-size: 16px; color: var(--text-2); font-weight: 400; }
.plan-credits { font-family: var(--font-mono); font-size: 14px; color: var(--accent-2); margin-bottom: 24px; }
.plan-features { list-style: none; margin-bottom: 28px; display: flex; flex-direction: column; gap: 10px; }
.plan-features li { font-size: 14px; color: var(--text-2); }

/* ---- FOOTER ---- */
.footer { background: var(--bg); border-top: 1px solid var(--border); padding: 40px 0; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; }
.footer-links { display: flex; gap: 24px; }
.footer-links a { color: var(--text-3); font-size: 14px; text-decoration: none; }
.footer-links a:hover { color: var(--text-2); }
.footer-copy { font-size: 13px; color: var(--text-3); }

/* ---- MODALS ---- */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 40px;
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--surface-2); border: none; color: var(--text-2);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }

/* ---- TOAST NOTIFICATIONS ---- */
.toast-stack {
  position: fixed; top: 84px; right: 24px; z-index: 2000;
  display: flex; flex-direction: column; gap: 12px;
  max-width: 380px; width: calc(100% - 48px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  backdrop-filter: blur(16px);
  font-family: var(--font-display);
  opacity: 0; transform: translateX(24px) scale(0.97);
  animation: toast-in 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast.toast-leaving {
  animation: toast-out 0.22s ease forwards;
}
@keyframes toast-in {
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px) scale(0.97); }
}
.toast-icon {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; margin-top: 1px;
}
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 14px; font-weight: 700; color: var(--text); line-height: 1.3; }
.toast-message { font-size: 13px; color: var(--text-2); line-height: 1.4; margin-top: 2px; }
.toast-close {
  flex-shrink: 0; background: transparent; border: none; color: var(--text-3);
  cursor: pointer; font-size: 14px; padding: 2px; line-height: 1;
  transition: color var(--transition);
}
.toast-close:hover { color: var(--text); }

.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { background: rgba(62,202,127,0.15); color: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-error .toast-icon { background: rgba(255,94,108,0.15); color: var(--error); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { background: rgba(232,162,61,0.15); color: var(--warning); }
.toast-info { border-left-color: var(--accent); }
.toast-info .toast-icon { background: var(--accent-glow); color: var(--accent-2); }

@media (max-width: 480px) {
  .toast-stack { left: 16px; right: 16px; top: 76px; max-width: none; }
}

/* ---- CUSTOM CONFIRM DIALOG ---- */
.confirm-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 32px;
  width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.confirm-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(232,162,61,0.15); color: var(--warning);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; margin: 0 auto 16px;
}
.confirm-title { font-size: 19px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.confirm-message { font-size: 14px; color: var(--text-2); line-height: 1.5; margin-bottom: 24px; }
.confirm-actions { display: flex; gap: 12px; justify-content: center; }
.confirm-actions .btn { flex: 1; }

/* ---- AUTH ---- */
.auth-panel h2 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.auth-sub { color: var(--text-2); font-size: 15px; margin-bottom: 28px; }
#signup-confirm-view { text-align: center; }
#signup-confirm-view .auth-sub { margin-bottom: 24px; }
#signup-confirm-view .auth-switch { margin-top: 18px; }
.auth-confirm-icon { font-size: 42px; margin-bottom: 12px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font-display); font-size: 15px;
  transition: border-color var(--transition); outline: none;
}
.form-group input:focus { border-color: var(--accent); }
.form-error { background: rgba(255,94,108,0.1); border: 1px solid var(--error); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--error); margin-bottom: 16px; }
.auth-switch { text-align: center; font-size: 14px; color: var(--text-2); margin-top: 16px; }
.auth-switch a { color: var(--accent-2); text-decoration: none; font-weight: 600; }

/* ---- APP NAV ---- */
.app-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(8,11,20,0.9); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border); height: 64px;
}
.app-nav-center { display: flex; gap: 4px; }
.app-nav-tab {
  padding: 8px 20px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-2);
  font-family: var(--font-display); font-size: 15px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
}
.app-nav-tab.active { background: var(--surface); color: var(--text); }
.app-nav-right { display: flex; align-items: center; gap: 12px; }
.credit-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 100px;
  font-family: var(--font-mono); font-size: 13px; font-weight: 700;
}
.credit-icon { color: var(--accent-2); }
#credit-count { color: var(--accent-2); }

/* ---- APP LAYOUT ---- */
.app-tab { display: none; }
.app-tab.active { display: block; }
.app-layout {
  display: grid; grid-template-columns: 360px 1fr;
  height: calc(100vh - 64px);
}

/* ---- CONTROL PANEL ---- */
.control-panel {
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: 24px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0;
}
.panel-section { margin-bottom: 24px; }
.panel-label { display: block; font-size: 18px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; letter-spacing: 0.3px; }
.optional { font-weight: 400; color: var(--text-3); }

.prompt-textarea {
  width: 100%; padding: 12px 14px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font-display); font-size: 14px;
  resize: vertical; outline: none; transition: border-color var(--transition);
  min-height: 80px;
}
.prompt-textarea.small { min-height: 50px; resize: none; }
.prompt-textarea:focus { border-color: var(--accent); }

.prompt-hints { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hint-tag {
  font-size: 12x; padding: 4px 10px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; transition: all var(--transition);
}
.hint-tag:hover { background: var(--surface-2); color: var(--accent-2); border-color: var(--accent); }

/* ── Model dropdown (replaces the old always-expanded grid) ── */
.model-dropdown { position: relative; }
.model-dropdown-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--bg-3); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
  color: var(--text); font-family: var(--font-display);
}
.model-dropdown-trigger:hover { border-color: var(--border-2); }
.model-dropdown.open .model-dropdown-trigger { border-color: var(--accent); background: rgba(200,30,44,0.1); }
.mdt-left { display: flex; align-items: center; gap: 8px; }
.mdt-right { display: flex; align-items: center; gap: 10px; }
.mdt-chevron {
  color: var(--text-2); font-size: 12px; transition: transform var(--transition);
}
.model-dropdown.open .mdt-chevron { transform: rotate(180deg); color: var(--accent-2); }

.model-dropdown-menu {
  position: fixed; z-index: 30;
  max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius); padding: 6px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}
.model-dropdown-menu.hidden { display: none; }

.model-option {
  padding: 10px 12px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.model-option:hover { background: var(--surface-2); }
.model-option.selected { border-color: var(--accent); background: rgba(200,30,44,0.1); }
.mo-top { display: flex; align-items: center; gap: 6px; }
.mo-icon { font-size: 15px; line-height: 1; flex-shrink: 0; }
.mo-name { font-size: 13px; font-weight: 600; }
.mo-cost { font-size: 13px; font-weight: 700; font-family: var(--font-mono); display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.mo-cost-num { color: var(--warning); font-weight: 700; }
.mo-cost-word { color: var(--text-2); font-weight: 600; }

.ratio-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.ratio-btn {
  flex: 1; padding: 8px; border-radius: var(--radius);
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-2); font-family: var(--font-mono); font-size: 12px;
  cursor: pointer; transition: all var(--transition);
}
.ratio-btn:hover { border-color: var(--border-2); }
.ratio-btn.active { border-color: var(--accent); background: rgba(200,30,44,0.1); color: var(--accent-2); }

/* ── Quality (1K/2K/4K) ── */
.quality-grid { display: flex; gap: 8px; }
.quality-btn {
  flex: 1; padding: 8px; border-radius: var(--radius);
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-2); font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all var(--transition);
}
.quality-btn:hover:not(:disabled) { border-color: var(--border-2); }
.quality-btn.active { border-color: var(--accent); background: rgba(200,30,44,0.1); color: var(--accent-2); }
.quality-btn:disabled,
.quality-btn.disabled {
  opacity: 0.35; cursor: not-allowed; color: var(--text-3);
}
.quality-hint { font-size: 11px; color: var(--text-3); margin-top: 6px; min-height: 14px; }

.count-control {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px; width: fit-content;
}
.count-control button {
  background: none; border: none; color: var(--text-2); font-size: 18px;
  cursor: pointer; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 4px; transition: all var(--transition);
}
.count-control button:hover { background: var(--surface); color: var(--text); }
.count-control span { font-family: var(--font-mono); font-weight: 700; font-size: 16px; min-width: 20px; text-align: center; }

/* ── Image-to-image upload (edit an existing image) ── */
.edit-dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; padding: 20px 12px; cursor: pointer;
  background: var(--bg-3); border: 1px dashed var(--border-2); border-radius: var(--radius);
  color: var(--text-3); font-size: 12px; transition: all var(--transition);
}
.edit-dropzone:hover { border-color: var(--accent); color: var(--text-2); }
.edit-dropzone .edit-dropzone-icon { font-size: 20px; }
.edit-dropzone.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.edit-preview { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.edit-preview img { display: block; width: 100%; max-height: 160px; object-fit: cover; }
.edit-preview-remove {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: rgba(0,0,0,0.65); color: #fff;
  font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.edit-preview-remove:hover { background: var(--accent); }
.edit-unsupported-hint { font-size: 11px; color: var(--warning); margin-top: 6px; display: none; }
.edit-unsupported-hint.visible { display: block; }

.generate-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.cost-preview { font-size: 13px; color: var(--text-3); margin-bottom: 12px; font-family: var(--font-mono); }
.cost-preview strong { color: var(--accent-2); }
.generate-btn { font-size: 16px; font-weight: 700; padding: 16px; }

/* ---- OUTPUT PANEL ---- */
.output-panel {
  display: flex; align-items: center; justify-content: center;
  padding: 32px; overflow-y: auto; background: var(--bg);
  position: relative; /* needed for video + content stacking */
}

/* ── Background video ── */
.output-bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  z-index: 0;
}
/* Show video only when the empty state is visible */
.output-panel:has(#output-empty:not(.hidden)) .output-bg-video { opacity: 1; }

/* All direct children of output-panel need to sit above the video */
.output-panel > *:not(.output-bg-video) { position: relative; z-index: 1; }

.output-empty { text-align: center; color: var(--text-3); }
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.output-empty p { font-size: 18px; margin-bottom: 8px; }
.empty-sub { font-size: 14px; }

.output-loading { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.spinner-ring {
  width: 56px; height: 56px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--text-2); font-size: 15px; }

.output-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; width: 100%; align-self: flex-start;
}
.output-img-wrap {
  position: relative; border-radius: var(--radius-lg); overflow: hidden;
  border: 1px solid var(--border); cursor: pointer;
  transition: all var(--transition); aspect-ratio: 1;
}
.output-img-wrap:hover { border-color: var(--accent); transform: scale(1.01); box-shadow: 0 8px 30px var(--accent-glow); }
.output-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.output-img-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  opacity: 0; transition: opacity var(--transition);
}
.output-img-wrap:hover .output-img-overlay { opacity: 1; }

/* ---- GALLERY ---- */
.gallery-header { padding: 40px 0 32px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.gallery-header h2 { font-size: 32px; font-weight: 700; margin-bottom: 8px; }
.gallery-header p { color: var(--text-2); }
.gallery-toolbar { display: flex; gap: 8px; align-items: center; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding-bottom: 60px; }
.gallery-item {
  position: relative;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); cursor: pointer;
  transition: all var(--transition); aspect-ratio: 1;
}
.gallery-item:hover { border-color: var(--accent); transform: scale(1.02); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item-checkbox {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px;
  border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 2;
}
.gallery-item.selected .gallery-item-checkbox { background: var(--accent); border-color: var(--accent); }
.gallery-item.selected img { opacity: 0.55; }
.gallery-item-checkbox svg { width: 14px; height: 14px; display: none; }
.gallery-item.selected .gallery-item-checkbox svg { display: block; }
.gallery-empty { text-align: center; padding: 80px 20px; color: var(--text-3); grid-column: 1/-1; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.gallery-empty p { font-size: 18px; }

/* ---- BUY CREDITS MODAL ---- */
.toggle-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.toggle-sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-2);
  margin-top: 2px;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 1px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border, #444);
  border-radius: 22px;
  transition: background 0.15s ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.img-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}

.credits-modal-toggle {
  display: flex; gap: 6px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px; margin: 20px 0 4px;
}
.cm-toggle-btn {
  flex: 1; background: transparent; border: none; cursor: pointer;
  color: var(--text-2); font-family: var(--font-display); font-size: 14px;
  font-weight: 600; padding: 10px; border-radius: 8px; transition: all var(--transition);
}
.cm-toggle-btn.active { background: var(--accent); color: #fff; }
.cm-toggle-btn:not(.active):hover { color: var(--text); }

.credit-packages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0; }
.credit-pkg {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 12px; text-align: center; cursor: pointer;
  position: relative; transition: all var(--transition);
}
.credit-pkg:hover { border-color: var(--border-2); }
.credit-pkg.selected { border-color: var(--accent); background: rgba(200,30,44,0.1); }
.credit-pkg.featured { border-color: var(--accent); }
.pkg-price { font-size: 24px; font-weight: 700; }
.pkg-credits { font-family: var(--font-mono); font-size: 13px; color: var(--accent-2); margin: 4px 0; }
.pkg-note { font-size: 11px; color: var(--text-3); }
.stripe-container { margin-top: 8px; }
.stripe-note { font-size: 12px; color: var(--text-3); margin-bottom: 16px; text-align: center; }
.stripe-field-mock {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 15px; color: var(--text-3);
  display: flex; justify-content: space-between; align-items: center;
}
.stripe-field-mock span { font-size: 11px; color: var(--success); }

/* ---- LIGHTBOX ---- */
.lightbox-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 24px;
  width: 90%; max-width: 720px; max-height: 90vh;
  display: flex; flex-direction: column; gap: 16px;
}
.lightbox-box img { width: 100%; border-radius: var(--radius); object-fit: contain; max-height: 60vh; }
.lightbox-actions { display: flex; gap: 12px; }
.lightbox-prompt { font-size: 13px; color: var(--text-3); font-style: italic; }
.lightbox-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 8px; flex-wrap: wrap; }
.lightbox-meta span { background: var(--bg-2); padding: 3px 9px; border-radius: 999px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; min-height: calc(100vh - 64px); }
  .control-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: none; }
  /* No forced min-height here — letting the output panel size to its actual
     content means the loading/empty state doesn't permanently eat half the
     screen on a phone. The spinner and empty-state already center themselves
     within whatever space they get. */
  .output-panel { min-height: 0; padding: 24px 16px; }
}
@media (max-width: 600px) {
  .nav-links .btn-ghost { display: none; }
  .hero-title { font-size: 40px; }
  .hero-stats { gap: 24px; }
  .credit-packages { grid-template-columns: 1fr; }
  .app-nav-center { display: none; }

  /* Tighter padding so controls aren't fighting a desktop-sized gutter on a
     narrow screen, but enough breathing room that things don't feel cramped. */
  .control-panel { padding: 16px; }
  .panel-section { margin-bottom: 20px; }

  /* Touch targets: anything tappable gets bumped to ~44px minimum (Apple/Google's
     own guideline) and gets more breathing room between adjacent buttons so
     mis-taps on the wrong option are less likely. */
  .ratio-grid, .quality-grid { gap: 10px; }
  .ratio-btn, .quality-btn { padding: 12px 8px; font-size: 13px; min-height: 44px; }

  .count-control { gap: 20px; padding: 10px 14px; }
  .count-control button { width: 36px; height: 36px; font-size: 20px; }

  .model-dropdown-trigger { padding: 14px 12px; }
  .model-option { padding: 14px 12px; }

  .form-group input, .prompt-textarea { padding: 14px; font-size: 15px; }
  .form-group { margin-bottom: 14px; }

  /* Buttons in general — more vertical room so labels don't feel squeezed
     against neighboring elements. */
  .btn { padding: 12px 20px; }
  .btn-lg { padding: 15px 28px; }

  .output-empty p { font-size: 16px; }
  .spinner-ring { width: 40px; height: 40px; }
}

/* ---- SETTINGS TAB ---- */
.container-narrow { max-width: 720px; }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 20px;
}
.settings-card h3 {
  font-size: 18px;
  margin-bottom: 16px;
}
.settings-card.danger-card {
  border-color: rgba(255, 94, 108, 0.3);
}
.settings-card.danger-card h3 { color: var(--error); }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }

.settings-label {
  font-size: 13px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.settings-value {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
}
.settings-note {
  font-size: 14px;
  color: var(--text-2);
  margin: 8px 0 16px;
  line-height: 1.5;
}

.settings-select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-display);
  font-size: 15px;
  margin-top: 6px;
  cursor: pointer;
}
.settings-select:focus { outline: none; border-color: var(--accent); }

.plan-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.plan-tag {
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-3);
  border: 1px solid var(--border-2);
}
.plan-tag.plan-tag-active {
  background: rgba(62, 202, 127, 0.15);
  color: var(--success);
  border-color: rgba(62, 202, 127, 0.4);
}

.sub-plans-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.sub-plans-grid-modal { grid-template-columns: repeat(3, 1fr); }

.sub-plan-card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.sub-plan-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.sub-plan-card.featured { border-color: var(--accent); }
.sub-plan-card.current {
  border-color: var(--success);
  background: rgba(62, 202, 127, 0.07);
}
.sub-plan-card.current::after {
  content: 'Current plan';
  position: absolute;
  top: -10px; left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #06140C;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.sub-plan-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.sub-plan-price { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.sub-plan-price span { font-size: 13px; color: var(--text-3); font-weight: 400; }
.sub-plan-credits { font-size: 13px; color: var(--accent-2); margin-bottom: 12px; }
.sub-plan-features {
  list-style: none;
  text-align: left;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#cancel-sub-btn { margin-top: 14px; color: var(--error); }
.settings-plan-actions { display: flex; gap: 10px; margin-top: 16px; }
.settings-plan-actions #cancel-sub-btn { margin-top: 0; }

/* ---- TRANSACTION HISTORY ---- */
.tx-list {
  display: flex; flex-direction: column;
  max-height: 420px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.tx-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.tx-row:last-child { border-bottom: none; }
.tx-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3); border-radius: 50%; font-size: 15px;
}
.tx-info { flex: 1; min-width: 0; }
.tx-desc { font-size: 14px; font-weight: 500; color: var(--text); }
.tx-date { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.tx-amount { font-family: var(--font-mono); font-size: 14px; font-weight: 700; white-space: nowrap; }
.tx-positive { color: var(--success); }
.tx-negative { color: var(--error); }

@media (max-width: 720px) {
  .sub-plans-grid, .sub-plans-grid-modal { grid-template-columns: 1fr; }
  .settings-row { flex-direction: column; align-items: flex-start; gap: 8px; }
}