/* =====================================================================
   ig2 — Editor Chrome (Instagram-clean light)
   White surfaces, neutral grays, single understated accent. Tajawal is
   the only UI font. Refined, minimal, attractive.
   ===================================================================== */

/* HafsSmart — Mushaf-style Hafs Quran font. Used as the default family
   for the verse block of آية slides. font-display: block holds visible
   text invisible until the font loads — critical for export, since
   html2canvas would otherwise rasterize a fallback glyph set and the
   ornate Quran ligatures wouldn't survive. */
@font-face {
  font-family: 'HafsSmart';
  src: url('HafsSmart_08.woff') format('woff');
  font-display: block;
  font-weight: normal;
  font-style: normal;
}

:root {
  /* Surface palette — Instagram-style clarity */
  --bg-app: #fafafa;             /* page background */
  --bg-editor: #ffffff;          /* editor surfaces (cards, panels) */
  --bg-preview: #f5f5f5;         /* preview workspace */
  --bg-soft: #fbfbfb;            /* alt section background */
  --paper-line: #efefef;         /* subtle dividers */
  --paper-line-strong: #dbdbdb;  /* card borders */
  --hairline: #e8e8e8;           /* very fine lines */

  /* Ink */
  --ink: #131313;                /* primary text */
  --ink-soft: #4b4b4b;           /* secondary text */
  --ink-faint: #8e8e8e;          /* tertiary / placeholder */
  --ink-muted: #c7c7c7;           /* iconography quiet */

  /* Accent — single understated indigo, NOT gold/brown */
  --accent: #1a1a1a;             /* primary actions = black (IG-style) */
  --accent-blue: #0095f6;        /* IG-style blue for links/highlights */
  --accent-blue-soft: #e7f3ff;
  --pos: #2e7d32;                /* success */
  --neg: #ed4956;                /* danger / IG red */

  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --text-faint: var(--ink-faint);

  /* Typography — Tajawal everywhere */
  --font-base: 'Tajawal', 'Segoe UI', 'Cairo', 'Tahoma', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;

  /* Spacing */
  --r-1: 4px;  --r-2: 8px;  --r-3: 12px;
  --r-4: 16px; --r-5: 24px; --r-6: 32px; --r-7: 48px;

  /* Shapes */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-soft: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lift: 0 6px 20px rgba(0,0,0,0.08);
  --shadow-deep: 0 24px 60px rgba(0,0,0,0.16);
}

html, body {
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'liga', 'kern';
}

/* ----- Topbar -------------------------------------------------------- */
.studio-topbar {
  background: white;
  border-bottom: 1px solid var(--paper-line);
  height: 60px;
  padding: 0 var(--r-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--r-5);
  position: relative;
  z-index: 5;
}

.studio-brand { display: flex; align-items: center; gap: var(--r-3); }
.studio-brand-mark {
  width: 36px;
  height: 36px;
  background: var(--ink);
  display: grid;
  place-items: center;
  color: white;
  font-family: var(--font-base);
  font-weight: 700;
  font-size: 16px;
  border-radius: 8px;
  overflow: hidden;
}
.studio-brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: invert(1);
}
.studio-brand-text h1 {
  font-family: var(--font-base);
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
  margin: 0;
  letter-spacing: 0;
}
.studio-brand-text p {
  font-size: 12px;
  color: var(--ink-faint);
  margin: 2px 0 0;
  letter-spacing: 0;
  font-weight: 400;
}

/* ----- Buttons ------------------------------------------------------- */
.btn {
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.06s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-ghost {
  color: var(--ink-soft);
  border-color: var(--paper-line-strong);
  background: white;
}
.btn-ghost:hover {
  color: var(--ink);
  background: var(--bg-soft);
}
.btn-danger {
  color: var(--neg);
  border-color: rgba(237, 73, 86, 0.25);
  background: white;
}
.btn-danger:hover {
  background: rgba(237, 73, 86, 0.06);
  border-color: var(--neg);
}
.btn-primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.btn-primary:hover {
  background: #2a2a2a;
  border-color: #2a2a2a;
}
.btn-link {
  background: transparent;
  color: var(--accent-blue);
  border-color: transparent;
  padding: 6px 8px;
}
.btn-link:hover { color: #0070b8; background: var(--accent-blue-soft); }
.btn-icon {
  padding: 8px;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
}

/* ----- Workspace layout --------------------------------------------- */
.studio-workspace {
  display: grid;
  grid-template-columns: minmax(0, 55fr) minmax(0, 45fr);
  flex: 1;
  min-height: 0;
  background: var(--bg-app);
}
/* ----- Editor side --------------------------------------------------- */
.studio-editor {
  background: var(--bg-editor);
  color: var(--text);
  overflow-y: auto;
  border-left: 1px solid var(--paper-line);
}
.studio-editor::-webkit-scrollbar { width: 8px; }
.studio-editor::-webkit-scrollbar-track { background: transparent; }
.studio-editor::-webkit-scrollbar-thumb { background: var(--paper-line-strong); border-radius: 4px; }
.studio-editor::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

.studio-section {
  border-bottom: 1px solid var(--paper-line);
  padding: var(--r-5) var(--r-6) var(--r-5);
}
.studio-section + .studio-section { padding-top: var(--r-5); }

.studio-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  margin-bottom: var(--r-4);
}
.studio-section-head h2 {
  font-family: var(--font-base);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--r-2);
}
.studio-section-head h2 i { color: var(--ink-faint); font-size: 13px; }
.studio-section-head .badge {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  padding: 3px 8px;
  border-radius: 100px;
  border: 1px solid var(--hairline);
  font-weight: 500;
}
.studio-section-head .chev {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  transition: transform 0.2s ease;
  font-size: 11px;
}
.studio-section.collapsed .chev { transform: rotate(-90deg); }
.studio-section.collapsed .studio-section-body { display: none; }

/* ----- Inputs -------------------------------------------------------- */
.field { margin-bottom: var(--r-4); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--r-3); }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--r-3); }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  font-family: var(--font-base);
}

.input, .select, .textarea {
  width: 100%;
  background: white;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-base);
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.input[dir="ltr"], .input.mono { font-family: var(--font-mono); font-size: 13px; }

/* Color input combo */
.color-combo {
  display: flex;
  align-items: center;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-sm);
  background: white;
  overflow: hidden;
  height: 38px;
}
.color-combo:focus-within { border-color: var(--ink); }
.color-combo input[type="color"] {
  width: 36px; height: 100%;
  border: none; padding: 0;
  cursor: pointer; background: transparent;
}
.color-combo input[type="text"] {
  flex: 1; border: none; padding: 0 10px;
  font-family: var(--font-mono); font-size: 12px;
  background: transparent; outline: none; color: var(--ink);
}
.color-combo .clear-color {
  border: none; background: transparent;
  padding: 0 10px; color: var(--ink-faint);
  cursor: pointer; font-size: 11px;
  border-right: 1px solid var(--hairline);
  height: 100%;
}
.color-combo .clear-color:hover { color: var(--neg); }

/* Segmented control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-sm);
  background: white;
  overflow: hidden;
}
.segmented button {
  border: none;
  background: transparent;
  padding: 7px 12px;
  font-size: 13px;
  font-family: var(--font-base);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.segmented button + button { border-right: 1px solid var(--paper-line); }
.segmented button:hover { color: var(--ink); background: var(--bg-soft); }
.segmented button.active {
  background: var(--ink);
  color: white;
}

/* ----- Slide list cards --------------------------------------------- */
.slides-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--r-4);
}

.slide-card {
  background: white;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.slide-card:hover { border-color: var(--ink-muted); }
.slide-card.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.04);
}
.slide-card.dragging { opacity: 0.45; }

.slide-card .grip { color: var(--ink-muted); cursor: grab; }
.slide-card .grip:hover { color: var(--ink-faint); }

.slide-card .meta { min-width: 0; }
.slide-card .meta-title {
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slide-card .meta-sub {
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 2px;
  font-weight: 400;
}

.slide-card .row-controls { display: flex; gap: 4px; }
.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--paper-line);
  background: white;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-muted); background: var(--bg-soft); }
.icon-btn.danger:hover { color: var(--neg); border-color: var(--neg); background: rgba(237, 73, 86, 0.06); }

.slide-card .ord {
  font-family: var(--font-base);
  font-size: 18px;
  font-weight: 700;
  color: var(--paper-line-strong);
  line-height: 1;
}
.slide-card.active .ord { color: var(--ink); }

/* ----- Add-slide row ------------------------------------------------- */
.add-slide-row {
  display: flex;
  gap: var(--r-3);
  align-items: stretch;
  background: var(--bg-soft);
  border: 1px dashed var(--paper-line-strong);
  border-radius: var(--radius-md);
  padding: 10px;
}
.add-slide-row .select { flex: 1; }

/* ----- Editor pane (now embedded inside .sec-editor section) ---------
   Was a sticky-bottom floating panel; promoted to the FIRST section of
   the editor column. The wrapping section already has padding, so this
   container is now layout-transparent. */
.editor-pane {
  background: transparent;
  border-top: none;
  padding: 0;
}
.editor-pane.hidden { display: none; }
.editor-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--r-4);
  padding-bottom: var(--r-3);
  border-bottom: 1px dashed var(--paper-line);
}
.editor-pane-head h3 {
  font-family: var(--font-base);
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--ink-soft);
  letter-spacing: 0;
}
.editor-pane-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.editor-pane-head .type-tag {
  /* Wraps the inline SELECT */
  display: inline-flex;
  align-items: center;
}
.editor-pane-head .type-switcher {
  font-family: var(--font-base);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: white;
  padding: 5px 28px 5px 10px;
  border-radius: 100px;
  border: 1px solid var(--paper-line-strong);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  background-size: 12px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.editor-pane-head .type-switcher:hover {
  border-color: var(--ink);
  background-color: var(--bg-soft);
}

/* Per-text style controls */
.text-style-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  background: white;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.text-style-bar .select {
  font-family: var(--font-base);
  font-size: 12px;
  padding: 4px 8px;
  border-color: transparent;
  background: var(--bg-soft);
  flex: 1;
  min-width: 100px;
}
.text-style-bar .color-combo {
  height: 30px;
  width: 70px;
  flex-shrink: 0;
}
.text-style-bar .color-combo input[type="color"] { width: 28px; }
.text-style-bar .color-combo input[type="text"] { display: none; }
.text-style-bar .segmented button { padding: 5px 9px; font-size: 12px; }
.text-style-bar .size-wrap {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  background: white;
  overflow: hidden;
  height: 30px;
  flex-shrink: 0;
}
.text-style-bar .size-wrap.overridden {
  border-color: var(--ink);
  background: var(--bg-soft);
}
.text-style-bar .size-input {
  width: 56px;
  border: none;
  padding: 0 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  text-align: center;
  background: transparent;
  color: var(--ink);
  outline: none;
  height: 100%;
}
.text-style-bar .size-wrap.overridden .size-input { font-weight: 700; }
.text-style-bar .size-reset {
  border: none;
  border-right: 1px solid var(--paper-line);
  background: transparent;
  padding: 0 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-faint);
  height: 100%;
}
.text-style-bar .size-reset:hover { color: var(--ink); background: var(--bg-soft); }
/* Hide spinner buttons */
.text-style-bar .size-input::-webkit-outer-spin-button,
.text-style-bar .size-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.text-style-bar .size-input { -moz-appearance: textfield; }

/* ----- Preview side -------------------------------------------------- */
.studio-preview {
  background: var(--bg-preview);
  display: grid;
  grid-template-columns: 1fr 88px;
  grid-template-rows: auto 1fr;
  position: relative;
  overflow: hidden;
}

.preview-toolbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--paper-line);
  background: white;
  position: relative;
  z-index: 2;
}
.preview-toolbar .title {
  font-family: var(--font-base);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.preview-toolbar .pos {
  font-family: var(--font-base);
  font-size: 13px;
  color: var(--ink);
  font-weight: 700;
}
.preview-toolbar .controls { display: flex; gap: 6px; align-items: center; }
.zoom-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  min-width: 38px;
  text-align: center;
}

.preview-stage {
  display: grid;
  place-items: center;
  /* Generous breathing room around the slide frame on all sides.
     Without this the preview hugs the edge of the workspace —
     especially noticeable in square (carousel) format where the
     frame fills the full available height. */
  padding: 28px 32px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.preview-frame {
  background: white;
  position: relative;
  box-shadow: var(--shadow-deep);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--paper-line);
  /* Fill the available area while maintaining aspect ratio. The actual
     px dimensions are computed in JS based on the parent's clientSize. */
}

.preview-frame .slide-render-wrap {
  width: 1080px;
  transform-origin: top right;
  position: absolute;
  top: 0;
  right: 0;
}

/* Thumbnail strip */
.thumb-strip {
  border-right: 1px solid var(--paper-line);
  padding: 14px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: white;
  position: relative;
  z-index: 1;
}
.thumb-strip::-webkit-scrollbar { width: 4px; }
.thumb-strip::-webkit-scrollbar-thumb { background: var(--paper-line-strong); border-radius: 2px; }

.thumb {
  position: relative;
  background: white;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.thumb.active { border-color: var(--ink); }
.thumb:hover { transform: translateX(2px); }
.thumb.format-portrait { width: 64px; height: 80px; }
.thumb.format-square { width: 64px; height: 64px; }
.thumb.format-story { width: 45px; height: 80px; }
.thumb .render-wrap {
  width: 1080px;
  transform-origin: top right;
  position: absolute;
  top: 0;
  right: 0;
}
.thumb-label {
  position: absolute;
  bottom: 2px;
  left: 2px;
  background: rgba(19,19,19,0.85);
  color: white;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 2px;
}

/* ----- Hidden export container -------------------------------------- */
#export-container {
  position: absolute;
  left: -100000px;
  top: 0;
  width: 1080px;
  pointer-events: none;
}

.slide-canvas {
  width: 1080px;
  background-color: #ffffff;
  color: var(--ink);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  font-family: var(--font-base);
}
.slide-canvas.format-square { height: 1080px; }
.slide-canvas.format-portrait { height: 1350px; }
.slide-canvas.format-story { height: 1920px; }

/* ----- Loading overlay ---------------------------------------------- */
.studio-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  place-items: center;
}
.studio-overlay.shown { display: grid; }
.overlay-card {
  background: white;
  padding: 32px 40px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--paper-line);
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-deep);
}
.overlay-card h3 {
  font-family: var(--font-base);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
}
.overlay-card p {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-family: var(--font-base);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--paper-line);
  border-top-color: var(--ink);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress {
  height: 3px;
  background: var(--paper-line);
  border-radius: 2px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--ink);
  transition: width 0.3s ease;
}

/* ----- Theme cards --------------------------------------------------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.theme-card {
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-md);
  padding: 0;
  cursor: pointer;
  background: white;
  transition: border-color 0.15s ease, transform 0.1s ease;
  overflow: hidden;
}
.theme-card:hover { border-color: var(--ink-muted); }
.theme-card.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}
.theme-card .preview-thumb {
  height: 70px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--paper-line);
  position: relative;
  overflow: hidden;
}
.theme-card .preview-thumb::before,
.theme-card .preview-thumb::after {
  content: '';
  position: absolute;
}
.theme-card .info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.theme-card .name {
  font-family: var(--font-base);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.theme-card .desc {
  font-size: 10px;
  color: var(--ink-faint);
  font-weight: 400;
  margin-top: 1px;
}

/* ----- Drop zone ---------------------------------------------------- */
.dropzone {
  border: 1.5px dashed var(--paper-line-strong);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align: center;
  background: var(--bg-soft);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
  display: block;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--ink);
  background: white;
}
.dropzone .dz-title {
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  display: block;
}
.dropzone .dz-hint {
  font-family: var(--font-base);
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 4px;
  font-weight: 400;
  display: block;
}
.dropzone a {
  color: var(--accent-blue);
  text-decoration: none;
  font-weight: 500;
}
.dropzone a:hover { text-decoration: underline; }

/* ----- Logo preview -------------------------------------------------- */
.logo-uploader {
  display: flex;
  gap: 10px;
  align-items: center;
}
.logo-thumb {
  width: 42px;
  height: 42px;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-sm);
  background: white;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.logo-thumb img { max-width: 80%; max-height: 80%; object-fit: contain; }
.logo-thumb .clear {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--neg);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.bg-controls { display: grid; gap: var(--r-3); }

.hint {
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 4px;
  font-family: var(--font-base);
  font-weight: 400;
  line-height: 1.5;
}

@keyframes saved-pulse {
  0% { background: var(--pos); color: white; border-color: var(--pos); }
  100% { background: white; color: var(--ink); }
}
.btn.saved { animation: saved-pulse 1.5s ease-out; }

/* Toggle switch — CSS Grid with explicit columns guarantees label and
   track NEVER overlap. Label fills column 1 (1fr), track gets its
   natural width in column 2. In RTL, column 1 = visual right (label),
   column 2 = visual left (track). Bordered card style. */
/* Toggle row — flex layout (RTL flows right-to-left, so DOM order
   [label, input, track] visually becomes [track | input | label]
   from left to right, putting the label on the visual right where
   Arabic reading begins, and the track on the visual left). The
   hidden checkbox is absolutely-positioned out of layout so it can
   never overlap the label or track. */
.toggle-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  user-select: none;
  width: 100%;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-md);
  position: relative; /* anchor for absolutely-positioned hidden input */
  transition: border-color 0.15s ease, background 0.15s ease;
}
.toggle:hover {
  border-color: var(--ink-faint);
  background: var(--bg-soft);
}
.toggle:has(input:checked) {
  background: var(--bg-soft);
  border-color: var(--ink-faint);
}
/* Hidden checkbox — visually erased but kept in DOM for the sibling
   selector (input:checked + .track) to drive the toggle state. */
.toggle input[type="checkbox"] {
  position: absolute;
  width: 0; height: 0;
  margin: 0; padding: 0;
  opacity: 0;
  pointer-events: none;
}
.toggle .label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toggle .toggle-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}
.toggle .toggle-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-faint);
  line-height: 1.4;
}
.toggle > .label:not(:has(.toggle-title)) {
  /* Backwards compat for toggles that pass a single-line label */
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}
.toggle .track {
  flex: 0 0 44px;
  width: 44px;
  height: 24px;
  background: #cbd0d8;
  border-radius: 100px;
  position: relative;
  transition: background 0.18s ease;
}
.toggle .track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28),
              0 0 0 0.5px rgba(0, 0, 0, 0.04);
  transition: transform 0.18s ease;
}
.toggle input:checked + .track { background: var(--ink); }
.toggle input:checked + .track::after { transform: translateX(20px); }

[dir="rtl"] .slide-card .meta { text-align: right; }

/* ----- Format selector cards (replaces the dropdown) --------------- */
.format-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.format-card {
  border: 1.5px solid var(--paper-line-strong);
  background: white;
  border-radius: var(--radius-md);
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
  font-family: var(--font-base);
}
.format-card:hover { border-color: var(--ink-faint); background: var(--bg-soft); }
.format-card:active { transform: translateY(1px); }
.format-card.active {
  border-color: var(--ink);
  background: white;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.04);
}
.format-shape {
  border: 2px solid var(--ink-faint);
  border-radius: 3px;
  background: var(--bg-soft);
  margin-bottom: 4px;
  flex-shrink: 0;
}
.format-card.active .format-shape { border-color: var(--ink); background: var(--ink); }
.format-shape.portrait { width: 28px; height: 35px; }
.format-shape.square   { width: 32px; height: 32px; }
.format-shape.story    { width: 22px; height: 38px; }
.format-card .format-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.format-card .format-size {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--ink-faint);
}

/* ===== Excluded slide treatment =====================================
   When a slide is hidden from export it stays in the editor (so users
   can finish or restore it), but is visually demoted: dim, struck row,
   and a clear "مستثنى" tag in the meta line. */
.slide-card.excluded { opacity: 0.55; }
.slide-card.excluded .meta-title {
  text-decoration: line-through;
  text-decoration-color: var(--ink-faint);
}
.slide-card .excluded-tag {
  background: rgba(237, 73, 86, 0.10);
  color: var(--neg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}

.thumb.excluded { opacity: 0.42; filter: grayscale(0.6); }
.thumb.excluded.active { opacity: 0.6; }
.thumb-excluded {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(19, 19, 19, 0.85);
  color: white;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 9px;
}

/* Banner over the preview frame when active slide is excluded */
.preview-frame.is-excluded::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    rgba(237, 73, 86, 0.04) 0 12px,
    transparent 12px 24px
  );
  pointer-events: none;
}
.preview-excluded-banner {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  background: rgba(19, 19, 19, 0.92);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-family: var(--font-base);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  letter-spacing: 0;
}

/* ===== Undo/Redo button refinements ================================ */
.btn-icon-only {
  padding: 8px 10px;
  min-width: 36px;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn:disabled:hover {
  background: white;
  border-color: var(--paper-line-strong);
}
.topbar-divider {
  width: 1px;
  align-self: stretch;
  background: var(--paper-line);
  margin: 6px 4px;
}

/* ===== Batch 3: line-height input prefix + focal grid + filters ===== */
.text-style-bar .size-prefix {
  padding: 0 8px 0 6px;
  font-size: 13px;
  color: var(--ink-faint);
  display: inline-flex;
  align-items: center;
  height: 100%;
  border-right: 1px solid var(--paper-line);
  background: var(--bg-soft);
}
.text-style-bar .lh-wrap .size-input {
  width: 50px;
}

/* 3×3 focal-point picker — used for both bg image and attachment.
   Each cell is a small toggleable square; clicking sets a CSS
   background-position / object-position keyword. */
.focal-grid {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  grid-template-rows: repeat(3, 22px);
  gap: 3px;
  background: var(--bg-soft);
  padding: 4px;
  border: 1px solid var(--paper-line-strong);
  border-radius: var(--radius-sm);
  width: max-content;
}
.focal-cell {
  border: 1px solid var(--paper-line-strong);
  background: white;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.focal-cell:hover {
  border-color: var(--ink-muted);
  background: var(--bg-soft);
}
.focal-cell.active {
  background: var(--ink);
  border-color: var(--ink);
}

/* Per-slide spacing override is just two size-wrap inputs; reuses
   existing `.size-wrap` styles. The overridden indicator appears in
   the section label as the existing `excluded-tag` reused with a
   blue tint. No new CSS needed beyond what's already defined. */

/* ===== Tailwind replacement utilities =================================
   Only the 8 utilities actually used in index.html. Replaces the 400 KB
   Tailwind JIT runtime to keep the editor fully offline-capable. */
.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.flex-1          { flex: 1 1 0%; }
.items-center    { align-items: center; }
.gap-2           { gap: 0.5rem; }
.h-screen        { height: 100vh; }
.hidden          { display: none; }
.overflow-hidden { overflow: hidden; }

/* =====================================================================
   Topbar actions cluster + responsive hide utility
   ===================================================================== */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--r-2);
  flex-wrap: nowrap;
  min-width: 0;
}
.btn .btn-label { display: inline; }

/* =====================================================================
   sec-editor — the promoted editor section at the top of the sidebar.
   Uses a sticky head so the slide title, position, and quick-nav stay
   in view while the user scrolls long forms.
   ===================================================================== */
.studio-section.sec-editor {
  padding-top: var(--r-4);
  background: var(--bg-editor);
}
.sec-editor-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-editor);
  padding: 12px 0 10px;
  margin: 0 0 var(--r-4);
  border-bottom: 1px solid var(--paper-line);
  cursor: default;
}
.sec-editor-head h2 .sec-editor-position {
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-soft);
  color: var(--ink-soft);
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--hairline);
  font-weight: 600;
}
.sec-editor-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sec-editor-actions .icon-btn {
  width: 30px;
  height: 30px;
  font-size: 12px;
}
.sec-editor-nav i { transform: translateY(0.5px); }
.sec-editor-body {
  padding-top: 2px;
}

/* Empty state — shows when no slide is selected/exists */
.editor-empty {
  background: var(--bg-soft);
  border: 1.5px dashed var(--paper-line-strong);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.editor-empty[hidden] { display: none; }
.editor-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--paper-line-strong);
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 22px;
  margin-bottom: 4px;
}
.editor-empty h3 {
  margin: 0;
  font-family: var(--font-base);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.editor-empty p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--ink-faint);
  font-family: var(--font-base);
  line-height: 1.6;
  max-width: 320px;
}

/* Theme actions row + Excel hints — extracted from inline styles in HTML */
.theme-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.excel-actions {
  margin-top: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.excel-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-faint);
}

/* =====================================================================
   Focus mode — desktop only. Hides the preview column and gives the
   editor the full workspace width. Triggered by the expand button in
   the sec-editor head or Cmd+E. Preview is still rendered (off-screen
   via display:none ancestor doesn't apply here — we hide the column
   visually but keep the renderer running so the next exit is instant).
   ===================================================================== */
body.focus-mode .studio-preview {
  display: none;
}
body.focus-mode .studio-workspace {
  grid-template-columns: minmax(0, 1fr);
}
body.focus-mode .studio-editor {
  border-left: none;
  max-width: 960px;
  margin-inline: auto;
}
/* Focus-mode icon swap is handled in JS (UI.syncFocusIcon) — swapping
   FA class names is safer than overriding FA's own ::before injection. */

/* =====================================================================
   Mobile tabbar (visible only at <=1100px) — fixed to the viewport
   bottom; switches between three view modes (edit / preview / slides).
   Mode is reflected via [data-mobile-mode] on <body>; the responsive
   block below uses it to show/hide editor sections accordingly.
   ===================================================================== */
.mobile-tabbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--paper-line);
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
}
.mobile-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 6px 9px;
  font-family: var(--font-base);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
  min-height: 56px;
}
.mobile-tab i {
  font-size: 17px;
  line-height: 1;
}
/* Active mobile-tab state is driven by body[data-mobile-mode="..."]
   rules inside the mobile media block (so they only apply at small
   widths where the tabbar is visible). */
.mobile-tab-badge {
  position: absolute;
  top: 6px;
  inset-inline-end: 14px;
  background: var(--ink);
  color: white;
  font-family: var(--font-mono);
  font-size: 9px;
  min-width: 16px;
  height: 16px;
  border-radius: 100px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  font-weight: 700;
  line-height: 1;
}
.mobile-tab:not(.active) .mobile-tab-badge {
  background: var(--ink-faint);
}

/* ===== Mobile / tablet portrait layout (<=1100px) =====================
   On narrow viewports the studio is a tabbed app shell — the bottom
   mobile-tabbar switches between three exclusive view modes:

     [data-mobile-mode="edit"]    → Edit Content + Slides only
     [data-mobile-mode="preview"] → Live preview frame + thumbnails
     [data-mobile-mode="slides"]  → Slides + Theme + Footer + Settings + Excel

   Each mode shows ONE primary region full-bleed below the topbar, so
   slide editing on a phone feels like a native app rather than a
   stacked desktop layout. The mobile-tabbar is fixed to the bottom of
   the viewport with safe-area-inset padding for notched devices.
==================================================================== */
@media (max-width: 1100px) {
  html, body {
    height: auto;
    overflow: visible;
  }
  body.overflow-hidden,
  body.h-screen {
    height: auto;
    overflow: visible;
  }
  /* Page padding so content never sits under the fixed bottom tabbar */
  body {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 6px);
  }

  /* ---- Topbar: compact, never wraps, scrolls naturally ------------- */
  .studio-topbar {
    height: auto;
    min-height: 56px;
    padding: 8px 12px env(safe-area-inset-top, 0) 12px;
    gap: 8px;
    flex-wrap: nowrap;
    /* NOT sticky on mobile — sticky chrome is annoying on small screens
       and steals vertical space from the editor. The bottom mobile-tabbar
       is the navigation anchor; topbar can scroll out of view. */
    position: relative;
  }

  /* Sec-editor head: also non-sticky on mobile (matches the topbar
     scrolling-naturally behavior). Stays sticky only on desktop. */
  .sec-editor-head {
    position: static;
    background: transparent;
    border-bottom: 1px solid var(--paper-line);
  }
  .studio-brand { gap: 8px; min-width: 0; flex: 0 1 auto; }
  .studio-brand-mark { width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0; }
  .studio-brand-text h1 { font-size: 14px; }
  .studio-brand-text p { display: none; }
  .topbar-actions { gap: 4px; flex-shrink: 0; }
  .studio-topbar .btn { padding: 7px 10px; font-size: 12px; }
  .studio-topbar .btn-icon-only { padding: 7px 9px; min-width: 32px; }
  .topbar-divider { display: none; }
  .hide-on-mobile { display: none !important; }
  /* Primary export button: collapse to icon only on tight widths */
  .topbar-actions .btn-primary .btn-label { display: none; }

  /* ---- Workspace: not a grid — siblings switched via mobile mode --- */
  .studio-workspace {
    display: block;
    overflow: visible;
    flex: none;
    min-height: 0;
    grid-template-columns: none;
    grid-template-rows: none;
  }

  /* ---- Editor + Preview: natural flow, but mode toggles visibility - */
  .studio-editor {
    overflow: visible;
    border-left: none;
    border-bottom: 1px solid var(--paper-line);
  }
  .studio-section { padding: 16px 14px; }
  .studio-section-head h2 { font-size: 14px; }
  .sec-editor-head { padding: 10px 0 8px; }

  .studio-preview {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    overflow: visible;
    min-height: calc(100vh - 64px - 56px - env(safe-area-inset-bottom, 0px));
  }
  .preview-toolbar { padding: 10px 14px; grid-column: 1 / -1; }
  .preview-toolbar .title { font-size: 12px; }
  .preview-stage {
    padding: 16px 14px;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  /* Thumb strip: horizontal swipe row */
  .thumb-strip {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-top: 1px solid var(--paper-line);
    padding: 10px 12px;
    gap: 8px;
    grid-column: 1 / -1;
  }
  .thumb:hover { transform: none; }

  /* Format picker stays 3-up but tighter */
  .format-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  /* Add-slide row wraps on narrow screens */
  .add-slide-row { flex-wrap: wrap; }
  .add-slide-row .select { min-width: 0; }

  /* ---- Mobile tab bar visible ------------------------------------- */
  .mobile-tabbar {
    display: flex;
  }

  /* Always keep these helpers visible: */
  /* No "focus mode" on mobile — controlled by tabs instead. */
  body.focus-mode .studio-preview { display: none; }
  body.focus-mode .studio-workspace { grid-template-columns: none; }

  /* ============== Mode: EDIT (default) =============================== */
  body[data-mobile-mode="edit"] .studio-preview,
  body[data-mobile-mode="edit"] #sec-slides,
  body[data-mobile-mode="edit"] #sec-theme,
  body[data-mobile-mode="edit"] #sec-footer,
  body[data-mobile-mode="edit"] #sec-settings,
  body[data-mobile-mode="edit"] #sec-excel {
    display: none;
  }

  /* ============== Mode: PREVIEW ====================================== */
  body[data-mobile-mode="preview"] .studio-editor {
    display: none;
  }
  body[data-mobile-mode="preview"] .preview-stage {
    /* Tall preview on phones so the slide reads at a comfortable size */
    min-height: calc(100vh - 64px - 56px - 56px - 90px - env(safe-area-inset-bottom, 0px));
  }

  /* ============== Mode: SLIDES (manage list + settings) ============== */
  body[data-mobile-mode="slides"] #sec-editor,
  body[data-mobile-mode="slides"] .studio-preview {
    display: none;
  }
  /* Make sure all the slides-mode sections are expanded (visible) in case
     a user previously collapsed them; we keep their toggleability. */

  /* Mobile tab active state synced with body data attribute */
  body[data-mobile-mode="edit"] .mobile-tab[data-mode="edit"],
  body[data-mobile-mode="preview"] .mobile-tab[data-mode="preview"],
  body[data-mobile-mode="slides"] .mobile-tab[data-mode="slides"] {
    color: var(--ink);
  }
  body[data-mobile-mode="edit"] .mobile-tab[data-mode="edit"]::before,
  body[data-mobile-mode="preview"] .mobile-tab[data-mode="preview"]::before,
  body[data-mobile-mode="slides"] .mobile-tab[data-mode="slides"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 22%;
    right: 22%;
    height: 2px;
    background: var(--ink);
    border-radius: 0 0 4px 4px;
  }

  /* Touch targets — make buttons & toggles min 44×44 (Apple HIG) */
  .icon-btn { min-width: 36px; min-height: 36px; }
  .btn { min-height: 38px; }
  .toggle { min-height: 56px; }
}

/* Phone-tier refinements (<=480px) — tighter spacing, larger touch targets */
@media (max-width: 480px) {
  .studio-section { padding: 14px 12px; }
  .studio-topbar { padding: 6px 10px; }
  .studio-topbar .btn { padding: 6px 9px; }
  .studio-brand-text h1 { font-size: 13px; }
  .sec-editor-head h2 { font-size: 13px; }
  .mobile-tab { font-size: 10px; padding: 9px 4px 7px; }
  .mobile-tab i { font-size: 16px; }
  /* Text-style toolbar — let it stack gracefully on tiny screens */
  .text-style-bar { gap: 5px; padding: 6px; }
  .text-style-bar .select { font-size: 11px; min-width: 90px; }
  .text-style-bar .size-input { width: 44px; font-size: 11px; }
}
