/* ===============================
   ROOT & DESIGN TOKENS
================================ */
:root {
  --primary: #c9963a;
  --primary-dark: #a37a2a;
  --primary-light: #e8b85a;
  --primary-glow: rgba(201,150,58,0.35);

  --gold-gradient: linear-gradient(135deg, #c9963a 0%, #f0c060 50%, #c9963a 100%);
  --dark-bg: #0f0d0a;
  --card-bg: rgba(20,17,12,0.85);
  --card-border: rgba(201,150,58,0.2);
  --surface: rgba(30,25,15,0.9);

  --text-primary: #f5ecd6;
  --text-secondary: #c9b07a;
  --text-muted: #8a7050;

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --shadow-glow: 0 0 40px rgba(201,150,58,0.15), 0 8px 32px rgba(0,0,0,0.6);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.5);

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

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans Sinhala', sans-serif;
  background: var(--dark-bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===============================
   BACKGROUND PARTICLES
================================ */
.bg-particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  background: var(--primary-glow);
  animation: floatParticle 12s infinite ease-in-out;
}

.particle:nth-child(1) { width: 300px; height: 300px; top: -100px; left: -100px; animation-delay: 0s; opacity: 0.4; }
.particle:nth-child(2) { width: 200px; height: 200px; top: 40%; right: -80px; animation-delay: -4s; opacity: 0.3; }
.particle:nth-child(3) { width: 150px; height: 150px; bottom: 10%; left: 20%; animation-delay: -8s; opacity: 0.25; }
.particle:nth-child(4) { width: 100px; height: 100px; top: 60%; left: 60%; animation-delay: -2s; opacity: 0.2; }
.particle:nth-child(5) { width: 250px; height: 250px; bottom: -80px; right: 20%; animation-delay: -6s; opacity: 0.35; }

@keyframes floatParticle {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.08); }
}

/* ===============================
   APP WRAPPER
================================ */
.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ===============================
   HEADER
================================ */
.app-header {
  padding: 32px 0 24px;
  text-align: center;
}

.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  font-size: 3rem;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(201,150,58,0.6));
  animation: spinSlow 20s linear infinite;
}

@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.logo-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.logo-title {
  font-family: 'Noto Serif Sinhala', serif;
  font-size: 2.2rem;
  font-weight: 700;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  letter-spacing: -0.5px;
}

.logo-sub {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.header-tagline {
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 1rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ===============================
   MAIN LAYOUT
================================ */
.main-content {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 28px;
  align-items: start;
  margin-top: 8px;
}

/* ===============================
   PANELS
================================ */
.controls-panel,
.preview-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-glow);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-light);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--card-border);
  letter-spacing: 0.3px;
}

.panel-icon { font-size: 1.2rem; }

/* ===============================
   CONTROL GROUPS
================================ */
.control-group {
  margin-bottom: 24px;
}

.control-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--gold-gradient);
  color: #1a1200;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  flex-shrink: 0;
}

/* ===============================
   UPLOAD ZONE
================================ */
.upload-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
  position: relative;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(201,150,58,0.04);
}

.upload-zone:hover {
  border-color: var(--primary);
  background: rgba(201,150,58,0.08);
  box-shadow: 0 0 20px rgba(201,150,58,0.1);
}

.upload-zone.drag-over {
  border-color: var(--primary-light);
  background: rgba(201,150,58,0.12);
  transform: scale(1.01);
}

.upload-content {
  text-align: center;
  padding: 24px;
}

.upload-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.7; }
.upload-title {
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.upload-sub { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }
.upload-hint { font-size: 0.72rem; color: var(--text-muted); opacity: 0.7; }

.upload-preview {
  width: 100%;
  position: relative;
}

.upload-preview img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.change-image-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0,0,0,0.75);
  color: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(8px);
}
.change-image-btn:hover { background: rgba(201,150,58,0.2); }

/* ===============================
   SELECT
================================ */
.select-wrapper {
  position: relative;
}

.verse-select {
  width: 100%;
  padding: 14px 44px 14px 16px;
  background: rgba(201,150,58,0.06);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 0.88rem;
  appearance: none;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.verse-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(201,150,58,0.15);
}

.verse-select optgroup {
  background: #1a1500;
  color: var(--primary-light);
  font-weight: 700;
}

.verse-select option {
  background: #1a1500;
  color: var(--text-primary);
  padding: 8px;
}

.select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--primary);
  pointer-events: none;
  font-size: 1rem;
}

/* ===============================
   BUTTONS
================================ */
.generate-btn, .download-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.generate-btn {
  background: var(--gold-gradient);
  color: #1a1200;
  box-shadow: 0 4px 20px rgba(201,150,58,0.4);
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(201,150,58,0.55);
}

.generate-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

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

.download-btn {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary-light);
  margin-top: 12px;
}

.download-btn:hover {
  background: rgba(201,150,58,0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(201,150,58,0.2);
}

.btn-icon { font-size: 1.1rem; }

/* ===============================
   PREVIEW PANEL
================================ */
.preview-panel { position: sticky; top: 24px; }

.preview-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-md);
  border: 1px solid rgba(201,150,58,0.08);
  overflow: hidden;
}

.preview-placeholder {
  text-align: center;
  padding: 48px 24px;
  opacity: 0.5;
}

.placeholder-icon {
  font-size: 4rem;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 20px;
  display: block;
}

.preview-placeholder p {
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.8;
}

#postCanvas {
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

/* ===============================
   BACKGROUND TAB SWITCHER
================================ */
.bg-tab-switcher {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.bg-tab {
  flex: 1;
  padding: 10px 12px;
  background: rgba(201,150,58,0.07);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.bg-tab.active {
  background: var(--gold-gradient);
  color: #1a1200;
  border-color: transparent;
}

.bg-tab:not(.active):hover {
  border-color: var(--primary);
  color: var(--primary-light);
}

/* ===============================
   AUTO BACKGROUND PANEL
================================ */
.bg-panel { }

.auto-bg-hint {
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.auto-bg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.auto-bg-grid::-webkit-scrollbar { width: 5px; }
.auto-bg-grid::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 8px; }

.auto-bg-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
  aspect-ratio: 1;
}

.auto-bg-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.auto-bg-item:hover img { transform: scale(1.06); }

.auto-bg-item .bg-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  color: #fff;
  font-size: 0.68rem;
  font-family: 'Noto Sans Sinhala', sans-serif;
  padding: 12px 6px 5px;
  text-align: center;
  font-weight: 600;
}

.auto-bg-item.selected {
  border-color: var(--primary-light);
  box-shadow: 0 0 16px rgba(201,150,58,0.55);
}

.auto-bg-item .selected-tick {
  display: none;
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  background: var(--gold-gradient);
  color: #1a1200;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}

.auto-bg-item.selected .selected-tick { display: flex; }

/* ===============================
   CAPTION SECTION
================================ */
.caption-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px dashed var(--card-border);
}

.caption-container {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
}

#postCaption {
  font-family: 'Noto Sans Sinhala', 'Inter', sans-serif;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

#postCaption::-webkit-scrollbar { width: 6px; }
#postCaption::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }

.copy-btn {
  width: 100%;
  padding: 10px;
  background: rgba(201,150,58,0.15);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--primary-light);
  font-family: 'Noto Sans Sinhala', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.copy-btn:hover {
  background: var(--primary);
  color: #1a1200;
}

.copy-btn.copied {
  background: #27ae60;
  border-color: #2ecc71;
  color: white;
}

/* ===============================
   RESPONSIVE
================================ */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  .preview-panel { position: static; }
}

@media (max-width: 600px) {
  .app-wrapper { padding: 0 16px 40px; }
  .logo-title { font-size: 1.6rem; }
  .controls-panel, .preview-panel { padding: 20px; }
}
