:root {
  --chrome-h: calc(var(--header-h) + var(--options-h, 0px));   /* what stays pinned above the page: the header, and the options bar when it shows */
  --ar: 16 / 9;             /* preview format, set from the Format switcher */
  --tile-min: 230px;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 46%);
  align-items: start;
  width: 100%;
  min-width: 0;
}
.library, .workbench { min-width: 0; max-width: 100%; }

/* Library ---------------------------------------------------------------- */

/* The library scrolls with the page; the stage beside it stays put under the header. */
.library {
  scroll-margin-top: var(--chrome-h);      /* arriving at ./#library from another page, it starts under the header */
  min-height: calc(100vh - var(--chrome-h));
  padding: 20px var(--gutter) 48px;
  border-right: 1px solid var(--line);
}

.masthead { margin-bottom: 4px; }

.tagline { margin: 0; color: var(--muted); }
.tagline span { color: var(--text); font-variant-numeric: tabular-nums; }

.filters {
  position: sticky;
  top: calc(var(--header-h) + var(--format-h, 0px));
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0;
  margin: 0 0 6px;
  background: linear-gradient(var(--bg) 80%, transparent);
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: #3a3e47; }
.chip[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .n { margin-left: 6px; opacity: 0.6; font-variant-numeric: tabular-nums; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile-min) * var(--tile-scale, 1)), 1fr));   /* --tile-min is per format (demo.js) */
  gap: 14px 12px;
}

.tile { position: relative; }
/* Brought into view by the keyboard, a tile stops clear of the pinned header and category bar. */
.tile-main {
  scroll-margin: calc(var(--chrome-h) + 72px) 0 20px;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.tile canvas {
  display: block;
  width: 100%;
  aspect-ratio: var(--ar);
  border-radius: 8px;
  background: #000;
  outline: 1px solid var(--line);
  outline-offset: -1px;
  transition: outline-color 0.12s;
}
.tile:hover canvas { outline-color: #4a4f5a; }
.tile-main[aria-pressed="true"] canvas { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-main:focus-visible { outline: none; }
/* The white ring is for a tile reached by the keyboard that is not the one on the stage. The one on the stage keeps
   its amber ring, focused or not, so there is never a white ring left behind on a tile you have moved on from. */
.tile-main:focus-visible:not([aria-pressed="true"]) canvas { outline: 2px solid var(--text); outline-offset: 2px; }

/* The star sits on the thumbnail's corner: always shown once starred, on hover otherwise. */
.star {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(8, 9, 11, 0.62);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
}
.star svg path { fill: none; stroke: currentColor; stroke-width: 1.2; }
.tile:hover .star, .star:focus-visible, .star[aria-pressed="true"] { opacity: 1; }
.star:hover { transform: scale(1.1); }
.star:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.star[aria-pressed="true"] { color: var(--accent); }
.star[aria-pressed="true"] svg path { fill: currentColor; }
@media (hover: none) { .star { opacity: 0.85; } }

.tile .label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
}
.tile .name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .num { color: var(--muted); font: 11px var(--mono); }
.tile-main[aria-pressed="true"] .name { color: var(--accent); }

/* Clip label ------------------------------------------------------------------ */
/* Drawn over the picture, not in it: one size, pinned to the top-left corner, in every format. */

.stage { position: relative; }
.slate {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px 0 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.slate i { width: 6px; height: 6px; border-radius: 50%; background: #ffb347; }
.slate[data-clip="b"] i { background: #5affaa; }
.slate b { font-weight: 600; }
.slate span { opacity: 0.85; }
.stage .slate { top: 14px; left: 14px; height: 26px; padding: 0 11px 0 9px; border-radius: 7px; font-size: 12px; gap: 8px; }
.stage .slate i { width: 7px; height: 7px; }

/* Format switcher ------------------------------------------------------------ */

.format-bar { display: flex; align-items: flex-start; gap: 10px; padding: 14px 0 2px; }
.format-bar + .format-bar { padding-top: 10px; }
/* The formats stay in reach while the list scrolls; the logo switcher scrolls away. The filters pin under it
   (--format-h is its height, measured in demo.js). */
.size-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 3;
  padding-bottom: 6px;
  background: var(--bg);
  box-shadow: 0 2px 0 var(--bg);      /* covers any rounding gap above the filters pinned under it */
}
.format-label { flex: none; width: 48px; padding-top: 7px; color: var(--muted); }
.formats { display: flex; flex-wrap: wrap; gap: 6px; }
.format {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.format svg { flex: none; }
.format rect { fill: none; stroke: currentColor; stroke-width: 1.6; }
.format:hover { color: var(--text); border-color: #3a3e47; }
.format[aria-checked="true"] { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
.format:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Views and favorites ------------------------------------------------------- */

.fav-bar { display: flex; align-items: center; gap: 16px; padding: 14px 0 12px; color: var(--muted); }
.fav-bar .spacer { flex: 1; }
.file-link { cursor: pointer; }
.file-link input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-link:focus-within { color: var(--text); text-decoration: underline; }

.empty-state { max-width: 44ch; margin: 56px auto; text-align: center; color: var(--muted); }
.empty-state svg { color: var(--accent); }
.empty-state h2 { margin: 10px 0 6px; font-size: 18px; color: var(--text); }
.empty-state p { margin: 0; }
.empty-state a { color: var(--text); }
kbd { padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--panel-2); font: 12px var(--mono); color: var(--text); }

.title-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.fav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.fav-btn svg path { fill: none; stroke: currentColor; stroke-width: 1.2; }
.fav-btn:hover { border-color: #4a4f5a; }
.fav-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.fav-btn[aria-pressed="true"] svg path { fill: currentColor; }
.fav-note { margin: -10px 0 18px; font-size: 12px; color: var(--muted); }
.fav-note .text-btn { color: var(--text); text-decoration: underline; }

/* Workbench -------------------------------------------------------------- */

.workbench {
  position: sticky;
  top: var(--chrome-h);
  height: calc(100vh - var(--chrome-h));
  overflow-y: auto;
  padding: 24px var(--gutter);
  background: var(--panel);
}

/* The stage keeps the chosen format; tall formats are capped in height and centred. */
.stage {
  width: min(100%, calc(64vh * (var(--ar))));
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 20px 50px -20px rgba(0, 0, 0, 0.8);
}
.stage canvas { display: block; width: 100%; aspect-ratio: var(--ar); }

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 22px;
}
.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.icon-btn:hover { filter: brightness(1.08); }
.icon-btn.quiet { width: 30px; height: 30px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.icon-btn.quiet:hover { filter: none; color: var(--text); border-color: #3a3e47; }
.icon-btn.quiet[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.hint a { color: var(--text-2); }
.hint a:hover { color: var(--accent); }
#readout { flex: none; width: 38px; color: var(--muted); text-align: right; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.transport input[type="range"] { flex: 1; }

.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.eyebrow { font: 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.inspector h1 { margin: 2px 0 0; font-size: 26px; line-height: 1.15; letter-spacing: -0.02em; text-wrap: balance; }
.id { flex: none; padding: 3px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); font: 12px var(--mono); color: var(--muted); }
.description { margin: 8px 0 20px; color: var(--muted); max-width: 56ch; text-wrap: pretty; }

.panel { border-top: 1px solid var(--line); padding: 14px 0 16px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 22px;
  margin-bottom: 10px;
  font: 11px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.text-btn { border: 0; background: none; padding: 2px 0; font: 12px var(--sans); letter-spacing: 0; text-transform: none; color: var(--muted); cursor: pointer; }
.text-btn:hover { color: var(--text); }

.controls { display: grid; gap: 10px; }
.control {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 12px;
}
.control > label, .control > .lbl { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.control output { text-align: right; font: 12px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.control .wide { grid-column: 2 / 4; }
.control .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.empty { color: var(--muted); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: #343841; }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: #343841; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--text);
  border: 0;
}
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--text); border: 0; }
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
input[type="color"] { width: 44px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }

.clip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-btn {
  display: block;
  padding: 8px 10px;
  border: 1px dashed #3a3e47;
  border-radius: 8px;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-btn:hover { border-color: var(--accent); }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn:focus-within { border-color: var(--accent); }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.snippet {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: #0c0d10;
  border: 1px solid var(--line);
  font: 12px/1.6 var(--mono);
  overflow-x: auto;
}

/* Watermarks: what this site adds to the family's stage ---------------------- */

/* The logo picker is the format switcher's twin; its last chip opens the file picker. */
.format.add { border-style: dashed; background: transparent; }
.format.add:hover { border-color: var(--accent); color: var(--text); }

/* A small flag on the tiles that move. */
.moves {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 9, 11, 0.62);
  font: 10px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  pointer-events: none;
}

/* "Overlay only": the watermark over a checkerboard, as the PNG is. */
[data-backdrop="clear"] .stage,
[data-backdrop="clear"] .tile canvas {
  background: repeating-conic-gradient(#20242d 0% 25%, #171a21 0% 50%) 0 0 / 20px 20px;
}

/* What is behind the watermark: one row of choices beside the play button. */
.segments { display: flex; flex: 1; flex-wrap: wrap; gap: 4px; min-width: 0; }
.segment {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.segment:hover { color: var(--text); border-color: #3a3e47; }
.segment[aria-checked="true"] { background: var(--panel-2); border-color: var(--accent); color: var(--text); }

.panel-note { font: 11px var(--mono); letter-spacing: 0.08em; color: var(--accent); }

.export-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.primary-btn {
  padding: 7px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled, .line-btn:disabled { opacity: 0.6; cursor: default; }

/* A moving watermark's own row: how long, how many frames a second, and the two files it can be saved as. */
.motion { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.motion-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.motion-fields label { color: var(--text); }
.motion-fields label + input, .motion-fields label + select { margin-right: 0; }
.motion-fields .unit { margin-right: 14px; color: var(--muted); }
.motion-fields input[type="number"] { width: 76px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-variant-numeric: tabular-nums; }
.motion-fields select { width: auto; }
.motion-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.line-btn { padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; }
.line-btn:hover { border-color: var(--accent); }

input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}
input[type="text"]::placeholder { color: var(--muted); opacity: 0.7; }
input[type="text"]:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#brand-files { margin-top: 12px; }
.clip-row.one { grid-template-columns: 1fr; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

.tabs { display: flex; gap: 14px; }
.tab {
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* Wide but not desktop, held sideways (an unfolded iPhone Duo, a tablet on its side): the library stays on the
   left and the stage takes the larger share, as tall as the screen allows under the header and its controls. */

@media (min-width: 600px) and (max-width: 1199px) and (orientation: landscape) {
  :root { --tile-scale: 0.75; }
  .app { grid-template-columns: minmax(220px, 2fr) minmax(0, 3fr); }
  .library { padding: 16px 20px 40px; }
  .workbench { padding: 16px 20px; }
  .stage { width: min(100%, calc((100vh - var(--chrome-h) - 120px) * (var(--ar)))); }
  .transport { margin: 12px 0 18px; }
}
/* The Duo's inner screen gives Safari about 667 x 375: smaller tiles so two fit a row, and less around the stage. */
@media (min-width: 600px) and (max-width: 819px) and (orientation: landscape) {
  :root { --tile-scale: 0.6; }
  .library { padding: 12px 12px 32px; }
  .workbench { padding: 12px 14px; }
  .stage { width: min(100%, calc((100vh - var(--chrome-h) - 92px) * (var(--ar)))); }
  .transport { gap: 8px; margin: 8px 0 14px; }
}
/* A short screen can't spare the height for the filters to stay pinned over the library: they scroll away with it. */
@media (max-height: 500px) {
  .filters { position: static; background: none; }
}
/* On a short screen or a phone, the pinned Format bar takes one row: its label and the shape icons go (the buttons
   still say 1:1, 9:16, 4:5, 16:9) and the buttons tighten. */
@media (max-height: 500px), (max-width: 599px) {
  .size-bar { padding-top: 8px; }
  .size-bar .format-label { display: none; }
  .size-bar .formats { flex-wrap: nowrap; gap: 5px; }
  .size-bar .format { padding: 5px 10px; }
  .size-bar .format svg { display: none; }
}

/* The options bar: Format and the categories in one row across the page under the header, so the library column
   below it is all tiles. Only where demo.js moves them in (a phone or tablet held sideways); it scrolls sideways
   when the row is longer than the screen. */
.options-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);   /* a hint that the row goes on */
}
.options-bar::-webkit-scrollbar { display: none; }
.options-bar[hidden] { display: none; }
.options-bar .size-bar { position: static; flex: none; padding: 0; box-shadow: none; background: none; }
.options-bar .size-bar .format-label { display: none; }
.options-bar .formats { flex-wrap: nowrap; }
.options-bar .filters { position: static; flex: none; flex-wrap: nowrap; padding: 0; margin: 0; background: none; }

/* Narrow (a phone, or a tablet upright): stage on top, library below. The same test is STACKED in demo.js. */

@media (max-width: 599px), (max-width: 980px) and (orientation: portrait) {
  .app { display: flex; flex-direction: column-reverse; }
  .workbench { position: static; height: auto; overflow: visible; padding: 16px var(--gutter); scroll-margin-top: var(--header-h); }
  .library { border-right: 0; min-height: 0; padding: 20px var(--gutter) 40px; }
  .control { grid-template-columns: 104px minmax(0, 1fr) 52px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
