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

:root {
  --bg: #050507;
  --bg2: #08080d;
  --surface: rgba(255,255,255,0.03);
  --surface-2: rgba(255,255,255,0.05);
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.15);
  --text: #f0f0f0;
  --text-dim: #555;
  --text-mid: #888;
  --accent: #7c5cff;
  --accent2: #c45cff;
  
  --green: --accent-soft);
  --radius: 14px;
  --radius-sm: 9px;
}

html, body { height: 100%; max-width: 100%; overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { width: 100vw; height: 100vh; display: flex; flex-direction: column; }

/* ===== NOISE OVERLAY ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

/* ===== AUTH ===== */
.auth-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(124,92,255,0.12) 0%, transparent 70%), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 44px;
  backdrop-filter: blur(20px);
  box-shadow: 0 0 80px rgba(124,92,255,0.08), 0 40px 80px rgba(0,0,0,0.4);
}

.auth-card h2 {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: var(--text);
  margin-bottom: 32px;
  text-align: center;
  background: linear-gradient(135deg, #fff 0%, --accent-soft) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-card button {
  display: none !important;
}

.auth-card button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 40px rgba(124,92,255,0.5);
}

.auth-toggle { text-align: center; margin-top: 20px; color: var(--text-mid); font-size: 15px; }
.auth-toggle a { color: var(--text); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.chip-row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:16px; }
.chip-row select { margin:0; }
.style-chip {
  padding: 6px 10px;
  background: rgba(139,92,246,0.08);
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: 7px;
  color: #c4b5fd;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.style-chip:hover { border-color: rgba(139,92,246,0.5); color: #ede9fe; background: rgba(139,92,246,0.15); }
.style-chip.active { background: rgba(124,92,255,0.28); border-color: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 0 14px rgba(124,92,255,0.3); }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #d4d0e8;
  margin-bottom: 8px;
}

input, select, textarea {
  width: 100%;
  background: #1c1c20;
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: background 0.15s;
  resize: none;
}

input:focus, select:focus, textarea:focus {
  background: #222228;
}

textarea { min-height: 90px; }

select {
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  display: inline-flex;
  align-items: center;
  background: #1e1e24;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 8px 36px 8px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  transition: border-color 0.15s, background 0.15s;
}
select:hover { border-color: rgba(255,255,255,0.18); background: #26262e; }
select:focus { border-color: var(--accent); outline: none; }
select, select option { accent-color: #3a3a3a; color-scheme: dark; }
select option { background: #1e1e24; color: #e5e7eb; }

/* ===== HEADER ===== */
.header {
  height: 60px;
  min-height: 60px;
  background: rgba(5,5,7,0.9);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  backdrop-filter: blur(30px);
  z-index: 10;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124,92,255,0.4), rgba(196,92,255,0.4), transparent);
}

.logo {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #ffffff 30%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right { display: flex; align-items: center; gap: 16px; }
.user-info { display: flex; flex-direction: column; align-items: flex-end; }
.username { font-size: 15px; font-weight: 500; color: var(--text); }
.credits { font-size: 13px; color: #a78bfa; font-weight: 600; }

.btn-buy {
  padding: 7px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 0 20px rgba(124,92,255,0.3);
}

.btn-buy:hover { box-shadow: 0 0 30px rgba(124,92,255,0.5); transform: translateY(-1px); }

.btn-logout {
  padding: 7px 14px;
  background: transparent;
  color: var(--text-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover { border-color: var(--border-hover); color: var(--text); }

/* ===== LAYOUT ===== */
.main-content { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 196px;
  min-width: 196px;
  background: rgba(5,5,7,0.8);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  overflow-y: auto;
  backdrop-filter: blur(20px);
}

.nav-item {
  display: block;
  padding: 10px 20px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  letter-spacing: 0.2px;
  position: relative;
}

.nav-item:hover { color: var(--text-mid); }

.nav-item.active {
  color: var(--text);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-radius: 0 2px 2px 0;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 36px;
  min-width: 0;
  background: radial-gradient(ellipse 100% 50% at 50% -10%, rgba(124,92,255,0.05) 0%, transparent 60%);
}

#page-script .form-card {
  background: #111113;
}

#script-typewriter {
  background: transparent;
  color: #f0ede8;
  font-size: 14.5px;
  line-height: 2;
  letter-spacing: 0.01em;
}

/* ===== SECTIONS ===== */
.generate-section { display: none; }
.generate-section.active { display: block; animation: fadeIn 0.25s ease; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  margin-bottom: 28px;
  background: linear-gradient(90deg, #ffffff 0%, #ffffff 25%, --accent-soft) 45%, var(--accent2) 55%, #ffffff 75%, #ffffff 100%);
  background-size: 250% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer-text 18s linear infinite;
}

@keyframes shimmer-text {
  0% { background-position: 200% center; }
  100% { background-position: -200% center; }
}

.result-container { margin-top: 24px; }

/* ===== FORM CARD ===== */
.form-card {
  background: #111114;
  border: none;
  border-radius: 18px;
  padding: 28px;
  margin-bottom: 14px;
}

.form-card:hover { background: #131316; }

/* ===== BUTTONS ===== */
.btn-generate {
  width: auto;
  padding: 12px 28px;
  background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 50%, #6d28d9 100%);
  background-size: 200% 200%;
  color: #fff;
  border: 1px solid rgba(167,139,250,0.3);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
  margin-top: 6px;
  font-family: inherit;
  box-shadow: 0 2px 12px rgba(109,40,217,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-generate:hover {
  background: linear-gradient(135deg, #7c3aed 0%, #8b5cf6 50%, #7c3aed 100%);
  box-shadow: 0 4px 20px rgba(124,58,237,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
  transform: translateY(-1px);
  border-color: rgba(196,181,253,0.4);
}
.btn-generate:active { transform: translateY(0); box-shadow: 0 1px 6px rgba(109,40,217,0.4); }
.btn-generate:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-download {
  padding: 8px 16px;
  background: var(--surface-2);
  color: var(--text-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-download:hover { border-color: var(--border-hover); color: var(--text); background: rgba(255,255,255,0.07); }

/* ===== RESULTS ===== */
.result-image {
  height: 260px;
  width: auto;
  max-width: 100%;
  border-radius: var(--radius);
  display: block;
  border: 1px solid var(--border);
  box-shadow: 0 0 60px rgba(124,92,255,0.12);
  animation: fadeIn 0.4s ease;
  object-fit: cover;
  cursor: pointer;
}

.result-video {
  width: 100%;
  max-width: 640px;
  border-radius: var(--radius);
  display: block;
  border: 1px solid var(--border);
  box-shadow: 0 0 60px rgba(0,229,160,0.1);
}

/* ===== LIBRARY ===== */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s;
}

.item-card:hover {
  border-color: rgba(124,92,255,0.3);
  transform: translateY(-2px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.item-thumbnail {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--surface-2);
  position: relative;
}

.item-thumbnail img, .item-thumbnail video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 0.3s;
}

.item-card:hover .item-thumbnail img { transform: scale(1.04); }

.play-button {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.7);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: white;
  border: 1px solid rgba(255,255,255,0.2);
}

.item-info { padding: 12px; }
.item-type { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 4px; }
.item-date { font-size: 13px; color: var(--text-mid); margin-bottom: 10px; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.item-btn {
  padding: 5px 10px;
  font-size: 13px; font-weight: 500;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-mid);
  cursor: pointer;
  transition: all 0.12s;
}

.item-btn:hover { border-color: rgba(124,92,255,0.4); color: var(--text); background: rgba(124,92,255,0.08); }

/* ===== LIGHTBOX ===== */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: 32px;
  backdrop-filter: blur(10px);
}

.lightbox.active { display: flex; animation: fadeIn 0.2s ease; }

.lightbox-content { position: relative; max-width: 90vw; max-height: 92vh; display:flex; flex-direction:column; align-items:center; gap:14px; }

.lightbox-close {
  position: absolute; top: -44px; right: 0;
  background: transparent; border: none;
  color: var(--text-mid); font-size: 30px; cursor: pointer;
  transition: color 0.15s; line-height: 1;
}

.lightbox-close:hover { color: var(--text); }

/* ===== STYLE OPTIONS ===== */
.style-option {
  cursor: pointer;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.style-option:hover { border-color: rgba(124,92,255,0.4); background: rgba(124,92,255,0.06); }

/* ===== PULSE / GLOW ANIMATIONS ===== */
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SEGMENTED GLOW SPINNER ===== */
.hx-spinner {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.hx-spinner-sm {
  width: 22px;
  height: 22px;
}
.hx-spinner canvas { display:block; }

@keyframes hx-spin-rotate { to { transform: rotate(360deg); } }
.hx-spinner-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  position: relative;
  animation: hx-spin-rotate 1s steps(12, end) infinite;
  flex-shrink: 0;
}
.hx-spinner-sm.hx-spinner-ring {
  width: 22px;
  height: 22px;
}
.hx-spinner-ring::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #c45cff;
  border-right-color: rgba(0,229,255,0.5);
  box-shadow: 0 0 10px rgba(0,229,255,0.8), 0 0 20px rgba(0,229,255,0.3);
  animation: hx-spin-rotate 0.9s linear infinite;
}
.hx-spinner-ring::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: rgba(0,229,255,0.35);
  animation: hx-spin-rotate 0.9s linear infinite reverse;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(124,92,255,0.2); }
  50% { box-shadow: 0 0 40px rgba(124,92,255,0.5), 0 0 60px rgba(196,92,255,0.2); }
}

@keyframes gradient-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* No pulse animation on buttons */

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  body { overflow-x: hidden; overflow-y: auto; }

  #app { height: auto; min-height: 100vh; max-width: 100vw; overflow-x: hidden; }

  .header {
    padding: 0 12px;
    height: 56px;
    min-height: 56px;
    gap: 8px;
  }

  .logo { font-size: 13px; letter-spacing: 2px; min-width: 0; flex-shrink: 1; }
  .logo > div { flex-shrink: 1; min-width: 0; }
  .logo img { height: 30px !important; width: 30px !important; flex-shrink: 0; }
  /* Tagline: tiny on mobile so it fits fully */
  .logo-tagline {
    font-size: 7px !important;
    letter-spacing: 0.5px !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: unset !important;
    max-width: none !important;
  }

  .header-right { gap: 6px; flex-shrink: 0; overflow: hidden; }
  .user-info { display: none; }
  #credits-display-mobile { display: block !important; }
  #hamburger-btn { display: block !important; }

  .btn-buy {
    padding: 5px 10px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .btn-logout {
    display: none !important;
  }

  .main-content {
    flex-direction: column;
    padding-bottom: 64px;
  }

  .sidebar {
    display: none;
  }

  /* Bottom nav bar on mobile */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 56px;
    background: rgba(8,8,8,0.97);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    z-index: 100;
    padding: 0 4px;
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    color: #888;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
    border: none;
    background: transparent;
    font-family: inherit;
    letter-spacing: 0.3px;
  }

  .mobile-nav-item.active { color: #ffffff; font-weight: 600; }

  .mobile-nav-item svg { width: 18px; height: 18px; }

  .content {
    padding: 20px 16px;
    overflow-y: visible;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  .form-card, .result-container, textarea, input, select {
    max-width: 100%;
    box-sizing: border-box;
  }

  .result-image {
    height: auto;
    width: 100%;
    max-width: 100%;
  }

  .form-card { padding: 16px; }

  .section-title { margin-bottom: 20px; }

  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
}

/* Hide mobile nav on desktop */
.mobile-nav { display: none; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(124,92,255,0.4); }

/* ===== UTILITY ===== */
::placeholder { color: var(--text-dim); }

/* ===== TYPEWRITER CURSOR ===== */
#script-typewriter::after {
  content: '|';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  font-weight: 300;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.15); }
}
