/* =============================================================
   STORYAT — Apple-grade UI
   Layout, components, refined interactions
   ============================================================= */

html {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--fg-primary);
  min-height: 100vh;
  font-feature-settings: "ss01", "cv01", "cv11";
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: 0;
  transition: background var(--duration-slow) var(--ease-out), color var(--duration-base) var(--ease-out);
}

[hidden] {
  display: none !important;
}

.icon-image { display: inline-block; object-fit: contain; flex-shrink: 0; }

/* Apple-style heading defaults */
h1, h2, h3, h4 {
  font-family: var(--font-sans);
  letter-spacing: 0;
  color: var(--fg-primary);
}

/* =============================================================
   HEADER
   ============================================================= */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-app) 80%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  height: 100%;
  color: var(--fg-primary);
  -webkit-tap-highlight-color: transparent;
}
.brand-logo {
  display: block;
  height: 24px;
  width: auto;
  object-fit: contain;
}

/* Show the correct logo per theme */
[data-theme="dark"] .brand-logo-light { display: none; }
[data-theme="light"] .brand-logo-dark { display: none; }

@media (max-width: 640px) {
  .brand-logo { height: 22px; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.header-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 32px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-secondary);
  border-radius: var(--radius-pill);
  transition: color var(--duration-base) var(--ease-out), background var(--duration-base) var(--ease-out);
}
.header-link:hover { color: var(--brand); background: var(--brand-soft); }

/* =============================================================
   DEVELOPER CREDIT (chip + popover)
   ============================================================= */
.developer-credit {
  position: relative;
}
.developer-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 12px 0 4px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  color: var(--fg-primary);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--duration-base) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.developer-chip:hover { background: var(--bg-input-hover); }
.developer-chip[aria-expanded="true"] { background: var(--bg-input-hover); }

.dev-avatar {
  position: relative;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0071E3, #6F1AB6);
  color: #ffffff;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700;
  font-family: var(--font-sans);
  overflow: hidden;
  flex-shrink: 0;
}
.dev-avatar.large {
  width: 48px; height: 48px;
  font-size: 20px;
}
/* Photo overlays the gradient + letter; if 404, JS removes it and fallback shows */
.dev-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  z-index: 1;
}
.dev-avatar-letter {
  position: relative;
  z-index: 0;
}

.dev-name { letter-spacing: 0; }

.dev-verified {
  display: inline-flex;
  align-items: center;
  color: var(--brand);
}
.dev-verified svg { display: block; }

/* Popover */
.developer-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 16px;
  box-shadow: var(--shadow-4);
  padding: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: pop-in var(--duration-slow) var(--ease-out-soft);
  transform-origin: top right;
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.developer-popover[hidden] { display: none; }

.dev-pop-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px 10px;
}
.dev-pop-meta { display: flex; flex-direction: column; gap: 2px; }
.dev-pop-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-primary);
  letter-spacing: 0;
}
.dev-pop-role {
  font-size: 12px;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
}
.dev-pop-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0 8px;
}

.dev-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 10px;
  color: var(--fg-primary);
  text-decoration: none;
  transition: background var(--duration-base) var(--ease-out);
}
.dev-link:hover { background: var(--accent-soft); }
.dev-link-icon {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--fg-secondary);
  flex-shrink: 0;
  box-shadow: var(--shadow-1);
}
.dev-link-icon svg { width: 20px; height: 20px; }
.dev-link-icon img { width: 20px; height: 20px; object-fit: contain; }

/* Real branded backgrounds for each platform (Apple Notification-Center style) */
.dev-link[data-brand="instagram"] .dev-link-icon {
  background: linear-gradient(45deg,
    #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  color: #ffffff;
}
.dev-link[data-brand="snapchat"] .dev-link-icon {
  background: #FFFC00;
  color: #000000;
}
.dev-link[data-brand="website"] .dev-link-icon {
  background: linear-gradient(135deg, #0071E3, #4A9FE8);
  color: #ffffff;
}
.dev-link-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.dev-link-platform {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-primary);
}
.dev-link-handle {
  font-size: 12px;
  color: var(--fg-tertiary);
  font-family: var(--font-mono);
}
.dev-link-arrow {
  color: var(--fg-tertiary);
  font-size: 14px;
  transition: transform var(--duration-base) var(--ease-out);
}
.dev-link:hover .dev-link-arrow {
  color: var(--brand);
  transform: translate(2px, -2px);
}

@media (max-width: 560px) {
  .dev-name { display: none; }
  .developer-chip { padding: 0 8px 0 4px; }
  .developer-popover { width: 260px; right: -40px; }
}

.icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: inline-grid; place-items: center;
  color: var(--fg-secondary);
  background: transparent;
  transition: color var(--duration-base) var(--ease-out), background var(--duration-base) var(--ease-out);
}
.icon-btn:hover { color: var(--fg-primary); background: var(--accent-soft); }

/* =============================================================
   APP SHELL
   ============================================================= */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

/* =============================================================
   SIDE PANEL — studio inspector redesign
   ============================================================= */
.side-panel {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg-panel) 96%, var(--brand) 4%), var(--bg-panel));
  border-right: 1px solid var(--border-subtle);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

.side-panel { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.side-panel::-webkit-scrollbar { width: 10px; }
.side-panel::-webkit-scrollbar-track { background: transparent; }
.side-panel::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-pill);
  border: 3px solid var(--bg-panel);
  background-clip: padding-box;
}
.side-panel::-webkit-scrollbar-thumb:hover { background-color: var(--fg-tertiary); background-clip: padding-box; }

.side-panel button,
.side-panel input,
.side-panel select,
.side-panel summary { touch-action: manipulation; }

/* iOS-style segmented control — unified pill */
.workflow-switcher {
  position: sticky;
  top: 14px;
  z-index: 3;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 4px;
  margin: 14px;
  padding: 3px;
  background: color-mix(in srgb, var(--bg-input) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.workflow-branch {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  min-height: 44px;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--fg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  text-align: center;
  gap: 1px;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out),
              color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}
.workflow-branch:hover:not(.is-active) {
  color: var(--fg-primary);
}
.workflow-branch:active:not(.is-active) {
  transform: scale(0.97);
}
.workflow-branch.is-active {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-2);
}
.workflow-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.workflow-sub {
  font-size: 10px;
  color: var(--fg-tertiary);
  margin-top: 1px;
  font-weight: 500;
  letter-spacing: 0;
}

.drawer {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  overflow: visible;
}
.drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 10px;
  min-height: 44px;
  user-select: none;
  font-weight: 600;
  font-size: 15px;
  color: var(--fg-primary);
}
.drawer-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--brand);
  flex-shrink: 0;
}
.drawer-icon svg { width: 16px; height: 16px; }
.drawer-title {
  flex: 1;
  letter-spacing: 0;
}
.drawer-chevron { display: none; }
.drawer-body {
  padding: 0 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: visible;
}

.drawer-empty {
  text-align: center;
  padding: var(--space-5) var(--space-3);
  color: var(--fg-tertiary);
  font-size: 12px;
}

/* =============================================================
   PANEL BLOCKS (inside drawers)
   ============================================================= */
.panel-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-block + .panel-block {
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.sub-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--fg-tertiary);
  margin-bottom: 2px;
  text-transform: uppercase;
}

/* =============================================================
   INPUTS
   ============================================================= */
/* Apple-style inputs: 8px radius, 44px touch target, blue focus ring */
.url-input,
.override-input,
.select-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0 14px;
  height: 44px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 400;
  color: var(--fg-primary);
  transition: background var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}
.url-input::placeholder,
.override-input::placeholder { color: var(--fg-tertiary); }
.url-input:hover,
.override-input:hover { background: var(--bg-input-hover); }
.url-input:focus,
.override-input:focus,
.select-input:focus {
  outline: none;
  background: var(--bg-elevated);
  border-color: var(--brand);
  box-shadow: var(--shadow-focus-ring);
}

.override-input:not(:last-child) { margin-bottom: var(--space-2); }

.select-wrap { position: relative; }
.select-input {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-end: 36px;
  cursor: pointer;
}
.select-chevron {
  position: absolute;
  inset-inline-end: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--fg-tertiary);
  font-size: 11px;
}

/* =============================================================
   BUTTONS
   ============================================================= */
/* Apple-style buttons: pill shape, 44px touch target, brand blue */
.btn-primary {
  background: var(--brand);
  color: var(--brand-fg);
  padding: 0 22px;
  height: 44px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: background var(--duration-base) var(--ease-out),
              opacity var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) {
  background: var(--brand-active);
  transform: translateY(0);
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Secondary — outlined Apple blue */
.btn-secondary {
  background: transparent;
  color: var(--brand);
  padding: 0 22px;
  height: 44px;
  border: 1.5px solid var(--brand);
  border-radius: 8px;
  font-weight: 500;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: background var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out),
              opacity var(--duration-base) var(--ease-out);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--brand-soft);
  border-color: var(--brand-hover);
}
.btn-secondary:active:not(:disabled) { border-color: var(--brand-active); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Ghost — neutral subdued (Apple-style flat) */
.btn-ghost {
  background: transparent;
  color: var(--fg-primary);
  padding: 0 16px;
  height: 44px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: background var(--duration-base) var(--ease-out), opacity var(--duration-base) var(--ease-out);
}
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }
.btn-ghost:active:not(:disabled) { background: var(--accent-hover); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-icon { display: inline-flex; width: 14px; height: 14px; }
.btn-icon svg { width: 100%; height: 100%; }

.btn-spinner {
  width: 12px; height: 12px;
  border: 2px solid color-mix(in srgb, var(--brand-fg) 30%, transparent);
  border-top-color: var(--brand-fg);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-message {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-top: var(--space-2);
}

/* =============================================================
   MODE TOGGLE (Link / Custom)
   ============================================================= */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-input);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  margin-bottom: var(--space-3);
}
.mode-btn {
  padding: 0 var(--space-3);
  height: 32px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-secondary);
  transition: all var(--duration-base) var(--ease-out);
}
.mode-btn.is-active {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-1);
  font-weight: 600;
}

/* =============================================================
   TOGGLE GROUP (3-button segmented)
   ============================================================= */
.toggle-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-input);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.toggle-btn {
  padding: 0;
  height: 32px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg-secondary);
  transition: all var(--duration-base) var(--ease-out);
}
.toggle-btn.is-active {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-1);
}

/* =============================================================
   TEMPLATE LIST
   ============================================================= */
.template-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.template-card {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: start;
  transition: all var(--duration-base) var(--ease-out);
}
.template-card:hover:not(.is-disabled) {
  background: var(--bg-input-hover);
  border-color: var(--border-default);
}
.template-card.is-active {
  background: var(--brand-soft);
  border-color: var(--brand);
}
.template-card.is-active .template-name { color: var(--brand); }
.template-name { font-weight: 600; font-size: 13px; color: var(--fg-primary); }
.template-meta { font-size: 11px; color: var(--fg-tertiary); letter-spacing: 0; }
.template-card.is-disabled { opacity: 0.3; pointer-events: none; }

/* =============================================================
   PLATFORM PICKER
   ============================================================= */
.platform-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.platform-cell {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  color: var(--fg-secondary);
  transition: all var(--duration-base) var(--ease-out);
}
.platform-cell svg { width: 50%; height: 50%; }
.platform-cell img { width: 50%; height: 50%; object-fit: contain; }
.platform-cell:hover {
  background: var(--bg-input-hover);
  color: var(--fg-primary);
  border-color: var(--border-default);
}
.platform-cell.is-active {
  background: var(--brand-soft);
  border-color: var(--brand);
}

/* =============================================================
   PALETTE SWATCHES
   ============================================================= */
.palette-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.palette-swatch {
  aspect-ratio: 1;
  min-height: 42px;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0;
  position: relative;
  overflow: hidden;
  transition: transform var(--duration-fast) var(--ease-out), border-color var(--duration-base) var(--ease-out);
}
.palette-swatch:hover { border-color: var(--border-default); }
.palette-swatch.is-active { border-color: var(--fg-primary); }
.swatch-bg { position: absolute; inset: 0; border-radius: calc(var(--radius-sm) - 2px); }

/* =============================================================
   ADVANCED TOGGLE
   ============================================================= */
.advanced-toggle {
  margin-top: 2px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}
.advanced-toggle > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-secondary);
  padding: 8px var(--space-3);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: color var(--duration-base) var(--ease-out);
}
.advanced-toggle > summary::-webkit-details-marker { display: none; }
.advanced-toggle > summary::after {
  content: "▾";
  color: var(--fg-tertiary);
  transition: transform var(--duration-base) var(--ease-out);
}
.advanced-toggle:hover > summary { color: var(--fg-primary); }
.advanced-toggle[open] > summary::after { transform: rotate(180deg); }
.advanced-fields {
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
}
.field-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-tertiary);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  margin-top: var(--space-2);
}

/* =============================================================
   COLOR PICKERS / GRADIENT
   ============================================================= */
.gradient-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
}
.color-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  background: var(--bg-elevated);
  padding: 6px;
  border-radius: var(--radius-xs);
}
.color-input span {
  font-size: 9px;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.color-input input[type="color"] {
  width: 28px; height: 28px;
  border: none; border-radius: var(--radius-xs);
  cursor: pointer; padding: 0; background: none;
}
.color-input input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input input[type="color"]::-webkit-color-swatch { border: none; border-radius: var(--radius-xs); }
.color-input input[type="number"] {
  width: 44px; text-align: center;
  background: transparent;
  font-size: 11px; font-weight: 600;
  color: var(--fg-primary);
}

.checkbox-row {
  display: flex; align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--fg-secondary);
  padding: var(--space-2);
  cursor: pointer;
}
.checkbox-row input { accent-color: var(--fg-primary); }

/* =============================================================
   UPLOAD AREA / BUTTON
   ============================================================= */
.upload-area {
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1.5px dashed var(--border-strong);
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  background-size: cover;
  background-position: center;
  transition: all var(--duration-base) var(--ease-out);
  margin-bottom: var(--space-2);
}
.upload-area:hover {
  border-color: var(--fg-secondary);
  background-color: var(--bg-input-hover);
}
.upload-area.has-image { border-style: solid; border-color: var(--border-default); }
.upload-prompt {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px;
  color: var(--fg-tertiary);
  text-align: center;
  padding: var(--space-3);
  transition: opacity var(--duration-base) var(--ease-out);
}
.upload-area.has-image .upload-prompt {
  background: rgba(0, 0, 0, 0.55);
  color: white;
  opacity: 0;
  border-radius: var(--radius-md);
}
.upload-area.has-image:hover .upload-prompt { opacity: 1; }
.upload-icon { width: 22px; height: 22px; display: inline-flex; }
.upload-icon svg { width: 100%; height: 100%; }
.upload-text { font-size: 12px; font-weight: 600; }
.upload-hint { font-size: 10px; letter-spacing: 0.06em; }

.upload-button {
  display: block;
  text-align: center;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-secondary);
  transition: all var(--duration-base) var(--ease-out);
}
.upload-button:hover {
  background: var(--bg-input-hover);
  color: var(--fg-primary);
}

/* =============================================================
   SLIDERS
   ============================================================= */
.slider-row { display: flex; flex-direction: column; gap: 6px; }
.slider-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px;
  color: var(--fg-secondary);
  font-weight: 500;
}
.slider-value {
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-primary);
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.slider {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  height: 18px;
}
.slider::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--bg-input-hover);
  border-radius: var(--radius-pill);
}
.slider::-moz-range-track {
  height: 4px;
  background: var(--bg-input-hover);
  border-radius: var(--radius-pill);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  background: var(--fg-primary);
  border-radius: 50%;
  margin-top: -6px;
  border: 2px solid var(--bg-elevated);
  box-shadow: var(--shadow-2);
  transition: transform var(--duration-fast) var(--ease-out);
}
.slider::-moz-range-thumb {
  width: 16px; height: 16px;
  background: var(--fg-primary);
  border-radius: 50%;
  border: 2px solid var(--bg-elevated);
  box-shadow: var(--shadow-2);
}
.slider:hover::-webkit-slider-thumb { transform: scale(1.15); }

/* =============================================================
   EXPORT SECTION
   ============================================================= */
.export-section {
  margin: 0;
  padding: 18px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.resolution-list { display: flex; flex-direction: column; gap: 6px; }
.radio-row {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  min-height: 42px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--fg-secondary);
  transition: background var(--duration-base) var(--ease-out), color var(--duration-base) var(--ease-out);
}
.radio-row:hover { background: var(--accent-soft); color: var(--fg-primary); }
.radio-row em { color: var(--fg-tertiary); font-style: normal; font-size: 11px; letter-spacing: 0; }
.radio-row input { accent-color: var(--brand); }
.radio-row:has(input:checked) { color: var(--fg-primary); font-weight: 500; background: var(--brand-soft); }

.export-buttons { display: grid; grid-template-columns: 2fr 1fr; gap: var(--space-2); }

/* =============================================================
   CANVAS AREA + STAGE + PHONE FRAME
   ============================================================= */
.canvas-area {
  background: var(--bg-stage);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-7);
  min-height: 100%;
  overflow: hidden;
  position: relative;
}
.canvas-area::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 30% 10%, color-mix(in srgb, var(--brand) 8%, transparent), transparent),
    radial-gradient(ellipse 50% 40% at 70% 90%, color-mix(in srgb, var(--info) 6%, transparent), transparent);
  pointer-events: none;
  z-index: 0;
}

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

/* Clean elevated story canvas — no frame, just the story */
.story-canvas {
  position: relative;
  width: clamp(260px, 42vh, 400px);
  aspect-ratio: 9 / 16;
  background: #1a1a22;
  border-radius: 20px;
  overflow: hidden;
  container-type: inline-size;
  box-shadow: var(--shadow-4);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: transform var(--duration-slower) var(--ease-out-soft),
              box-shadow var(--duration-slower) var(--ease-out-soft);
}
.story-canvas:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-5);
}

.stage-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  color: var(--fg-tertiary);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.stage-meta-dot { color: var(--fg-quaternary); }

/* Empty state */
.empty-state {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--fg-tertiary);
  text-align: center;
  padding: var(--space-6);
  background: radial-gradient(ellipse at center, var(--accent-soft) 0%, transparent 70%);
}
.empty-mark {
  color: var(--fg-quaternary);
  animation: float 4s ease-in-out infinite;
}
.empty-title { font-size: 14px; font-weight: 600; color: var(--fg-secondary); margin-top: var(--space-3); }
.empty-sub { font-size: 12px; color: var(--fg-tertiary); }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* Project entry animation */
@keyframes story-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
body[data-has-project="true"] .story-canvas .tmpl-root {
  animation: story-enter var(--duration-slower) var(--ease-out-soft) both;
}

/* =============================================================
   AUTO-SHOW POLISH SECTIONS WHEN PROJECT LOADED
   ============================================================= */
body[data-has-project="true"] #textOverridesPanel,
body[data-has-project="true"] #backgroundReplaceBlock,
body[data-has-project="true"] .effects-panel { display: flex !important; }
body[data-has-project="true"] #polishEmpty { display: none; }

/* =============================================================
   FOCUS ACCESSIBILITY
   ============================================================= */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus-ring);
  border-radius: var(--radius-sm);
}

/* =============================================================
   RESPONSIVE — Tablet
   ============================================================= */
@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .side-panel {
    height: auto;
    max-height: none;
    overflow-y: visible;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .canvas-area {
    padding: var(--space-5);
    min-height: 60vh;
  }
}

/* =============================================================
   RESPONSIVE — Mobile (Apple-style compact UI)
   Token overrides + tight spacing + smaller type
   ============================================================= */
@media (max-width: 640px) {
  :root {
    --header-h: 44px;
  }

  body {
    font-size: 14px;
    line-height: 1.45;
  }

  /* ---------- HEADER ---------- */
  .app-header {
    padding: 0 14px;
    height: 44px;
  }
  .brand-name { font-size: 12px; letter-spacing: 0.08em; }
  .brand-mark svg { width: 18px; height: 18px; }

  .header-actions { gap: 6px; }
  .header-link {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }
  .icon-btn { width: 30px; height: 30px; }

  .developer-chip {
    height: 30px;
    padding: 0 8px 0 3px;
    font-size: 12px;
  }
  .dev-avatar { width: 22px; height: 22px; font-size: 10px; }
  .dev-name { display: none; }
  .developer-popover {
    width: calc(100vw - 24px);
    max-width: 320px;
    right: -8px;
    padding: 12px;
    border-radius: 14px;
  }
  .dev-pop-head { padding: 4px 2px 8px; gap: 10px; }
  .dev-avatar.large { width: 42px; height: 42px; font-size: 17px; }
  .dev-pop-name { font-size: 14px; }
  .dev-pop-role { font-size: 11px; }
  .dev-link { padding: 8px 6px; gap: 10px; }
  .dev-link-icon { width: 32px; height: 32px; }
  .dev-link-icon svg, .dev-link-icon img { width: 18px; height: 18px; }
  .dev-link-platform { font-size: 12px; }
  .dev-link-handle { font-size: 11px; }

  /* ---------- APP SHELL ---------- */
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* ---------- SIDE PANEL ---------- */
  .side-panel {
    padding: 0;
    border-bottom: 1px solid var(--border-subtle);
  }

  /* ---------- WORKFLOW SWITCHER (compact segmented) ---------- */
  .workflow-switcher {
    margin: 12px;
    padding: 3px;
    gap: 4px;
    top: 12px;
  }
  .workflow-branch {
    min-height: 40px;
    padding: 5px 8px;
    border-radius: 8px;
  }
  .workflow-title { font-size: 12px; }
  .workflow-sub { font-size: 9px; margin-top: 0; }

  /* ---------- DRAWERS ---------- */
  .drawer-head {
    padding: 12px 14px 8px;
    min-height: 36px;
    font-size: 14px;
    gap: 8px;
  }
  .drawer-icon { width: 24px; height: 24px; border-radius: 7px; }
  .drawer-icon svg { width: 14px; height: 14px; }
  .drawer-body {
    padding: 0 14px 14px;
    gap: 12px;
  }
  .drawer-empty {
    padding: 14px 10px;
    font-size: 11px;
  }

  /* ---------- PANEL BLOCKS ---------- */
  .panel-block { gap: 8px; }
  .panel-block + .panel-block {
    padding-top: 12px;
  }
  .sub-title {
    font-size: 10px;
    letter-spacing: 0.06em;
    margin-bottom: 0;
  }

  /* ---------- INPUTS ---------- */
  .url-input,
  .override-input,
  .select-input {
    height: 42px;
    padding: 0 12px;
    font-size: 14px;
    border-radius: 10px;
  }
  .select-input { padding-inline-end: 32px; }
  .select-chevron { inset-inline-end: 10px; font-size: 10px; }

  /* ---------- BUTTONS ---------- */
  .btn-primary {
    height: 42px;
    padding: 0 16px;
    font-size: 14px;
    border-radius: 10px;
    font-weight: 600;
  }
  .btn-secondary {
    height: 42px;
    padding: 0 16px;
    font-size: 14px;
    border-radius: 10px;
  }
  .btn-ghost {
    height: 42px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 10px;
  }
  .btn-icon { width: 13px; height: 13px; }

  /* ---------- MODE / TOGGLE GROUPS ---------- */
  .mode-toggle,
  .toggle-group {
    border-radius: 10px;
    padding: 2px;
    gap: 2px;
  }
  .mode-btn,
  .toggle-btn {
    height: 30px;
    font-size: 12px;
    border-radius: 8px;
  }

  /* ---------- TEMPLATE LIST ---------- */
  .template-list {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .template-card {
    padding: 8px 10px;
    border-radius: 10px;
    min-height: 44px;
    gap: 1px;
  }
  .template-name { font-size: 12px; font-weight: 600; }
  .template-meta { font-size: 10px; }

  /* ---------- PLATFORM PICKER ---------- */
  .platform-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }
  .platform-cell {
    min-height: 38px;
    border-radius: 10px;
  }
  .platform-cell svg,
  .platform-cell img { width: 55%; height: 55%; }

  /* ---------- PALETTE ---------- */
  .palette-list { gap: 6px; }
  .palette-swatch {
    min-height: 36px;
    border-radius: 10px;
    border-width: 2px;
  }

  /* ---------- ADVANCED TOGGLE ---------- */
  .advanced-toggle {
    border-radius: 10px;
  }
  .advanced-toggle > summary {
    padding: 8px 12px;
    font-size: 12px;
  }
  .advanced-fields {
    padding: 0 12px 10px;
    gap: 8px;
  }
  .field-label {
    font-size: 9px;
    margin-top: 4px;
  }

  /* ---------- GRADIENT PICKERS ---------- */
  .gradient-pickers { gap: 6px; }
  .color-input { padding: 5px; }
  .color-input input[type="color"] { width: 24px; height: 24px; }
  .color-input input[type="number"] { width: 36px; font-size: 10px; }
  .color-input span { font-size: 8px; }

  /* ---------- UPLOAD AREA ---------- */
  .upload-area {
    border-radius: 10px;
  }
  .upload-prompt { gap: 4px; padding: 10px; }
  .upload-icon { width: 18px; height: 18px; }
  .upload-text { font-size: 11px; }
  .upload-hint { font-size: 9px; }

  .upload-button {
    padding: 9px;
    font-size: 11px;
    border-radius: 10px;
  }

  /* ---------- SLIDERS ---------- */
  .slider-row { gap: 4px; }
  .slider-label { font-size: 10px; }
  .slider-value { font-size: 9px; padding: 2px 5px; border-radius: 5px; }
  .slider { height: 16px; }
  .slider::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -5px; }
  .slider::-moz-range-thumb { width: 14px; height: 14px; }

  /* ---------- EXPORT ---------- */
  .export-section {
    padding: 14px;
    gap: 10px;
  }
  .resolution-list { gap: 3px; }
  .radio-row {
    min-height: 38px;
    padding: 0 10px;
    font-size: 13px;
    border-radius: 10px;
    gap: 8px;
  }
  .radio-row em { font-size: 10px; }
  .export-buttons { gap: 6px; }

  /* ---------- CANVAS / STAGE ---------- */
  .canvas-area {
    padding: 16px 12px 24px;
    min-height: 50vh;
  }
  .stage { gap: 12px; }
  .story-canvas {
    width: clamp(220px, 78vw, 340px);
    border-radius: 16px;
  }
  .stage-meta {
    font-size: 10px;
    letter-spacing: 0.06em;
    gap: 6px;
  }
  .empty-title { font-size: 13px; margin-top: 10px; }
  .empty-sub { font-size: 11px; }

  /* ---------- ERROR MESSAGE ---------- */
  .error-message {
    padding: 10px;
    font-size: 11px;
    border-radius: 10px;
  }

  /* ---------- CHECKBOX ROW ---------- */
  .checkbox-row {
    font-size: 11px;
    padding: 6px;
    gap: 6px;
  }
}

/* =============================================================
   RESPONSIVE — Very small phones (iPhone SE, etc.)
   ============================================================= */
@media (max-width: 380px) {
  .app-header { padding: 0 10px; }
  .workflow-switcher { margin: 10px; padding: 3px; }
  .workflow-branch { min-height: 38px; padding: 4px 6px; }
  .drawer-head { padding: 10px 12px 6px; }
  .drawer-body { padding: 0 12px 12px; }
  .export-section { padding: 12px; }
  .canvas-area { padding: 12px 10px 20px; }
  .story-canvas { width: clamp(200px, 82vw, 300px); }
  .platform-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* =============================================================
   MOBILE — Native app layout (sticky canvas + bottom tab bar)
   ============================================================= */
@media (max-width: 640px) {
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--header-h));
  }

  /* Canvas: pinned at top, always visible */
  .canvas-area {
    order: -1;
    position: sticky;
    top: var(--header-h);
    z-index: 5;
    height: 42vh;
    min-height: 0;
    padding: 14px 12px;
    background: var(--bg-app);
    border-bottom: 1px solid var(--border-subtle);
  }
  .canvas-area .stage { height: 100%; justify-content: center; gap: 8px; }
  .story-canvas {
    width: auto;
    max-height: 100%;
    height: 100%;
    aspect-ratio: 9 / 16;
  }
  .stage-meta { display: none; }

  /* Side panel: scrollable content below canvas */
  .side-panel {
    order: 1;
    padding: 0;
    overflow: visible;
    height: auto;
    max-height: none;
    position: static;
  }

  /* Hide all tabbed sections by default */
  .side-panel > [data-mobile-tab] { display: none; }

  /* Show only the active tab's sections */
  body[data-mobile-tab="source"] .side-panel > [data-mobile-tab="source"],
  body[data-mobile-tab="design"] .side-panel > [data-mobile-tab="design"],
  body[data-mobile-tab="polish"] .side-panel > [data-mobile-tab="polish"],
  body[data-mobile-tab="export"] .side-panel > [data-mobile-tab="export"],
  body[data-mobile-tab="settings"] .side-panel > [data-mobile-tab="settings"] {
    display: block;
    animation: m-tab-fade 220ms var(--ease-out) both;
  }

  /* Workflow-switcher: no sticky inside mobile tab */
  body[data-mobile-tab="source"] .workflow-switcher {
    position: static;
  }

  /* Drawer chrome is redundant in tab-based mobile UI */
  .drawer .drawer-head { display: none; }
  .drawer { border: 0; background: transparent; border-bottom: 0; }
  .drawer-body { padding: 14px; }

  /* Export section no longer needs its own border-bottom */
  .export-section { border-bottom: 0; }

  /* Bottom tab bar — iOS-style glassmorphic */
  .mobile-tab-bar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: color-mix(in srgb, var(--bg-app) 70%, transparent);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    border-top: 1px solid var(--border-subtle);
    z-index: 60;
  }
  .m-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: 0;
    color: var(--fg-tertiary);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color 180ms var(--ease-out), transform 180ms var(--ease-out);
    -webkit-tap-highlight-color: transparent;
  }
  .m-tab-icon { display: inline-flex; }
  .m-tab-icon svg { width: 22px; height: 22px; }
  .m-tab.is-active { color: var(--brand); }
  .m-tab.is-active .m-tab-icon { transform: scale(1.06); }
  .m-tab:active { transform: scale(0.96); }

  @keyframes m-tab-fade {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* Tab bar is mobile-only */
@media (min-width: 641px) {
  .mobile-tab-bar { display: none; }
}

/* =============================================================
   PREVIEW — Floating expand button + fullscreen overlay
   ============================================================= */
.preview-expand-btn {
  position: absolute;
  bottom: 14px;
  inset-inline-start: 14px;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(20, 20, 26, 0.55);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f5f5f7;
  display: inline-grid;
  place-items: center;
  z-index: 4;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform var(--duration-fast) var(--ease-out),
              background var(--duration-base) var(--ease-out),
              opacity var(--duration-base) var(--ease-out);
}
.preview-expand-btn:hover {
  background: rgba(20, 20, 26, 0.72);
  transform: scale(1.06);
}
.preview-expand-btn:active {
  transform: scale(0.94);
}
.preview-expand-btn svg { display: block; }

/* On light theme, give the chip a light-glass appearance */
[data-theme="light"] .preview-expand-btn {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.08);
  color: #1d1d1f;
}
[data-theme="light"] .preview-expand-btn:hover {
  background: rgba(255, 255, 255, 0.92);
}

/* ----- Fullscreen overlay ----- */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(36px) saturate(180%);
  -webkit-backdrop-filter: blur(36px) saturate(180%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px)
           20px
           calc(env(safe-area-inset-bottom, 0px) + 24px);
  animation: preview-overlay-in var(--duration-slow) var(--ease-out-soft);
}
.preview-overlay[hidden] { display: none; }

@keyframes preview-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.preview-overlay-stage {
  width: 100%;
  max-width: min(420px, 100%);
  aspect-ratio: 9 / 16;
  max-height: 100%;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.55), 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: preview-stage-in var(--duration-slower) var(--ease-spring);
  position: relative;
}
.preview-overlay-stage .story-canvas {
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
  transition: none;
}
.preview-overlay-stage .story-canvas:hover {
  transform: none;
  box-shadow: none;
}

@keyframes preview-stage-in {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}

.preview-close-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  inset-inline-end: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  z-index: 201;
  transition: background var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}
.preview-close-btn:hover { background: rgba(255, 255, 255, 0.24); }
.preview-close-btn:active { transform: scale(0.92); }

/* Body lock when preview open */
body.preview-open { overflow: hidden; }

@media (max-width: 640px) {
  .preview-expand-btn {
    bottom: 10px;
    inset-inline-start: 10px;
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }
  .preview-expand-btn svg { width: 16px; height: 16px; }
  .preview-overlay-stage { border-radius: 20px; }
  .preview-close-btn {
    width: 36px; height: 36px;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    inset-inline-end: 12px;
  }
}

/* =============================================================
   FORCE — Workflow switcher must always be horizontal segmented
   (placed at end of file with !important to override any cache)
   ============================================================= */
.workflow-switcher {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  width: auto !important;
  box-sizing: border-box;
}
.workflow-switcher > .workflow-branch {
  flex: 1 1 50% !important;
  flex-basis: 50% !important;
  width: 50% !important;
  max-width: 50% !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center;
}
.workflow-switcher > .workflow-branch .workflow-title,
.workflow-switcher > .workflow-branch .workflow-sub {
  display: block;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =============================================================
   LANGUAGE TOGGLE BUTTON
   ============================================================= */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--fg-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.lang-toggle:hover {
  background: var(--bg-input-hover);
  border-color: var(--border-default);
}
.lang-toggle:active { transform: scale(0.96); }

.lang-toggle-flag {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-fg);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.lang-toggle-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-primary);
  letter-spacing: 0;
}

@media (max-width: 640px) {
  .lang-toggle {
    height: 30px;
    padding: 0 10px;
    gap: 5px;
  }
  .lang-toggle-flag { width: 20px; height: 20px; font-size: 9px; }
  .lang-toggle-label { font-size: 11px; }
}

/* =============================================================
   ARABIC LANGUAGE — Thmanyah Serif Display + RTL adjustments
   Applies when body[data-lang="ar"] OR html[dir="rtl"]
   ============================================================= */
html[dir="rtl"] body,
body[data-lang="ar"] {
  font-family: var(--font-arabic);
  font-feature-settings: normal;
}

body[data-lang="ar"] h1,
body[data-lang="ar"] h2,
body[data-lang="ar"] h3,
body[data-lang="ar"] h4,
body[data-lang="ar"] .brand-name,
body[data-lang="ar"] .workflow-title,
body[data-lang="ar"] .workflow-sub,
body[data-lang="ar"] .drawer-title,
body[data-lang="ar"] .sub-title,
body[data-lang="ar"] .btn-primary,
body[data-lang="ar"] .btn-secondary,
body[data-lang="ar"] .btn-ghost,
body[data-lang="ar"] .mode-btn,
body[data-lang="ar"] .toggle-btn,
body[data-lang="ar"] .header-link,
body[data-lang="ar"] .lang-toggle-label,
body[data-lang="ar"] .m-tab-label,
body[data-lang="ar"] .radio-row,
body[data-lang="ar"] .field-label,
body[data-lang="ar"] .slider-label,
body[data-lang="ar"] .empty-title,
body[data-lang="ar"] .empty-sub,
body[data-lang="ar"] .upload-text,
body[data-lang="ar"] .template-name,
body[data-lang="ar"] .template-meta,
body[data-lang="ar"] .drawer-empty,
body[data-lang="ar"] .url-input,
body[data-lang="ar"] .override-input,
body[data-lang="ar"] .select-input,
body[data-lang="ar"] input::placeholder {
  font-family: var(--font-arabic);
}

/* Brand name stays Latin even in Arabic (it is the brand) */
body[data-lang="ar"] .brand-name {
  font-family: var(--font-sans);
  letter-spacing: var(--tracking-wider);
}

/* Adjust line-heights for Arabic descenders */
body[data-lang="ar"] .workflow-title,
body[data-lang="ar"] .btn-label,
body[data-lang="ar"] .drawer-title,
body[data-lang="ar"] .sub-title {
  line-height: 1.4;
}

/* Subtle weight tweak for Arabic readability */
body[data-lang="ar"] .sub-title {
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

/* RTL: mirror the developer popover origin */
html[dir="rtl"] .developer-popover {
  right: auto;
  left: 0;
  transform-origin: top left;
}

/* RTL: tab bar order — keep visual order LTR via grid (grid auto-flow) */
html[dir="rtl"] .mobile-tab-bar {
  direction: rtl;
}

/* =============================================================
   MOBILE TAB BAR — 5 columns (Source / Design / Polish / Export / Settings)
   ============================================================= */
@media (max-width: 640px) {
  .mobile-tab-bar {
    grid-template-columns: repeat(5, 1fr);
    height: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .m-tab {
    gap: 5px;
  }
  .m-tab-icon { font-size: 22px; }
  .m-tab-icon svg { width: 26px; height: 26px; }
  .m-tab-icon .fa-solid,
  .m-tab-icon .fa-brands,
  .m-tab-icon i { font-size: 22px; }
  .m-tab-label { font-size: 10px; font-weight: 600; }
  .m-tab.is-active .m-tab-icon { transform: scale(1.1); }
}

/* Settings section is mobile-only (lives inside the side-panel but only shown when tab is active) */
@media (min-width: 641px) {
  .settings-section { display: none !important; }
}

/* When Settings tab is active on mobile — hide canvas + workflow-switcher
   so the user gets a full-screen settings experience (no preview chrome). */
@media (max-width: 640px) {
  body[data-mobile-tab="settings"] .canvas-area { display: none !important; }
  body[data-mobile-tab="settings"] .workflow-switcher { display: none !important; }

  /* Also hide workflow-switcher whenever the active tab is not Source */
  body:not([data-mobile-tab="source"]) .workflow-switcher { display: none !important; }
}

/* Hide header controls on mobile (moved to Settings tab) */
@media (max-width: 640px) {
  .header-only-desktop { display: none !important; }
}

/* =============================================================
   SETTINGS SECTION — iOS-style grouped lists with proper rhythm
   ============================================================= */
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 28px 18px calc(48px + env(safe-area-inset-bottom, 0px));
  min-height: 100%;
}

/* Top page title (appears only inside Settings tab) */
.settings-section::before {
  content: "Settings";
  display: block;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--fg-primary);
  margin-bottom: 24px;
}
body[data-lang="ar"] .settings-section::before { content: "الإعدادات"; }

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 40px;
}
.settings-group:first-of-type {
  margin-top: 0;
}

.settings-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-tertiary);
  padding: 0 8px;
  margin: 0 0 8px;
}
body[data-lang="ar"] .settings-group-title {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  min-height: 60px;
}

.settings-row-label {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--fg-primary);
}

.settings-row-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  font-size: 14px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}

/* iOS-style segmented control inside settings */
.seg-control {
  display: inline-flex;
  background: var(--bg-input);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  height: 28px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--fg-secondary);
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out),
              color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}
.seg-btn.is-active {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-1);
}

/* Install card */
.settings-install-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  text-align: start;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  width: 100%;
}
.settings-install-btn:hover { background: var(--bg-input-hover); }
.settings-install-btn:active { transform: scale(0.98); }

.settings-install-icon {
  width: 42px; height: 42px;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #5b8dee);
  color: #fff;
  border-radius: 12px;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px -2px rgba(0, 113, 227, 0.35);
}
.settings-install-text { flex: 1; min-width: 0; }
.settings-install-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-primary);
  margin-bottom: 3px;
}
.settings-install-sub {
  display: block;
  font-size: 12px;
  color: var(--fg-tertiary);
  line-height: 1.4;
}
.settings-install-arrow {
  font-size: 12px;
  color: var(--fg-tertiary);
  flex-shrink: 0;
}

/* Profile / Company cards */
.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.settings-card-avatar {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0071E3, #6F1AB6);
  color: #fff;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 22px;
  flex-shrink: 0;
}
.settings-card-avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}
.settings-card-avatar-letter { position: relative; z-index: 0; }
.settings-card-avatar-company {
  background: linear-gradient(135deg, #1a1a22, #3a3a45);
  border-radius: 14px;
}

.settings-card-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.settings-card-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--fg-primary);
  letter-spacing: -0.01em;
}
.settings-verified {
  color: var(--brand);
  font-size: 14px;
}
.settings-card-role {
  font-size: 13px;
  color: var(--fg-tertiary);
}
.settings-card-desc {
  font-size: 13px;
  color: var(--fg-secondary);
  line-height: 1.55;
  margin: 0;
  padding: 0 2px;
}

/* Card link rows (social links / website) */
.settings-card-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -6px -6px;
}
.settings-link-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--fg-primary);
  transition: background var(--duration-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.settings-link-row:hover { background: var(--accent-soft); }
.settings-link-row:active { background: var(--accent-hover); }

.settings-link-icon {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--fg-primary);
  font-size: 15px;
  flex-shrink: 0;
}
.settings-link-row[data-brand="instagram"] .settings-link-icon {
  background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  color: #fff;
}
.settings-link-row[data-brand="snapchat"] .settings-link-icon {
  background: #FFFC00;
  color: #000;
}
.settings-link-row[data-brand="website"] .settings-link-icon {
  background: linear-gradient(135deg, var(--brand), #5b8dee);
  color: #fff;
}

.settings-link-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-link-platform {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-primary);
}
.settings-link-handle {
  font-size: 12px;
  color: var(--fg-tertiary);
}
.settings-link-arrow {
  font-size: 11px;
  color: var(--fg-tertiary);
  flex-shrink: 0;
}

.settings-footer {
  text-align: center;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-footer-brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--fg-secondary);
}
.settings-footer-version {
  font-size: 11px;
  color: var(--fg-tertiary);
  font-variant-numeric: tabular-nums;
}

/* =============================================================
   iOS SAFARI INSTALL BANNER — auto-shown floating top banner
   Only visible on iPhone Safari (not standalone, not other browsers)
   ============================================================= */
.ios-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  inset-inline: 10px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--border-default);
  border-radius: 14px;
  box-shadow: var(--shadow-3);
  animation: ios-banner-in 0.5s var(--ease-spring) both;
  -webkit-tap-highlight-color: transparent;
}
.ios-banner[hidden] { display: none; }

@keyframes ios-banner-in {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.ios-banner-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #5b8dee);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.ios-banner-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ios-banner-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-primary);
  line-height: 1.2;
}
.ios-banner-sub {
  font-size: 11px;
  color: var(--fg-tertiary);
  line-height: 1.3;
}
.ios-banner-cta {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-fg);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}
.ios-banner-cta:hover { background: var(--brand-hover); }
.ios-banner-cta:active { transform: scale(0.94); }

.ios-banner-close {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--fg-tertiary);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
  transition: color var(--duration-base) var(--ease-out),
              background var(--duration-base) var(--ease-out);
}
.ios-banner-close:hover {
  color: var(--fg-primary);
  background: var(--accent-soft);
}

/* Hide banner on desktop and when app is installed */
@media (min-width: 641px) {
  .ios-banner { display: none !important; }
}
body[data-pwa-installed="true"] .ios-banner { display: none !important; }

/* =============================================================
   INSTALL MODAL — iOS instructions sheet (Apple-style bottom sheet)
   ============================================================= */
.install-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: install-modal-in var(--duration-slow) var(--ease-out-soft);
}
.install-modal[hidden] { display: none; }

@keyframes install-modal-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.install-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.install-modal-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  background: var(--bg-panel);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: install-sheet-up var(--duration-slower) var(--ease-spring) both;
  text-align: center;
}

@keyframes install-sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.install-modal-handle {
  width: 38px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 999px;
  margin: 0 auto 18px;
}

.install-modal-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 0;
  color: var(--fg-primary);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--duration-base) var(--ease-out);
}
.install-modal-close:hover { background: var(--bg-input-hover); }

.install-modal-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--brand), #5b8dee);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 28px;
  margin-bottom: 14px;
  box-shadow: 0 12px 28px -8px rgba(0, 113, 227, 0.4);
}

.install-modal-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg-primary);
  margin: 0 0 6px;
}
.install-modal-sub {
  font-size: 13px;
  color: var(--fg-tertiary);
  margin: 0 0 22px;
}

.install-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: start;
}
.install-steps li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: 12px;
}
.install-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-fg);
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.install-step-body {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.install-step-text {
  font-size: 13px;
  color: var(--fg-primary);
  font-weight: 500;
}
.install-step-icon {
  color: var(--brand);
  font-size: 16px;
}

.install-android-btn {
  width: 100%;
  margin-bottom: 12px;
}

.install-modal-dismiss {
  width: 100%;
  background: transparent;
  color: var(--fg-secondary);
  border: 0;
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out);
}
.install-modal-dismiss:hover { background: var(--accent-soft); color: var(--fg-primary); }

/* =============================================================
   PWA-only — standalone display tweaks
   ============================================================= */
@media (display-mode: standalone) {
  /* Hide install card when already installed */
  body[data-pwa-installed="true"] #installAppBtn { display: none; }

  /* Pad for status bar area on iOS standalone */
  .app-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  }
}

/* Disable text selection/callout on iOS for UI chrome */
.mobile-tab-bar,
.app-header,
.settings-section,
.install-modal {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Allow selection in inputs/textareas */
input, textarea, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}
