/* ─── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1b2e;
  --surface: #132540;
  --surface2: #1b3055;
  --border: #253d6e;
  --accent: #c9a227;
  --accent2: #e8c76a;
  --gold: #d4a843;
  --text: #e8eaf0;
  --text-muted: #c0963a;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

html {
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Header ───────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-right { display: flex; align-items: center; flex-shrink: 0; }
.btn-login {
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(192,150,58,.3);
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.btn-login:hover {
  border-color: var(--text-muted);
  color: var(--accent2);
}
.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(192,150,58,.3);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.user-btn:hover { border-color: var(--text-muted); color: var(--accent2); }
.user-chevron { font-size: 10px; color: var(--text-muted); }
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dropdown-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent2);
}
.bookmark-search {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  outline: none;
}
.bookmark-search:focus { border-color: var(--accent); }
.bookmark-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bookmark-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.bookmark-item:hover { background: var(--surface2); }
.bookmark-empty { font-size: 13px; color: var(--text-muted); padding: 8px 10px; }
.col-group { display: flex; flex-direction: column; }
.col-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; font-size: 13px; font-weight: 400; color: var(--accent2);
  background: transparent; border: none; cursor: pointer; text-align: left;
  width: 100%; font-family: inherit;
}
.col-toggle:hover { background: var(--surface2); }
.col-toggle span:first-child { flex: 1; }
.col-count { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.col-chevron { font-size: 10px; color: var(--text-muted); }
.col-items { display: flex; flex-direction: column; }
.col-items .bookmark-item { padding-left: 20px; }
.dropdown-divider { height: 1px; background: var(--border); }
.btn-logout {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.btn-logout:hover { color: var(--error); background: rgba(239,68,68,.08); }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 9999;
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { border-color: var(--error); color: var(--error); }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-img { width: 64px; height: 64px; border-radius: 8px; flex-shrink: 0; }
.logo-text { font-size: 20px; font-weight: 600; color: var(--accent2); }
.logo-sub { font-size: 12px; color: var(--text-muted); font-weight: 300; margin-left: 2px; }
.hero {
  text-align: center;
  padding: 14px 24px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.hero-headline {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(120deg, var(--accent2) 0%, #e8c96a 50%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.3;
}
.hero-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  opacity: .8;
}
.hero-platforms {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}
.platform-badge {
  font-size: 11px;
  color: var(--text-muted);
  opacity: .6;
  white-space: nowrap;
}
.platform-dot {
  font-size: 11px;
  color: var(--text-muted);
  opacity: .35;
}

/* ─── Main ─────────────────────────────────────────────── */
.main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─── Cards ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent2);
}

/* ─── Form fields ──────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label:not(.tc-custom) {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }

select, input[type="number"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  appearance: none;
  outline: none;
  transition: border-color .2s;
}
select:focus, input[type="number"]:focus {
  border-color: var(--accent);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c0963a' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* ─── Toggle ───────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  user-select: none;
}
.toggle-label input { display: none; }
.toggle-track {
  width: 40px; height: 22px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 11px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: left .2s, background .2s;
}
.toggle-label input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-label input:checked ~ .toggle-track .toggle-thumb { left: 21px; background: #fff; }

/* ─── Background tabs ─────────────────────────────────── */
.bg-tabs { display: flex; gap: 8px; }
.bg-mode-tabs { justify-content: center; }
.bg-tab {
  padding: 7px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.bg-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ─── Color picker ─────────────────────────────────────── */
.color-picker-wrap { display: flex; flex-direction: column; gap: 14px; }
.color-input-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] {
  accent-color: var(--accent2);
  cursor: pointer;
}
.text-bg-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
}
.text-bg-opacity-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.text-bg-opacity-inline input[type="range"] {
  flex: 1;
}
.text-bg-opacity-inline span {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}
input[type="color"] {
  width: 48px; height: 48px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface2);
  cursor: pointer;
}
#bg-color-hex, #bg-color-end-hex {
  font-family: monospace;
  font-size: 14px;
  color: var(--text-muted);
}
/* ─── Field header row + gradient UI ───────────────────── */
.field-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.compact-toggle { font-size: 13px; color: var(--text-muted); gap: 6px; }
.gradient-color-row {
  display: flex;
  align-items: flex-end;
  gap: 0;
}
.gradient-end-inline {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  flex: 1;
  gap: 0;
  min-width: 0;
}
.color-swatch-cell { display: flex; flex-direction: column; gap: 4px; }
.color-swatch-cell.align-right { align-items: flex-end; }
.swatch-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
}
/* ─── Text color swatches ──────────────────────────────── */
.text-color-swatches {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: auto;
}
.tc-swatch {
  padding: 8px 16px;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: border-color .15s;
}
.tc-swatch:hover:not(.active) { border-color: var(--text-muted); }
.tc-swatch.active { border-color: var(--accent); }
.tc-custom {
  position: relative;
  overflow: hidden;
  display: inline-block;
  background: linear-gradient(135deg, #0ea5e9, #34d399, #fbbf24);
  color: #111;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: normal;
}
.tc-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: none;
}
#text-color-hex {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
}
.color-preview-bar {
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-family: 'Scheherazade New', serif;
  transition: background .2s, color .2s;
}

/* ─── Upload area ──────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(201,162,39,.06);
}
.upload-icon { font-size: 32px; margin-bottom: 8px; }
.upload-area p { color: var(--text-muted); font-size: 14px; }
.upload-area p strong { color: var(--text); }
.upload-hint { font-size: 12px; margin-top: 4px; }
.bismillah-note { font-size: 12px; color: var(--accent2); opacity: .7; margin: 6px 0 0; }
#bg-image-panel > .field { margin-top: 10px; }
.field-row-meta {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.field-row-meta .field { flex: 1; }
.field-row-meta .verse-meta { flex: 1; }
.field-align-right label { text-align: right; display: block; }
.verse-meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 10px;
  gap: 2px;
  white-space: nowrap;
}
.verse-meta-count { font-size: 12px; color: var(--accent2); line-height: 1; }
.verse-meta-duration { font-size: 11px; color: var(--text-muted); opacity: .7; line-height: 1; }
.verse-meta-duration.loading { font-style: italic; }
.badge-sep { opacity: .5; }
.upload-area input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}

.image-preview {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.image-preview .thumb {
  width: 80px; height: 80px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid var(--border);
  position: relative;
}
.image-preview .thumb-wrap {
  position: relative;
  width: 80px; height: 80px;
}
.image-preview .thumb-remove {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--error);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px; height: 18px;
  font-size: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  z-index: 2;
}
.thumb-order {
  position: absolute;
  bottom: 4px; left: 4px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 10px;
  border-radius: 4px;
  padding: 1px 5px;
}

.upload-status {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(201,162,39,.12);
  color: var(--accent2);
}

.upload-type-warning {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(220,60,60,.15);
  color: #f87171;
  margin-top: 8px;
}

/* ─── Text / background preview ────────────────────────────── */
.text-preview-wrap { display: flex; justify-content: center; }
.text-preview-frame {
  width: 240px;
  aspect-ratio: 9 / 16;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}
.text-preview-frame.landscape {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 16 / 9;
}
.preview-inner {
  position: absolute;
  top: 0; left: 0;
  width: 1080px;
  height: 1920px;
  transform-origin: top left;
}
.preview-bg-container { position: absolute; inset: 0; overflow: hidden; }
.preview-watermark {
  position: absolute;
  left: 50%;
  top: 120px;
  width: 80px;
  height: 74px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 6;
  opacity: 0.95;
  background: #fff;
  -webkit-mask-image: url('/static/wm_white.png');
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
  mask-image: url('/static/wm_white.png');
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
}
.preview-bg-img {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transform: scale(1.06) translate3d(0, 0, 0);
  transition: opacity 1.4s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}
.preview-bg-img.active {
  opacity: 1;
  animation: none;
}

.preview-bg-img.zoom-enabled.active {
  animation: bgZoomIn 8s cubic-bezier(.16,1,.3,1) 1 both;
}

@keyframes bgZoomIn {
  0%   { transform: scale(1.06) translate3d(0, 0, 0); }
  100% { transform: scale(1.18) translate3d(0, 0, 0); }
}
/* Each text element is independently positioned, mirroring the ASS \an5\pos() layout */
.preview-abs-text {
  position: absolute;
  top: 50%;
  left: 60px; right: 60px;
  text-align: center;
  transform: translateY(-50%);
}
.preview-surah-ar {
  font-family: 'Scheherazade New', serif;
  direction: rtl;
  line-height: 1.1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  color: #fff;
}
.preview-surah-la {
  font-family: 'Inter', sans-serif;
  line-height: 1.1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  color: #fff;
}
.preview-arabic-text {
  font-family: 'Scheherazade New', serif;
  direction: rtl;
  line-height: 1.1;
  text-shadow: 0 2px 10px rgba(0,0,0,0.9);
  color: #fff;
}
.preview-translation-text {
  font-family: 'Inter', sans-serif;
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  color: #fff;
}

/* ─── Position selector ───────────────────────────────── */
.position-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 92px;
}
.pos-btn {
  width: 100%;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.pos-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pos-btn:hover:not(.active) { border-color: var(--text-muted); color: var(--text); }

/* ─── Output info box ──────────────────────────────────── */
.video-info-box {
  background: rgba(201,162,39,.08);
  border: 1px solid rgba(201,162,39,.25);
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.output-info { display: contents; }
.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-muted);
}
#duration-estimate strong { color: var(--accent2); }

/* ─── Buttons ──────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, opacity .2s, transform .1s;
  font-family: inherit;
}
.btn-primary:hover:not(:disabled) { background: #a8871e; transform: translateY(-1px); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.result-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-download {
  display: inline-block;
  padding: 12px 32px;
  background: var(--success);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: background .2s;
}
.btn-download:hover { background: #16a34a; }

.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 28px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-share:hover:not(:disabled) { background: #1d4ed8; }
.btn-share:disabled { opacity: .6; cursor: not-allowed; }

.btn-retry {
  padding: 10px 24px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.btn-retry:hover { border-color: var(--text-muted); color: var(--text); }

/* ─── Progress ─────────────────────────────────────────── */
.progress-area { display: flex; flex-direction: column; gap: 10px; }
.progress-bar-wrap {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width .4s ease;
}
.progress-msg { font-size: 13px; color: var(--text-muted); }
#elapsed-time { opacity: .55; margin-left: 4px; }
.progress-tip { font-size: 11px; color: var(--text-muted); opacity: .5; margin-top: 4px; }

/* ─── Result / error ───────────────────────────────────── */
.result-area, .error-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0 4px;
  text-align: center;
}
.result-icon, .error-icon { font-size: 36px; }
.result-area p { color: var(--text-muted); font-size: 14px; }
.error-area p { color: var(--error); font-size: 14px; max-width: 420px; }

/* ─── Footer ───────────────────────────────────────────── */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 24px 36px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.footer-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.footer-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 2px;
}
.footer-resources { opacity: .45; }
.footer-disclaimer {
  width: 100%;
  text-align: center;
  font-size: 10px;
  opacity: .45;
  margin: 4px 0 0;
  line-height: 1.2;
}
.footer-resources-list {
  display: flex;
  align-items: center;
  gap: 8px;
}
.footer-link {
  color: var(--text-muted);
  text-decoration: none;
}
.footer-link:hover { color: var(--accent2); }
.footer-links-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  opacity: .45;
}
.footer-sep { opacity: .4; }

/* ─── Subtitle section — compact content rows ──────────── */
.subtitle-divider {
  height: 1px;
  background: var(--border);
}
.sub-content-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}
.sub-content-row .toggle-label { flex-shrink: 0; width: 162px; }
.sub-content-label {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  flex-shrink: 0;
}
.sub-content-tag {
  font-size: 11px;
  color: var(--text-muted);
  opacity: .55;
}
.sub-lang-field { flex: 1; }
.sub-lang-field select { width: 100%; }

/* ─── Layout card ───────────────────────────────────────── */
.layout-controls-row {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}
.layout-left-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.layout-tabs {
  width: 100%;
}
.layout-orient-stack {
  display: flex;
  flex-direction: row;
  gap: 6px;
}
.layout-orient-stack .bg-tab {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
}

.position-selector {
  flex: 0 0 auto;
  width: 100%;
}

/* Phone mockup diagram */
.position-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}
.phone-frame {
  width: 92px;
  height: 164px;   /* 9:16 */
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  position: relative;
  overflow: hidden;
  transition: width .25s ease, height .25s ease, border-radius .25s ease;
  flex-shrink: 0;
}
.phone-frame.landscape {
  width: 146px;
  height: 82px;   /* 16:9 */
  border-radius: 8px;
}

@media (max-width: 520px) {
  .layout-controls-row {
    grid-template-columns: minmax(160px, 190px) minmax(0, 1fr);
    gap: 10px;
  }
  .phone-frame.landscape {
    width: 130px;
    height: 73px;
  }
}
.pos-indicator {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-size: 7px;
  color: var(--accent2);
  background: rgba(201,162,39,.25);
  padding: 2px 0;
  white-space: nowrap;
  transition: top .25s ease;
  transform: translateY(-50%);
  pointer-events: none;
}

/* ─── Appearance — style grid ───────────────────────────── */
.style-grid {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.style-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  width: 72px;
}
.style-num {
  width: 60px !important;
  padding: 6px 8px !important;
  font-size: 13px !important;
  flex-shrink: 0;
}
.style-select {
  flex: 1;
  padding: 6px 28px 6px 10px !important;
  font-size: 13px !important;
  min-width: 0;
}
#surah-font,
#trans1-font,
#trans2-font {
  flex: 0 0 96px;
}
.size-select {
  flex: 0 0 96px;
  padding: 5px 24px 5px 8px !important;
  font-size: 12px !important;
}
.size-btn {
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.size-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.size-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }
.bold-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  min-width: 56px;
  line-height: 1;
}
.bold-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.bold-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }
.appearance-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.swatch-all-note {
  margin-top: 0;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
  white-space: normal;
}

.inline-color-box {
  width: 28px !important;
  height: 28px !important;
  border-radius: 6px !important;
  padding: 0 !important;
  border-width: 1px !important;
  flex: 0 0 28px;
}

.style-color-pack {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
}

.style-color-pack .color-hex-inline {
  min-width: 62px;
  font-size: 12px;
  display: none;
}

.color-hex-inline {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
  min-width: 72px;
  text-align: right;
}

@media (max-width: 640px) {
  .appearance-row {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .text-color-swatches {
    width: 100%;
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .style-grid {
    gap: 8px;
    align-items: center;
  }

  .style-label {
    width: 100%;
    white-space: normal;
  }

  .style-color-pack {
    flex: 0 1 auto;
  }

  .size-select,
  #surah-font,
  #trans1-font,
  #trans2-font {
    flex: 1 1 110px;
    min-width: 0;
  }

  .bold-btn {
    min-width: 0;
    flex: 0 0 auto;
    padding: 4px 8px;
  }

  .color-hex-inline,
  #text-color-hex {
    min-width: 0;
  }

  .field-header-row,
  .gradient-color-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .gradient-end-inline {
    width: 100%;
    justify-content: flex-end;
  }

  .color-swatch-cell.align-right {
    align-items: flex-end;
  }
}

/* ─── Utilities ────────────────────────────────────────── */
.hidden { display: none !important; }
