/*
 * Squishless app (/app). Builds on tokens.css + base.css; only app layout and
 * app-specific pieces live here (stage, handles, filmstrip, presets, sheet).
 */

/* ===================== Page frame ===================== */
body.app { display: flex; flex-direction: column; min-height: 100dvh; }
body.app[data-view="editor"] { height: 100dvh; overflow: hidden; }

.app-header {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 3.75rem;
  padding: var(--space-2) var(--gutter);
  padding-top: max(var(--space-2), env(safe-area-inset-top));
  flex: none;
}
.app-header__nav { display: flex; align-items: center; gap: var(--space-1); margin-left: auto; }
.app-header__link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text); font-weight: var(--weight-medium); font-size: var(--text-sm);
  text-decoration: none;
}
.app-header__link:hover { background: var(--color-sunken); }
.app-header .btn--icon svg { width: 1.35em; height: 1.35em; }

.engine-chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 2rem; padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-sunken); color: var(--color-muted);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  animation: sq-pop-in var(--duration-slow) var(--ease-spring) both;
}
.engine-chip .spinner { width: 0.9em; height: 0.9em; border-width: 2px; }
.engine-chip[data-state="error"] { background: var(--color-danger-soft); color: var(--color-danger); padding-right: 4px; }
.engine-chip[data-state="error"] .btn { min-height: 1.6rem; padding: 0 var(--space-2); box-shadow: none; }

.app-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ===================== Welcome (empty state) ===================== */
.welcome {
  width: min(100% - 2 * var(--gutter), 56rem);
  margin: 0 auto;
  padding-block: var(--space-6) var(--space-8);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-6);
  text-align: center;
}
.welcome__intro { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.welcome__title { font-size: var(--text-3xl); max-width: 16ch; }
.welcome__lead { font-size: var(--text-lg); line-height: var(--leading-snug); color: var(--color-muted); max-width: 44ch; }

.welcome__drop {
  width: 100%;
  padding: var(--space-7) var(--space-5) var(--space-6);
  gap: var(--space-4);
  cursor: pointer;
}
.welcome__drop-title { font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--text-2xl); line-height: var(--leading-tight); }
.welcome__drop-hint { max-width: 48ch; }
/* Touch phones cannot drop files or press Ctrl+V: show "pick a photo" copy instead */
.welcome__touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .welcome__desk { display: none; }
  .welcome__touch { display: inline; }
}

/* A tiny photo that trims itself, forever (stopped for reduced motion) */
.welcome__drop-art { position: relative; width: 150px; height: 92px; display: grid; place-items: center; }
.welcome__drop-photo {
  position: relative;
  width: 132px; height: 84px;
  border: 3px solid var(--color-text);
  border-radius: 12px;
  box-shadow: 0 4px 0 0 var(--color-text);
  background:
    radial-gradient(circle at 50% 47%, var(--color-highlight) 0 9px, transparent 10px),
    radial-gradient(120% 70% at 50% 120%, var(--color-accent) 0 60%, transparent 61%),
    radial-gradient(90% 60% at 18% 110%, color-mix(in srgb, var(--color-accent) 55%, var(--color-surface)) 0 60%, transparent 61%),
    radial-gradient(90% 60% at 84% 108%, color-mix(in srgb, var(--color-accent) 55%, var(--color-surface)) 0 60%, transparent 61%),
    linear-gradient(var(--color-accent-soft), var(--color-surface));
  background-size: 132px 78px;
  background-position: center;
  background-repeat: no-repeat;
  justify-self: start;
  margin-left: 4px;
}
.welcome__drop-handle {
  position: absolute; top: 50%; left: 132px;
  width: 14px; height: 46px; margin: -23px 0 0 -3px;
  border-radius: var(--radius-pill);
  background: var(--raspberry-500); border: 3px solid var(--plum-950);
  box-shadow: 0 3px 0 0 var(--plum-950);
}
@media (prefers-reduced-motion: no-preference) {
  .welcome__drop-photo { animation: app-trim 3.6s var(--ease-in-out) infinite; }
  .welcome__drop-handle { animation: app-trim-handle 3.6s var(--ease-in-out) infinite; }
}
@keyframes app-trim { 0%, 18%, 100% { width: 132px; } 45%, 70% { width: 84px; } }
@keyframes app-trim-handle { 0%, 18%, 100% { left: 136px; } 45%, 70% { left: 88px; } }

.welcome__samples { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); width: 100%; }
.welcome__samples-title { font-family: var(--font-text); font-size: var(--text-md); font-weight: var(--weight-bold); }
.sample-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); width: 100%; }
.sample {
  position: relative;
  display: flex; flex-direction: column; gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  font-weight: var(--weight-bold); font-size: var(--text-sm);
  transition: transform var(--duration-slow) var(--ease-spring), background-color var(--duration-fast) ease;
}
.sample img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: var(--radius-md); border: 2px solid var(--color-text); box-shadow: 0 4px 0 0 var(--color-text); background: var(--color-sunken); }
.sample:hover { transform: translateY(-3px) rotate(-1deg); }
.sample:nth-child(even):hover { transform: translateY(-3px) rotate(1deg); }
.sample:active { transform: scale(0.97); }
.sample[aria-busy="true"] { pointer-events: none; }
.sample[aria-busy="true"] img { opacity: 0.6; }
.sample[aria-busy="true"]::after {
  content: ""; position: absolute; left: 50%; top: 38%; width: 1.6rem; height: 1.6rem; margin: -0.8rem;
  border-radius: 50%; border: 3px solid var(--color-text); border-right-color: transparent;
  animation: sq-spin 0.7s linear infinite;
}

.privacy {
  display: inline-flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-success-soft); color: var(--color-text);
  font-size: var(--text-sm); text-align: left;
}
.privacy svg { width: 1.5rem; height: 1.5rem; flex: none; color: var(--color-success); }

/* ===================== Editor layout ===================== */
.editor {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 23rem;
  gap: var(--space-4);
  padding: 0 var(--gutter) var(--space-4);
}
.workspace { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; min-height: 0; }

.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); min-height: var(--control-md); }
.toolbar__mark-short { display: none; }
.toolbar__views label:has(input:disabled), .preset:has(input:disabled) { opacity: 0.5; pointer-events: none; }
.toolbar__mark.has-marks::after {
  content: ""; position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-highlight); border: 2px solid var(--color-text);
}
.readout { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.readout__size { font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--text-xl); }
.subbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); animation: sq-pop-in var(--duration-base) var(--ease-out) both; }

.brushbar { padding: var(--space-2); border-radius: var(--radius-lg); background: var(--color-surface); border: var(--border-width) solid var(--color-border); }
.brushbar__tools span { gap: var(--space-2); }
.swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 50%; border: 2px solid var(--color-text); }
.swatch--keep { background: #22c578; }
.swatch--remove { background: repeating-linear-gradient(45deg, #ff3460 0 3px, #ffb3c3 3px 6px); }
.brushbar__size { display: flex; align-items: center; gap: var(--space-2); color: var(--color-muted); }
.brushbar__size svg { width: 1rem; height: 1rem; flex: none; }
.brushbar__size .range { width: 8.5rem; height: var(--control-sm); }
.brushbar__actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; padding-bottom: 4px; }
.brushbar__hint { flex-basis: 100%; padding: 0 var(--space-2) 2px; color: var(--color-muted); line-height: var(--leading-snug); }
.brushbar__hint strong { color: var(--color-text); }
.brushbar__hint .swatch { width: 0.7rem; height: 0.7rem; vertical-align: -0.05em; margin-right: 0.15em; }
.brushbar__hint .swatch + strong, .brushbar__hint .swatch { white-space: nowrap; }
.brushbar__hint .swatch--remove { margin-left: 0.4em; }

/* ===================== Stage ===================== */
.stage {
  position: relative;
  flex: 1; min-height: 14rem;
  border-radius: var(--radius-xl);
  background-color: var(--color-sunken);
  background-image: radial-gradient(circle, color-mix(in srgb, var(--color-text) 13%, transparent) 1.1px, transparent 1.6px);
  background-size: 20px 20px;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage__canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; }
.stage__bounds {
  position: absolute; z-index: 1;
  border: 2px dashed var(--color-border-strong);
  border-radius: 8px;
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--color-text) 7%, transparent) 0 2px, transparent 2px 11px);
  opacity: 0;
  transition: opacity var(--duration-base) ease;
  pointer-events: none;
}
.stage__bounds.is-visible { opacity: 1; }
.stage__frame {
  position: absolute; z-index: 3;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--color-text), 0 6px 0 0 color-mix(in srgb, var(--color-text) 85%, transparent), var(--shadow-3);
  pointer-events: none;
}
.stage:not(.has-photo) .stage__frame, .stage:not(.has-photo) .handle, .stage:not(.has-photo) .stage__bubble { display: none; }
.stage__overlay { position: absolute; z-index: 4; pointer-events: none; border-radius: 6px; }
.stage[data-mode="edit"] .stage__overlay { display: none; }

/* Handles: gummy pills that squish when grabbed */
.handle {
  position: absolute; left: 0; top: 0; z-index: 5;
  translate: -50% -50%;
  display: grid; place-items: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.handle--x { width: 44px; height: 76px; cursor: ew-resize; }
.handle--y { width: 76px; height: 44px; cursor: ns-resize; }
.handle--xy { width: 44px; height: 44px; cursor: nwse-resize; translate: -40% -40%; }
.handle:focus-visible { outline: none; }
.handle__grip {
  position: relative;
  display: block;
  border-radius: var(--radius-pill);
  background: var(--raspberry-500);
  border: 3px solid var(--plum-950);
  box-shadow: 0 3px 0 0 var(--plum-950), 0 6px 14px rgb(30 12 20 / 0.3);
  transition: transform var(--duration-slow) var(--ease-spring), background-color var(--duration-fast) ease;
}
.handle--x .handle__grip { width: 18px; height: 60px; }
.handle--y .handle__grip { width: 60px; height: 18px; }
.handle--xy .handle__grip { width: 22px; height: 22px; border-radius: 7px; background: #fff; }
/* grip ridges */
.handle--x .handle__grip::before, .handle--y .handle__grip::before {
  content: ""; position: absolute; inset: 0; margin: auto;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--plum-950) 0 2px, transparent 2px 5px, var(--plum-950) 5px 7px);
  opacity: 0.55;
}
.handle--x .handle__grip::before { width: 7px; height: 18px; }
.handle--y .handle__grip::before { width: 18px; height: 7px; background: linear-gradient(180deg, var(--plum-950) 0 2px, transparent 2px 5px, var(--plum-950) 5px 7px); }
.handle:hover .handle__grip { transform: scale(1.1); background: var(--raspberry-400); }
.handle--xy:hover .handle__grip { background: #fff; }
.handle--x.is-grabbed .handle__grip { transform: scale(1.3, 0.88); transition-duration: var(--duration-base); }
.handle--y.is-grabbed .handle__grip { transform: scale(0.88, 1.3); transition-duration: var(--duration-base); }
.handle--xy.is-grabbed .handle__grip { transform: scale(1.25) rotate(45deg); }
.handle:focus-visible .handle__grip { box-shadow: 0 0 0 3px var(--color-focus-halo), 0 0 0 6px var(--color-focus); }
.stage[data-mode="mark"] .handle, .stage.is-animating .handle { pointer-events: none; }
.stage[data-mode="mark"] .handle { opacity: 0; visibility: hidden; }

.stage__bubble {
  position: absolute; left: 0; top: 0; z-index: 6;
  padding: 0.2em 0.7em;
  border-radius: var(--radius-pill);
  background: var(--color-text); color: var(--color-bg);
  font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--text-sm);
  white-space: nowrap;
  opacity: 0;
  scale: 0.8;
  transition: opacity var(--duration-fast) ease, scale var(--duration-base) var(--ease-bounce);
  pointer-events: none;
}
.stage.is-dragging .stage__bubble, .stage.is-animating .stage__bubble { opacity: 1; scale: 1; }

.coach {
  position: absolute; left: 0; top: 0; z-index: 6;
  translate: calc(-100% - 22px) -50%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-text); color: var(--color-bg);
  font-weight: var(--weight-bold); font-size: var(--text-sm);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-2);
}
.coach::after {
  content: ""; position: absolute; right: -6px; top: 50%; width: 12px; height: 12px; margin-top: -6px;
  background: inherit; transform: rotate(45deg); border-radius: 2px;
}
@media (prefers-reduced-motion: no-preference) {
  .coach:not([hidden]) { animation: sq-pop-in var(--duration-slow) var(--ease-spring) 400ms both, app-coach 2.4s var(--ease-in-out) 1s infinite; }
  .stage.has-photo:has(.coach:not([hidden])) .handle--x .handle__grip { animation: app-wiggle 2.4s var(--ease-in-out) 1s infinite; }
}
@keyframes app-coach { 0%, 60%, 100% { margin-left: 0; } 30% { margin-left: -8px; } }
@keyframes app-wiggle { 0%, 60%, 100% { transform: none; } 20% { transform: translateX(-8px) scale(1.1, 0.95); } 40% { transform: translateX(2px); } }
.stage[data-mode="mark"] .coach, .stage:not(.has-photo) .coach { display: none; }

.stage__chips { position: absolute; left: var(--space-3); top: var(--space-3); z-index: 6; display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); pointer-events: none; max-width: calc(100% - 2 * var(--space-3)); }
.stage-chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 0.25em 0.75em;
  border-radius: var(--radius-pill);
  background: var(--color-scrim-label); color: var(--color-on-scrim);
  font-size: var(--text-xs); font-weight: var(--weight-bold);
  animation: sq-fade-in var(--duration-base) ease both;
}
.stage-chip .spinner { width: 0.9em; height: 0.9em; border-width: 2px; }
.stage-chip .chip-short, .brushbar__hint .chip-short { display: none; }

/* Progress ring for the exact result */
.job {
  position: absolute; right: var(--space-3); bottom: var(--space-3); z-index: 7;
  display: flex; align-items: center; gap: var(--space-2);
  padding: 4px 4px 4px 6px;
  border: var(--border-width) solid var(--color-text);
  border-radius: var(--radius-pill);
  background: var(--color-raised);
  box-shadow: 0 3px 0 0 var(--color-text), var(--shadow-2);
  animation: sq-pop-in var(--duration-slow) var(--ease-spring) 180ms both;
}
.job__ring { width: 30px; height: 30px; transform: rotate(-90deg); flex: none; }
.job__track, .job__fill { fill: none; stroke-width: 6; }
.job__track { stroke: var(--color-sunken); }
.job__fill { stroke: var(--color-accent); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset var(--duration-base) var(--ease-out); }
.job.is-indeterminate .job__ring { animation: sq-spin 1s linear infinite; }
.job.is-indeterminate .job__fill { transition: none; }
.job__text { font-weight: var(--weight-bold); font-size: var(--text-sm); min-width: 6.5em; font-variant-numeric: tabular-nums; }
.job__cancel { --btn-h: 2rem; }
.job__retry { --btn-h: 2rem; box-shadow: none; }
/* Cancelled: "Not resized [Resize]" in place of the ring */
.job.is-cancelled { padding-left: var(--space-4); }
.job.is-cancelled .job__ring { display: none; }
.job.is-cancelled .job__text { min-width: 0; }

.stage__cursor {
  position: absolute; left: 0; top: 0; z-index: 6;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px rgb(20 8 14 / 0.7), inset 0 0 0 1.5px rgb(20 8 14 / 0.7);
  pointer-events: none;
  opacity: 0;
}
.stage__cursor[data-tool="keep"] { background: rgb(34 197 120 / 0.25); }
.stage__cursor[data-tool="remove"] { background: rgb(255 52 96 / 0.25); }
.stage__cursor.is-on { opacity: 1; }
.stage[data-mode="mark"] { touch-action: none; cursor: crosshair; }
@media (pointer: fine) { .stage[data-mode="mark"] { cursor: none; } }

.stage__skeleton { position: absolute; inset: 12% 14%; z-index: 1; border-radius: var(--radius-lg); }
.notice {
  position: absolute; inset: 0; z-index: 8; margin: auto;
  width: min(100% - 2 * var(--space-4), 28rem); height: fit-content;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-6) var(--space-5);
  border: var(--border-width) solid var(--color-text);
  border-radius: var(--radius-xl);
  background: var(--color-raised);
  box-shadow: 0 6px 0 0 var(--color-text), var(--shadow-3);
  text-align: center;
  animation: sq-pop-in var(--duration-slow) var(--ease-spring) both;
}
.notice__title { font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--text-xl); line-height: var(--leading-snug); }
.notice__text { color: var(--color-muted); }
.notice__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); padding-bottom: 6px; }

/* ===================== Compare ===================== */
.compare-wrap { flex: 1; min-height: 14rem; display: flex; flex-direction: column; justify-content: center; }
/* Different shapes: the empty part of the frame reads as "trimmed away" (as in the editor),
   and each label stays on its own image (main.js sets the insets). */
.compare-wrap .compare__frame, .compare-wrap .compare__panel-frame {
  background-image: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--color-text) 7%, transparent) 0 2px, transparent 2px 11px);
}
.compare-wrap .compare__label--before { left: calc(var(--cmp-bx, 0%) + var(--space-3)); top: calc(var(--cmp-by, 0%) + var(--space-3)); }
.compare-wrap .compare__label--after { right: calc(var(--cmp-ax, 0%) + var(--space-3)); top: calc(var(--cmp-ay, 0%) + var(--space-3)); }
.compare-wrap .compare__panel:first-child .compare__label { left: calc(var(--cmp-bx, 0%) + var(--space-2)); top: calc(var(--cmp-by, 0%) + var(--space-2)); }
.compare-wrap .compare__panel:first-child .compare__dims { left: calc(var(--cmp-bx, 0%) + var(--space-2)); bottom: calc(var(--cmp-by, 0%) + var(--space-2)); }
.compare-wrap .compare__panel:last-child .compare__label { left: calc(var(--cmp-ax, 0%) + var(--space-2)); top: calc(var(--cmp-ay, 0%) + var(--space-2)); }
.compare-wrap .compare__panel:last-child .compare__dims { left: calc(var(--cmp-ax, 0%) + var(--space-2)); bottom: calc(var(--cmp-ay, 0%) + var(--space-2)); }
.compare-wrap__wait { display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-weight: var(--weight-medium); }

/* ===================== Filmstrip ===================== */
.filmstrip { display: flex; align-items: center; gap: var(--space-3); min-height: 5rem; }
.filmstrip__add {
  flex: none;
  display: grid; place-items: center;
  width: 4rem; height: 4rem;
  border: 2.5px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-muted);
  transition: transform var(--duration-slow) var(--ease-spring), border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.filmstrip__add svg { width: 1.6rem; height: 1.6rem; }
.filmstrip__add:hover { border-color: var(--color-text); color: var(--color-text); transform: rotate(-4deg); }
.filmstrip__add:active { transform: scale(0.92); }
.filmstrip__list {
  /* room for the remove badges: overflow-x also clips vertically */
  list-style: none; padding: 12px 14px 8px 4px; margin: 0;
  display: flex; gap: var(--space-3);
  overflow-x: auto; overscroll-behavior-x: contain;
  scrollbar-width: thin;
  min-width: 0;
}
.film { position: relative; flex: none; }
/* Only once, when the photo is added (re-renders must not replay it) */
.film.is-new { animation: sq-pop-in var(--duration-slow) var(--ease-spring) both; }
.film__thumb {
  position: relative; display: block;
  width: 4rem; height: 4rem;
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--color-border);
  overflow: hidden;
  background: var(--color-sunken);
  transition: transform var(--duration-slow) var(--ease-spring), border-color var(--duration-fast) ease, box-shadow var(--duration-base) var(--ease-bounce);
}
.film__img { width: 100%; height: 100%; }
.film__thumb:hover { transform: translateY(-2px); border-color: var(--color-text); }
.film.is-selected .film__thumb { border-color: var(--color-text); box-shadow: 0 4px 0 0 var(--color-accent); transform: translateY(-3px); }
.film__thumb:focus-visible { outline-offset: 2px; }
.film__badge {
  position: absolute; right: 3px; bottom: 3px;
  width: 1.25rem; height: 1.25rem;
  border-radius: 50%;
  display: none;
  border: 2px solid var(--color-text);
  background: var(--color-surface);
}
.film[data-status="working"] .film__badge {
  display: block;
  background: conic-gradient(var(--color-accent) calc(var(--p, 0) * 1%), var(--color-surface) 0);
}
.film[data-status="done"] .film__badge {
  display: block;
  background: var(--color-success);
  animation: sq-pop-in var(--duration-slow) var(--ease-spring) both;
}
.film[data-status="done"] .film__badge::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 0.55rem; height: 0.55rem;
  background: var(--color-on-status);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.film[data-status="toobig"] .film__badge, .film[data-status="error"] .film__badge {
  display: grid; place-items: center;
  background: var(--color-highlight);
}
.film[data-status="error"] .film__badge { background: var(--color-danger); }
.film[data-status="toobig"] .film__badge::after, .film[data-status="error"] .film__badge::after {
  content: "!"; font-weight: 900; font-size: 0.75rem; line-height: 1; color: var(--plum-950);
}
.film[data-status="error"] .film__badge::after { color: var(--color-on-status); }
.film[data-status="loading"] .film__thumb { animation: sq-shimmer 1.4s ease-in-out infinite; background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--color-surface) 70%, transparent) 50%, transparent 70%) var(--color-sunken); background-size: 250% 100%; }
.film.is-adjusted .film__thumb::before {
  content: ""; position: absolute; left: 4px; top: 4px; z-index: 1; width: 0.6rem; height: 0.6rem; border-radius: 50%;
  background: var(--color-highlight); border: 2px solid var(--color-text);
}
.film__remove {
  position: absolute; top: -8px; right: -10px;
  width: 1.6rem; height: 1.6rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--color-text); color: var(--color-bg);
  opacity: 0; scale: 0.6;
  transition: opacity var(--duration-fast) ease, scale var(--duration-base) var(--ease-bounce);
}
.film__remove svg { width: 0.9rem; height: 0.9rem; }
.film:hover .film__remove, .film:focus-within .film__remove, .film.is-selected .film__remove { opacity: 1; scale: 1; }
/* Bigger touch target, grown up and to the right (away from the thumbnail) */
.film__remove::before { content: ""; position: absolute; top: -10px; right: -12px; bottom: -4px; left: -4px; }
/* Touch: only the selected photo shows its X, so a tap on another thumbnail just selects it.
   (Removing can be undone from the toast.) */
@media (hover: none) { .film.is-selected .film__remove { opacity: 1; scale: 1; } .film:not(.is-selected):not(:focus-within) .film__remove { visibility: hidden; } }
body:not(.has-many) .filmstrip { min-height: 0; }

/* ===================== Panel ===================== */
.panel {
  display: flex; flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  scrollbar-width: thin;
}
.panel__grabber { display: none; }
.panel__section { padding: var(--space-4) var(--space-5); }
.panel__section + .panel__section, .panel__more > .panel__section:first-child:not([hidden]) { border-top: var(--border-width) solid var(--color-border); }
.panel__size { padding-top: var(--space-5); }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.panel__title { font-size: var(--text-xl); }
.panel__subtitle { font-family: var(--font-text); font-size: var(--text-md); font-weight: var(--weight-bold); margin-bottom: var(--space-3); }
.panel__note { font-variant-numeric: tabular-nums; text-align: right; }
.panel__more-btn { display: none; }
.panel__more > [hidden] { display: none; }

/* Presets */
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.preset {
  position: relative;
  display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); align-items: center; gap: var(--space-2);
  min-height: 3.5rem;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  transition: transform var(--duration-base) var(--ease-bounce), border-color var(--duration-fast) ease, background-color var(--duration-fast) ease, box-shadow var(--duration-base) var(--ease-bounce);
}
.preset input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.preset:hover { border-color: var(--color-border-strong); }
.preset:active { transform: scale(0.96); }
.preset:has(input:checked) {
  border-color: var(--color-text);
  background: var(--color-accent-soft);
  box-shadow: 0 3px 0 0 var(--color-text);
  transform: translateY(-1px);
}
.preset:has(input:focus-visible) { outline: 3px solid var(--color-focus); outline-offset: 2px; }
.preset__glyph { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; }
.preset__shape {
  display: block; width: 26px; height: 18px;
  border: 2.5px solid var(--color-text);
  border-radius: 4px;
  background: var(--color-surface);
  transition: background-color var(--duration-fast) ease;
}
.preset__shape--original { width: 28px; height: 20px; background: linear-gradient(transparent 55%, var(--color-sunken) 55%); }
.preset__shape--custom { width: 22px; height: 22px; border-style: dashed; }
.preset:has(input:checked) .preset__shape { background: var(--color-accent); }
@media (prefers-reduced-motion: no-preference) {
  .preset:has(input:checked) .preset__shape { animation: app-squish var(--duration-slow) var(--ease-out) both; }
}
@keyframes app-squish { 30% { transform: scale(1.3, 0.75); } 60% { transform: scale(0.88, 1.12); } 100% { transform: none; } }
.preset__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.preset__name { font-weight: var(--weight-bold); font-size: var(--text-sm); }
.preset__ratio { font-weight: var(--weight-bold); color: var(--color-text); }
.preset__use { font-size: var(--text-xs); color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.adjusted {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-warning-soft);
}

/* Custom size */
.custom__modes { width: 100%; }
.custom__fields { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: var(--space-2); margin-block: var(--space-3) var(--space-2); }
.custom__lock { margin-bottom: 4px; }
.custom__lock svg { opacity: 0.55; }
.custom__lock[aria-pressed="true"] svg { opacity: 1; }
.custom[data-mode="width"] .custom__h, .custom[data-mode="width"] .custom__lock,
.custom[data-mode="height"] .custom__w, .custom[data-mode="height"] .custom__lock { display: none; }
.custom[data-mode="width"] .custom__fields, .custom[data-mode="height"] .custom__fields { grid-template-columns: minmax(0, 1fr); }

/* Fine-tune */
.fine { padding-block: 0; }
.fine__summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 3.25rem;
  font-weight: var(--weight-bold);
  cursor: pointer;
  list-style: none;
}
.fine__summary::-webkit-details-marker { display: none; }
.fine__summary svg { width: 1.25rem; height: 1.25rem; transition: transform var(--duration-slow) var(--ease-spring); }
.fine[open] .fine__summary svg { transform: rotate(180deg); }
.fine__summary:focus-visible { outline-offset: -3px; border-radius: var(--radius-sm); }
.fine__body { display: flex; flex-direction: column; gap: var(--space-4); padding-bottom: var(--space-4); }
.fine__body > .btn { align-self: flex-start; }
.fine__row { display: flex; flex-direction: column; gap: 2px; }
.fine__row--switch { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-4); cursor: pointer; }
.fine__label { display: flex; flex-direction: column; gap: 2px; }
.fine__label-row { display: flex; align-items: center; justify-content: space-between; }

/* Save */
.save__formats { width: 100%; }
.save .hint { margin-top: var(--space-2); }
.save__quality { margin-top: var(--space-3); }
.shortcuts { padding: 0 var(--space-5) var(--space-4); }
.shortcuts__all, .shortcuts__brush { white-space: nowrap; }

/* Actions (sticky at the bottom of the panel) */
.panel__actions {
  position: sticky; bottom: 0; z-index: 2;
  margin-top: auto;
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4) var(--space-5) calc(var(--space-4) + 4px);
  border-top: var(--border-width) solid var(--color-border);
  background: var(--color-surface);
}
.panel__buttons { display: flex; flex-direction: column; gap: var(--space-3); }
/* Desktop: a fade above the sticky buttons while settings are scrolled out of view */
@media (min-width: 1024px) {
  .panel__actions::before {
    content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 2.75rem;
    margin-bottom: var(--border-width);
    background: linear-gradient(to bottom, color-mix(in srgb, var(--color-surface) 0%, transparent), var(--color-surface) 85%);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--duration-base) ease;
  }
  .panel.has-more-below .panel__actions::before { opacity: 1; }
  .panel.has-more-below .panel__actions { box-shadow: 0 -6px 12px -8px rgb(30 12 20 / 0.25); }
}
.batchbar { display: flex; align-items: center; gap: var(--space-3); }
.label-short { display: none; }
.batchbar .progress { flex: 1; }

/* ===================== Drop overlay ===================== */
.drop-overlay {
  position: fixed; inset: var(--space-3); z-index: var(--z-overlay);
  display: none; place-items: center;
  border: 3px dashed var(--color-accent-text);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--color-accent-soft) 88%, transparent);
  font-family: var(--font-display); font-size: var(--text-2xl); font-weight: var(--weight-display);
  pointer-events: none;
}
body.is-dragover[data-view="editor"] .drop-overlay { display: grid; animation: sq-fade-in var(--duration-fast) ease both; }

/* ===================== Toasts in the editor ===================== */
/* Just below the toolbar, centred over the photo (main.js measures both): clear of the
   handles, the filmstrip, the Download button and the bottom sheet. */
body[data-view="editor"] .toast-region {
  top: var(--toast-top, calc(env(safe-area-inset-top) + 7rem)); bottom: auto;
  left: var(--toast-x, 50%);
  flex-direction: column;
  width: min(100% - 2 * var(--space-4), 28rem);
}

/* ===================== Tablet and phone ===================== */
/* Tall enough: the panel is a bottom sheet. Short (phone landscape, a laptop at 200% zoom):
   the panel sits below the photo and the page scrolls (see the next block). */
@media (max-width: 1023.98px) and (min-height: 560px) {
  .editor { padding-bottom: calc(var(--sheet-h, 9rem) + var(--space-3)); }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    width: min(100%, 44rem); margin-inline: auto;
    max-height: min(82dvh, 46rem);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: 0;
    box-shadow: 0 -2px 0 0 var(--color-border), var(--shadow-3);
    padding-bottom: env(safe-area-inset-bottom);
    transition: box-shadow var(--duration-base) ease;
  }
  .panel__grabber {
    display: grid; place-items: center;
    position: sticky; top: 0; z-index: 3;
    width: 100%; min-height: 1.75rem;
    background: var(--color-surface);
    cursor: pointer;
  }
  .panel__grabber-bar { width: 3rem; height: 5px; border-radius: var(--radius-pill); background: var(--color-border-strong); transition: width var(--duration-base) var(--ease-bounce); }
  .panel__grabber:hover .panel__grabber-bar { width: 3.75rem; }
  .panel__more { display: none; }
  .panel.is-open .panel__more { display: block; }
  /* A visible way into Save as, Custom and Fine-tune (the grabber alone is easy to miss) */
  .panel__more-btn { display: inline-flex; margin-left: auto; margin-block: -6px; --btn-pad: var(--space-2); gap: var(--space-1); color: var(--color-muted); font-size: var(--text-xs); }
  .panel__more-btn svg { width: 1rem; height: 1rem; transition: transform var(--duration-slow) var(--ease-spring); }
  .panel__more-btn .panel__more-close { display: none; }
  .panel.is-open .panel__more-btn .panel__more-open { display: none; }
  .panel.is-open .panel__more-btn .panel__more-close { display: inline; }
  .panel.is-open .panel__more-btn svg { transform: rotate(180deg); }
  .panel__head .panel__note { margin-left: 0; }
  body.sheet-open::after {
    content: ""; position: fixed; inset: 0; z-index: calc(var(--z-sticky) - 1);
    background: var(--color-overlay);
    animation: sq-fade-in var(--duration-base) ease both;
  }
}
@media (max-width: 1023.98px) {
  .editor { display: flex; flex-direction: column; gap: 0; }
  .workspace { flex: 1; }
  .panel__size { order: 1; padding: 0 var(--space-4) var(--space-2); }
  .panel__actions { order: 2; position: static; border-top: 0; padding: var(--space-2) var(--space-4) var(--space-3); margin-top: 0; }
  .panel__more { order: 3; border-top: var(--border-width) solid var(--color-border); }
  .panel__head { margin-bottom: var(--space-2); }
  .panel__title { font-size: var(--text-lg); }
  .presets { display: flex; overflow-x: auto; gap: var(--space-2); padding: 2px 2px 8px; margin-inline: -2px; scroll-snap-type: x proximity; scrollbar-width: none; }
  /* fade at the right edge: there are more presets to scroll to */
  .presets { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent); }
  .presets.is-at-end { -webkit-mask-image: none; mask-image: none; }
  .presets::-webkit-scrollbar { display: none; }
  .preset { flex: none; grid-template-columns: auto; justify-items: center; gap: 2px; min-height: 0; min-width: 4.75rem; padding: var(--space-2) var(--space-2) 6px; scroll-snap-align: start; }
  .preset__text { align-items: center; }
  .preset__use { display: none; }
  .panel__buttons { flex-direction: row; }
  .panel__buttons > .btn { flex: 1 1 0; min-width: 0; --btn-pad: var(--space-3); }
  .panel__buttons > .btn span { overflow: hidden; text-overflow: ellipsis; }
  body.has-many .panel__buttons { flex-wrap: wrap; }
  .panel__buttons .label-long { display: none; }
  .panel__buttons .label-short { display: inline; }
  .panel__buttons #download-btn.is-many svg { display: none; }
  .shortcuts { display: none; }
  .stage { border-radius: var(--radius-lg); }
}

@media (max-width: 1023.98px) and (max-height: 559.98px) {
  body.app[data-view="editor"] { height: auto; overflow: visible; }
  .editor { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); gap: var(--space-3); }
  .workspace { flex: none; }
  /* The photo gets most of the screen; the settings follow below it */
  .stage, .compare-wrap { flex: none; height: max(12rem, calc(100dvh - 7.5rem)); min-height: 0; }
  .panel { overflow: visible; }
  .panel__size { padding-top: var(--space-4); }
}

@media (max-width: 767.98px) {
  .app-header { min-height: 3.25rem; }
  .app-header__link { display: none; }
  .brand { font-size: var(--text-md); }
  .engine-chip span:not(.spinner) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .engine-chip[data-state="error"] span { position: static; width: auto; height: auto; clip-path: none; }
  .editor { padding-inline: var(--space-3); }
  .workspace { gap: var(--space-2); }
  .toolbar { gap: var(--space-2); }
  .toolbar__mark-label { display: none; }
  .toolbar__mark-short { display: inline; }
  .toolbar__mark { --btn-pad: var(--space-3); }
  .readout__size { font-size: var(--text-lg); }
  .readout__from { font-size: var(--text-xs); }
  .brushbar { gap: var(--space-2); }
  .brushbar__size .range { width: 6rem; }
  .brushbar__actions { margin-left: 0; }
  .subbar .segmented { width: 100%; }
  .welcome { padding-block: var(--space-4) var(--space-7); gap: var(--space-5); }
  .welcome__drop { padding: var(--space-6) var(--space-4) var(--space-5); }
  .sample-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filmstrip { min-height: 4.25rem; gap: var(--space-2); }
  .filmstrip__add, .film__thumb { width: 3.5rem; height: 3.5rem; }
  .job.is-indeterminate .job__ring { animation: sq-spin 1s linear infinite; }
.job.is-indeterminate .job__fill { transition: none; }
.job__text { min-width: 0; }
  .stage__chips { right: var(--space-3); }
  /* Short chip text, so it never covers the handles at the bottom and right */
  .stage-chip .chip-long, .brushbar__hint .chip-long { display: none; }
  .stage-chip .chip-short, .brushbar__hint .chip-short { display: inline; }
  .stage { min-height: 9rem; }
  .coach { transform: none !important; left: 50%; top: var(--space-3); translate: -50% 0; }
  .coach::after { display: none; }
  .brushbar__hint { font-size: var(--text-xs); }
}

@media (forced-colors: active) {
  .handle__grip { background: Highlight; border-color: CanvasText; }
  .stage__frame { box-shadow: 0 0 0 2px CanvasText; }
  .preset:has(input:checked) { outline: 3px solid Highlight; }
}
