/* ==========================================================================
   Stickerify - Custom Premium Design System (Light Theme)
   ========================================================================== */

:root {
  --font-primary: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Color Palette (Premium Light Theme) */
  --bg-app: #f4f6fa;
  --bg-card: rgba(255, 255, 255, 0.75);
  --bg-card-hover: rgba(255, 255, 255, 0.9);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-glow: rgba(124, 58, 237, 0.2);
  
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-glow: rgba(124, 58, 237, 0.25);
  
  --success: #10b981;
  --success-hover: #059669;
  
  --accent: #f43f5e;
  --accent-hover: #e11d48;
  
  --text-primary: #1e293b;   /* Slate 800 */
  --text-secondary: #475569; /* Slate 600 */
  --text-muted: #64748b;     /* Slate 500 */

  /* Layout Constants */
  --header-height: 70px;
  --border-radius-lg: 24px;
  --border-radius-md: 16px;
  --border-radius-sm: 8px;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-primary);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  /* Support iOS safe area offsets */
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   App Wrapper & Layout
   ========================================================================== */

.app-container {
  width: 100%;
  max-width: 540px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  position: relative;
}

/* Background glowing decorative elements in soft pastel colors */
.app-container::before {
  content: '';
  position: absolute;
  top: 10%;
  left: 5%;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.08) 0%, transparent 70%);
  z-index: -1;
  pointer-events: none;
}

.app-container::after {
  content: '';
  position: absolute;
  bottom: 20%;
  right: 5%;
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, rgba(244, 63, 94, 0.06) 0%, transparent 70%);
  z-index: -1;
  pointer-events: none;
}

/* ==========================================================================
   Header Component
   ========================================================================== */

.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #7c3aed 0%, #f43f5e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon {
  background: linear-gradient(135deg, #7c3aed 0%, #f43f5e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(124, 58, 237, 0.2));
}

.badge {
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.15);
  color: #7c3aed;
  padding: 6px 12px;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   Shared Card Component (Glassmorphism Light)
   ========================================================================== */

.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  box-shadow: 0 10px 30px rgba(31, 41, 55, 0.06);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), 
              border-color 0.3s ease, 
              box-shadow 0.3s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, transparent 100%);
  pointer-events: none;
}

.card:hover {
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 35px rgba(31, 41, 55, 0.08);
}

/* ==========================================================================
   Upload Section & Drag and Drop
   ========================================================================== */

.upload-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  cursor: pointer;
  border: 2px dashed rgba(0, 0, 0, 0.12);
}

.upload-section:hover, .upload-section.dragover {
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.1);
  background: var(--bg-card-hover);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.glow-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.1) 0%, rgba(124, 58, 237, 0) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(124, 58, 237, 0.1);
  transition: transform 0.3s ease;
}

.upload-section:hover .glow-circle {
  transform: scale(1.1);
  background: radial-gradient(circle, rgba(124, 58, 237, 0.15) 0%, rgba(124, 58, 237, 0) 70%);
  border-color: rgba(124, 58, 237, 0.2);
}

.upload-icon {
  font-size: 32px;
  color: var(--primary);
}

.upload-placeholder h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.upload-placeholder p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.5;
}

/* Image Preview state */
.upload-preview-container {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#source-preview {
  max-width: 100%;
  max-height: 350px;
  border-radius: var(--border-radius-md);
  object-fit: contain;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.btn-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.btn-clear:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}

/* ==========================================================================
   Config Section & Input Controls
   ========================================================================== */

.config-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.control-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Style Select input */
select {
  width: 100%;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 15px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e293b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 16px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

select:focus {
  border-color: var(--primary);
  background-color: rgba(0, 0, 0, 0.05);
}

/* CRITICAL FIX: Ensure select options have solid background and dark text */
select option {
  background-color: #ffffff !important;
  color: #1e293b !important;
  padding: 12px;
}

/* Sliders Style */
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-value {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary);
  background: rgba(124, 58, 237, 0.08);
  padding: 2px 8px;
  border-radius: 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  outline: none;
  margin: 10px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
  transition: transform 0.1s ease, background-color 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  background: #6d28d9;
}

/* ==========================================================================
   Button System
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-primary);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 24px;
  border-radius: var(--border-radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.35);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}

.btn-success:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.3);
}

.btn-success:disabled {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-upload {
  width: auto;
  padding: 10px 20px;
  font-size: 14px;
}

.btn-zip {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  color: #fff;
  padding: 10px 18px;
  font-size: 14px;
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.15);
}

.btn-zip:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(124, 58, 237, 0.3);
}

/* ==========================================================================
   Loader / Spinner
   ========================================================================== */

.processing-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  gap: 16px;
  text-align: center;
}

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

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(0, 0, 0, 0.05);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Results Area & Stickers Grid
   ========================================================================== */

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.results-info h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.stickers-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 380px) {
  .stickers-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.sticker-item {
  background: rgba(0, 0, 0, 0.01);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  position: relative;
}

.sticker-item:hover {
  transform: scale(1.03);
  border-color: rgba(124, 58, 237, 0.25);
  background: #ffffff;
  box-shadow: 0 4px 15px rgba(31, 41, 55, 0.04);
}

.sticker-preview-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background-image: 
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-color: #f8fafc;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.sticker-preview-box img {
  width: 90%;
  height: 90%;
  object-fit: contain;
}

.sticker-actions {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 6px;
}

.sticker-actions .btn-download {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 0;
  border-radius: 6px;
  text-align: center;
  display: inline-block;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
}

.btn-save-photo {
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
  color: #fff;
  border: none;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.2);
}

.btn-save-photo:hover {
  background: linear-gradient(135deg, #6d28d9 0%, #3f37c9 100%);
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.35);
  transform: scale(1.02);
}

.file-formats {
  display: flex;
  gap: 6px;
  width: 100%;
}

.btn-png {
  background: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.btn-png:hover {
  background: #f8fafc;
}

.btn-webp {
  background: rgba(124, 58, 237, 0.06);
  color: var(--primary);
  border: 1px solid rgba(124, 58, 237, 0.15);
}

.btn-webp:hover {
  background: rgba(124, 58, 237, 0.12);
}

/* ==========================================================================
   Footer instructions
   ========================================================================== */

.app-instructions {
  background: rgba(0, 0, 0, 0.01);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  margin-top: 10px;
}

.app-instructions h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.app-instructions ol {
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.5;
}

.app-instructions li strong {
  color: var(--primary);
}

/* ==========================================================================
   Modal Component for iOS Save Instructions
   ========================================================================== */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(7, 7, 10, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 400px;
  padding: 30px 24px 24px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
  position: relative;
  animation: modalEntrance 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalEntrance {
  0% { transform: scale(0.9) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

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

.modal-content h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-sticker-preview {
  width: 160px;
  height: 160px;
  background-image: 
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-color: #f8fafc;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.modal-sticker-preview img {
  width: 140px;
  height: 140px;
  object-fit: contain;
  -webkit-touch-callout: default; /* Enables native iOS long-press callout menu */
}

.modal-instruction {
  background: rgba(124, 58, 237, 0.05);
  border: 1px solid rgba(124, 58, 237, 0.12);
  border-radius: var(--border-radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.tap-icon {
  font-size: 24px;
  color: var(--primary);
  animation: pulse 1.5s infinite;
}

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

.modal-instruction p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-instruction strong {
  color: var(--primary);
}
