:root {
  --bg-primary: #0A0A0B;
  --bg-secondary: #141416;
  --bg-tertiary: #1E1E22;
  --accent-color: #6366F1;
  --accent-hover: #4F46E5;
  --text-primary: #FFFFFF;
  --text-secondary: #9CA3AF;
  --border-color: #27272A;
  --border-focus: #4ade80;

  --shadow-glow: 0 0 15px rgba(99, 102, 241, 0.3);
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --border-radius-pill: 9999px;

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --navbar-height: 70px;
  --controls-width: 400px;
  --login-title-size: 4.5rem;
  --spinner-duration: 1s;
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

/* Allow scrolling on mobile by default, but hide on desktop if needed */
@media (min-width: 769px) {
  body {
    height: 100vh;
    overflow: hidden;
  }
}

/* Layout Setup */
.app-container {
  display: flex;
  width: 100%;
  flex: 1;
}

@media (min-width: 769px) {
  .app-container {
    overflow: hidden;
  }
}

.top-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: var(--navbar-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  z-index: 50;
}

.brand-info h1 {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, #FFF, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2px;
}

.brand-info p {
  color: var(--text-secondary);
  font-size: 13px;
}

.controls-panel {
  width: var(--controls-width);
  min-width: var(--controls-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  gap: 20px;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, #FFF, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

header p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Forms */
#generator-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select,
input {
  width: 100%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--border-radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  transition: var(--transition);
  outline: none;
  appearance: none;
}

select {
  cursor: pointer;
  background-image: url('data:image/svg+xml;utf8,<svg fill="none" class="w-6 h-6" stroke="gray" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"></path></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 32px;
}

select:focus,
input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.hidden-input {
  display: none;
  margin-top: 8px;
}

.hidden-input.active {
  display: block;
}

/* Prompt Preview */
.prompt-preview {
  display: none;
  margin-top: 8px;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 16px;
  border-radius: var(--border-radius-sm);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.prompt-preview strong {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-color);
}

/* Buttons */
button {
  background-color: var(--accent-color);
  color: #fff;
  border: none;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

button:hover {
  background-color: var(--accent-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.secondary-btn {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 14px;
}

.secondary-btn:hover {
  background-color: var(--bg-secondary);
  border-color: var(--text-secondary);
  box-shadow: none;
}

/* Preview Panel */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 40px;
  background: radial-gradient(circle at center, #1E1E22 0%, #0A0A0B 100%);
  position: relative;
  overflow-y: auto;
}

#image-container {
  width: auto;
  height: auto;
  min-width: 300px;
  min-height: 300px;
  max-width: 100%;
  max-height: 80vh;
  aspect-ratio: 1;
  background-color: rgba(0, 0, 0, 0.4);
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

#image-container.has-image {
  border-color: transparent;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  background-color: #000;
}

img#generated-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.hidden {
  display: none !important;
}

.placeholder-content {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
}

.placeholder-icon {
  margin-bottom: 16px;
  opacity: 0.5;
}

.actions {
  display: flex;
  gap: 16px;
  margin-top: 24px;
  opacity: 1;
  transition: var(--transition);
}

.actions.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Loader spinner */
.loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-bottom-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: rotation var(--spinner-duration) linear infinite;
}

.loader.hidden {
  display: none;
}

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* --- Firebase Login & Auth UI --- */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  /* Use solid color to hide everything underneath */
  display: flex;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

.login-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background-color: #0A0A0B;
  position: relative;
  z-index: 2;
}

/* Subtle Tech background on left side */
.login-left::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.05) 0%, transparent 40%),
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255, 255, 255, 0.02) 10px, rgba(255, 255, 255, 0.02) 11px);
  pointer-events: none;
  z-index: -1;
}

.login-content {
  max-width: 480px;
  width: 100%;
  text-align: left;
}

.login-title {
  font-family: inherit;
  font-size: var(--login-title-size);
  font-weight: 800;
  line-height: 1.1;
  margin-top: 0;
  margin-bottom: 24px;
  color: #FFFFFF;
  letter-spacing: -0.03em;
}

.login-subtitle {
  font-size: 1.15rem;
  color: #9CA3AF;
  margin-bottom: 0px;
  line-height: 1.5;
}

.login-btn-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 40px 0;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: white !important;
  color: #000 !important;
  border: none !important;
  font-weight: 600 !important;
  font-size: 1.05rem !important;
  padding: 14px 28px !important;
  border-radius: var(--border-radius-pill) !important;
  width: fit-content;
  min-width: 250px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
  margin-top: 0 !important;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.15) !important;
}


.google-icon {
  width: 24px;
  height: 24px;
  margin-right: 12px;
}

.login-right {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0A0A0B;
  overflow: hidden;
}

.split-hero {
  display: flex;
  width: 100%;
  height: 100%;
}

.hero-img {
  width: 50%;
  height: 100%;
  object-fit: cover;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
  background: transparent;
}

.credit-counter {
  display: flex;
  align-items: center;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 4px 12px;
  border-radius: var(--border-radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-color);
  gap: 12px;
}

.buy-btn {
  background-color: transparent !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  padding: 4px 10px !important;
  font-size: 0.75rem !important;
  margin: 0 !important;
  border-radius: 999px !important;
}

.buy-btn:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
  box-shadow: none !important;
}

.user-info {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 12px;
}

.small-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* --- History Panel --- */
.history-panel {
  margin-top: 40px;
  border-top: 1px solid var(--border-color);
  padding-top: 24px;
  width: 100%;
}

.history-panel h3 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  width: 100%;
}

.history-item {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.history-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent-color);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.credit-notice {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
  font-weight: 500;
  opacity: 0.8;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--bg-secondary);
  padding: 32px;
  border-radius: var(--border-radius-lg);
  max-width: 500px;
  width: 90%;
  border: 1px solid var(--border-color);
  position: relative;
  text-align: center;
}

.modal-content h2 {
  margin-bottom: 16px;
  color: #fff;
}

.modal-content p {
  color: var(--text-secondary);
  line-height: 1.6;
  font-size: 15px;
}

.modal-content strong {
  color: var(--accent-color);
}

.close-modal {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.close-modal:hover {
  color: #fff;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
  .top-nav-bar {
    height: auto;
    padding: 16px;
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }

  .brand-info h1 {
    font-size: 20px;
  }

  .user-bar {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 12px;
  }

  .app-container {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    min-width: 100% !important;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    box-shadow: none;
    overflow-y: visible;
  }

  .preview-panel {
    padding: 24px 16px;
    overflow-y: visible;
    min-height: 50vh;
  }

  #image-container {
    min-width: unset;
    width: 100%;
  }

  .login-overlay {
    flex-direction: column;
    overflow-y: auto;
  }

  .login-left {
    padding: 40px 20px 0 20px;
    min-height: auto;
    width: 100%;
    flex: none;
  }

  .login-right {
    display: flex;
    width: 100%;
    height: 40vh;
    /* Show hero images below the login form */
    flex: none;
    border-top: 1px solid var(--border-color);
  }

  .login-title {
    font-size: 2.5rem;
    text-align: center;
  }

  .login-subtitle {
    font-size: 1rem;
    text-align: center;

    br {
      display: none;
    }
  }

  .login-btn-container {
    align-items: center;
    margin: 40px 0;
  }

  .login-content {
    text-align: center;
  }

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