/* ── Thai Modern design system ───────────────────── */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&display=swap');

:root {
  --bg:           #FAF7F2;   /* jasmine cream */
  --surface:      #FFFFFF;
  --surface-alt:  #F4EFE6;
  --primary:      #E97132;   /* saffron */
  --primary-hover:#C95A1E;
  --primary-soft: rgba(233,113,50,0.10);
  --accent:       #D4A437;   /* gold */
  --text:         #1F1A14;
  --text-muted:   #736B5E;
  --text-faint:   #A89A82;
  --border:       #E8E2D8;
  --success:      #16a34a;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(31,26,20,0.05);
  --shadow-md: 0 4px 16px rgba(31,26,20,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'IBM Plex Sans Thai', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar workspace";
  -webkit-font-smoothing: antialiased;
}

/* ── Topbar (logo + ads) ─────────────────────────── */
.topbar {
  grid-area: topbar;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 78px;
}

.topbar .brand {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border);
}

.topbar .brand-logo { max-width: 180px; }

.ads-topbar {
  margin: 0;
  border: none;
  border-radius: 0;
  background: var(--surface);
  min-height: 78px;
  width: 100%;
}

/* Topbar hamburger menu + dropdown */
.topbar { grid-template-columns: 240px 1fr auto; }

.topbar-menu-btn {
  width: 42px;
  height: 42px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 14px;
  align-self: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.topbar-menu-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.topbar-menu {
  position: absolute;
  top: 80px;
  right: 14px;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 8px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.topbar-menu a:hover { background: var(--surface-alt); color: var(--text); }
.topbar-menu a svg { flex-shrink: 0; opacity: 0.7; }
.topbar-menu a:hover svg { opacity: 1; }

/* Privacy banner (home) */
.privacy-banner {
  background: #ECFDF3;
  color: #14532D;
  border: 1px solid #A7F3D0;
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.93rem;
  line-height: 1.55;
}

.privacy-banner svg { flex-shrink: 0; color: #16a34a; }
.privacy-banner b { color: #166534; }
.privacy-banner a { color: #166534; font-weight: 700; text-decoration: underline; margin-left: 4px; }

/* Content page (about, privacy, terms, help) */
.content-page { max-width: 760px; margin: 0 auto; }

.content-page h1 {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.02em;
}

.content-page .lead {
  font-size: 1.02rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 28px;
}

.content-page h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 36px;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.content-page h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 20px;
  margin-bottom: 8px;
}

.content-page p {
  line-height: 1.8;
  margin-bottom: 14px;
  color: var(--text-muted);
}

.content-page ul, .content-page ol {
  margin-left: 24px;
  margin-bottom: 14px;
}

.content-page li {
  line-height: 1.8;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.content-page .callout {
  background: var(--surface-alt);
  border-left: 3px solid var(--primary);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
  color: var(--text);
}

.content-page .callout b { color: var(--primary); }

.faq-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 12px;
  background: var(--surface);
}

.faq-item h3 { margin: 0 0 8px; color: var(--text); }
.faq-item p:last-child { margin-bottom: 0; }

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  position: sticky;
  top: 78px;
  align-self: start;          /* prevent grid from stretching cell height */
  height: calc(100vh - 78px); /* fixed height so internal scroll works */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: block;
  text-decoration: none;
  padding: 0 6px;
}

.brand-logo {
  width: 100%;
  height: auto;
  display: block;
  max-width: 200px;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 12px 6px;
}

.tools-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tool-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.tool-link svg { flex-shrink: 0; opacity: 0.8; }
.tool-link:hover { background: var(--surface-alt); color: var(--text); }
.tool-link:hover svg { opacity: 1; }

.tool-link.active {
  background: var(--primary);
  color: white;
  font-weight: 600;
}
.tool-link.active svg { opacity: 1; }

/* Tool group with expand sub-menu */
.tool-group { display: flex; flex-direction: column; }

.tool-link-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.tool-link-row .tool-link { flex: 1; min-width: 0; }

.tool-expand-btn {
  flex-shrink: 0;
  width: 30px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  padding: 0;
  line-height: 1;
}

.tool-expand-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.tool-submenu {
  display: flex;
  flex-direction: column;
  margin: 4px 0 6px 14px;
  border-left: 2px solid var(--border);
  padding-left: 4px;
}

.tool-submenu span {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: default;
}

.tool-submenu span::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  background: var(--text-faint);
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0 8px;
  font-size: 0.72rem;
  color: var(--text-faint);
}

/* ── Workspace ───────────────────────────────────── */
.workspace {
  grid-area: workspace;
  padding: 40px 40px 60px;
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  margin-bottom: 32px;
  text-align: center;
}

.page-header h1 {
  font-size: 2.3rem;
  font-weight: 700;
  margin-bottom: 14px;
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.98rem;
  line-height: 1.75;
}

.page-header p b {
  color: var(--text);
  font-weight: 600;
}

/* ── Drop zone ───────────────────────────────────── */
#drop-zone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 52px 32px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s, background 0.2s;
  cursor: default;
  margin-bottom: 24px;
}

#drop-zone.hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

#drop-zone.compact {
  padding: 22px 32px;
  gap: 0;
}

#drop-zone.compact .drop-icon { display: none; }
#drop-zone.compact .drop-hint { margin-top: 6px; }
#drop-zone.compact .format-hint { display: none; }

.drop-icon { margin-bottom: 16px; }

#selectBtn {
  display: inline-block;
  text-align: center;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 40px;
  border-radius: var(--radius-md);
  font-size: 1.02rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(233,113,50,0.28);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

#selectBtn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(233,113,50,0.35);
}
#selectBtn:active { transform: translateY(0); }

.drop-hint { color: var(--text-muted); font-size: 0.875rem; margin-top: 10px; }
.format-hint { color: var(--text-faint); font-size: 0.78rem; letter-spacing: 0.5px; margin-top: 6px; }

/* ── File section ────────────────────────────────── */
#file-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.file-area {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 20px 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#file-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 14px;
}

.file-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  transition: transform 0.15s, box-shadow 0.2s;
}

.file-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.file-card img {
  width: 100%;
  height: 112px;
  object-fit: cover;
  display: block;
}

.heic-thumb {
  width: 100%;
  height: 112px;
  background: linear-gradient(135deg, #F5E6CE, #E8D4A8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary-hover);
  letter-spacing: 3px;
}

.file-card-name {
  padding: 8px 10px 9px;
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(31,26,20,0.55);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  backdrop-filter: blur(4px);
  line-height: 1;
}

.file-card:hover .file-card-remove { opacity: 1; }

/* ── Action bar ──────────────────────────────────── */
.action-bar {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.add-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.add-more-btn:hover { background: var(--primary-soft); border-color: var(--primary); }

.file-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.progress-bar-wrap {
  width: 100%;
  height: 5px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 3px;
  width: 0%;
  transition: width 0.25s ease;
}

#progress-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

.convert-btn {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  padding: 15px 22px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(233,113,50,0.28);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.convert-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(233,113,50,0.35);
}
.convert-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.convert-btn.done {
  background: var(--success);
  box-shadow: 0 4px 14px rgba(22,163,74,0.3);
}

/* ── File card extras (compress) ─────────────────── */
.file-card-size {
  padding: 0 10px 9px;
  font-size: 0.68rem;
  color: var(--text-faint);
}

/* ── PDF: file card reorder ──────────────────────── */
.file-card.draggable { cursor: grab; }
.file-card.draggable:active { cursor: grabbing; }
.file-card.dragging { opacity: 0.4; }
.file-card.drag-over { outline: 2px dashed var(--primary); outline-offset: 2px; }

.page-num {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--primary);
  color: white;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  z-index: 2;
  pointer-events: none;
}

/* ── Quality selector (compress) ─────────────────── */
.quality-selector {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 0 4px;
}

.quality-label {
  font-size: 0.83rem;
  color: var(--text-muted);
  font-weight: 600;
}

.quality-buttons {
  display: flex;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}

.quality-btn {
  padding: 8px 24px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
  min-width: 88px;
  transition: background 0.15s, color 0.15s;
}

.quality-btn:not(:last-child) { border-right: 1px solid var(--border); }
.quality-btn:hover:not(.active) { background: var(--primary-soft); color: var(--primary); }
.quality-btn.active { background: var(--primary); color: white; }

.q-name { font-size: 0.875rem; font-weight: 600; }
.q-pct  { font-size: 0.7rem; opacity: 0.65; font-weight: 500; }
.quality-btn.active .q-pct { opacity: 0.95; }

/* Format-only button (used by HEIC → JPG/PNG/WEBP selector) */
.format-btn {
  padding: 10px 24px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  min-width: 80px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}
.format-btn:not(:last-child) { border-right: 1px solid var(--border); }
.format-btn:hover:not(.active) { background: var(--primary-soft); color: var(--primary); }
.format-btn.active { background: var(--primary); color: white; }

/* ── Resize selector (resize) ────────────────────── */
.resize-selector {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 0 4px;
}

.resize-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.scale-btn {
  padding: 9px 22px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-width: 76px;
  transition: background 0.15s, color 0.15s;
}

.scale-btn:not(:last-child) { border-right: 1px solid var(--border); }
.scale-btn:hover:not(.active) { background: var(--primary-soft); color: var(--primary); }
.scale-btn.active { background: var(--primary); color: white; }

.pixel-group { width: 100%; max-width: 360px; }

.pixel-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.pixel-inputs input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  outline: none;
  background: var(--surface);
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.pixel-inputs input::-webkit-outer-spin-button,
.pixel-inputs input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.pixel-inputs input:focus,
.pixel-inputs input:not(:placeholder-shown) { border-color: var(--primary); }

.pixel-x { color: var(--text-faint); font-weight: 600; font-size: 1rem; }

.pixel-hint {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-align: center;
  margin-top: 4px;
}

/* ── Crop stage (crop) ───────────────────────────── */
.crop-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.crop-image-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  background: var(--surface-alt);
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

#cropImg {
  display: block;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  -webkit-user-drag: none;
  user-select: none;
}

#cropBox {
  position: absolute;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(31,26,20,0.45);
  cursor: move;
  box-sizing: border-box;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border: 2px solid var(--primary);
  border-radius: 2px;
  box-sizing: border-box;
}

.crop-handle[data-h="nw"] { top: -7px; left: -7px; cursor: nwse-resize; }
.crop-handle[data-h="ne"] { top: -7px; right: -7px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { bottom: -7px; left: -7px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { bottom: -7px; right: -7px; cursor: nwse-resize; }
.crop-handle[data-h="n"]  { top: -7px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle[data-h="s"]  { bottom: -7px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle[data-h="w"]  { top: 50%; left: -7px; transform: translateY(-50%); cursor: ew-resize; }
.crop-handle[data-h="e"]  { top: 50%; right: -7px; transform: translateY(-50%); cursor: ew-resize; }

.crop-controls {
  width: 100%;
  max-width: 400px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.crop-controls h3 {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 700;
  margin-bottom: 2px;
}

.crop-field { display: flex; flex-direction: column; gap: 4px; }

.crop-field label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  padding-left: 4px;
}

.crop-field input {
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  outline: none;
  background: var(--surface);
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.crop-field input:focus { border-color: var(--primary); }
.crop-field input::-webkit-outer-spin-button,
.crop-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ── Edit page: toolbar ──────────────────────────── */
.edit-toolbar {
  width: 100%;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
}

.tool-tab {
  flex: 1;
  min-width: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.tool-tab:hover { background: var(--surface-alt); color: var(--primary); }
.tool-tab.active { background: var(--primary-soft); color: var(--primary); }

/* ── Edit page: tool panel ───────────────────────── */
.tool-panel { width: 100%; margin-bottom: 14px; }

.tool-panel.coming-soon {
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px 18px;
  text-align: center;
}
.tool-panel.coming-soon p { color: var(--text-faint); font-size: 0.9rem; }

/* ── Edit page: filter strip ─────────────────────── */
.filter-strip {
  width: 100%;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scrollbar-width: thin;
}

.filter-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.filter-item img {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  border: 3px solid transparent;
  display: block;
  transition: border-color 0.15s, transform 0.15s;
}

.filter-item:hover img { transform: translateY(-2px); }
.filter-item.active img { border-color: var(--primary); }

.filter-item span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  max-width: 78px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-item.active span { color: var(--primary); }

/* ── Edit page: Draw panel ───────────────────────── */
.draw-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.draw-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.draw-label {
  font-size: 0.83rem;
  color: var(--text-muted);
  font-weight: 600;
  min-width: 88px;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  transition: transform 0.1s;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { outline: 2px solid var(--primary); outline-offset: 2px; }

.color-custom-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  border: 2px dashed var(--border);
  background: linear-gradient(135deg, #ff0080, #ff8c00 50%, #40e0d0);
}

#customColor, #textCustomColor {
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  opacity: 0;
}

.draw-range { flex: 1; min-width: 120px; accent-color: var(--primary); }

.draw-hint { font-size: 0.78rem; color: var(--text-faint); text-align: center; }

.edit-stage.draw-mode #editCanvas {
  cursor: crosshair;
  touch-action: none;
}

/* ── Edit page: Text panel ───────────────────────── */
.text-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.text-input {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  background: var(--surface);
  transition: border-color 0.15s;
  width: 100%;
}
.text-input:focus { border-color: var(--primary); }

.text-font-select {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
}
.text-font-select:focus { border-color: var(--primary); }

.text-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  transition: transform 0.1s;
}
.text-color-swatch:hover { transform: scale(1.1); }
.text-color-swatch.active { outline: 2px solid var(--primary); outline-offset: 2px; }

.text-apply-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  align-self: center;
  transition: background 0.15s, transform 0.1s;
}
.text-apply-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.text-apply-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Edit page: Sticker panel ────────────────────── */
.sticker-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--bg);
  border-radius: 8px;
}

.sticker-item {
  font-size: 1.7rem;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif;
  transition: background 0.15s, border-color 0.15s;
}
.sticker-item:hover { background: var(--surface-alt); }
.sticker-item.active { border-color: var(--primary); background: var(--primary-soft); }

/* ── Edit page: Canvas wrap + overlays ───────────── */
.canvas-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}

#textOverlay {
  position: absolute;
  font-weight: 700;
  line-height: 1;
  white-space: pre;
  cursor: move;
  user-select: none;
  touch-action: none;
  outline: 2px dashed var(--primary);
  outline-offset: 3px;
  text-shadow: 0 0 4px rgba(0,0,0,0.15);
}

#stickerOverlay {
  position: absolute;
  line-height: 1;
  cursor: move;
  user-select: none;
  touch-action: none;
  outline: 2px dashed var(--primary);
  outline-offset: 4px;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif;
}

#wmOverlay {
  position: absolute;
  font-weight: 700;
  line-height: 1;
  white-space: pre;
  cursor: move;
  user-select: none;
  touch-action: none;
  outline: 2px dashed var(--primary);
  outline-offset: 3px;
}

/* ── Watermark: position preset grid ─────────────── */
.wm-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  transition: transform 0.1s;
}
.wm-color-swatch:hover { transform: scale(1.1); }
.wm-color-swatch.active { outline: 2px solid var(--primary); outline-offset: 2px; }

.wm-position-grid {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  gap: 4px;
}

.wm-pos-btn {
  width: 32px;
  height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.wm-pos-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.wm-pos-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Edit page: BG removal panel ─────────────────── */
.bg-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.bg-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.bg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(233,113,50,0.28);
  transition: background 0.15s, transform 0.1s;
}
.bg-action-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.bg-action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.bg-status {
  font-size: 0.83rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.2em;
}

/* ── Edit page: canvas stage ─────────────────────── */
.edit-stage {
  width: 100%;
  display: flex;
  justify-content: center;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
  line-height: 0;
  background-color: var(--surface-alt);
  background-image:
    linear-gradient(45deg, #E5DDCE 25%, transparent 25%),
    linear-gradient(-45deg, #E5DDCE 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #E5DDCE 75%),
    linear-gradient(-45deg, transparent 75%, #E5DDCE 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#editCanvas {
  display: block;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
}

/* ── Home: Hero ──────────────────────────────────── */
.home-workspace { max-width: 1180px; padding: 32px 40px 60px; }

/* Ads slot */
.ads-slot {
  width: 100%;
  min-height: 96px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  color: var(--text-faint);
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.hero {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 36px;
  align-items: start;
  margin-bottom: 56px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 18px;
}

.hero-title {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 18px;
  letter-spacing: -0.02em;
}

@media (min-width: 1100px) {
  .hero-title { font-size: 2.6rem; }
}

.hero-title .highlight { color: var(--primary); }

.hero-desc {
  color: var(--text-muted);
  font-size: 1.02rem;
  line-height: 1.7;
  margin-bottom: 22px;
}

.hero-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-feature {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.83rem;
  color: var(--text);
  font-weight: 500;
}

.hero-feature .check {
  color: #16a34a;
  font-weight: 700;
}

/* Hero-right popular tools panel */
.hero-tools-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 18px 20px;
}

.hero-tools-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.tools-grid-compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 1100px) {
  .tools-grid-compact { grid-template-columns: repeat(3, 1fr); }
}

.tools-grid-compact .tool-card {
  padding: 6px;
  gap: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: block;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.2s;
}

.tools-grid-compact .tool-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.tool-card-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

/* ── Home: Why us / features ─────────────────────── */
.why-us {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  margin-top: 40px;
}

.why-us h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: -0.01em;
}

.why-us-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.why-feature {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border-radius: 10px;
}

.why-feature .why-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.why-feature .why-text { display: flex; flex-direction: column; gap: 2px; }
.why-feature h3 { font-size: 0.92rem; font-weight: 700; }
.why-feature p { font-size: 0.78rem; color: var(--text-muted); line-height: 1.5; }

/* ── Home: Popular tools ─────────────────────────── */
.popular-tools { margin-top: 8px; }

.popular-tools-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}

.popular-tools h2 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.see-all-link {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.see-all-link:hover { color: var(--primary-hover); }

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 18px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.tool-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.tool-card-icon.icon-compress { background: #DCFCE7; color: #16a34a; }
.tool-card-icon.icon-resize   { background: #FEF3C7; color: #C9890E; }
.tool-card-icon.icon-convert  { background: #F3E8FF; color: #9333EA; }
.tool-card-icon.icon-crop     { background: #FCE7F3; color: #DB2777; }
.tool-card-icon.icon-edit     { background: #DBEAFE; color: #2563EB; }
.tool-card-icon.icon-bg       { background: #FEE2E2; color: #DC2626; }

.tool-card h3 {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.tool-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "sidebar"
      "workspace";
  }

  .topbar {
    grid-template-columns: 1fr;
    min-height: 64px;
  }
  .topbar .brand { border-right: none; padding: 10px 14px; }
  .topbar .brand-logo { max-width: 140px; }
  .ads-topbar { display: none; }   /* save space on mobile */

  .sidebar {
    flex-direction: row;
    position: sticky;
    top: 64px;
    height: auto;
    padding: 10px 14px;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 99;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-section-label, .sidebar-footer { display: none; }

  .tools-nav {
    flex-direction: row;
    gap: 4px;
    flex: 1;
  }

  .tool-link {
    padding: 7px 12px;
    font-size: 0.82rem;
    white-space: nowrap;
  }
  .tool-link svg { display: none; }

  .workspace { padding: 28px 16px 48px; }
  .home-workspace { padding: 28px 16px 48px; }
  .page-header h1 { font-size: 1.7rem; }

  #drop-zone { padding: 36px 20px 28px; }

  .hero {
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 36px;
  }
  .hero-title { font-size: 1.85rem; }
  .hero-desc { font-size: 0.95rem; }
}

/* ── Tool SEO content section (below tool widget) ── */
.tool-seo {
  max-width: 760px;
  margin: 56px auto 0;
  padding: 32px 0;
  border-top: 1px solid var(--border);
}

.tool-seo h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.tool-seo h3 {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 28px 0 10px;
  color: var(--text);
}

.tool-seo p {
  line-height: 1.8;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.tool-seo p b { color: var(--text); }

.tool-seo ol, .tool-seo ul {
  padding-left: 22px;
  margin: 0 0 12px;
}

.tool-seo li {
  line-height: 1.85;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.tool-faq {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
  background: var(--surface);
  transition: border-color .15s;
}

.tool-faq[open] { border-color: var(--primary); }

.tool-faq summary {
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  list-style: none;
  position: relative;
  padding-right: 28px;
}

.tool-faq summary::-webkit-details-marker { display: none; }

.tool-faq summary::after {
  content: "+";
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.4rem;
  color: var(--primary);
  font-weight: 400;
  line-height: 1;
}

.tool-faq[open] summary::after { content: "−"; }

.tool-faq p {
  margin: 12px 0 0;
  line-height: 1.75;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .tool-seo { margin-top: 36px; padding: 24px 0; }
  .tool-seo h2 { font-size: 1.25rem; }
}

/* ── PWA smart install card (bottom-right, dismissable, after engagement) ── */
.pwa-install-card {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 380px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(31, 26, 20, 0.15);
  font-family: inherit;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .25s ease, transform .25s ease;
}

.pwa-install-card.show {
  opacity: 1;
  transform: translateY(0);
}

.pwa-install-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 10px;
}

.pwa-install-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.pwa-install-text b {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.pwa-install-text span {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.pwa-install-cta {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.pwa-install-cta:hover { background: var(--primary-hover); }

.pwa-install-close {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-faint);
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.pwa-install-close:hover {
  background: var(--surface-alt);
  color: var(--text);
}

@media (max-width: 480px) {
  .pwa-install-card {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
    padding: 12px 14px;
    gap: 10px;
  }
  .pwa-install-icon { width: 36px; height: 36px; }
  .pwa-install-text b { font-size: 0.88rem; }
  .pwa-install-text span { font-size: 0.74rem; }
  .pwa-install-cta { padding: 7px 12px; font-size: 0.82rem; }
}

/* ────────────────────────────────────────────────────
   Templates Gallery (/templates)
   ──────────────────────────────────────────────────── */
.template-tabs {
  display: flex;
  gap: 8px;
  margin: 24px 0 28px;
  flex-wrap: wrap;
}

.template-tab {
  padding: 9px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}

.template-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.template-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 60px;
}

.template-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}

.template-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.template-card-canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface-alt);
}

.template-card-meta {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.template-card-cat {
  font-size: 0.74rem;
  color: var(--primary);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.template-card-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

/* ────────────────────────────────────────────────────
   Editor (/templates/editor)
   ──────────────────────────────────────────────────── */
.editor-body {
  display: flex !important;
  flex-direction: column;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
  grid-template-areas: none !important;
  background: var(--surface-alt);
  overflow: hidden;
  height: 100vh;
}

.editor-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.editor-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all .15s;
}

.editor-back:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.editor-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-download-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.editor-download-btn:hover { background: var(--primary-hover); }

.editor-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

.editor-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#editorCanvas {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  max-width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.editor-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Edit overlay (drag-to-pan photo slot) ── */
.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 80px 20px 180px;
}

.editor-overlay.show { display: flex; }

#overlayCanvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  touch-action: none;
  cursor: grab;
}

#overlayCanvas:active { cursor: grabbing; }

.editor-edit-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 18px 20px;
  z-index: 1001;
  display: none;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.15);
}

.editor-edit-panel.show { display: flex; }

.edit-panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.edit-panel-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.edit-panel-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.edit-btn {
  padding: 10px 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  min-width: 44px;
}

.edit-btn:hover { background: var(--border); }

.edit-btn-text { padding: 10px 14px; font-weight: 500; }

.edit-btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  flex: 1;
  min-width: 100px;
}

.edit-btn-primary:hover { background: var(--primary-hover); }

.edit-btn-danger {
  color: #DC2626;
  border-color: #FCA5A5;
}

.edit-btn-danger:hover { background: #FEE2E2; }

/* ── Text edit panel ── */
.editor-text-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 18px 20px;
  z-index: 1001;
  display: none;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.15);
}

.editor-text-panel.show { display: flex; }

.text-panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.text-panel-textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}

.text-panel-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.text-panel-controls {
  display: flex;
  gap: 8px;
}

@media (max-width: 768px) {
  .editor-topbar { padding: 10px 12px; gap: 10px; }
  .editor-back span { display: none; }
  .editor-title { font-size: 0.9rem; }
  .editor-download-btn span { display: none; }
  .editor-download-btn { padding: 10px 12px; }

  .templates-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

/* ── Shape selector buttons in editor ── */
.edit-panel-shape-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.edit-panel-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

.shape-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}

.shape-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.shape-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.shape-btn svg { display: block; }

/* Aspect ratio buttons (text-based) */
.shape-btn-text {
  width: auto;
  min-width: 56px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.edit-panel-shape-row {
  flex-wrap: wrap;
}
