:root {
  --bg: #1b1d22;
  --workspace: #14161a;
  --panel: #232730;
  --panel-2: #2b3038;
  --rail: #1e2228;
  --border: #353b45;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #ec4899; /* the single brand accent (matches the Pictools gradient) */
  --danger: #ff5a52;
  --sheet-h: 54dvh; /* height of the mobile bottom sheet (photo fits above it) */
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
/* 100dvh (dynamic viewport height) so the bottom dock/status bar aren't hidden behind the
   mobile browser's address bar; 100vh is the fallback for older browsers. */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---- Scrollbars: thin, floating, transparent track (no ugly white gutters) ---- */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.22) transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border: 3px solid transparent;     /* padding around the thumb -> floating look */
  border-radius: 8px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.34); background-clip: padding-box; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 46px;
  padding: 0 12px;
  background: var(--rail);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { font-weight: 700; letter-spacing: 0.3px; }
.brand span { color: var(--accent); margin: 0 2px; }
.topbar-group { display: flex; align-items: center; gap: 6px; }
.opt-label { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.topselect { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font-size: 12px; }
.status { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Body layout ---- */
.body { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---- Center column: image area + docked controls below it ---- */
.center { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ---- Snapseed-style Tools grid sheet ---- */
.toolsheet {
  position: absolute; inset: 0;
  z-index: 25;
  background: transparent; /* keep the image visible above the grid */
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.toolgrid {
  width: 100%;
  max-height: 82%;
  overflow-y: auto;
  background: #232730db; /* translucent — the photo shows through */
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 8px 8px 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.55);
}
@media (min-width: 760px) {
  .toolgrid { grid-template-columns: repeat(6, 1fr); max-width: 760px; border-radius: 16px; margin-bottom: 10px; }
}
.toolgroup { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 12px 6px 2px; }
.toolitem {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 13px 4px;
  background: transparent; border: none; color: var(--text);
  cursor: pointer; border-radius: 10px;
}
.toolitem:hover { background: var(--panel-2); }
.toolitem .ic { font-size: 22px; line-height: 1; height: 24px; display: grid; place-items: center; }
.toolitem .lb { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; }

/* The dock sits below the image (not over it): active control, pill strip, main tab menu —
   each a centered, horizontally-scrollable row, like the Android photo editor. */
.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 10px;
  background: var(--rail);
  border-top: 1px solid var(--border);
}
.tabbar { display: flex; align-items: center; justify-content: safe center; gap: 4px; align-self: stretch; max-width: 100%; overflow-x: auto; padding: 2px 4px; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 16px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--accent); }
.workspace { position: relative; }
.mode-label { position: absolute; top: 10px; left: 14px; z-index: 30; font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 7px; }
.mode-label::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
/* Busy: a filter frame is rendering in the fx worker. */
.mode-label.busy::after {
  content: "";
  width: 12px; height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  margin-left: 4px;
  animation: fxspin 0.7s linear infinite;
}
@keyframes fxspin { to { transform: rotate(360deg); } }
.modal-actions { justify-content: space-between; align-items: center; padding: 4px 14px; }
.modal-actions .modal-mid { display: flex; align-items: center; gap: 18px; }
/* Bigger undo/redo/compare in the middle */
.modal-actions .modal-mid .btn { flex: 0 0 auto; width: 46px; height: 44px; font-size: 23px; padding: 0; background: transparent; border-color: transparent; }
/* Compact, background-less cancel/apply pinned to the far edges */
.modal-actions .btn.lg { flex: 0 0 auto; width: 40px; height: 40px; font-size: 22px; padding: 0; background: transparent; border: none; }
#modalApply { color: #5ad27a; }
#modalCancel { color: var(--muted); }
/* No global toolbar while inside a tool session (Social, Healing, …) */
.app.social-mode .topbar { display: none; }
.optrow { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 92vw; }
.optbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 52px; padding: 6px 8px; background: var(--panel-2); border: 2px solid var(--border); border-radius: 10px; color: var(--text); cursor: pointer; }
.optbtn .opt-ic { font-size: 18px; line-height: 1; }
.optbtn .opt-lb { font-size: 10px; color: var(--muted); white-space: nowrap; }
.optbtn.sel { border-color: #ec4899; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; padding: 0; }
.swatch.sel { border-color: #ec4899; box-shadow: 0 0 0 2px rgba(236,72,153,0.35); }
/* safe center: when the strip overflows, fall back to flex-start so the left end
   stays scroll-reachable (plain `center` strands half the chips off-screen left). */
.optrow.txtrow { flex-wrap: nowrap; overflow-x: auto; max-width: 96vw; scrollbar-width: none; padding-bottom: 2px; justify-content: safe center; }
.optrow.txtrow::-webkit-scrollbar { display: none; }
.txtpreset { flex: 0 0 auto; min-width: 54px; height: 52px; padding: 2px 10px 4px; background: #40454e; border: 2px solid transparent; border-radius: 8px; color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.txtpreset .ag { font-size: 19px; line-height: 1.15; }
.txtpreset .nm { font-family: system-ui, sans-serif; font-size: 8.5px; line-height: 1; color: var(--muted); letter-spacing: 0; white-space: nowrap; }
.txtpreset.sel { border-color: #ec4899; }
.txtpreset[data-frame] { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.45); }
.txtpreset[data-frame="circle"], .txtpreset[data-frame="hex"] { border-radius: 50%; }
.optbtn.sel .opt-lb { color: var(--text); }
/* Preset picker tiles: pink border on the current preset + a small dimensions line. */
#presetgrid .toolitem { border: 2px solid transparent; border-radius: 12px; }
#presetgrid .toolitem.sel { border-color: #ec4899; }
#presetgrid .toolitem .dim { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
#presetgrid .toolitem.sel .lb { color: var(--text); }
/* Subtle purple tint on the canvas area while in the Social preset editor. */
.workspace { transition: background-color 0.25s ease; }
.app.social-mode .workspace { background-color: #191426; }
.app.social-mode .dock { background: linear-gradient(0deg, rgba(139, 61, 255, 0.06), transparent); }

.contextbar {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 8px;
  align-self: stretch;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 16px;
  scrollbar-width: none;
  /* edge fade = "there's more, scroll" affordance on narrow screens */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.contextbar::-webkit-scrollbar { display: none; }
.chip {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 7px 14px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  flex: 0 0 auto;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.go { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.chip.danger { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.4); }
.ctx-mini {
  display: flex; flex-direction: column; gap: 3px; min-width: 138px; flex: 0 0 auto;
  font-size: 11px; color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 12px;
}
.ctx-mini > span { display: flex; justify-content: space-between; }
.ctx-mini output { font-variant-numeric: tabular-nums; color: var(--muted); }
.ctx-mini input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }

/* The active single-control block (e.g. an Adjust slider), centered above the pill strip. */
.ctxcontrol { display: flex; justify-content: safe center; align-self: stretch; max-width: 100%; overflow-x: auto; padding: 0 8px; scrollbar-width: none; }
.ctxcontrol::-webkit-scrollbar { display: none; }
.ctxcontrol .ctrl {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text);
}
.ctxcontrol .ctrl > span { white-space: nowrap; }
.ctxcontrol .ctrl input[type="range"] { width: min(240px, 38vw); min-width: 96px; accent-color: var(--accent); }
.ctxcontrol .ctrl output { min-width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctxcontrol .ctrl .chip { padding: 5px 11px; }
.ctxcontrol .ctrl.propctrl { flex-wrap: wrap; max-width: 94vw; row-gap: 8px; column-gap: 14px; justify-content: center; }
.ctxcontrol .ctrl.propctrl .field, .ctxcontrol .ctrl.propctrl .check { gap: 6px; font-size: 12px; }
.ctxcontrol .ctrl.propctrl .field > span { white-space: nowrap; }
.ctxcontrol .ctrl.propctrl input[type="color"] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.ctxcontrol .ctrl.propctrl input[type="number"] { width: 60px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 4px 6px; font: inherit; }
.ctxcontrol .ctrl.propctrl select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.ctxcontrol .ctrl input[type="number"] { width: 64px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 4px 6px; font: inherit; }
.ctxcontrol .ctrl .lockchk { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); }

/* Curves session: the tone block moves into the dynamic control area. */
.ctxcontrol .tone {
  width: min(440px, 92vw);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

/* Layers sheet: the layer stack as a bottom overlay (same surface as the Tools sheet). */
.layersheet-body {
  width: 100%;
  background: #232730db;
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  max-height: 55dvh;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.55);
}
.layersheet-body .toolgroup { margin-bottom: 8px; }
@media (min-width: 760px) {
  .layersheet-body { max-width: 480px; border-radius: 14px; margin-bottom: 10px; }
}

/* ---- Bottom status / zoom bar ---- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 28px;
  padding: 0 12px;
  background: var(--rail);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.statusbar .status { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.zoombar { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.zbtn {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 5px;
  height: 22px;
  min-width: 24px;
  padding: 0 6px;
  font-size: 13px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.zbtn:hover { background: var(--panel-2); }
.zbtn.zlevel { min-width: 54px; font-size: 12px; }
.zbtn.ztext { font-size: 11px; color: var(--muted); }
.zbtn.ztext:hover { color: var(--text); }

.toolrail {
  width: 48px;
  flex: 0 0 auto;
  background: var(--rail);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}
.tool {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 17px;
  cursor: pointer;
}
.tool:hover { background: var(--panel-2); }
.tool.tool-on { background: var(--accent); color: #fff; }
.tool-sep { width: 24px; height: 1px; background: var(--border); margin: 4px 0; }

.workspace {
  flex: 1;
  min-width: 0;
  background:
    linear-gradient(45deg, #101216 25%, transparent 25%) -10px 0 / 20px 20px,
    linear-gradient(-45deg, #101216 25%, transparent 25%) -10px 0 / 20px 20px,
    linear-gradient(45deg, transparent 75%, #101216 75%) -10px 0 / 20px 20px,
    linear-gradient(-45deg, transparent 75%, #101216 75%) -10px 0 / 20px 20px,
    var(--workspace);
  display: flex;
  overflow: auto;
  padding: 24px;
  touch-action: none; /* we handle pinch-zoom/pan ourselves */
}
/* margin:auto centers the stage in the flex container without clipping when it overflows (zoom). */
.stage { position: relative; margin: auto; width: min(100%, 860px); flex: 0 0 auto; box-shadow: 0 8px 40px rgba(0,0,0,0.5); }
.stage #canvas { width: 100%; height: auto; display: block; }
.stage #overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
.stage.cropping #overlay { pointer-events: auto; cursor: crosshair; }
.stage.moving:not(.cropping) #overlay { pointer-events: auto; }

/* On-canvas text editor */
.text-edit {
  position: absolute;
  background: rgba(20, 22, 28, 0.4);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 3px;
  outline: none;
  padding: 0;
  margin: 0;
  resize: none;
  line-height: 1.2;
  font-family: inherit;
  overflow: hidden;
}

/* ---- Panels (right) ---- */
/* Retired: the desktop accordion panels. The DOM stays as the state store for the dock's
   proxied controls (sliders, curve data, export fields), but it is never shown — the dock
   is the single UI on every viewport. */
.panels { display: none !important; }
.panel { border-bottom: 1px solid var(--border); }
.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▸"; font-size: 10px; transition: transform 0.12s; }
.panel[open] > summary::before { transform: rotate(90deg); }
.panel > summary:hover { color: var(--text); }
.panel-body { padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.subhead { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-top: 4px; }

/* ---- Controls ---- */
.row { display: flex; gap: 6px; }
.row.buttons { display: flex; gap: 6px; }
.row.wrap { flex-wrap: wrap; }
.iconbar { display: flex; flex-wrap: wrap; gap: 4px; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  text-align: center;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost.tool-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.sm { padding: 6px 10px; font-size: 12px; flex: 0 0 auto; }
.btn.xs { padding: 5px 8px; font-size: 12px; flex: 0 0 auto; min-width: 30px; }
.btn.icon { width: 30px; padding: 6px 0; }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.slider { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.slider span { display: flex; justify-content: space-between; }
.slider output { color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.field > span { color: var(--muted); }
.field input[type="number"] { width: 72px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font-size: 12px; }
.slider textarea { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; font-size: 12px; resize: vertical; min-height: 40px; }

.fmt-row { border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; margin: 4px 0; }
.fmt-row > summary { cursor: pointer; padding: 6px 0; font-size: 12px; font-weight: 600; }
.fmt-rowbody { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 10px; }
.fmt-rowbody input[type="text"] { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; font-size: 12px; }
#formatBody select { max-width: 190px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.histmode { margin-left: auto; }

.dims { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.dims label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.dims input[type="number"], .field select, .dims select {
  width: 64px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font-size: 12px;
}
.field select { width: auto; flex: 1; }

.seg { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 2px; }
.seg button { flex: 1; background: transparent; color: var(--muted); border: none; border-radius: 5px; padding: 5px 0; font-size: 12px; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }

.tone #curve { width: 100%; height: auto; aspect-ratio: 280 / 170; background: #0f1115; border: 1px solid var(--border); border-radius: 7px; touch-action: none; cursor: crosshair; }

.hint { margin: 2px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ---- Layers list ---- */
.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.layer-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid transparent; border-radius: 6px; background: var(--panel-2); cursor: pointer; font-size: 12px; }
.layer-row:hover { border-color: var(--border); }
.layer-row.active { border-color: var(--accent); background: rgba(236, 72, 153, 0.12); }
.layer-row.photo { opacity: 0.85; font-style: italic; }
.layer-row input[type="checkbox"] { accent-color: var(--accent); }
.layer-row .layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .layer-kind { color: var(--muted); font-size: 10px; }
.layer-row.child { background: transparent; border-style: dashed; opacity: 0.92; }

#layerProps { display: flex; flex-direction: column; gap: 9px; }
#layerProps input[type="color"] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); cursor: pointer; }
#layerProps textarea { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; font-size: 12px; resize: vertical; min-height: 40px; }

/* ---- Responsive: phones/tablets — panels become a slide-up bottom sheet ---- */
.panels-toggle { display: none; }
.panels-header { display: none; } /* shown only on mobile (below) */
@media (max-width: 900px) {
  .panels-toggle { display: inline-flex; }
  .topbar { gap: 8px; padding: 0 8px; }
  .topbar-group { gap: 4px; }
  .toolrail { width: 44px; overflow-y: auto; }

  /* Right panels dock to the bottom as a swipe-up sheet, off-flow so the image fills width. */
  .panels {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    height: var(--sheet-h);
    z-index: 30;
    border-left: none;
    border-top: 1px solid var(--border);
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    transform: translateY(100%);
    transition: transform 0.22s ease;
    box-shadow: 0 -8px 34px rgba(0, 0, 0, 0.55);
  }
  .panels.open { transform: translateY(0); }
  /* When the sheet is open, shrink the photo to fit ABOVE it (so you can see edits live),
     and drop the bottom bar (the sheet's Done handles navigation). */
  .app.sheet-open .dock { display: none; }
  .app.sheet-open .workspace { flex: 0 0 auto; height: calc(100dvh - 46px - var(--sheet-h)); }
  /* Header with the tool name + a Done button so you can always get out. */
  .panels-header {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 3;
    padding: 10px 12px 10px 16px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    font-weight: 600; letter-spacing: 0.3px;
  }
  /* When a single tool is focused, show only that panel (not the whole stack). */
  .panels.solo-mode .panel { display: none; }
  .panels.solo-mode .panel.solo { display: block; }
  .panels.solo-mode .panel.solo > summary { display: none; } /* title is in the header already */
}
@media (max-width: 520px) {
  .brand { display: none; }
}

/* ---- Pictools branding ---- */
.brand-pictools {
  font-weight: 800; font-size: 17px; letter-spacing: -0.4px; white-space: nowrap;
  background: linear-gradient(90deg, #8b3dff, #ec4899);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-pictools span { -webkit-text-fill-color: var(--muted); color: var(--muted); font-weight: 700; }

/* ---- My Images gallery ---- */
.gallery { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; }
.gallery.hidden { display: none; }
.gallery-top {
  display: flex; align-items: center; gap: 12px;
  height: 56px; flex: 0 0 auto; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: var(--rail);
}
.gallery-toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px 2px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.gallery-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; padding: 12px 16px 110px; align-content: start;
}
.gal-card { position: relative; border-radius: 14px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); cursor: pointer; aspect-ratio: 1; }
.gal-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-card:hover { border-color: var(--accent); }
.gal-card .gal-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,0.7)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal-card .gal-del { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 8px; border: none; background: rgba(0,0,0,0.55); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 13px; opacity: 0; transition: opacity 0.15s; }
.gal-card:hover .gal-del { opacity: 1; }
.gallery-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.gallery-empty .big { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.gallery-actions {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, var(--bg) 34%);
}
.add-photo {
  flex: 1; border: none; cursor: pointer;
  background: linear-gradient(90deg, #8b3dff, #ec4899);
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: 0.3px;
  padding: 15px 12px; border-radius: 14px;
  box-shadow: 0 8px 22px rgba(160, 60, 220, 0.35);
}
.add-photo:hover { filter: brightness(1.06); }
.add-photo:active { transform: translateY(1px); }
.sample-btn {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); border-radius: 14px; padding: 8px 16px 8px 8px;
}
.sample-btn img { width: 30px; height: 30px; border-radius: 9px; object-fit: cover; display: block; }
.sample-btn:hover { border-color: var(--accent); }
.gal-cloud { font-size: 12px; color: var(--muted); padding: 2px 16px 0; }
.camera-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); border-radius: 14px; padding: 13px 16px;
}
.camera-btn:hover { border-color: var(--accent); }

/* ---- In-app camera ---- */
.camsheet { position: fixed; inset: 0; z-index: 120; background: #000; display: flex; flex-direction: column; }
.camsheet video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.camsheet video.mirror { transform: scaleX(-1); }
.cam-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 30px calc(16px + env(safe-area-inset-bottom, 0px));
  background: #000;
}
.cam-controls .btn { color: #fff; }
#camShutter {
  width: 66px; height: 66px; border-radius: 50%; cursor: pointer;
  border: 4px solid #fff; background: rgba(255, 255, 255, 0.28);
  transition: background 0.1s;
}
#camShutter:active { background: #fff; }

/* Bundled fonts (also used by the core text renderer) so previews/editor match. */
@font-face { font-family: ff-sans; src: url("assets/fonts/sans.ttf"); }
@font-face { font-family: ff-sans; font-weight: 700; src: url("assets/fonts/sans-bold.ttf"); }
@font-face { font-family: ff-serif; src: url("assets/fonts/serif.ttf"); }
@font-face { font-family: ff-serif; font-weight: 700; src: url("assets/fonts/serif-bold.ttf"); }
@font-face { font-family: ff-mono; src: url("assets/fonts/mono.ttf"); }
@font-face { font-family: ff-mono; font-weight: 700; src: url("assets/fonts/mono-bold.ttf"); }
@font-face { font-family: ff-gothic; src: url("assets/fonts/gothic.ttf"); }
@font-face { font-family: ff-gothic; font-weight: 700; src: url("assets/fonts/gothic-bold.ttf"); }
@font-face { font-family: ff-bookman; src: url("assets/fonts/bookman.ttf"); }
@font-face { font-family: ff-bookman; font-weight: 700; src: url("assets/fonts/bookman-bold.ttf"); }
@font-face { font-family: ff-palatino; src: url("assets/fonts/palatino.ttf"); }
@font-face { font-family: ff-palatino; font-weight: 700; src: url("assets/fonts/palatino-bold.ttf"); }
@font-face { font-family: ff-script; src: url("assets/fonts/script.ttf"); }
/* Google Fonts (OFL/Apache — assets/fonts/LICENSES.md). DOM previews must match
   what the Rust core renders, so these load the exact same TTFs. */
@font-face { font-family: ff-montserrat; src: url("assets/fonts/montserrat.ttf"); }
@font-face { font-family: ff-oswald; src: url("assets/fonts/oswald.ttf"); }
@font-face { font-family: ff-bebas; src: url("assets/fonts/bebas.ttf"); }
@font-face { font-family: ff-anton; src: url("assets/fonts/anton.ttf"); }
@font-face { font-family: ff-archivo; src: url("assets/fonts/archivo.ttf"); }
@font-face { font-family: ff-playfair; src: url("assets/fonts/playfair.ttf"); }
@font-face { font-family: ff-pacifico; src: url("assets/fonts/pacifico.ttf"); }
@font-face { font-family: ff-lobster; src: url("assets/fonts/lobster.ttf"); }
@font-face { font-family: ff-dancing; src: url("assets/fonts/dancing.ttf"); }
@font-face { font-family: ff-caveat; src: url("assets/fonts/caveat.ttf"); }
@font-face { font-family: ff-marker; src: url("assets/fonts/marker.ttf"); }
@font-face { font-family: ff-amatic; src: url("assets/fonts/amatic.ttf"); }
@font-face { font-family: ff-amatic; font-weight: 700; src: url("assets/fonts/amatic-bold.ttf"); }
@font-face { font-family: ff-righteous; src: url("assets/fonts/righteous.ttf"); }
@font-face { font-family: ff-bangers; src: url("assets/fonts/bangers.ttf"); }
@font-face { font-family: ff-vibes; src: url("assets/fonts/vibes.ttf"); }
