/* Dark, photo first: the interface steps back, one warm accent marks what is selected. */
:root {
  color-scheme: dark;
  --bg: #0c0c0b;
  --surface: #1a1917;
  --surface-2: #262522;
  --text: #f3f0e8;
  --muted: #aaa59a;      /* 7.9:1 on --bg */
  --accent: #ffb547;     /* 11:1 on --bg */
  --on-accent: #1a1206;
  --danger-bg: #3a1714;
  --radius: 14px;
  --target: 24px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
@media (pointer: coarse) { :root { --target: 44px; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-block-size: 100dvh;
  block-size: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow-wrap: break-word;
}
h1 { text-wrap: balance; }
p { text-wrap: pretty; }

.visually-hidden {
  position: absolute !important;
  inline-size: 1px; block-size: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---------- bars ---------- */
.bar {
  padding-inline: max(1rem, env(safe-area-inset-left, 0px)) max(1rem, env(safe-area-inset-right, 0px));
}
.top { padding-block: max(0.5rem, env(safe-area-inset-top, 0px)) 0.5rem; }
.top-row { display: flex; align-items: center; gap: 0.5rem; min-block-size: max(40px, var(--target)); }
.top-row .brand { margin-inline-end: auto; }
.top-actions { display: flex; align-items: center; gap: 0.25rem; margin-inline-start: auto; }
.counter { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.brand { font-weight: 650; letter-spacing: 0.02em; }
.brand { white-space: nowrap; }
/* Three actions share the phone's top bar: tighter padding keeps them on one line in Italian too. */
.top-actions { gap: 0; }
.top-actions .button { padding-inline: 0.625rem; }
.top-actions .button.accent { margin-inline-start: 0.25rem; padding-inline: 1rem; }
/* The empty state has its own big button: the top one appears once a photo is open. */
body:has(.stage[data-state="empty"]) #open-label { visibility: hidden; }
.bottom {
  padding-block: 0.25rem max(0.75rem, env(safe-area-inset-bottom, 0px));
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem;
}
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.hint {
  position: absolute; inset-block-end: 1rem; inset-inline: 1.5rem; margin: 0 auto; inline-size: fit-content;
  padding: 0.3rem 0.75rem; border-radius: 999px; font-size: 0.8125rem; text-align: center;
  background: rgb(12 12 11 / 0.75); color: var(--text); pointer-events: none;
}
.stage.comparing .hint { display: none; }

/* ---------- buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-block-size: max(40px, var(--target)); padding: 0 1rem;
  border: 0; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--surface-2);
  transition: background-color 150ms ease-out, scale 150ms var(--ease-out);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.button svg, .icon-button svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.button:hover { background: #33312d; }
.button:active { scale: 0.96; }
.button.primary { background: var(--accent); color: var(--on-accent); min-block-size: 48px; padding: 0 1.5rem; }
.button.primary:hover { background: #ffc46b; }
.button.ghost { background: transparent; }
.button.ghost:hover { background: var(--surface); }
.icon-button {
  display: inline-grid; place-items: center; flex: none;
  inline-size: var(--target); block-size: var(--target); min-inline-size: 32px; min-block-size: 32px;
  border: 0; border-radius: 999px; background: transparent; color: inherit; cursor: pointer;
}
:where(a, button, [tabindex]):focus-visible,
label.button:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- stage ---------- */
.stage { position: relative; min-block-size: 0; overflow: hidden; }

.empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 0.75rem;
  padding: 1.5rem; text-align: center;
}
.empty h1 { margin: 0; font-size: clamp(1.5rem, 1.1rem + 2vw, 2.25rem); line-height: 1.15; max-inline-size: 18ch; }
.empty p { margin: 0; color: var(--muted); max-inline-size: 34ch; line-height: 1.45; }
.empty .button { margin-block-start: 0.75rem; }
.drop-hint { font-size: 0.875rem; }
@media (hover: none) { .drop-hint { display: none; } }

.photo {
  position: absolute; inset: 0; margin: 0; padding: 0.5rem 1rem; display: block; border-radius: var(--radius);
  touch-action: pan-y; /* horizontal moves are ours: they change photo */
}
.photo:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.frame { position: absolute; inset: 0.5rem 1rem; }
/* Sized and placed by layoutPhoto(): the photo in its own pixels, turned, straightened and
   scaled into the frame; the frame is clipped to the crop. */
.frame canvas {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  touch-action: pan-y;
}
.photo.animating {
  @media (prefers-reduced-motion: no-preference) {
    & .frame canvas { transition: transform 300ms var(--ease-out); }
    & .frame { transition: clip-path 300ms var(--ease-out); }
    & .crop-box { transition: left 300ms var(--ease-out), top 300ms var(--ease-out), width 300ms var(--ease-out), height 300ms var(--ease-out); }
  }
}

/* ---------- crop ---------- */
.crop-box {
  position: absolute; box-sizing: border-box;
  border: 1px solid rgb(243 240 232 / 0.9);
  box-shadow: 0 0 0 100vmax rgb(12 12 11 / 0.6); /* dims the photo outside the crop */
  cursor: move; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.crop-box:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
/* rule of thirds while dragging */
.crop-box.dragging {
  background:
    linear-gradient(to right, transparent calc(33.33% - 0.5px), rgb(243 240 232 / 0.5) 0 calc(33.33% + 0.5px), transparent 0 calc(66.67% - 0.5px), rgb(243 240 232 / 0.5) 0 calc(66.67% + 0.5px), transparent 0),
    linear-gradient(to bottom, transparent calc(33.33% - 0.5px), rgb(243 240 232 / 0.5) 0 calc(33.33% + 0.5px), transparent 0 calc(66.67% - 0.5px), rgb(243 240 232 / 0.5) 0 calc(66.67% + 0.5px), transparent 0);
}
/* corners: a small L to see, a 44px area to grab */
.crop-handle {
  position: absolute; inline-size: 44px; block-size: 44px; translate: -50% -50%; touch-action: none;
}
.crop-handle::before {
  content: ""; position: absolute; inset: 50% auto auto 50%; inline-size: 18px; block-size: 18px;
  border: 3px solid var(--text); border-radius: 2px;
}
.crop-handle[data-corner="-1,-1"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-handle[data-corner="1,-1"] { left: 100%; top: 0; cursor: nesw-resize; }
.crop-handle[data-corner="-1,1"] { left: 0; top: 100%; cursor: nesw-resize; }
.crop-handle[data-corner="1,1"] { left: 100%; top: 100%; cursor: nwse-resize; }
.crop-handle[data-corner="-1,-1"]::before { translate: -3px -3px; border-inline-end: 0; border-block-end: 0; }
.crop-handle[data-corner="1,-1"]::before { translate: -15px -3px; border-inline-start: 0; border-block-end: 0; }
.crop-handle[data-corner="-1,1"]::before { translate: -3px -15px; border-inline-end: 0; border-block-start: 0; }
.crop-handle[data-corner="1,1"]::before { translate: -15px -15px; border-inline-start: 0; border-block-start: 0; }
.stage.cropping :is(.hint, .photo-nav, .badge) { display: none; }
.stage.cropping .photo { touch-action: none; }

.aspects { display: contents; }
.icon-tool { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--text); }
.icon-tool svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#original { visibility: hidden; }
.stage.comparing #original { visibility: visible; }
.badge {
  position: absolute; inset-block-start: 1rem; inset-inline-start: 50%; translate: -50% 0;
  padding: 0.3rem 0.75rem; border-radius: 999px; font-size: 0.8125rem; font-weight: 600;
  background: rgb(12 12 11 / 0.75); color: var(--text);
  opacity: 0; transition: opacity 120ms ease-out; pointer-events: none;
}
.stage.comparing #original-badge { opacity: 1; }

/* While the screen-sized photo is being decoded, its small copy is shown with a quiet note. */
.developing {
  display: flex; align-items: center; gap: 0.5rem; margin: 0; inset-block-start: auto; inset-block-end: 1rem;
}
.stage[data-developing]:not(.comparing) .developing { opacity: 1; transition-delay: 300ms; /* only when it takes a while */ }
.spinner.small { inline-size: 14px; block-size: 14px; border-width: 2px; }

/* Previous / next photo: at the sides of the photo, outside the area that answers to holding. */
.photo-nav {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: space-between; padding-inline: 0.25rem;
}
.nav-button {
  pointer-events: auto; inline-size: 44px; block-size: 44px;
  background: rgb(12 12 11 / 0.55); color: var(--text);
  transition: background-color 150ms ease-out, opacity 150ms ease-out, scale 150ms var(--ease-out);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.nav-button:hover { background: rgb(38 37 34 / 0.85); }
.nav-button:active { scale: 0.92; }
.nav-button[aria-disabled="true"] { opacity: 0.3; cursor: default; }
.stage.comparing .photo-nav { opacity: 0; }

/* ---------- grid ---------- */
.grid-view {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior-y: contain;
  padding: 0.25rem 1rem 1rem; scrollbar-gutter: stable;
}
.grid-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-block: 0.25rem 0.625rem; }
.grid-title { margin: 0; font-size: 1.0625rem; font-weight: 650; }
.grid-title:focus { outline: none; }
.grid-count { margin: 0; font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(min(9.5rem, calc((100% - 8px) / 3)), 1fr));
}
.tile {
  position: relative; display: block; inline-size: 100%; aspect-ratio: 1; padding: 0; border: 0;
  border-radius: 6px; overflow: hidden; background: var(--surface); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: scale 150ms var(--ease-out);
}
.tile canvas { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; transition: opacity 200ms ease-out; }
.tile:hover canvas { opacity: 0.88; }
.tile:active { scale: 0.97; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* opening: a spinner on the empty tile */
.tile[data-status="loading"] { cursor: progress; }
.tile[data-status="loading"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; inline-size: 22px; block-size: 22px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-block-start-color: var(--accent);
  @media (prefers-reduced-motion: no-preference) { animation: spin 0.9s linear infinite; }
}
/* cannot be opened: words, not only colour */
.tile-status {
  position: absolute; inset: 0; display: none; place-content: center; padding: 0.5rem;
  font-size: 0.8125rem; font-weight: 600; text-align: center; color: var(--text);
}
.tile[data-status="error"] { background: var(--danger-bg); }
.tile[data-status="error"] .tile-status { display: grid; }
/* adjusted: a dot, like the adjustment tools */
.tile[data-edited]::before {
  content: ""; position: absolute; inset-block-start: 6px; inset-inline-end: 6px; z-index: 1;
  inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 2px rgb(12 12 11 / 0.6);
}
/* choosing: an empty circle on every tile, filled with a tick on the chosen ones */
.tile-check {
  position: absolute; inset-block-end: 6px; inset-inline-start: 6px; display: none;
  inline-size: 22px; block-size: 22px; border-radius: 50%;
  border: 2px solid var(--text); background: rgb(12 12 11 / 0.45);
}
.stage.selecting .tile:not([data-status="loading"]) .tile-check { display: block; }
.tile[aria-pressed="true"] .tile-check {
  border-color: var(--accent); background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%231a1206' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 16px; background-position: center; background-repeat: no-repeat;
}
.tile[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile[aria-pressed="true"] canvas { opacity: 0.75; }

/* ---------- choosing photos (bottom bar) ---------- */
.select-bar { display: grid; gap: 0.5rem; padding-block: 0.25rem; }
.select-row { display: flex; align-items: center; gap: 0.5rem; }
.select-count { margin-inline-end: auto; font-weight: 600; font-size: 0.9375rem; min-inline-size: 0; }
.select-row.actions .button { flex: 1; }
.pill.quiet { color: var(--text); }
:is(.button, .pill)[aria-disabled="true"] { opacity: 0.45; cursor: default; }
:is(.button, .pill)[aria-disabled="true"]:active { scale: 1; }

/* ---------- messages ---------- */
.toast {
  position: fixed; inset: auto 1rem auto; inset-block-start: calc(max(0.5rem, env(safe-area-inset-top, 0px)) + 3.25rem);
  margin: 0 auto; max-inline-size: min(28rem, calc(100% - 2rem)); inline-size: max-content;
  display: none; align-items: center; gap: 0.5rem;
  padding: 0.375rem 0.25rem 0.375rem 1rem; border: 1px solid var(--surface-2); border-radius: var(--radius);
  background: var(--surface); color: var(--text); line-height: 1.35; font-size: 0.9375rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
}
.toast:popover-open { display: flex; }
.toast p { margin: 0; flex: 1; min-inline-size: 0; padding-block: 0.375rem; }
.toast {
  @media (prefers-reduced-motion: no-preference) {
    transition: opacity 180ms ease-out, translate 220ms var(--ease-out), display 220ms allow-discrete, overlay 220ms allow-discrete;
    &:popover-open { @starting-style { opacity: 0; translate: 0 -8px; } }
  }
}

/* loading: dims the photo (or the empty stage) and shows what is happening */
.loading {
  position: absolute; inset: 0; display: none; place-content: center; justify-items: center; gap: 0.75rem;
  background: rgb(12 12 11 / 0.6); color: var(--text); font-size: 0.9375rem;
}
.stage[data-busy] .loading { display: grid; }
.spinner {
  inline-size: 28px; block-size: 28px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-block-start-color: var(--accent);
  @media (prefers-reduced-motion: no-preference) { animation: spin 0.9s linear infinite; }
}
@keyframes spin { to { rotate: 1turn; } }

.drop-overlay {
  position: absolute; inset: 0.5rem; display: none; place-content: center;
  border: 2px dashed var(--accent); border-radius: var(--radius);
  background: rgb(12 12 11 / 0.8); font-weight: 600;
}
.stage.dragging .drop-overlay { display: grid; }

.error {
  position: absolute; inset-inline: 1rem; inset-block-end: 1rem;
  display: flex; align-items: start; gap: 0.5rem;
  padding: 0.75rem 0.5rem 0.75rem 1rem; border-radius: var(--radius);
  background: var(--danger-bg); color: var(--text); line-height: 1.4;
}
.error[hidden] { display: none; }
.error p { margin: 0; flex: 1; min-inline-size: 0; padding-block: 0.15rem; }

/* ---------- look bar ---------- */
.looks {
  display: flex; gap: 0.625rem;
  overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scroll-padding-inline: 0.25rem; padding: 0.375rem 0.25rem 0.25rem;
  scrollbar-width: none;
}
.looks::-webkit-scrollbar { display: none; }
.look {
  flex: none; scroll-snap-align: start;
  display: grid; gap: 0.375rem; justify-items: center;
  inline-size: 84px; padding: 0; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 0.75rem; line-height: 1.2; text-align: center; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.look .thumb {
  inline-size: 84px; block-size: 84px; border-radius: 12px; object-fit: cover;
  background: var(--surface); display: block;
  outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color 150ms ease-out, scale 150ms var(--ease-out);
}
.look:hover .thumb { outline-color: var(--surface-2); }
.look:active .thumb { scale: 0.96; }
.look[aria-pressed="true"] { color: var(--text); font-weight: 600; }
.look[aria-pressed="true"] .thumb { outline: 2px solid var(--accent); }
.look:focus-visible { outline: none; }
.look:focus-visible .thumb { outline: 2px solid var(--text); }
.look[aria-pressed="true"]:focus-visible .thumb { outline-width: 3px; }

@media (min-width: 60rem) {
  .looks { justify-content: safe center; }
}

/* ---------- tabs: Look / Adjust ---------- */
.tabs { display: flex; gap: 0.25rem; }
.tabs [role="tab"] {
  position: relative;
  min-block-size: var(--target); padding: 0 0.75rem;
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [aria-selected="true"] { color: var(--text); }
.tabs [aria-selected="true"]::after {
  content: ""; position: absolute; inset: auto 0.75rem 0.25rem;
  border-block-end: 2px solid var(--accent);
}
/* Both panels take the same height, so the photo does not jump when switching. */
/* minmax(0, 1fr): the scrolling rows inside must not widen the page. */
.panels { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
/* The panels share one cell and the hidden ones keep their space: the footer is as tall as the
   tallest panel on every tab, so the photo above never jumps. */
.panels > [role="tabpanel"] { grid-area: 1 / 1; min-inline-size: 0; }
.panels > [role="tabpanel"][hidden] { display: block !important; visibility: hidden; }

/* ---------- value controls (app/ui/scrubber.js) ---------- */
.control { display: grid; gap: 0.25rem; min-inline-size: 0; }
.control-head {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; column-gap: 0.5rem;
  padding-inline: 0.25rem; min-block-size: var(--target);
}
.control-head span { font-weight: 600; font-size: 0.9375rem; min-inline-size: 0; }
.control-head output {
  font-variant-numeric: tabular-nums; font-size: 1.0625rem; font-weight: 600; color: var(--text);
  min-inline-size: 5ch; text-align: end;
}
.pill {
  min-block-size: var(--target); padding: 0 0.75rem; border: 0; border-radius: 999px;
  background: var(--surface); color: var(--accent); font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease-out, scale 150ms var(--ease-out);
}
.pill:hover { background: var(--surface-2); }
.pill:active { scale: 0.95; }
.scrubber {
  --slider-track-color: #6e6a62; /* 3.6:1 on --bg (WCAG non-text minimum 3:1) */
  position: relative; block-size: 4.25rem; border-radius: 12px; min-inline-size: 0;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.scrubber:active { cursor: grabbing; }
.scrubber canvas { display: block; max-inline-size: 100%; }
.scrubber:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Switching tool: the new scale comes in with a short fade. */
.control.switching .scrubber, .control.switching output {
  @media (prefers-reduced-motion: no-preference) { animation: control-in 220ms var(--ease-out); }
}
@keyframes control-in { from { opacity: 0; translate: 0 4px; } }

/* Look intensity replaces the row of looks while it is open. */
.intensity:not([hidden]) {
  @media (prefers-reduced-motion: no-preference) { animation: control-in 240ms var(--ease-out); }
}
#panel-looks:has(.intensity:not([hidden])) .looks { display: none; }


/* Row of adjustment tools: one slider at a time keeps the photo large on a phone. */
.tools {
  display: flex; gap: 0.5rem;
  overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
  padding: 0.25rem; scrollbar-width: none;
}
.tools::-webkit-scrollbar { display: none; }
.tool {
  flex: none; scroll-snap-align: start; position: relative;
  min-block-size: var(--target); padding: 0.375rem 0.875rem;
  border: 1px solid var(--surface-2); border-radius: 999px;
  background: none; color: var(--muted); font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.tool:hover { color: var(--text); background: var(--surface); }
.tool[aria-pressed="true"] { color: var(--text); border-color: var(--accent); background: var(--surface); }
/* A changed adjustment gets a dot (shape, not only colour). */
.tool[data-changed]::after {
  content: ""; position: absolute; inset-block-start: 0.3rem; inset-inline-end: 0.45rem;
  inline-size: 6px; block-size: 6px; border-radius: 50%; background: var(--accent);
}
.stage[data-developing] .hint { display: none; }

/* saving failed: words on the tile, not only the message that came and went */
.tile-note {
  position: absolute; inset-inline: 4px; inset-block-end: 4px; display: none;
  padding: 0.125rem 0.375rem; border-radius: 4px; inline-size: fit-content; margin-inline-start: auto;
  font-size: 0.6875rem; font-weight: 600; color: var(--text); background: rgb(12 12 11 / 0.75);
}
.tile[data-unsaved] .tile-note { display: block; }

/* ---------- saving: the export sheet ---------- */
.button.accent { background: var(--accent); color: var(--on-accent); }
.button.accent:hover { background: #ffc46b; }
.button.wide { inline-size: 100%; min-block-size: 48px; }
.sheet {
  inline-size: min(100% - 2rem, 28rem); max-inline-size: none; max-block-size: calc(100dvh - 2rem);
  padding: 0; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--text);
}
/* Scrolling inside the sheet or over the backdrop never moves the page behind. */
.sheet:modal { overscroll-behavior: contain; }
.sheet::backdrop { background: rgb(0 0 0 / 0.7); overflow: hidden; overscroll-behavior: contain; }
/* Phone: a sheet along the bottom edge, within reach of the thumb. */
@media (max-width: 40rem) {
  .sheet {
    inline-size: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0;
    padding-block-end: env(safe-area-inset-bottom, 0px);
  }
}
.sheet-head { display: flex; align-items: center; gap: 0.5rem; padding: 1rem 0.75rem 0 1.25rem; }
.sheet-head h1 { margin: 0 auto 0 0; font-size: 1.25rem; line-height: 1.2; }
.sheet-body { display: grid; gap: 1.25rem; padding: 1rem 1.25rem 1.25rem; }
.choice { display: grid; gap: 0.5rem; min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.choice legend { padding: 0; margin-block-end: 0.5rem; font-weight: 600; font-size: 0.9375rem; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--bg); }
.segmented label {
  position: relative; flex: 1; display: grid; place-items: center;
  min-block-size: max(40px, var(--target)); padding-inline: 0.5rem; border-radius: 999px;
  font-weight: 600; font-size: 0.9375rem; text-align: center; color: var(--muted); cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
  -webkit-tap-highlight-color: transparent;
}
.segmented input {
  position: absolute; inline-size: 1px; block-size: 1px; margin: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.segmented label:hover { color: var(--text); }
.segmented label:has(:checked) { background: var(--surface-2); color: var(--accent); }
.segmented label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.field-hint, .sheet-note { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
.sheet-result { margin: 0; font-size: 1.0625rem; font-weight: 600; }
.sheet-failures { margin: 0; padding-inline-start: 1.1rem; color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
#export-step { font-weight: 600; font-variant-numeric: tabular-nums; }
#export-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet progress {
  --progress-bar-radius: 1e5px;
  appearance: none; border: 0 solid; overflow: clip;
  inline-size: 100%; block-size: 8px;
  border-radius: var(--progress-bar-radius);
  background: var(--surface-2);
}
.sheet progress::-webkit-progress-bar { background: transparent; }
.sheet progress::-webkit-progress-value {
  background: var(--accent); border-radius: var(--progress-bar-radius); transition: inline-size 0.3s;
}
.sheet progress::-moz-progress-bar {
  background: var(--accent); border-radius: var(--progress-bar-radius); transition: inline-size 0.3s;
}
@media (prefers-reduced-motion: reduce) {
  .sheet progress::-webkit-progress-value { transition: none; }
  .sheet progress::-moz-progress-bar { transition: none; }
}

/* Preview of the frame on the first photos. */
.export-preview {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  block-size: 9rem; min-inline-size: 0;
}
.export-preview canvas {
  inline-size: auto; block-size: auto; max-block-size: 100%; max-inline-size: calc((100% - 1.5rem) / 3);
  border-radius: 3px; box-shadow: 0 0 0 1px rgb(255 255 255 / 0.14); /* a black frame still shows its edge */
}

/* Effects: on/off chips, any combination. */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips label {
  position: relative; display: inline-grid; place-items: center;
  min-block-size: max(40px, var(--target)); padding-inline: 0.875rem; border-radius: 999px;
  font-weight: 600; font-size: 0.9375rem; color: var(--text); cursor: pointer;
  background: var(--bg); box-shadow: inset 0 0 0 1px var(--surface-2);
  transition: background-color 150ms ease-out, color 150ms ease-out;
  -webkit-tap-highlight-color: transparent;
}
.chips input {
  position: absolute; inline-size: 1px; block-size: 1px; margin: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.chips label:hover { background: var(--surface-2); }
.chips label:has(:checked) { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.chips label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Not colour alone: a chip that is on also shows a tick (hidden from screen readers, which read the checkbox). */
.chips label:has(:checked) span::before { content: "✓\00a0" / ""; }
/* A tall sheet scrolls under its title, while the Save button stays within reach. */
.sheet-head { position: sticky; inset-block-start: 0; z-index: 1; background: var(--surface); padding-block-end: 0.5rem; }
#export-start {
  position: sticky; inset-block-end: 0.75rem; z-index: 1;
  box-shadow: 0 0 0 0.75rem var(--surface);
}
/* Narrowest phones: "Open" keeps only its + (its name stays for screen readers), so the top bar fits. */
@media (max-width: 22.5rem) {
  #open-label > span {
    position: absolute; inline-size: 1px; block-size: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .top-actions .button { padding-inline: 0.5rem; }
  #open-label { min-inline-size: 44px; padding-inline: 0.5rem; } /* touch target */
  #top-grid { gap: 0.25rem; }
  .brand { letter-spacing: 0; }
  .top-actions .button.accent { padding-inline: 0.75rem; }
}
