/* ═══════════════════════════════════════════
   ilovi — Letter Creator Styles (refined)
   Compact, fast, accessible. Romantic look preserved.
   ═══════════════════════════════════════════ */

/* ───── Scrollbar & selection ───── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(251, 113, 133, 0.4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(251, 113, 133, 0.65); }
::selection { background: rgba(244, 63, 94, 0.35); color: #fff; }

/* ═══════════════════════════════════════════
   ROOT VARIABLES
   ═══════════════════════════════════════════ */
:root {
  --creator-bg: #0a0a0a;
  --creator-surface: rgba(255, 255, 255, 0.04);
  --creator-surface-hover: rgba(255, 255, 255, 0.08);
  --creator-border: rgba(255, 255, 255, 0.08);
  --creator-border-strong: rgba(255, 255, 255, 0.14);
  --creator-text: #fff1f2;
  --creator-muted: rgba(255, 241, 242, 0.55);
  --creator-accent: #fb7185;
  --creator-accent-dark: #e11d48;
  --header-height: 52px;
  --toolbar-height: 56px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body.creator-page {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #150510 0%, #0a0a0a 50%, #0c0612 100%);
  min-height: 100vh;
  color: var(--creator-text);
  overflow-x: hidden;
  padding-bottom: calc(var(--toolbar-height) + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Visually-hidden but available to screen readers and search crawlers */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* SEO/About copy block — discreet, sits below the toolbar so it never
   interferes with the editor UI. Visible but unobtrusive. */
.seo-about {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 96px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.82rem;
  line-height: 1.65;
}
.seo-about h2 {
  color: rgba(255, 255, 255, 0.85);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 10px;
}
.seo-about h3 {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 18px 0 6px;
}
.seo-about p { margin: 0 0 10px; }
.seo-about ul { margin: 0 0 10px; padding-left: 18px; }
.seo-about li { margin: 2px 0; }
.seo-about a { color: #fb7185; text-decoration: underline; text-underline-offset: 2px; }

/* Accessible focus ring everywhere */
:focus-visible {
  outline: 2px solid var(--creator-accent);
  outline-offset: 2px;
  border-radius: 6px;
}
button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--creator-accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════ */
.creator-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  padding: 0 16px;
  background: rgba(10, 5, 16, 0.85);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--creator-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.creator-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--creator-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  transition: color 0.2s, background 0.2s;
}
.creator-header .back-link:hover { color: var(--creator-text); background: var(--creator-surface); }
.creator-header .page-title {
  font-family: 'Great Vibes', cursive;
  font-size: 1.55rem;
  line-height: 1;
  margin: 0;
  background: linear-gradient(135deg, #fda4af, #fb7185 60%, #f43f5e);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.creator-header .action-group { display: flex; gap: 4px; }

/* Header undo/redo buttons */
.creator-header .toolbar-btn {
  flex-direction: row;
  gap: 0;
  padding: 8px;
  min-width: 36px;
  border-radius: 8px;
}
.creator-header .toolbar-btn svg { width: 18px; height: 18px; }

/* ═══════════════════════════════════════════
   TEMPLATE SELECTOR STRIP
   ═══════════════════════════════════════════ */
.template-selector {
  width: 100%;
  padding: 12px 0 4px;
}
.template-selector-label {
  padding: 0 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--creator-muted);
}
.template-scroll {
  display: flex;
  gap: 10px;
  padding: 4px 16px 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.template-scroll::-webkit-scrollbar { display: none; }

.template-card {
  flex: 0 0 auto;
  width: 80px;
  height: 100px;
  padding: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  scroll-snap-align: center;
  transition: transform 0.2s var(--ease), border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.template-card::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
}
.template-card::after {
  content: attr(data-label);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 4px 5px;
  font-size: 0.58rem;
  font-weight: 500;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  z-index: 2;
  letter-spacing: 0.04em;
}
.template-card:hover { transform: translateY(-2px); }
.template-card.active {
  border-color: var(--creator-accent);
  box-shadow: 0 0 0 2px rgba(251, 113, 133, 0.25), 0 4px 14px rgba(244, 63, 94, 0.25);
  transform: translateY(-2px);
}
.template-card.active .check-badge { opacity: 1; transform: scale(1); }
.check-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--creator-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.18s, transform 0.18s var(--ease);
  box-shadow: 0 1px 4px rgba(225, 29, 72, 0.5);
}
.check-badge svg { width: 11px; height: 11px; color: #fff; }

/* Template card mini-preview content */
.tpl-mini-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.tpl-mini-content .mini-heading {
  font-size: 0.6rem;
  font-weight: 600;
  margin-bottom: 3px;
  opacity: 0.95;
}
.tpl-mini-content .mini-lines {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 70%;
}
.tpl-mini-content .mini-line {
  height: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.32);
}
.tpl-mini-content .mini-line:nth-child(2) { width: 85%; }
.tpl-mini-content .mini-line:nth-child(3) { width: 60%; }

/* ───── Template card backgrounds (mini) ───── */
.tc-classic-rose::before { background: linear-gradient(135deg, #9f1239, #be123c, #e11d48); }
.tc-midnight-love::before { background: linear-gradient(135deg, #0f172a, #1e1b4b, #312e81); }
.tc-cherry-blossom::before { background: linear-gradient(135deg, #fce7f3, #fbcfe8, #f9a8d4); }
.tc-rose-gold::before { background: linear-gradient(135deg, #3b1520, #5b2333, #b76e79); }
.tc-passionate-red::before { background: linear-gradient(135deg, #450a0a, #7f1d1d, #dc2626); }
.tc-ocean-breeze::before { background: linear-gradient(135deg, #042f2e, #0d4f4d, #14b8a6); }
.tc-starlight::before { background: linear-gradient(135deg, #2e1065, #4c1d95, #7c3aed); }
.tc-autumn-warmth::before { background: linear-gradient(135deg, #431407, #78350f, #d97706); }
.tc-butterfly::before { background: linear-gradient(135deg, #3b0764, #581c87, #a855f7); }
.tc-vintage::before { background: linear-gradient(135deg, #44403c, #78716c, #d6d3d1); }

.tc-cherry-blossom .mini-heading,
.tc-vintage .mini-heading { color: #4a3728; }
.tc-cherry-blossom .mini-line,
.tc-vintage .mini-line { background: rgba(0, 0, 0, 0.15); }

/* ═══════════════════════════════════════════
   EDITOR / PREVIEW CARD
   ═══════════════════════════════════════════ */
.editor-container {
  max-width: 620px;
  margin: 0 auto;
  padding: 4px 14px 16px;
}
.letter-preview-card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 460px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.3s var(--ease);
}
.letter-preview-card .letter-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.letter-preview-card .letter-bg-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.letter-preview-card .letter-content {
  position: relative;
  z-index: 2;
  padding: 32px 26px;
  min-height: 460px;
  display: flex;
  flex-direction: column;
}

/* Corner decoration */
.letter-preview-card .corner-decor {
  position: absolute;
  width: 40px;
  height: 40px;
  z-index: 3;
  opacity: 0.3;
  pointer-events: none;
}
.corner-decor.tl { top: 10px; left: 10px; border-top: 2px solid; border-left: 2px solid; border-radius: 4px 0 0 0; }
.corner-decor.tr { top: 10px; right: 10px; border-top: 2px solid; border-right: 2px solid; border-radius: 0 4px 0 0; }
.corner-decor.bl { bottom: 10px; left: 10px; border-bottom: 2px solid; border-left: 2px solid; border-radius: 0 0 0 4px; }
.corner-decor.br { bottom: 10px; right: 10px; border-bottom: 2px solid; border-right: 2px solid; border-radius: 0 0 4px 0; }

/* Editable zones */
.editable-zone {
  outline: none;
  border-radius: 8px;
  padding: 4px 8px;
  margin: -4px -8px;
  transition: background 0.15s, box-shadow 0.15s;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.editable-zone:hover { background: rgba(255, 255, 255, 0.04); }
.editable-zone:focus {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1.5px rgba(251, 113, 133, 0.45);
}
.editable-zone:empty::before {
  content: attr(data-placeholder);
  opacity: 0.4;
  pointer-events: none;
  font-style: italic;
}
.editable-heading {
  font-size: 2.2rem;
  line-height: 1.2;
  margin-bottom: 18px;
  font-weight: 400;
}
.editable-body {
  font-size: 1.05rem;
  line-height: 1.85;
  flex: 1;
  min-height: 180px;
  margin-bottom: 18px;
}
.editable-body img {
  max-width: 100%;
  border-radius: 10px;
  margin: 10px 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.editable-signature {
  font-size: 1.5rem;
  text-align: right;
  margin-top: auto;
}

/* Divider inside letter */
.letter-divider {
  width: 56px;
  height: 1px;
  margin: 12px 0;
  opacity: 0.4;
}

/* ═══════════════════════════════════════════
   TEMPLATE FULL STYLES (10 templates)
   ═══════════════════════════════════════════ */
.tpl-classic-rose .letter-bg { background: linear-gradient(160deg, #4c0519, #9f1239, #be123c); }
.tpl-classic-rose .letter-bg-overlay { background: radial-gradient(ellipse at 20% 20%, rgba(251, 113, 133, 0.15) 0%, transparent 60%); }
.tpl-classic-rose .editable-heading { font-family: 'Great Vibes', cursive; color: #fda4af; }
.tpl-classic-rose .editable-body { font-family: 'Dancing Script', cursive; color: rgba(255, 241, 242, 0.88); }
.tpl-classic-rose .editable-signature { font-family: 'Parisienne', cursive; color: #fb7185; }
.tpl-classic-rose .corner-decor { border-color: #fb7185; }
.tpl-classic-rose .letter-divider { background: linear-gradient(90deg, transparent, #fb7185, transparent); }

.tpl-midnight-love .letter-bg { background: linear-gradient(160deg, #020617, #1e1b4b, #312e81); }
.tpl-midnight-love .letter-bg-overlay {
  background:
    radial-gradient(2px 2px at 15% 20%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(2px 2px at 45% 35%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(1px 1px at 70% 15%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 25% 70%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(2px 2px at 85% 60%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(1px 1px at 60% 85%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(ellipse at 30% 80%, rgba(99, 102, 241, 0.1) 0%, transparent 50%);
}
.tpl-midnight-love .editable-heading { font-family: 'Parisienne', cursive; color: #c7d2fe; }
.tpl-midnight-love .editable-body { font-family: 'Poppins', sans-serif; font-weight: 300; color: rgba(224, 231, 255, 0.85); }
.tpl-midnight-love .editable-signature { font-family: 'Great Vibes', cursive; color: #818cf8; }
.tpl-midnight-love .corner-decor { border-color: #6366f1; }
.tpl-midnight-love .letter-divider { background: linear-gradient(90deg, transparent, #818cf8, transparent); }

.tpl-cherry-blossom .letter-bg { background: linear-gradient(160deg, #fce7f3, #fbcfe8, #fdf2f8); }
.tpl-cherry-blossom .letter-bg-overlay {
  background:
    radial-gradient(circle at 80% 20%, rgba(244, 114, 182, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 20% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 40%);
}
.tpl-cherry-blossom .editable-heading { font-family: 'Great Vibes', cursive; color: #be185d; }
.tpl-cherry-blossom .editable-body { font-family: 'Dancing Script', cursive; color: #831843; font-size: 1.12rem; }
.tpl-cherry-blossom .editable-signature { font-family: 'Parisienne', cursive; color: #ec4899; }
.tpl-cherry-blossom .corner-decor { border-color: #f472b6; }
.tpl-cherry-blossom .letter-divider { background: linear-gradient(90deg, transparent, #f472b6, transparent); }

.tpl-rose-gold .letter-bg { background: linear-gradient(160deg, #1a0a0d, #2a1015, #3b1520); }
.tpl-rose-gold .letter-bg-overlay {
  background:
    linear-gradient(135deg, rgba(183, 110, 121, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 30%, rgba(232, 180, 184, 0.1) 0%, transparent 50%);
}
.tpl-rose-gold .editable-heading { font-family: 'Parisienne', cursive; color: #e8b4b8; }
.tpl-rose-gold .editable-body { font-family: 'Poppins', sans-serif; font-weight: 300; color: rgba(232, 180, 184, 0.78); }
.tpl-rose-gold .editable-signature { font-family: 'Great Vibes', cursive; color: #b76e79; }
.tpl-rose-gold .corner-decor { border-color: #b76e79; }
.tpl-rose-gold .letter-divider { background: linear-gradient(90deg, transparent, #b76e79, transparent); }

.tpl-passionate-red .letter-bg { background: linear-gradient(160deg, #450a0a, #7f1d1d, #991b1b); }
.tpl-passionate-red .letter-bg-overlay {
  background:
    radial-gradient(circle at 50% 100%, rgba(239, 68, 68, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 0%, rgba(252, 165, 165, 0.08) 0%, transparent 40%);
}
.tpl-passionate-red .editable-heading { font-family: 'Great Vibes', cursive; color: #fca5a5; }
.tpl-passionate-red .editable-body { font-family: 'Dancing Script', cursive; color: rgba(254, 226, 226, 0.88); }
.tpl-passionate-red .editable-signature { font-family: 'Parisienne', cursive; color: #f87171; }
.tpl-passionate-red .corner-decor { border-color: #ef4444; }
.tpl-passionate-red .letter-divider { background: linear-gradient(90deg, transparent, #ef4444, transparent); }

.tpl-ocean-breeze .letter-bg { background: linear-gradient(160deg, #042f2e, #0d4f4d, #115e59); }
.tpl-ocean-breeze .letter-bg-overlay {
  background:
    radial-gradient(ellipse at 50% 100%, rgba(20, 184, 166, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 20% 20%, rgba(94, 234, 212, 0.08) 0%, transparent 40%);
}
.tpl-ocean-breeze .editable-heading { font-family: 'Parisienne', cursive; color: #5eead4; }
.tpl-ocean-breeze .editable-body { font-family: 'Poppins', sans-serif; font-weight: 300; color: rgba(204, 251, 241, 0.85); }
.tpl-ocean-breeze .editable-signature { font-family: 'Great Vibes', cursive; color: #14b8a6; }
.tpl-ocean-breeze .corner-decor { border-color: #2dd4bf; }
.tpl-ocean-breeze .letter-divider { background: linear-gradient(90deg, transparent, #2dd4bf, transparent); }

.tpl-starlight .letter-bg { background: linear-gradient(160deg, #2e1065, #4c1d95, #5b21b6); }
.tpl-starlight .letter-bg-overlay {
  background:
    radial-gradient(2px 2px at 10% 15%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 30% 40%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(2px 2px at 55% 10%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(1px 1px at 75% 55%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(2px 2px at 40% 75%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(ellipse at 60% 40%, rgba(167, 139, 250, 0.1) 0%, transparent 50%);
}
.tpl-starlight .editable-heading { font-family: 'Great Vibes', cursive; color: #c4b5fd; }
.tpl-starlight .editable-body { font-family: 'Dancing Script', cursive; color: rgba(221, 214, 254, 0.88); }
.tpl-starlight .editable-signature { font-family: 'Parisienne', cursive; color: #a78bfa; }
.tpl-starlight .corner-decor { border-color: #8b5cf6; }
.tpl-starlight .letter-divider { background: linear-gradient(90deg, transparent, #a78bfa, transparent); }

.tpl-autumn-warmth .letter-bg { background: linear-gradient(160deg, #431407, #78350f, #92400e); }
.tpl-autumn-warmth .letter-bg-overlay {
  background:
    radial-gradient(circle at 70% 80%, rgba(217, 119, 6, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 20% 30%, rgba(251, 191, 36, 0.08) 0%, transparent 40%);
}
.tpl-autumn-warmth .editable-heading { font-family: 'Parisienne', cursive; color: #fbbf24; }
.tpl-autumn-warmth .editable-body { font-family: 'Poppins', sans-serif; font-weight: 300; color: rgba(254, 243, 199, 0.85); }
.tpl-autumn-warmth .editable-signature { font-family: 'Great Vibes', cursive; color: #f59e0b; }
.tpl-autumn-warmth .corner-decor { border-color: #d97706; }
.tpl-autumn-warmth .letter-divider { background: linear-gradient(90deg, transparent, #d97706, transparent); }

.tpl-butterfly .letter-bg { background: linear-gradient(160deg, #3b0764, #581c87, #6b21a8); }
.tpl-butterfly .letter-bg-overlay {
  background:
    radial-gradient(circle at 80% 70%, rgba(192, 132, 252, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 15% 25%, rgba(168, 85, 247, 0.08) 0%, transparent 40%);
}
.tpl-butterfly .editable-heading { font-family: 'Great Vibes', cursive; color: #d8b4fe; }
.tpl-butterfly .editable-body { font-family: 'Dancing Script', cursive; color: rgba(233, 213, 255, 0.88); }
.tpl-butterfly .editable-signature { font-family: 'Parisienne', cursive; color: #c084fc; }
.tpl-butterfly .corner-decor { border-color: #a855f7; }
.tpl-butterfly .letter-divider { background: linear-gradient(90deg, transparent, #a855f7, transparent); }

.tpl-vintage-parchment .letter-bg { background: linear-gradient(160deg, #f5f0e8, #ede4d4, #e8dcc8); }
.tpl-vintage-parchment .letter-bg-overlay {
  background: radial-gradient(circle at 50% 50%, rgba(120, 100, 70, 0.04) 0%, transparent 60%);
}
.tpl-vintage-parchment .editable-heading { font-family: 'Great Vibes', cursive; color: #78350f; }
.tpl-vintage-parchment .editable-body { font-family: 'Dancing Script', cursive; color: #44403c; font-size: 1.12rem; }
.tpl-vintage-parchment .editable-signature { font-family: 'Parisienne', cursive; color: #92400e; }
.tpl-vintage-parchment .corner-decor { border-color: #a8967b; }
.tpl-vintage-parchment .letter-divider { background: linear-gradient(90deg, transparent, #a8967b, transparent); }

/* Background image user-uploaded */
.letter-bg.has-custom-bg {
  background-size: cover !important;
  background-position: center !important;
}
.letter-bg.has-custom-bg + .letter-bg-overlay {
  background: rgba(0, 0, 0, 0.45) !important;
}

/* ═══════════════════════════════════════════
   DRAGGABLE / RESIZABLE IMAGES
   ═══════════════════════════════════════════ */
.draggable-image {
  position: absolute;
  z-index: 5;
  cursor: move;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}
.draggable-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  -webkit-user-drag: none;
}
.draggable-image .resize-handle,
.draggable-image .image-del-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.draggable-image:hover {
  outline: 1px dashed rgba(251, 113, 133, 0.5);
  outline-offset: 3px;
}
.draggable-image.selected {
  outline: 2px dashed var(--creator-accent);
  outline-offset: 3px;
}
.draggable-image.selected .resize-handle,
.draggable-image.selected .image-del-btn {
  opacity: 1;
  pointer-events: auto;
}
.draggable-image.dragging { cursor: grabbing; }
.draggable-image.dragging,
.draggable-image.resizing { outline-color: var(--creator-accent-dark); }

.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--creator-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  z-index: 6;
  touch-action: none;
}
.handle-nw { top: -8px; left: -8px; cursor: nwse-resize; }
.handle-ne { top: -8px; right: -8px; cursor: nesw-resize; }
.handle-sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.handle-se { bottom: -8px; right: -8px; cursor: nwse-resize; }

.image-del-btn {
  position: absolute;
  top: -34px;
  right: -8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: var(--creator-accent-dark);
  border: 2px solid #fff;
  color: #fff;
  cursor: pointer;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.18s;
}
.image-del-btn:hover { transform: scale(1.1); }

/* Larger touch targets on mobile */
@media (max-width: 640px) {
  .resize-handle { width: 18px; height: 18px; }
  .handle-nw { top: -10px; left: -10px; }
  .handle-ne { top: -10px; right: -10px; }
  .handle-sw { bottom: -10px; left: -10px; }
  .handle-se { bottom: -10px; right: -10px; }
  .image-del-btn { width: 30px; height: 30px; top: -40px; right: -10px; }
}

/* ═══════════════════════════════════════════
   ACTION ROW (above toolbar)
   ═══════════════════════════════════════════ */
.action-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 16px 14px 20px;
  flex-wrap: wrap;
  max-width: 620px;
  margin: 0 auto;
}
.creator-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 9999px;
  font-size: 0.83rem;
  font-weight: 500;
  border: 1px solid var(--creator-border-strong);
  background: var(--creator-surface);
  color: var(--creator-text);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  font-family: inherit;
}
.creator-btn svg { width: 16px; height: 16px; }
.creator-btn:hover {
  background: var(--creator-surface-hover);
  border-color: rgba(251, 113, 133, 0.5);
}
.creator-btn:active { transform: scale(0.97); }
.creator-btn-primary {
  background: linear-gradient(135deg, var(--creator-accent-dark), var(--creator-accent));
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(225, 29, 72, 0.32);
  color: #fff;
}
.creator-btn-primary:hover {
  background: linear-gradient(135deg, #c91041, var(--creator-accent));
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.45);
}

/* ═══════════════════════════════════════════
   FORMATTING TOOLBAR (bottom)
   ═══════════════════════════════════════════ */
.formatting-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: var(--toolbar-height);
  padding: 0 8px env(safe-area-inset-bottom, 0px);
  background: rgba(10, 5, 16, 0.92);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--creator-border);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
}
.formatting-toolbar::-webkit-scrollbar { display: none; }
.toolbar-btn-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.toolbar-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--creator-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.08s;
  position: relative;
  min-width: 48px;
  font-family: inherit;
  flex-shrink: 0;
}
.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--creator-text);
}
.toolbar-btn:active { transform: scale(0.94); }
.toolbar-btn.active {
  color: var(--creator-accent);
  background: rgba(251, 113, 133, 0.12);
}
.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.toolbar-btn svg { width: 20px; height: 20px; }
.toolbar-btn-label {
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  line-height: 1;
}
.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--creator-border);
  flex-shrink: 0;
  margin: 0 2px;
}

/* Character counter */
.char-counter {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
  margin-left: auto;
}
.char-counter .counter-num { font-size: 0.72rem; }
.char-counter.safe { color: #4ade80; }
.char-counter.warning { color: #fbbf24; }
.char-counter.danger { color: #f87171; }
.char-counter.full {
  color: #fff;
  background: rgba(239, 68, 68, 0.85);
}

/* ═══════════════════════════════════════════
   TOOLBAR DROPDOWNS / PANELS
   ═══════════════════════════════════════════ */
.toolbar-dropdown {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: rgba(20, 10, 25, 0.97);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--creator-border);
  border-radius: var(--radius-md);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s var(--ease), visibility 0s linear 0.18s;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
  z-index: 300;
  min-width: 200px;
  max-width: min(320px, calc(100vw - 24px));
}
.toolbar-dropdown.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
  transition: opacity 0.18s ease, transform 0.18s var(--ease), visibility 0s;
}
.toolbar-dropdown::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 11px;
  height: 11px;
  background: rgba(20, 10, 25, 0.97);
  border-right: 1px solid var(--creator-border);
  border-bottom: 1px solid var(--creator-border);
}

/* Sheet dropdowns: re-parented to body so they can't be clipped by the
   toolbar's horizontal overflow. Pinned above the toolbar, centered. */
.toolbar-dropdown--sheet {
  position: fixed;
  bottom: calc(var(--toolbar-height) + env(safe-area-inset-bottom, 0px) + 10px);
  z-index: 350;
}
.toolbar-dropdown--sheet::after { display: none; }

/* Font picker dropdown */
.font-option {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--creator-text);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
  font-size: 0.95rem;
}
.font-option:hover { background: rgba(255, 255, 255, 0.06); }
.font-option.selected {
  background: rgba(251, 113, 133, 0.12);
  color: var(--creator-accent);
}

/* Color picker */
.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.color-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
}
.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

/* Music / download list option */
.music-track-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: transparent;
  color: var(--creator-text);
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.music-track-option:hover { background: rgba(255, 255, 255, 0.06); }
.music-track-option.playing { background: rgba(251, 113, 133, 0.12); }
.music-track-option .track-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--creator-accent-dark), var(--creator-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.music-track-option .track-info { flex: 1; min-width: 0; }
.music-track-option .track-name {
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.music-track-option .track-artist {
  font-size: 0.66rem;
  color: var(--creator-muted);
}

/* ═══════════════════════════════════════════
   EMOJI PICKER
   ═══════════════════════════════════════════ */
.emoji-dropdown {
  padding: 0 !important;
  min-width: 0 !important;
  overflow: hidden;
}
.emoji-dropdown::after { display: none; }
emoji-picker {
  --background: rgba(20, 10, 25, 0.98);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-size: 0;
  --button-active-background: rgba(251, 113, 133, 0.18);
  --button-hover-background: rgba(255, 255, 255, 0.06);
  --category-emoji-padding: 0.4rem;
  --emoji-padding: 0.4rem;
  --emoji-size: 1.4rem;
  --indicator-color: var(--creator-accent, #fb7185);
  --input-border-color: rgba(255, 255, 255, 0.12);
  --input-border-radius: 10px;
  --input-font-color: #fff;
  --input-padding: 0.5rem 0.7rem;
  --input-placeholder-color: rgba(255, 255, 255, 0.4);
  --num-columns: 7;
  --outline-color: rgba(251, 113, 133, 0.4);
  --skintone-border-radius: 8px;
  width: 320px;
  height: 360px;
  display: block;
  border-radius: var(--radius-md);
}
@media (max-width: 480px) {
  emoji-picker {
    width: min(290px, calc(100vw - 32px));
    height: 320px;
    --emoji-size: 1.25rem;
  }
}

/* ═══════════════════════════════════════════
   STICKER GRID
   ═══════════════════════════════════════════ */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.sticker-option {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--creator-border);
  border-radius: 9px;
  cursor: pointer;
  padding: 5px;
  transition: background 0.12s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sticker-option:hover {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.35);
}
.sticker-option:active { transform: scale(0.92); }
.sticker-option img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* ═══════════════════════════════════════════
   PREVIEW MODAL
   ═══════════════════════════════════════════ */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  padding: 20px;
}
.preview-modal.active {
  opacity: 1;
  visibility: visible;
}
.preview-modal .preview-content {
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.94);
  transition: transform 0.25s var(--ease);
}
.preview-modal.active .preview-content { transform: scale(1); }
.preview-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--creator-border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.preview-close:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--creator-accent);
}

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */
.toast {
  position: fixed;
  top: calc(var(--header-height) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  background: rgba(20, 10, 25, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--creator-border);
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--creator-text);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 24px);
}
.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.toast-success { border-color: rgba(74, 222, 128, 0.55); }
.toast-error { border-color: rgba(248, 113, 113, 0.6); }

/* ═══════════════════════════════════════════
   PROGRESS MODAL
   ═══════════════════════════════════════════ */
.progress-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  padding: 20px;
}
.progress-modal.active {
  opacity: 1;
  visibility: visible;
}
.progress-content {
  background: rgba(20, 10, 25, 0.97);
  border: 1px solid var(--creator-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.progress-modal .spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(251, 113, 133, 0.2);
  border-top-color: var(--creator-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }
.progress-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--creator-text);
}
.progress-text {
  font-size: 0.83rem;
  color: var(--creator-muted);
}
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--creator-accent-dark), var(--creator-accent));
  transition: width 0.25s ease;
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (min-width: 768px) {
  .creator-header { padding: 0 24px; }
  .editor-container { padding: 8px 20px 20px; }
  .letter-preview-card .letter-content { padding: 40px 32px; }
  .editable-heading { font-size: 2.4rem; margin-bottom: 22px; }
  .editable-body { font-size: 1.1rem; }
  .editable-signature { font-size: 1.6rem; }
  .template-card { width: 88px; height: 110px; }
  .formatting-toolbar { padding: 0 16px env(safe-area-inset-bottom, 0px); gap: 4px; justify-content: center; }
  .char-counter { margin-left: 12px; }
}

@media (max-width: 480px) {
  .creator-header .page-title { font-size: 1.4rem; }
  .editable-heading { font-size: 1.7rem; margin-bottom: 14px; }
  .editable-body { font-size: 0.98rem; line-height: 1.75; min-height: 160px; }
  .editable-signature { font-size: 1.3rem; }
  .letter-preview-card .letter-content { padding: 26px 20px; min-height: 420px; }
  .letter-preview-card { min-height: 420px; }
  .corner-decor { width: 30px; height: 30px; }
  .action-row { padding: 12px 14px 18px; gap: 6px; }
  .creator-btn { padding: 9px 14px; font-size: 0.78rem; }
  .toolbar-dropdown { min-width: 180px; }
}

@media (max-width: 380px) {
  .toolbar-btn { padding: 6px 8px; min-width: 40px; }
  .toolbar-btn-label { display: none; }
  .toolbar-btn svg { width: 19px; height: 19px; }
  .toolbar-separator { margin: 0 1px; }
  .template-card { width: 72px; height: 92px; }
}

/* ═══════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
