* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-dark: #1a1a1a;
  --bg-panel: #242424;
  --border: #3a3a3a;
  --accent: #6b9fff;
  --accent-warm: #ff9f6b;
  --text-primary: #e0e0e0;
  --text-dim: #888;
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
}

/* ========================================
   Editor Page Styles
   ======================================== */

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 16px;
  gap: 12px;
  overflow: hidden;
}

header {
  text-align: center;
  padding: 8px;
  flex-shrink: 0;
}

.header-content {
    text-align: left;
}

h1 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Navigation */
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 14px;
  background: rgba(107, 159, 255, 0.1);
  border: 1px solid var(--accent);
  border-radius: 16px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: rgba(107, 159, 255, 0.2);
}

/* Mode Toggle Buttons */
.mode-toggles {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--bg-panel);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
  font-family: inherit;
}

.mode-toggle:hover {
  border-color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
}

.mode-toggle.active {
  border-color: var(--accent);
  background: rgba(107, 159, 255, 0.15);
  color: var(--text-primary);
}

.mode-toggle.active .mode-icon {
  transform: scale(1.1);
}

.mode-toggle.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mode-toggle.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.mode-icon {
  font-size: 1.1rem;
  transition: transform 0.2s ease;
}

.mode-label {
  font-weight: 500;
}

.mode-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 8px;
  opacity: 0.8;
}

/* Option Toggle Buttons (Second Pass, etc.) */
.option-toggles {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

.option-toggle:hover {
  border-color: var(--text-dim);
}

.option-toggle.active {
  border-color: var(--accent);
  color: var(--text-primary);
}

.option-toggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.option-toggle:disabled:hover {
  border-color: var(--border);
}

/* Segmented Controls (Model & Resolution Toggles) */
.model-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: transparent;
}

.model-toggle .model-option {
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
}

.model-toggle .model-option:first-child {
  border-right: 1px solid var(--border);
}

.model-toggle .model-option:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

.model-toggle .model-option[data-model="gemini"].active {
  background: rgba(107, 159, 255, 0.2);
  color: var(--accent);
}

.model-toggle .model-option[data-model="grok"].active {
  background: rgba(255, 107, 53, 0.2);
  color: #ff6b35;
}

/* Resolution Toggle (Segmented Control) */
.resolution-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: transparent;
}

.resolution-toggle .res-option {
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
}

.resolution-toggle .res-option:first-child {
  border-right: 1px solid var(--border);
}

.resolution-toggle .res-option:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

.resolution-toggle .res-option.active {
  background: rgba(107, 159, 255, 0.2);
  color: var(--accent);
}

/* Aspect Ratio Toggle (Segmented Control) */
.aspect-ratio-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: transparent;
}

.aspect-ratio-toggle .ar-option {
  padding: 5px 8px;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
}

.aspect-ratio-toggle .ar-option:last-child {
  border-right: none;
}

.aspect-ratio-toggle .ar-option:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

.aspect-ratio-toggle .ar-option.active {
  background: rgba(107, 159, 255, 0.2);
  color: var(--accent);
}

/* Temperature Slider */
.temperature-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  font-size: 0.75rem;
}

.temperature-slider .slider-label {
  color: var(--text-dim);
  font-weight: 500;
}

.temperature-slider .slider-value {
  color: var(--accent);
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}

.temperature-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.temperature-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.temperature-slider input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 8px rgba(107, 159, 255, 0.5);
}

.temperature-slider input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.temperature-slider input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 8px rgba(107, 159, 255, 0.5);
}

.temperature-slider input[type="range"]::-moz-range-track {
  background: var(--border);
  height: 4px;
  border-radius: 2px;
}

.main-content {
  display: flex;
  flex: 1;
  gap: 16px;
  min-height: 0;
}

@media (max-width: 900px) {
  /* Allow scrolling on mobile instead of forcing viewport height */
  .container {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  
  .main-content {
    flex-direction: column;
    flex: none;
  }
  
  /* Let panels size naturally based on content */
  .panel {
    flex: none;
  }
  
  .panel-split {
    flex: none;
  }
  
  .panel-upper {
    flex: none;
  }
  
  .panel-lower {
    flex: none;
    min-height: 200px;
  }
  
  /* Result panel needs explicit height since it has no inherent content */
  .panel:not(.panel-split) {
    min-height: 300px;
  }
  
  .instructions-section {
    flex-direction: column;
    gap: 8px;
  }
  
  .instructions-textarea {
    min-height: 100px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
  
  .submit-btn {
    flex-direction: row;
    padding: 14px 24px;
    width: 100%;
  }
  
  .upload-zone {
    min-height: 200px;
  }
  
  .output-zone {
    min-height: 250px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .container {
    padding: 10px;
    gap: 10px;
  }
  
  .panel {
    padding: 12px;
  }
  
  .instructions-textarea {
    min-height: 80px;
    padding: 10px;
  }
  
  .panel-title {
    font-size: 0.75rem;
    margin-bottom: 8px;
  }
  
  .upload-zone {
    min-height: 150px;
  }
  
  .output-zone {
    min-height: 200px;
  }
}

.panel {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Split Panel Layout (80/20) */
.panel-split {
  gap: 12px;
}

.panel-upper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-lower {
  flex: 4;
  display: flex;
  flex-direction: column;
  min-height: 120px;
}

/* Instructions Section */
.instructions-section {
  flex: 1;
  display: flex;
  gap: 10px;
  min-height: 0;
}

.instructions-textarea {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.5;
  resize: none;
  transition: border-color 0.2s;
}

.instructions-textarea::placeholder {
  color: var(--text-dim);
  opacity: 0.7;
}

.instructions-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.submit-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--accent) 0%, #9f6bff 100%);
  border: none;
  border-radius: 8px;
  color: white;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  min-width: 90px;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(107, 159, 255, 0.4);
}

.submit-btn:active {
  transform: translateY(0);
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.submit-icon {
  font-size: 1.2rem;
}

.submit-btn.simple {
  background: var(--accent);
  padding: 10px 20px;
  flex-direction: row;
}

.submit-btn.simple:hover {
  transform: none;
  box-shadow: none;
  opacity: 0.9;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.upload-zone {
  flex: 1;
  border: 2px dashed var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.upload-zone:hover {
  border-color: var(--accent);
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(107, 159, 255, 0.05);
}

.upload-zone.has-image {
  border-style: solid;
  border-color: var(--accent);
}

.upload-zone.has-image .upload-content {
  display: none;
}

.upload-zone.disabled {
  pointer-events: none;
  cursor: not-allowed;
}

.instructions-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(26, 26, 26, 0.7);
}

.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.upload-text {
  font-size: 0.95rem;
  color: var(--text-dim);
  text-align: center;
}

/* Turnstile Modal */
.turnstile-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.turnstile-modal.active {
  display: flex;
}

.turnstile-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}

.turnstile-modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.turnstile-modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.turnstile-modal-widget {
  display: flex;
  justify-content: center;
  min-height: 65px;
}

.turnstile-modal-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.upload-text strong {
  color: var(--text-primary);
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 6px;
  opacity: 0.7;
}

#upload-input {
  display: none;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* Remove Image Button */
.remove-image-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  z-index: 10;
  align-items: center;
  justify-content: center;
}

.remove-image-btn:hover {
  background: rgba(220, 53, 69, 0.9);
  transform: scale(1.1);
}

.upload-zone.has-image .remove-image-btn {
  display: flex;
}

/* Image Action Buttons Container */
.image-action-buttons {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 6px;
  z-index: 10;
}

.upload-zone.has-image .image-action-buttons {
  display: flex;
}

.upload-zone.has-image .image-action-buttons .remove-image-btn {
  position: static;
  display: flex;
}

/* Blur Image Button */
.blur-image-btn {
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

.blur-image-btn svg {
  width: 100%;
  height: 100%;
}

.blur-image-btn:hover {
  background: rgba(107, 159, 255, 0.9);
  transform: scale(1.1);
}

/* Quick Blur Tool Modal */
.blur-tool-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.blur-tool-modal.active {
  display: flex;
}

.blur-tool-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
}

.blur-tool-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modalSlideIn 0.3s ease;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
}

.blur-tool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.blur-tool-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.blur-tool-close {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.blur-tool-close:hover {
  background: rgba(220, 53, 69, 0.2);
  border-color: #dc3545;
  color: #dc3545;
}

.blur-tool-canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  min-height: 300px;
  max-height: 60vh;
  overflow: hidden;
  position: relative;
}

#blur-canvas {
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
}

.blur-tool-controls {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.blur-control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.blur-control-group label {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
}

.blur-control-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.blur-control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.blur-control-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(107, 159, 255, 0.6);
}

.blur-control-group input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.blur-control-group span {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  min-width: 40px;
}

.blur-tool-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.blur-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.blur-action-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text-primary);
  background: rgba(107, 159, 255, 0.1);
}

.blur-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.blur-action-btn span {
  font-size: 1rem;
}

.blur-action-btn.blur-clear:hover:not(:disabled) {
  border-color: var(--accent-warm);
  color: var(--accent-warm);
  background: rgba(255, 159, 107, 0.1);
}

.blur-tool-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.blur-cancel-btn {
  padding: 10px 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.blur-cancel-btn:hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

.blur-apply-btn {
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--accent) 0%, #9f6bff 100%);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.blur-apply-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(107, 159, 255, 0.4);
}

/* Brush cursor preview */
.blur-cursor-preview {
  position: fixed;
  pointer-events: none;
  border: 2px solid rgba(107, 159, 255, 0.8);
  border-radius: 50%;
  background: rgba(107, 159, 255, 0.1);
  transform: translate(-50%, -50%);
  z-index: 3000;
  display: none;
}

.blur-tool-modal.active .blur-cursor-preview {
  display: block;
}

/* Mobile adjustments for blur tool */
@media (max-width: 768px) {
  .blur-tool-content {
    max-width: 95vw;
    max-height: 95vh;
  }
  
  .blur-tool-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .blur-control-group {
    justify-content: space-between;
  }
  
  .blur-control-group input[type="range"] {
    flex: 1;
    max-width: 150px;
  }
  
  .blur-tool-actions {
    margin-left: 0;
    justify-content: center;
  }
  
  .blur-tool-footer {
    flex-direction: column;
  }
  
  .blur-cancel-btn,
  .blur-apply-btn {
    width: 100%;
  }
}

.output-zone {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.output-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  color: var(--text-dim);
}


.output-placeholder .icon {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.4;
}

.loading-spinner {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-spinner.active {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.cancel-btn {
  margin-top: 8px;
  padding: 6px 20px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cancel-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
}

.result-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.download-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  display: none;
}

.download-btn.show {
  display: block;
}

.download-btn:hover {
  opacity: 0.9;
}

.retry-container {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.retry-container.show {
  display: flex;
}

.retry-message {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.retry-btn {
  background: rgba(255, 180, 80, 0.9);
  color: #1a1a1a;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.retry-btn:hover {
  background: rgba(255, 180, 80, 1);
}

/* ========================================
   Gallery Page Styles
   ======================================== */

.gallery-container {
  min-height: 100vh;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.gallery-header h1 {
  font-size: 1.6rem;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #9f6bff 100%);
  border-radius: 20px;
  color: white;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: transform 0.2s, box-shadow 0.2s;
}

.nav-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(107, 159, 255, 0.4);
}

.nav-icon {
  font-size: 1.1rem;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.gallery-card {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  aspect-ratio: 1;
}

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  border-color: var(--accent);
}

.card-images {
  position: relative;
  width: 100%;
  height: 100%;
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
}

.card-original {
  opacity: 0;
}

.card-generated {
  opacity: 1;
}

.gallery-card:hover .card-original {
  opacity: 1;
}

.gallery-card:hover .card-generated {
  opacity: 0;
}

/* Single image cards (text-only generations without original) */
.card-images.single-image .card-generated {
  opacity: 1;
}

.gallery-card:hover .card-images.single-image .card-generated {
  opacity: 1;
}

.card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 12px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.card-modes {
  display: flex;
  gap: 6px;
}

.mode-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 0.85rem;
}

.mode-badge.grok-badge {
  background: rgba(255, 107, 53, 0.3);
}

.mode-badge.model-badge {
  background: linear-gradient(90deg, rgba(255, 107, 53, 0.3) 0%, rgba(107, 159, 255, 0.3) 100%);
}

.card-date {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Gallery States */
.gallery-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-dim);
}

.gallery-loading .spinner {
  width: 24px;
  height: 24px;
  border-width: 2px;
}

.gallery-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 4rem;
  opacity: 0.5;
  margin-bottom: 16px;
}

.gallery-empty h2 {
  font-size: 1.4rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.gallery-empty p {
  color: var(--text-dim);
  margin-bottom: 24px;
}

.create-btn {
  display: inline-block;
  padding: 12px 28px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 24px;
  font-weight: 500;
  transition: transform 0.2s, box-shadow 0.2s;
}

.create-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(107, 159, 255, 0.4);
}

.gallery-end {
  display: none;
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
}

.lightbox.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-content {
  max-width: 1200px;
  width: 100%;
  margin: auto;
}

.lightbox-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.lightbox-images.single-image {
  grid-template-columns: 1fr;
}

@media (max-width: 768px) {
  .lightbox-images {
    grid-template-columns: 1fr;
  }
}

.lightbox-image-container {
  position: relative;
}

.lightbox-label {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 12px;
  border-radius: 8px 0 6px 0;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lightbox-image-container a {
  display: block;
  cursor: pointer;
}

.lightbox-image-container img {
  width: 100%;
  border-radius: 8px;
  background: var(--bg-panel);
  transition: opacity 0.15s ease;
}

.lightbox-image-container a:hover img {
  opacity: 0.85;
}

.lightbox-meta {
  background: var(--bg-panel);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.lightbox-modes {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.lightbox-instructions {
  color: var(--accent);
  line-height: 1.6;
  margin-bottom: 12px;
  font-size: 0.9rem;
  padding: 10px 12px;
  background: rgba(107, 159, 255, 0.1);
  border: 1px solid rgba(107, 159, 255, 0.3);
  border-radius: 8px;
}

.lightbox-instructions::before {
  content: 'Instructions: ';
  font-weight: 600;
}

.lightbox-mode {
  background: rgba(107, 159, 255, 0.15);
  border: 1px solid var(--accent);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.85rem;
}

.lightbox-mode.grok-mode {
  background: rgba(255, 107, 53, 0.15);
  border-color: #ff6b35;
  color: #ff6b35;
}

.lightbox-mode.gemini-mode {
  background: rgba(107, 159, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.lightbox-mode.model-mode {
  background: linear-gradient(90deg, rgba(255, 107, 53, 0.15) 0%, rgba(107, 159, 255, 0.15) 100%);
  border-image: linear-gradient(90deg, #ff6b35, var(--accent)) 1;
  color: var(--text-primary);
}

.lightbox-prompt {
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 16px;
  font-size: 0.95rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  white-space: pre-wrap;
}

.lightbox-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.lightbox-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.lightbox-stats {
  font-size: 0.75rem;
  color: var(--text-dim);
  opacity: 0.8;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
}

@media (max-width: 768px) {
  .lightbox-footer {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .lightbox-stats {
    width: 100%;
  }
}

a {
  color: var(--accent);
  text-decoration: none;
}