/*
  Grain: photo editor app (Screenery template)
  A professional creative tool: neutral mid-dark greys so colour judgement is not biased, one amber safelight accent, small exact labels.
  The first screen is a full-viewport app shell (grid: top bar, looks, stage, adjustments, filmstrip); the About sections follow below.
  Under 1100px the tools wrapper becomes a bottom sheet with tabs and the histogram floats over the stage.

  Contents
   1. Tokens
   2. Base and browser surfaces
   3. Controls: buttons, segments, sliders, number fields, selects
   4. App shell grid
   5. Top bar
   6. Stage: frame, canvases, split, crop, fallback
   7. Filmstrip
   8. Panels: looks, history, histogram, adjustments, curve, crop
   9. Export dialog
  10. About: intro, looks table, keys, pricing, questions, footer
  11. Narrow screens (bottom sheet)
  12. Motion
*/

/* ---------- 1. Tokens ---------- */
:root {
  /* Neutral greys, zero chroma. Numbers are rough L* so the surround stays honest. */
  --g-0: #1c1c1c;   /* stage well, deepest */
  --g-1: #232323;   /* app ground, top bar */
  --g-2: #2a2a2a;   /* panels */
  --g-3: #333333;   /* raised controls */
  --g-4: #3d3d3d;   /* hover, tracks */
  --g-5: #4a4a4a;   /* strong rules */
  --line: #363636;  /* hairlines */
  --stage: #2f2f2f; /* mid-dark neutral around the photo */

  --tx: #ececec;    /* primary text */
  --tx-2: #b9b9b9;  /* secondary labels */
  --tx-3: #a2a2a2;  /* hints, only on g-0..g-2 */

  /* The single accent: darkroom safelight amber */
  --accent: #f2a541;
  --accent-hi: #f7b960;
  --accent-ink: #1b1611;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--g-2));

  --err: #ff8a7a;   /* errors only */

  /* Type */
  --sans: "Funnel Sans", "Helvetica Neue", Arial, sans-serif;
  --display: "Funnel Display", "Funnel Sans", "Helvetica Neue", Arial, sans-serif;
  --fs-2xs: 0.6875rem; /* 11 */
  --fs-xs: 0.75rem;    /* 12, panel labels */
  --fs-sm: 0.8125rem;  /* 13, UI body */
  --fs-md: 1rem;       /* 16, reading */
  --fs-lg: 1.25rem;
  --fs-xl: clamp(1.75rem, 1.2rem + 1.8vw, 2.5rem);
  --fs-2xl: clamp(2.125rem, 1.3rem + 3.2vw, 3.75rem);

  /* Space and shape */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 72px; --s-9: 112px;
  --r-1: 4px; --r-2: 6px; --r-3: 10px;
  --topbar: 48px;
  --strip: 92px;
  --left: 236px;
  --right: 304px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 12px 40px -8px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

/* ---------- 2. Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--g-1); scroll-behavior: smooth; scrollbar-color: var(--g-5) var(--g-1); }
body {
  margin: 0;
  font: 400 var(--fs-sm)/1.45 var(--sans);
  color: var(--tx);
  background: var(--g-1);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
::selection { background: var(--accent); color: var(--accent-ink); }
input, textarea { caret-color: var(--accent); }
:root { accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-1); }
a { color: var(--tx); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:not(.btn):not(.skip):hover { color: var(--accent-hi); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }
kbd { font: 500 var(--fs-2xs)/1 var(--sans); padding: 3px 6px; border: 1px solid var(--g-5); border-bottom-width: 2px; border-radius: var(--r-1); background: var(--g-3); color: var(--tx); min-width: 22px; display: inline-block; text-align: center; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.skip { position: absolute; left: var(--s-3); top: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: var(--s-2) var(--s-3); border-radius: var(--r-2); }
.skip:focus { top: var(--s-2); }
[hidden] { display: none !important; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--g-5); border-radius: 10px; border: 3px solid var(--g-2); }

/* ---------- 3. Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 var(--s-3);
  border-radius: var(--r-2); border: 1px solid var(--g-5);
  background: var(--g-3); color: var(--tx); font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s;
}
.btn:hover { background: var(--g-4); color: var(--tx); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: var(--accent-ink); }
.btn-quiet { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-2);
  border: 1px solid transparent; background: transparent; color: var(--tx-2);
  transition: background-color .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--g-3); color: var(--tx); }
.icon-btn:disabled { color: var(--g-5); cursor: not-allowed; }
.text-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 var(--s-2); color: var(--tx-2); text-decoration: none; border-radius: var(--r-2); }
.text-btn:hover { color: var(--tx); background: var(--g-3); }
.mini-btn { display: grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: var(--r-1); background: transparent; color: var(--tx-3); }
.mini-btn:hover { background: var(--g-4); color: var(--tx); }
.mini-btn .ic { width: 15px; height: 15px; }

/* Segmented controls (view, channel, aspect, billing) */
.viewseg, .chanseg, .billing { display: inline-flex; padding: 2px; gap: 2px; background: var(--g-0); border: 1px solid var(--line); border-radius: var(--r-2); }
.seg, .chanseg button, .billing button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 var(--s-3);
  border: 0; border-radius: 4px; background: transparent; color: var(--tx-2); font-weight: 500; white-space: nowrap;
}
.seg .ic { width: 16px; height: 16px; }
.seg:hover, .chanseg button:hover, .billing button:hover { color: var(--tx); background: var(--g-3); }
.seg[aria-pressed="true"], .chanseg [aria-checked="true"], .billing [aria-checked="true"] { background: var(--g-4); color: var(--tx); box-shadow: 0 1px 2px rgb(0 0 0 / .4); }
#toolCrop[aria-pressed="true"], #viewSplit[aria-pressed="true"] { color: var(--accent); }

/* Slider row: label, numeric field, range */
.sl { display: grid; grid-template-columns: 1fr 56px; grid-template-rows: auto 22px; column-gap: var(--s-2); align-items: center; padding: 3px 0; }
.sl label { font-size: var(--fs-xs); color: var(--tx-2); user-select: none; }
.sl.is-moved label { color: var(--tx); }
.num {
  grid-column: 2; grid-row: 1; justify-self: end; width: 56px; height: 22px; padding: 0 6px; text-align: right;
  font-size: var(--fs-xs); font-variant-numeric: tabular-nums; color: var(--tx);
  background: transparent; border: 1px solid transparent; border-radius: var(--r-1);
}
.num:hover { border-color: var(--g-5); }
.num:focus { background: var(--g-0); border-color: var(--accent); outline: none; }
.num[aria-invalid="true"] { border-color: var(--err); color: var(--err); }
.sl input[type="range"] { grid-column: 1 / -1; grid-row: 2; }

input[type="range"] {
  --fill-a: 50%; --fill-b: 50%;   /* JS sets the filled span; bipolar sliders fill from the centre */
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent var(--fill-a), var(--accent) var(--fill-a), var(--accent) var(--fill-b), transparent var(--fill-b)),
    var(--track, var(--g-5));
}
input[type="range"]::-moz-range-track {
  height: 3px; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent var(--fill-a), var(--accent) var(--fill-a), var(--accent) var(--fill-b), transparent var(--fill-b)),
    var(--track, var(--g-5));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%;
  background: var(--tx); border: 2px solid var(--g-2); box-shadow: 0 1px 3px rgb(0 0 0 / .6);
  transition: transform .12s var(--ease);
}
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--tx); border: 2px solid var(--g-2); }
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
input[type="range"]:focus-visible::-moz-range-thumb { background: var(--accent); }
/* Tracks that show what they do */
.sl-temp input { --track: linear-gradient(90deg, #4f7fc4, #8a8a8a 50%, #d9a24a); }
.sl-tint input { --track: linear-gradient(90deg, #4fa66a, #8a8a8a 50%, #c35fb4); }
.sl-hue input { --track: linear-gradient(90deg, #c45252, #c4a552, #6ec452, #52c4a5, #5277c4, #9a52c4, #c45252); --fill-a: 0%; --fill-b: 0%; }
.sl-temp input, .sl-tint input { --fill-a: 50%; --fill-b: 50%; }
.sl-temp input::-webkit-slider-runnable-track, .sl-tint input::-webkit-slider-runnable-track, .sl-hue input::-webkit-slider-runnable-track { height: 4px; background: var(--track); }
.sl-temp input::-moz-range-track, .sl-tint input::-moz-range-track, .sl-hue input::-moz-range-track { height: 4px; background: var(--track); }

select {
  min-height: 28px; padding: 0 28px 0 var(--s-2); border-radius: var(--r-1); border: 1px solid var(--g-5);
  background: var(--g-3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' fill='none' stroke='%23b9b9b9' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 6px center / 16px no-repeat;
  -webkit-appearance: none; appearance: none; font-size: var(--fs-xs);
}
select:hover { background-color: var(--g-4); }

/* ---------- 4. App shell grid ---------- */
.app {
  position: relative;
  height: 100vh; height: 100dvh; min-height: 620px;
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  grid-template-rows: var(--topbar) minmax(0, 1fr) var(--strip);
  grid-template-areas: "top top top" "left stage right" "left film right";
  background: var(--g-1);
  border-bottom: 1px solid var(--line);
}
.tools { display: contents; }
.tabs { display: none; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--g-2); }
.side-left { grid-area: left; border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; }
.side-right { grid-area: right; border-left: 1px solid var(--line); }
.adjust { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* ---------- 5. Top bar ---------- */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: var(--s-4); padding: 0 var(--s-3) 0 var(--s-4);
  border-bottom: 1px solid var(--line); background: var(--g-1); min-width: 0;
}
.logo { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font: 600 17px/1 var(--display); letter-spacing: -0.01em; color: var(--tx); }
.logo svg, .foot-brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2; }
.logo-dot { fill: var(--accent); stroke: none; }
.docname { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; color: var(--tx); font-weight: 500; white-space: nowrap; overflow: hidden; }
.docname > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.docmeta { font-size: var(--fs-xs); color: var(--tx-3); font-variant-numeric: tabular-nums; }
.viewseg { margin-left: auto; }
.topactions { display: flex; align-items: center; gap: var(--s-1); margin-left: var(--s-2); }
.about-link { margin: 0 var(--s-2); }

/* ---------- 6. Stage ---------- */
.stage { grid-area: stage; position: relative; display: grid; place-items: center; background: var(--stage); overflow: hidden; outline: none; padding: var(--s-5); }
.frame { position: relative; width: 600px; height: 400px; overflow: hidden; box-shadow: 0 10px 34px -10px rgb(0 0 0 / .6); background: var(--g-0); }
.layer { position: absolute; left: 0; top: 0; display: block; width: 100%; height: 100%; image-rendering: auto; }
.before { clip-path: inset(0 100% 0 0); }
.app[data-view="split"] .before { clip-path: inset(0 calc(100% - var(--split, 50%)) 0 0); }
.app.show-before .before { clip-path: inset(0 0 0 0); }
.split { display: none; position: absolute; top: 0; bottom: 0; left: var(--split, 50%); width: 44px; margin-left: -22px; cursor: ew-resize; touch-action: none; outline: none; }
.app[data-view="split"] .split { display: block; }
.split-line { position: absolute; left: 21px; top: 0; bottom: 0; width: 2px; background: var(--tx); box-shadow: 0 0 0 1px rgb(0 0 0 / .35); }
.split-knob { position: absolute; left: 50%; top: 50%; width: 32px; height: 32px; translate: -50% -50%; display: grid; place-items: center; border-radius: 50%; background: var(--tx); color: var(--g-1); box-shadow: 0 2px 8px rgb(0 0 0 / .5); }
.split-knob svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.split:focus-visible .split-knob { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 3px rgb(0 0 0 / .5); }
.split-tag { position: absolute; top: var(--s-3); padding: 3px 8px; border-radius: var(--r-1); background: rgb(28 28 28 / .9); color: var(--tx); font-size: var(--fs-2xs); font-weight: 500; white-space: nowrap; pointer-events: none; }
.split-tag-l { right: 30px; }
.split-tag-r { left: 30px; }
.stage-badge { position: absolute; top: var(--s-3); left: var(--s-3); padding: 4px 10px; border-radius: var(--r-1); background: var(--g-0); color: var(--accent); font-size: var(--fs-xs); font-weight: 600; }

/* Crop overlay: the frame shows the full image, the rectangle shows what stays */
.crop { position: absolute; inset: 0; }
.crop-rect { position: absolute; box-shadow: 0 0 0 9999px rgb(20 20 20 / .66); outline: 1px solid rgb(255 255 255 / .85); cursor: move; touch-action: none; }
.crop-rect:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.crop-thirds { position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, transparent calc(33.333% - .5px), rgb(255 255 255 / .35) calc(33.333% - .5px), rgb(255 255 255 / .35) calc(33.333% + .5px), transparent calc(33.333% + .5px), transparent calc(66.666% - .5px), rgb(255 255 255 / .35) calc(66.666% - .5px), rgb(255 255 255 / .35) calc(66.666% + .5px), transparent calc(66.666% + .5px)),
    linear-gradient(180deg, transparent calc(33.333% - .5px), rgb(255 255 255 / .35) calc(33.333% - .5px), rgb(255 255 255 / .35) calc(33.333% + .5px), transparent calc(33.333% + .5px), transparent calc(66.666% - .5px), rgb(255 255 255 / .35) calc(66.666% - .5px), rgb(255 255 255 / .35) calc(66.666% + .5px), transparent calc(66.666% + .5px));
}
.crop-h { position: absolute; width: 28px; height: 28px; touch-action: none; }
.crop-h::before { content: ""; position: absolute; width: 16px; height: 16px; border: 3px solid var(--tx); }
.crop-h[data-h="nw"] { left: -6px; top: -6px; cursor: nwse-resize; } .crop-h[data-h="nw"]::before { left: 3px; top: 3px; border-right: 0; border-bottom: 0; }
.crop-h[data-h="ne"] { right: -6px; top: -6px; cursor: nesw-resize; } .crop-h[data-h="ne"]::before { right: 3px; top: 3px; border-left: 0; border-bottom: 0; }
.crop-h[data-h="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; } .crop-h[data-h="sw"]::before { left: 3px; bottom: 3px; border-right: 0; border-top: 0; }
.crop-h[data-h="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; } .crop-h[data-h="se"]::before { right: 3px; bottom: 3px; border-left: 0; border-top: 0; }
.crop-size { position: absolute; left: 50%; bottom: 8px; translate: -50% 0; padding: 2px 8px; border-radius: var(--r-1); background: rgb(28 28 28 / .9); font-size: var(--fs-2xs); font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }

/* No-script fallback */
.fallback { display: none; position: absolute; inset: 0; width: 100%; height: 100%; }
.nojs-note { display: none; }
.no-js .fallback { display: block; }
.no-js .frame { width: min(100%, 720px); height: auto; aspect-ratio: 3 / 2; }
.no-js .nojs-note { display: block; position: absolute; left: 50%; bottom: var(--s-4); translate: -50% 0; width: min(90%, 52ch); padding: var(--s-2) var(--s-3); background: var(--g-0); border: 1px solid var(--line); border-radius: var(--r-2); text-align: center; color: var(--tx-2); }
.no-js .split, .no-js .crop { display: none; }

/* ---------- 7. Filmstrip ---------- */
.filmstrip { grid-area: film; display: flex; align-items: center; gap: var(--s-4); padding: 0 var(--s-4); background: var(--g-1); border-top: 1px solid var(--line); min-width: 0; }
.strip { display: flex; gap: var(--s-2); margin: 0; padding: 0; list-style: none; overflow-x: auto; min-width: 0; scrollbar-width: thin; }
.strip li { position: relative; flex: none; display: grid; gap: 4px; padding: 4px; border-radius: var(--r-2); cursor: pointer; border: 1px solid transparent; }
.strip li:hover { background: var(--g-3); }
.strip li[aria-selected="true"] { border-color: var(--accent); background: var(--g-2); }
.strip canvas { display: block; width: 84px; height: 56px; border-radius: 2px; background: var(--g-0); }
.strip-label { font-size: var(--fs-2xs); color: var(--tx-2); white-space: nowrap; max-width: 84px; overflow: hidden; text-overflow: ellipsis; }
.strip-label b { color: var(--tx); font-weight: 600; margin-right: 2px; }
.strip li[aria-selected="true"] .strip-label { color: var(--tx); }
.strip-dot { position: absolute; top: 8px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--g-1); opacity: 0; }
.strip li.is-edited .strip-dot { opacity: 1; }
.perf { margin-left: auto; font-size: var(--fs-xs); color: var(--tx-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 8. Panels ---------- */
.panel { border-bottom: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; gap: var(--s-1); padding: 0 var(--s-2) 0 0; font: inherit; }
.panel-toggle {
  flex: 1; display: flex; align-items: center; gap: var(--s-2); min-height: 40px; padding: 0 var(--s-2) 0 var(--s-4);
  border: 0; background: transparent; color: var(--tx); font-weight: 600; font-size: var(--fs-sm); text-align: left;
}
.panel-toggle .ic { width: 16px; height: 16px; color: var(--tx-2); }
.panel-toggle .chev { margin-left: auto; transition: rotate .2s var(--ease); }
.panel-toggle[aria-expanded="false"] .chev { rotate: -90deg; }
.panel-toggle:hover { color: var(--accent-hi); }
.panel-body { padding: 0 var(--s-4) var(--s-4); }
.count { font-size: var(--fs-2xs); color: var(--tx-3); font-variant-numeric: tabular-nums; padding-right: var(--s-2); }
.subhead { margin: var(--s-3) 0 2px; padding-top: var(--s-3); border-top: 1px solid var(--line); font-size: var(--fs-2xs); font-weight: 600; color: var(--tx-2); text-transform: uppercase; letter-spacing: .06em; }
.hint { margin-top: var(--s-3); font-size: var(--fs-xs); color: var(--tx-3); line-height: 1.45; }

/* Looks */
.looks { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.look { width: 100%; display: grid; gap: 5px; padding: 4px 4px 6px; border: 1px solid transparent; border-radius: var(--r-2); background: transparent; text-align: left; }
.look canvas { width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 2px; background: var(--g-0); display: block; }
.look span { font-size: var(--fs-xs); color: var(--tx-2); padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.look:hover { background: var(--g-3); }
.look:hover span { color: var(--tx); }
.look[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.look[aria-pressed="true"] span { color: var(--tx); font-weight: 600; }

/* History */
.panel-history { flex: 1; }
.history { margin: 0; padding: 0; list-style: none; display: grid; gap: 1px; counter-reset: h; }
.history button {
  width: 100%; display: flex; justify-content: space-between; gap: var(--s-2); min-height: 28px; padding: 0 var(--s-2);
  border: 0; border-radius: var(--r-1); background: transparent; color: var(--tx-2); font-size: var(--fs-xs); text-align: left; font-variant-numeric: tabular-nums;
}
.history button:hover { background: var(--g-3); color: var(--tx); }
.history button[aria-current="step"] { background: var(--g-4); color: var(--tx); }
.history button i { font-style: normal; color: var(--tx-3); white-space: nowrap; }
.history button[aria-current="step"] i { color: var(--tx-2); }
.history li.is-future button { color: var(--tx-3); text-decoration: line-through; text-decoration-color: var(--g-5); }

/* Histogram */
.histo { padding: var(--s-3) var(--s-4) var(--s-2); border-bottom: 1px solid var(--line); background: var(--g-2); }
.histo canvas { display: block; width: 100%; height: 96px; background: var(--g-0); border-radius: var(--r-1); }
.histo-meta { display: flex; justify-content: space-between; margin-top: 6px; font-size: var(--fs-2xs); color: var(--tx-3); font-variant-numeric: tabular-nums; }
.histo-meta .is-clip { color: var(--accent); }

/* Curve */
.chanseg { display: flex; width: 100%; margin-bottom: var(--s-3); }
.chanseg button { flex: 1; justify-content: center; padding: 0; font-size: var(--fs-xs); }
.chanseg [data-ch="r"][aria-checked="true"] { color: #ff9c8f; }
.chanseg [data-ch="g"][aria-checked="true"] { color: #8fe0a0; }
.chanseg [data-ch="b"][aria-checked="true"] { color: #9cbcff; }
.curve-wrap { position: relative; }
.curve { display: block; width: 100%; height: auto; aspect-ratio: 1; background: var(--g-0); border-radius: var(--r-1); cursor: crosshair; touch-action: none; overflow: visible; }
.curve-grid { stroke: var(--g-3); stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; }
.curve-diag { stroke: var(--g-4); stroke-width: 1; stroke-dasharray: 3 4; fill: none; vector-effect: non-scaling-stroke; }
.curve-hist { fill: rgb(255 255 255 / .09); stroke: none; }
.curve-line { stroke: var(--tx); stroke-width: 1.75; fill: none; vector-effect: non-scaling-stroke; }
.curve[data-ch="r"] .curve-line { stroke: #ff8a7a; }
.curve[data-ch="g"] .curve-line { stroke: #7fdb93; }
.curve[data-ch="b"] .curve-line { stroke: #8fb2ff; }
.curve-pt { fill: var(--g-0); stroke: var(--tx); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: grab; outline: none; }
.curve-pt:hover { fill: var(--tx); }
.curve-pt:focus { fill: var(--accent); stroke: var(--accent); }
.curve-pt.is-drag { cursor: grabbing; fill: var(--accent); stroke: var(--accent); }
.curve-read { margin-top: 6px; font-size: var(--fs-2xs); color: var(--tx-3); font-variant-numeric: tabular-nums; }
.field-inline { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-top: var(--s-3); font-size: var(--fs-xs); color: var(--tx-2); }

/* Crop */
.aspects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.aspects button { min-height: 30px; border: 1px solid var(--g-5); border-radius: var(--r-1); background: transparent; color: var(--tx-2); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.aspects button:hover { background: var(--g-3); color: var(--tx); }
.aspects [aria-checked="true"] { border-color: var(--accent); color: var(--tx); background: var(--accent-soft); }
.crop-dims { margin-top: var(--s-3); font-size: var(--fs-xs); color: var(--tx-2); font-variant-numeric: tabular-nums; }
.crop-actions { display: flex; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-3); }
.app:not([data-tool="crop"]) .crop-actions { display: none; }

/* ---------- 9. Export dialog ---------- */
.dialog { width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--g-5); border-radius: var(--r-3); background: var(--g-2); color: var(--tx); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(12 12 12 / .6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-3) var(--s-2) var(--s-5); }
.dlg-head h2 { font: 500 var(--fs-lg)/1.2 var(--display); }
.dlg-body { padding: var(--s-2) var(--s-5) var(--s-4); display: grid; gap: var(--s-4); }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-5) var(--s-5); }
.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-size: var(--fs-xs); color: var(--tx-2); padding: 0; margin-bottom: 6px; }
.field label { margin-bottom: 0; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--g-5); border-radius: var(--r-2); background: var(--g-0); }
.input-suffix:focus-within { border-color: var(--accent); }
.input-suffix input { flex: 1; min-width: 0; height: 38px; padding: 0 var(--s-3); border: 0; background: transparent; outline: none; font-size: var(--fs-sm); }
.input-suffix span { padding-right: var(--s-3); color: var(--tx-3); }
.field-msg { font-size: var(--fs-xs); color: var(--tx-3); }
.field.is-invalid .input-suffix { border-color: var(--err); }
.field.is-invalid .field-msg { color: var(--err); }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
.size { position: relative; cursor: pointer; }
.size input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.size span { display: grid; gap: 2px; padding: var(--s-2) var(--s-3); min-height: 52px; border: 1px solid var(--g-5); border-radius: var(--r-2); }
.size b { font-weight: 600; font-size: var(--fs-sm); }
.size i { font-style: normal; font-size: var(--fs-2xs); color: var(--tx-2); font-variant-numeric: tabular-nums; }
.size input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.size input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dlg-note { font-size: var(--fs-xs); color: var(--tx-3); line-height: 1.5; }
.busy-title { font-weight: 500; }
.bar { height: 6px; border-radius: 6px; background: var(--g-0); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .12s linear; }
.busy-meta { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--tx-2); font-variant-numeric: tabular-nums; }
.result { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--fs-sm); line-height: 1.45; }
.result .ic { margin-top: 1px; }
.result .ok { color: var(--accent); }
.result-err { color: var(--err); }
.result-dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); margin: 0; }
.result-dl div { padding: var(--s-2) var(--s-3); background: var(--g-0); border-radius: var(--r-2); }
.result-dl dt { font-size: var(--fs-2xs); color: var(--tx-3); }
.result-dl dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }

/* ---------- 10. About ---------- */
.about { background: var(--g-1); }
.ab-wrap { width: min(1160px, 100% - 48px); margin-inline: auto; }
.about section { padding: var(--s-9) 0; border-bottom: 1px solid var(--line); }
.about h2 { font: 500 var(--fs-xl)/1.1 var(--display); letter-spacing: -0.02em; }
#ab-title { font-size: var(--fs-2xl); max-width: 14ch; }
.lede { font-size: var(--fs-lg); line-height: 1.5; color: var(--tx); margin-top: var(--s-5); max-width: 40ch; }
.about p { max-width: 66ch; }
.about p:not(.lede):not(.price) { font-size: var(--fs-md); line-height: 1.6; color: var(--tx-2); }
.ab-intro-grid p + p { margin-top: var(--s-4); }
.ab-sub { margin-top: var(--s-3); }
.ab-intro-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: var(--s-8); align-items: start; }
.ab-cta { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-6); }
.ab-cta .btn { min-height: 44px; padding: 0 var(--s-5); }
.ab-cta .text-btn { min-height: 44px; }
.ab-order { margin: 0; padding: var(--s-5); border: 1px solid var(--line); border-radius: var(--r-3); background: var(--g-2); }
.ab-order figcaption { font-size: var(--fs-xs); color: var(--tx-2); font-weight: 600; margin-bottom: var(--s-3); }
.ab-order ol { list-style: none; margin: 0; padding: 0; counter-reset: op; display: grid; }
.ab-order li { counter-increment: op; display: grid; grid-template-columns: 28px 1fr; column-gap: var(--s-3); padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.ab-order li::before { content: counter(op); grid-row: span 2; font: 500 var(--fs-sm)/1.4 var(--display); color: var(--accent); font-variant-numeric: tabular-nums; }
.ab-order b { font-weight: 600; }
.ab-order span { font-size: var(--fs-sm); color: var(--tx-2); }

.look-table-wrap { margin-top: var(--s-6); overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-3); }
.look-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 760px; }
.look-table th, .look-table td { padding: var(--s-3) var(--s-4); text-align: left; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.look-table thead th { font-size: var(--fs-xs); color: var(--tx-2); font-weight: 600; background: var(--g-2); }
.look-table tbody tr:last-child > * { border-bottom: 0; }
.look-table tbody th { font-weight: 600; white-space: nowrap; }
.look-table td:not(:last-child) { text-align: right; width: 1%; white-space: nowrap; }
.look-table thead th:not(:first-child):not(:last-child) { text-align: right; }
.look-table td:last-child { color: var(--tx-2); }
.sw { display: inline-block; width: 28px; height: 18px; border-radius: 2px; vertical-align: -4px; margin-right: var(--s-3); }
.sw-portra { background: linear-gradient(90deg, #5d5a5f, #c9a99a 55%, #f1dccb); }
.sw-chrome { background: linear-gradient(90deg, #0e1426, #2f5fa8 50%, #f0c35a); }
.sw-tungsten { background: linear-gradient(90deg, #12313a, #5f8fa4 55%, #d8e2e6); }
.sw-silver { background: linear-gradient(90deg, #0d0d0d, #777 50%, #f2f2f2); }
.sw-faded { background: linear-gradient(90deg, #4a423d, #a6938a 55%, #ecdcc4); }
.sw-cine { background: linear-gradient(90deg, #0d2b30, #3f6f6c 45%, #e3a35c); }

.ab-keys-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: var(--s-8); align-items: start; }
.keys { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-6); }
.keys div { display: grid; grid-template-columns: 100px 1fr; gap: var(--s-3); align-items: baseline; padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.keys dt { display: flex; gap: 4px; flex-wrap: wrap; }
.keys dd { margin: 0; color: var(--tx-2); font-size: var(--fs-sm); }

.price-head { display: flex; align-items: end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.billing button { min-height: 36px; }
.plans { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: var(--s-4); margin-top: var(--s-6); align-items: stretch; }
.plan { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-6) var(--s-5) var(--s-5); border: 1px solid var(--line); border-radius: var(--r-3); background: var(--g-2); }
.plan-main { border-color: var(--accent); }
.plan h3 { font: 500 var(--fs-lg)/1.2 var(--display); }
.price { display: grid; gap: 4px; }
.price b { font: 500 2.5rem/1 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.price span { font-size: var(--fs-sm); color: var(--tx-2); }
.plan ul { margin: 0; padding: var(--s-4) 0 0; border-top: 1px solid var(--line); list-style: none; display: grid; gap: var(--s-2); flex: 1; }
.plan li { padding-left: 18px; position: relative; color: var(--tx-2); font-size: var(--fs-sm); }
.plan li::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--accent); }
.plan .btn { min-height: 44px; white-space: normal; text-align: center; }

.ab-faq-grid { display: grid; grid-template-columns: 1fr 2fr; gap: var(--s-8); }
.faq { display: grid; }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-child { border-bottom: 1px solid var(--line); }
.faq summary { display: flex; justify-content: space-between; align-items: center; gap: var(--s-4); min-height: 56px; padding: var(--s-3) 0; cursor: pointer; list-style: none; font-size: var(--fs-md); font-weight: 500; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary .ic { transition: rotate .2s var(--ease); color: var(--tx-2); }
.faq details[open] summary .ic { rotate: 180deg; }
.faq summary:hover { color: var(--accent-hi); }
.faq details p { padding-bottom: var(--s-5); }

.foot { padding: var(--s-7) 0 var(--s-8); }
.foot-grid { display: grid; grid-template-columns: auto 1fr; gap: var(--s-4) var(--s-6); align-items: center; }
.foot-brand { display: inline-flex; align-items: center; gap: 8px; font: 600 17px/1 var(--display); }
.foot-links { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); justify-content: flex-end; margin: 0; padding: 0; list-style: none; }
.foot-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--tx-2); text-decoration: none; }
.foot-links a:hover { color: var(--tx); text-decoration: underline; }
.foot-small { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--tx-3); }

/* ---------- 11. Narrow screens: bottom sheet with tabs ---------- */
@media (max-width: 1279px) {
  :root { --left: 208px; --right: 284px; }
  .about-link span { display: none; }
}
@media (max-width: 1099px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar) minmax(0, 1fr) 76px auto;
    grid-template-areas: "top" "stage" "film" "sheet";
    min-height: 600px;
  }
  .tools { display: flex; flex-direction: column; grid-area: sheet; min-height: 0; height: min(42dvh, 380px); background: var(--g-2); border-top: 1px solid var(--line); }
  .tabs { display: flex; flex: none; gap: 2px; padding: 6px var(--s-2) 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; min-height: 40px; padding: 0 var(--s-3); border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--tx-2); font-weight: 500; white-space: nowrap; }
  .tabs button[aria-selected="true"] { color: var(--tx); border-bottom-color: var(--accent); }
  .side, .adjust { display: contents; }
  .panel { display: none; border: 0; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .panel.is-tab { display: block; }
  .panel-head { display: none; }
  .panel-body { display: block !important; padding: var(--s-3) var(--s-4) var(--s-4); }
  .panel-body[hidden] { display: block !important; }
  .looks { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .curve-wrap { max-width: 260px; margin-inline: auto; }
  #b-colour, #b-light, #b-effects { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); column-gap: var(--s-5); align-content: start; }
  #b-colour .subhead { grid-column: 1 / -1; }
  /* Histogram floats over the top-right of the stage */
  .histo { position: absolute; z-index: 3; top: calc(var(--topbar) + 8px); right: 8px; width: 132px; padding: 4px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--g-1); }
  .histo canvas { height: 52px; }
  .histo-meta { display: none; }
  .stage { padding: var(--s-3); }
  .filmstrip { padding: 0 var(--s-3); gap: var(--s-3); }
  .strip canvas { width: 60px; height: 40px; }
  .strip-label { display: none; }
  .strip li { padding: 3px; }
  .strip-dot { top: 6px; right: 6px; }
  .about-link { display: none; }
  .docname { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } /* hidden from view on narrow screens, still the page heading for screen readers */
  .viewseg { margin-left: auto; }
  .ab-intro-grid, .ab-keys-grid, .ab-faq-grid { grid-template-columns: 1fr; gap: var(--s-6); }
  .plans { grid-template-columns: 1fr; max-width: 560px; }
  .about section { padding: var(--s-8) 0; }
}
@media (max-width: 560px) {
  .topbar { gap: var(--s-2); padding: 0 var(--s-2) 0 var(--s-3); }
  .logo span { display: none; }
  .seg { padding: 0 10px; }
  .seg span { display: none; }
  #viewEdit { padding: 0 10px; }
  #exportBtn span { display: none; }
  .tabs button { padding: 0 8px; }
  #exportBtn { width: 36px; padding: 0; }
  .topactions { margin-left: 0; gap: 0; }
  .tools { height: min(44dvh, 360px); }
  .ab-wrap { width: calc(100% - 32px); }
  .keys { grid-template-columns: 1fr; }
  .keys div { grid-template-columns: 92px 1fr; }
  .sizes { grid-template-columns: 1fr; }
  .result-dl { grid-template-columns: 1fr 1fr 1fr; }
  .dlg-body, .dlg-foot { padding-inline: var(--s-4); }
  .foot-grid { grid-template-columns: 1fr; }
  .foot-links { justify-content: flex-start; }
  .histo { width: 108px; }
  .histo canvas { height: 44px; }
}

/* ---------- 12. Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .dialog[open] { animation: dlg-in .28s var(--ease); }
  @keyframes dlg-in { from { opacity: 0; translate: 0 8px; scale: .985; } }
  .frame.is-swap { animation: swap .36s var(--ease); }
  @keyframes swap { from { opacity: .35; filter: blur(6px); } }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
}

/* Crop mode hides the split; the before layer stays hidden */
.app[data-tool="crop"] .split { display: none; }
.app[data-tool="crop"] .before { clip-path: inset(0 100% 0 0); }

/* Contact sheet of the six looks (About) */
.contact { margin: var(--s-6) 0 0; padding: var(--s-4); background: var(--g-0); border: 1px solid var(--line); border-radius: var(--r-3); }
.sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); margin: 0; padding: 0; list-style: none; }
.sheet-frame { display: grid; gap: var(--s-2); width: 100%; padding: 0; border: 0; background: transparent; text-align: left; }
.sheet-frame canvas { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; background: var(--g-2); border-radius: 2px; transition: outline-color .15s; outline: 1px solid transparent; outline-offset: 3px; }
.sheet-frame:hover canvas { outline-color: var(--accent); }
.sheet-frame span { font-size: var(--fs-sm); font-weight: 500; color: var(--tx); }
.sheet-frame:hover span { color: var(--accent-hi); }
.contact figcaption { margin-top: var(--s-4); font-size: var(--fs-xs); color: var(--tx-3); }
.no-js .contact { display: none; }
.about .foot-small { font-size: var(--fs-xs); color: var(--tx-3); }
@media (max-width: 1099px) {
  .sheet { grid-template-columns: repeat(2, 1fr); gap: var(--s-3); }
  .filmstrip { position: relative; }
  .perf { position: absolute; left: var(--s-3); bottom: calc(100% + 8px); max-width: calc(100% - 24px); padding: 3px 8px; border-radius: var(--r-1); background: var(--g-1); font-size: var(--fs-2xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 2; }
  .stage { padding: 64px var(--s-3) 36px; }
}

/* While cropping the frame shows the whole image, so the corner handles may hang over its edge */
.app[data-tool="crop"] .frame { overflow: visible; }

/* Without script the sheet shows the Light panel */
@media (max-width: 1099px) { .no-js .panel[data-tab="light"] { display: block; } }

/* Lead review fix: the open photo name is the page heading (h1), styled exactly as the old paragraph */
h1.docname { margin: 0; font-size: inherit; line-height: inherit; }
