:root {
  --primary: #c62332;
  --primary-hover: #b01c2a;
  --primary-active: #941522;
  --bg-dark: #0b0f19;
  --bg-card: #151d2e;
  --bg-card-subtle: #1c263c;
  --bg-input: #232f48;
  --border: #2e3d5b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* Light Theme Variables */
body.theme-light {
  --bg-dark: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-subtle: #f8fafc;
  --bg-input: #f1f5f9;
  --border: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 30px;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* App Container */
.mobile-app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* App Top Bar (Theme Toggle & Mode Switcher) */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 8px;
  background: transparent;
}

/* Mode Switcher Tabs */
.mode-switcher {
  display: flex;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px;
  gap: 4px;
}

.mode-tab {
  padding: 7px 14px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.mode-tab.active {
  background-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(198, 35, 50, 0.4);
}

/* Theme Toggle Button */
.btn-theme {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-theme:hover {
  background-color: var(--bg-input);
}

/* Preview Section */
.preview-section {
  width: 100%;
  background: #060911;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: relative;
}

body.theme-light .preview-section {
  background: #0f172a;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 863 / 1080; /* Changes dynamically to 810/1440 for story */
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  background: #000;
  touch-action: none; /* Prevents page scroll when interacting with canvas */
  user-select: none;
  transition: aspect-ratio 0.3s ease, max-width 0.3s ease;
}

.canvas-wrapper.mode-story {
  aspect-ratio: 810 / 1440;
  max-width: 290px;
}

#feedCanvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
}

.canvas-hint {
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  text-align: center;
}

/* Controls Section */
.controls-section {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Card Styling */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-badge {
  width: 22px;
  height: 22px;
  background-color: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
}

/* Upload Button */
.file-input {
  display: none;
}

.btn-upload {
  width: 100%;
  padding: 14px;
  background-color: var(--bg-input);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-upload:active {
  background-color: rgba(198, 35, 50, 0.15);
  border-color: var(--primary);
}

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

/* Control Row (Sliders) */
.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.control-val {
  color: var(--text-main);
  font-weight: 700;
}

.slider {
  width: 100%;
  height: 8px;
  accent-color: var(--primary);
  background-color: var(--bg-input);
  border-radius: 4px;
  cursor: pointer;
}

/* Button Group (Fit / Center) */
.btn-group {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  flex: 1;
  padding: 10px;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-secondary:active {
  background-color: var(--border);
}

/* Headline Textarea */
.headline-textarea {
  width: 100%;
  min-height: 85px;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text-main);
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 16px; /* 16px prevents iOS Safari from auto-zooming */
  line-height: 1.35;
  text-transform: uppercase;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s ease;
}

.headline-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(198, 35, 50, 0.3);
}

/* Action Card (Download & Copy) */
.action-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}

.btn-download {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, #dc2626 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(198, 35, 50, 0.4);
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn-download:active {
  transform: scale(0.98);
  background: var(--primary-active);
}

.btn-copy {
  width: 100%;
  padding: 12px;
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.btn-copy:active {
  background-color: var(--bg-input);
  color: var(--text-main);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #10b981;
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Desktop Enhancement: side-by-side on wider screens */
@media (min-width: 900px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }

  .mobile-app {
    max-width: 980px;
    flex-direction: row-reverse;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    position: relative;
  }

  .top-bar {
    position: absolute;
    top: 14px;
    left: 24px;
    z-index: 20;
    padding: 0;
  }

  .preview-section {
    flex: 1.2;
    padding: 30px;
    border-bottom: none;
    border-left: 1px solid var(--border);
    justify-content: center;
  }

  .canvas-wrapper {
    max-width: 440px;
  }

  .canvas-wrapper.mode-story {
    max-width: 330px;
  }

  .controls-section {
    flex: 1;
    padding: 70px 24px 30px;
    justify-content: center;
  }

  .card {
    background-color: var(--bg-card-subtle);
  }
}
