/* ==========================================================================
   Diwali Mela Poster Generator - Style Sheet
   Exact Poster Color Palette: Royal Blue (#082e87), Green (#00a859), Gold (#facd2a)
   ========================================================================== */

/* --- Local Font Declarations --- */
@font-face {
  font-family: 'Noto Sans Gujarati';
  src: url('assets/fonts/NotoSansGujarati-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Noto Sans Gujarati';
  src: url('assets/fonts/NotoSansGujarati-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --- Design Tokens & Variables --- */
:root {
  --font-primary: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-gujarati: "Noto Sans Gujarati", -apple-system, BlinkMacSystemFont, sans-serif;

  /* Poster Theme Color Palette */
  --color-poster-navy: #082e87;        /* Primary royal navy from poster */
  --color-poster-blue-dark: #041a54;   /* Deep shadow navy */
  --color-poster-blue-light: #113c9e;  /* Vibrant royal blue */
  --color-poster-green: #00a859;       /* Signature green from poster frame */
  --color-poster-green-dark: #008746;  /* Deep green */
  --color-poster-green-bg: #e8f8f0;    /* Light green tint */
  --color-poster-gold: #facd2a;        /* Festive gold/marigold */
  --color-poster-amber: #fbbb46;       /* Warm amber */
  --color-poster-red: #ad2018;         /* Festive crimson red */

  /* Neutral Surface & Background Colors */
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-surface-hover: #f8fafc;
  --color-border: #dbe4f2;
  --color-border-hover: #b8cbe6;
  --color-border-focus: #082e87;

  --color-text-main: #0c1c38;
  --color-text-muted: #576b8a;
  --color-text-light: #8fa0ba;

  --color-error: #ad2018;
  --color-error-bg: #fdf2f2;

  /* Elevation Shadows */
  --shadow-sm: 0 1px 3px 0 rgba(8, 46, 135, 0.06);
  --shadow-md: 0 4px 10px -1px rgba(8, 46, 135, 0.1), 0 2px 4px -2px rgba(8, 46, 135, 0.05);
  --shadow-lg: 0 12px 24px -4px rgba(8, 46, 135, 0.12), 0 4px 8px -3px rgba(8, 46, 135, 0.06);
  --shadow-canvas: 0 16px 36px -6px rgba(8, 46, 135, 0.28), 0 4px 12px rgba(0, 0, 0, 0.12);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* --- Global Reset & Box Sizing --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-primary);
  background-color: var(--color-bg);
  color: var(--color-text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Accessibility: Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Utility Hidden */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Main Application Layout
   ========================================================================== */
.app-main {
  flex: 1;
  padding: 24px 20px 48px;
}

.app-container {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 36px;
  align-items: start;
}

/* ==========================================================================
   Controls Panel
   ========================================================================== */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.control-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.control-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-poster-navy) 0%, var(--color-poster-blue-light) 100%);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(8, 46, 135, 0.25);
}

.step-title-group {
  flex: 1;
  display: flex;
  align-items: center;
}

.step-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-poster-navy);
  line-height: 1.2;
}

.step-title-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* --- Step 1: Dropzone --- */
.dropzone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: 26px 16px;
  text-align: center;
  background: var(--color-surface-hover);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.dropzone:hover, .dropzone:focus-within {
  border-color: var(--color-poster-navy);
  background: #f0f4fb;
}

.dropzone.dragover {
  border-color: var(--color-poster-green);
  background: var(--color-poster-green-bg);
  transform: scale(1.01);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone-icon {
  color: var(--color-poster-navy);
  margin-bottom: 8px;
  display: flex;
  justify-content: center;
}

.dropzone-main-text {
  font-size: 0.92rem;
  color: var(--color-text-main);
  margin-bottom: 4px;
}

.dropzone-main-text strong {
  color: var(--color-poster-navy);
}

.dropzone-desktop-icon {
  display: block;
}

.dropzone-mobile-icon {
  display: none;
}

.dropzone-desktop-text {
  display: inline;
}

.dropzone-mobile-text {
  display: none;
}

.dropzone-sub-text {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* --- Photo Info Bar --- */
.photo-info-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.photo-thumb-wrap {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 2px solid var(--color-poster-navy);
  flex-shrink: 0;
  background: #e2e8f0;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.photo-name {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.photo-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* --- Photo Adjust & Zoom Controls --- */
.photo-adjust-box {
  margin-top: 12px;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.adjust-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.adjust-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-poster-navy);
}

.zoom-level-badge {
  background: rgba(8, 46, 135, 0.1);
  color: var(--color-poster-navy);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  min-width: 44px;
  text-align: center;
}

.zoom-control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-zoom-step {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid var(--color-border);
  color: var(--color-poster-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.btn-zoom-step:hover {
  background: #eff4fc;
  border-color: var(--color-poster-navy);
  color: var(--color-poster-blue-light);
  transform: scale(1.05);
}

.btn-zoom-step:active {
  transform: scale(0.95);
}

.slider-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
}

.zoom-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #dbe4f2;
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.zoom-slider:hover {
  background: #cbd5e1;
}

/* Chrome / Safari / Edge Range Thumb */
.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-poster-navy) 0%, var(--color-poster-blue-light) 100%);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(8, 46, 135, 0.3);
  cursor: grab;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.zoom-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(8, 46, 135, 0.2);
}

/* Firefox Range Thumb */
.zoom-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-poster-navy) 0%, var(--color-poster-blue-light) 100%);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(8, 46, 135, 0.3);
  cursor: grab;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.zoom-slider::-moz-range-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(8, 46, 135, 0.2);
}

.adjust-hint {
  font-size: 0.74rem;
  color: var(--color-text-muted);
  line-height: 1.35;
}

/* --- Step 2: Name Input --- */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.text-input {
  width: 100%;
  padding: 12px 38px 12px 14px;
  font-family: var(--font-gujarati);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-poster-navy);
  background: #ffffff;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.text-input:focus {
  border-color: var(--color-poster-navy);
  box-shadow: 0 0 0 3px rgba(8, 46, 135, 0.15);
}

.input-clear-btn {
  position: absolute;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: #e2e8f0;
  color: var(--color-text-muted);
  border: none;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.input-clear-btn:hover {
  background: #cbd5e1;
  color: var(--color-text-main);
}

/* --- Action Container --- */
.action-card {
  width: 100%;
  box-sizing: border-box;
  padding: 0;
  background: transparent;
  border: none;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-primary);
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all var(--transition-normal);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-poster-navy) 0%, var(--color-poster-blue-light) 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(8, 46, 135, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--color-poster-blue-light) 0%, var(--color-poster-navy) 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(8, 46, 135, 0.45);
}

.btn-primary:hover:not(:disabled) .btn-icon {
  color: var(--color-poster-gold);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.7;
}

.btn-download {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  gap: 10px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 2px 8px;
  font-size: 0.73rem;
  border-radius: var(--radius-sm);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-border-hover);
  color: var(--color-poster-navy);
}

.btn-outline:hover {
  background: #eff4fc;
  border-color: var(--color-poster-navy);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  color: var(--color-error);
  background: var(--color-error-bg);
}

/* --- Error Alert --- */
.error-msg {
  background: var(--color-error-bg);
  border: 1px solid rgba(173, 32, 24, 0.3);
  color: var(--color-poster-red);
  font-size: 0.82rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
}

/* ==========================================================================
   Preview Panel & Canvas
   ========================================================================== */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 20px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-poster-navy);
}

.preview-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-poster-navy);
  background: rgba(8, 46, 135, 0.08);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: var(--color-poster-green);
  border-radius: var(--radius-full);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

.canvas-wrapper {
  background: linear-gradient(145deg, #07193f 0%, #04102b 100%);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-canvas);
  border: 1px solid rgba(8, 46, 135, 0.35);
  display: flex;
  justify-content: center;
  align-items: center;
}

.canvas-inner {
  position: relative;
  width: 100%;
  max-width: 580px;
  /* Poster aspect ratio: 1638 / 2048 = 0.8 */
  aspect-ratio: 1638 / 2048;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius-lg) - 4px);
  overflow: hidden;
  background: #04102b;
}

#posterCanvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1638 / 2048;
  display: block;
  object-fit: contain;
  border-radius: calc(var(--radius-lg) - 4px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: high-quality;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Loading Overlay */
.canvas-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 16, 43, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #ffffff;
  z-index: 10;
  transition: opacity var(--transition-normal);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-poster-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: #e2e8f0;
}

/* ==========================================================================
   Bottom Credit Strip (Fixed / Constant)
   ========================================================================== */
.app-credit-strip {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  padding: 8px 20px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--color-border);
  text-align: center;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(8, 46, 135, 0.04);
}

.credit-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.credit-text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.credit-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.credit-logo {
  height: 20px;
  width: auto;
  max-width: 80px;
  object-fit: contain;
  display: block;
}

.credit-company {
  font-size: 0.82rem;
  color: var(--color-poster-navy);
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Mobile-Only Responsive Overrides (767px and below)
   ========================================================================== */
@media (max-width: 767px) {
  .app-main {
    padding: 10px 12px 42px;
    width: 100%;
    box-sizing: border-box;
  }

  .app-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    gap: 10px;
    margin: 0;
  }

  /* Unroll panels into the main flex flow for exact component ordering */
  .controls-panel, 
  .preview-panel {
    display: contents;
  }

  /* --- Mobile Component Flow Ordering & Full Width Alignment --- */
  #step-photo {
    order: 1;
    width: 100%;
    box-sizing: border-box;
  }

  #step-name {
    order: 2;
    width: 100%;
    box-sizing: border-box;
  }

  .preview-header {
    order: 3;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0;
  }

  .canvas-wrapper {
    order: 4;
    width: 100%;
    box-sizing: border-box;
    padding: 6px;
    border-radius: var(--radius-md);
    max-width: 100%;
    box-shadow: 0 8px 24px -4px rgba(8, 46, 135, 0.22);
  }

  #photoAdjustBox {
    order: 5;
    width: 100%;
    box-sizing: border-box;
    margin-top: 10px;
    padding: 12px 14px;
  }

  #actionCard {
    order: 6;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  /* --- Compact Card & Input Styling --- */
  .control-card {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border-radius: var(--radius-md);
  }

  .input-group {
    width: 100%;
    box-sizing: border-box;
  }

  .card-header {
    margin-bottom: 8px;
    gap: 8px;
  }

  .step-num {
    width: 22px;
    height: 22px;
    font-size: 0.75rem;
  }

  .step-title {
    font-size: 0.92rem;
  }

  /* Compact Button-Style Upload on Mobile */
  .dropzone {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 16px;
    background: #ffffff;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(8, 46, 135, 0.05);
  }

  .dropzone:hover, .dropzone:active {
    border-color: var(--color-poster-navy);
    background: #f0f4fb;
  }

  .dropzone-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .dropzone-icon {
    margin-bottom: 0;
    color: var(--color-poster-navy);
    display: inline-flex;
    align-items: center;
  }

  .dropzone-desktop-icon {
    display: none;
  }

  .dropzone-mobile-icon {
    display: inline-block;
    color: var(--color-poster-navy);
  }

  .dropzone-main-text {
    margin-bottom: 0;
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--color-poster-navy);
  }

  .dropzone-desktop-text {
    display: none;
  }

  .dropzone-mobile-text {
    display: inline;
  }

  .dropzone-sub-text {
    display: none;
  }

  .photo-info-bar {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    gap: 8px;
  }

  .photo-thumb-wrap {
    width: 36px;
    height: 36px;
  }

  .photo-name {
    font-size: 0.86rem;
  }

  /* Compact Name Input */
  .text-input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 34px 9px 12px;
    font-size: 0.96rem;
  }

  /* Preview Header & Canvas */
  .preview-panel {
    position: static;
    width: 100%;
  }

  .preview-title {
    font-size: 1.02rem;
  }

  .live-indicator {
    display: none;
  }

  .canvas-inner {
    width: 100%;
    max-width: 100%;
    border-radius: calc(var(--radius-md) - 2px);
  }

  #posterCanvas {
    width: 100%;
    height: auto;
    border-radius: calc(var(--radius-md) - 2px);
  }

  /* Strong Full-Width Download CTA */
  .btn-download {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 18px;
    font-size: 1.02rem;
    border-radius: var(--radius-md);
  }

  /* Slim Credit Strip Mobile */
  .app-credit-strip {
    padding: 6px 12px;
  }

  .credit-text,
  .credit-company {
    font-size: 0.76rem;
  }

  .credit-logo {
    height: 17px;
  }
}
