/* paper — components. Needs tokens.css. Every class is prefixed `ui-`; variants use data-attributes.
   The idea: a grey desk with paper objects on it. Objects float (soft shadow), lift under the pointer,
   and stack like real paper. No borders anywhere. */

/* ── Base: put .ui on <body> or any container ─────────────────────────── */
.ui {
  font: var(--weight) var(--text-md) / var(--leading) var(--font);
  letter-spacing: var(--tracking);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.ui *, .ui *::before, .ui *::after { box-sizing: border-box; }
.ui :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── Text ─────────────────────────────────────────────────────────────── */
.ui-display { margin: 0; font-size: var(--text-3xl); font-weight: var(--weight-display); line-height: 1.02; letter-spacing: var(--tracking-display); }
.ui-statement { margin: 0; font-size: var(--text-2xl); font-weight: var(--weight-display); line-height: var(--leading-tight); letter-spacing: var(--tracking-display); color: var(--muted); }
.ui-statement strong { font-weight: inherit; color: var(--ink); }
.ui-title { margin: 0; font-size: var(--text-xl); font-weight: var(--weight-ui); line-height: var(--leading-tight); letter-spacing: -0.015em; }
.ui-label { font-weight: var(--weight-ui); }
.ui-muted { color: var(--muted); }
.ui-caption { font-size: var(--text-sm); color: var(--muted); }
.ui-mono { font-family: var(--font-mono); font-size: 0.9em; letter-spacing: var(--tracking-mono); font-variant-numeric: tabular-nums; }

/* Pair — title + muted line under it. data-variant="kicker" flips it: muted kicker on top, ink title under,
   same size — the references' signature ("Untitled / Spatial organisation…", "3 Items / Archived notes"). */
.ui-pair { display: flex; flex-direction: column; min-width: 0; }
.ui-pair > :first-child { font-weight: var(--weight-ui); }
.ui-pair > :not(:first-child) { color: var(--muted); }
.ui-pair > * { margin: 0; }
.ui-pair[data-variant='kicker'] { line-height: var(--leading-tight); letter-spacing: -0.015em; }
.ui-pair[data-variant='kicker'] > :first-child { font-weight: var(--weight); color: var(--muted); }
.ui-pair[data-variant='kicker'] > :not(:first-child) { font-weight: var(--weight-ui); color: var(--ink); }

.ui-link { color: var(--muted); text-decoration: none; transition: color var(--fast) var(--ease); }
.ui-link:hover, .ui-link[aria-current] { color: var(--ink); }

/* Highlighter — <mark class="ui-mark">. Always dark text: it's yellow in both themes. */
.ui-mark { padding: 0.05em 0.2em; margin: 0 -0.1em; background: var(--mark); color: #17181a; border-radius: 1px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }

/* ── Tile = a sheet of paper on the desk ──────────────────────────────── */
.ui-tile {
  --field: var(--well);
  --field-hover: var(--well-hover);
  --sheets: 0 0 transparent;
  position: relative;
  padding: var(--s-7);
  border-radius: var(--r-lg);
  background: var(--paper, var(--tile));
  box-shadow: var(--sheets), var(--shadow-paper);
  color: inherit;
  text-decoration: none;
  transform: rotate(var(--rot, 0deg));
}
:where(.ui-tile) { display: block; } /* zero specificity: .ui-pair, .ui-row, .ui-stack on a tile win */
.ui-tile[data-pad='sm'] { padding: var(--s-5); }
.ui-tile[data-pad='none'] { padding: 0; overflow: hidden; }
a.ui-tile, button.ui-tile, .ui-tile[data-interactive] {
  cursor: pointer; border: 0; font: inherit; text-align: inherit; width: 100%;
  transition: background var(--fast) var(--ease), box-shadow var(--base) var(--ease), transform var(--base) var(--ease);
}
a.ui-tile:hover, button.ui-tile:hover, .ui-tile[data-interactive]:hover {
  background: var(--paper, var(--tile-hover));
  box-shadow: var(--sheets), var(--shadow-lift);
  transform: translateY(-3px) rotate(var(--rot, 0deg));
}
a.ui-tile:active, button.ui-tile:active { transform: translateY(-1px) rotate(var(--rot, 0deg)) scale(0.995); transition-duration: var(--fast); }
.ui-tile > img, .ui-tile > video { display: block; width: 100%; height: 100%; object-fit: cover; }
/* a tile inside a tile is a flat panel, not another sheet */
.ui-tile .ui-tile { box-shadow: none; background: var(--well); }
.ui-tile a.ui-tile:hover { background: var(--well-hover); box-shadow: none; transform: none; }

/* Stack of sheets behind a note: data-sheets="1 | 2" (drawn with shadows, so the tile can still lift) */
.ui-tile[data-sheets] {
  --sheets: 0 4px 0 -2px var(--paper, var(--tile)), 0 4.5px 0 -1.5px var(--sheet-edge);
  margin-bottom: 5px;
}
.ui-tile[data-sheets='2'] {
  --sheets: 0 4px 0 -2px var(--paper, var(--tile)), 0 4.5px 0 -1.5px var(--sheet-edge),
            0 8px 0 -4px var(--paper, var(--tile)), 0 8.5px 0 -3.5px var(--sheet-edge);
  margin-bottom: 9px;
}
/* Tones — stickies and coloured paper. Text stays dark on light tones in both themes. */
.ui-tile[data-tone], .ui-folder[data-tone] { --ink: #17181a; --muted: #55575b; --field: rgb(0 0 0 / 0.07); --field-hover: rgb(0 0 0 / 0.1); color: var(--ink); }
[data-tone='lime']  { --paper: var(--tone-lime); }
[data-tone='pink']  { --paper: var(--tone-pink); }
[data-tone='peach'] { --paper: var(--tone-peach); }
[data-tone='mint']  { --paper: var(--tone-mint); }
.ui-tile[data-tone='mint'], .ui-folder[data-tone='mint'] { --ink: var(--tone-mint-ink); --muted: var(--tone-mint-muted); }
.ui-tile[data-tone='dark'] { --paper: var(--tone-dark); --ink: #f1f2f3; --muted: #a3a5aa; --field: rgb(255 255 255 / 0.1); --field-hover: rgb(255 255 255 / 0.14); }
/* Tilt — stickies and loose prints: data-tilt="l | r" */
[data-tilt='l'] { --rot: calc(-1 * var(--tilt)); }
[data-tilt='r'] { --rot: var(--tilt); }

.ui-grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(min(var(--min, 240px), 100%), 1fr)); }
.ui-stack { display: flex; flex-direction: column; gap: var(--gap, var(--s-4)); }
.ui-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s-3)); }
.ui-spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s-5); }

/* ── Button ───────────────────────────────────────────────────────────── */
.ui-btn {
  --btn-bg: var(--ink); --btn-fg: var(--bg); --btn-hover: color-mix(in srgb, var(--ink) 84%, var(--bg)); --btn-shadow: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--h-md); padding: 0 var(--s-5);
  border: 0; border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg); box-shadow: var(--btn-shadow);
  font: var(--weight-ui) var(--text-md) / 1 var(--font); letter-spacing: var(--tracking);
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.ui-btn:hover { background: var(--btn-hover); }
.ui-btn:active { transform: scale(0.96); }
/* soft = a white square on the desk (the references' dock); on paper it becomes a recessed well */
.ui-btn[data-variant='soft']   { --btn-bg: var(--raised); --btn-fg: var(--ink); --btn-hover: var(--tile-hover); --btn-shadow: var(--shadow-sm); }
.ui-tile .ui-btn[data-variant='soft'], .ui-dialog .ui-btn[data-variant='soft'] { --btn-bg: var(--field); --btn-hover: var(--field-hover); --btn-shadow: none; }
.ui-btn[data-variant='accent'] { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-hover: var(--accent-hover); }
.ui-btn[data-variant='ghost']  { --btn-bg: transparent; --btn-fg: var(--ink); --btn-hover: var(--field, var(--well)); }
/* pressed = the active dock square turns ink */
.ui-btn[aria-pressed='true'] { --btn-bg: var(--ink); --btn-fg: var(--bg); --btn-hover: var(--ink); }
.ui-btn[data-size='sm'] { height: var(--h-sm); padding: 0 var(--s-3); border-radius: 8px; font-size: var(--text-sm); }
.ui-btn[data-size='lg'] { height: var(--h-lg); padding: 0 var(--s-6); border-radius: 12px; font-size: var(--text-lg); }
.ui-btn[data-icon] { width: var(--h-md); padding: 0; }
.ui-btn[data-icon][data-size='sm'] { width: var(--h-sm); }
.ui-btn[data-icon][data-size='lg'] { width: var(--h-lg); }
.ui-btn:disabled, .ui-btn[aria-disabled='true'] { opacity: 0.4; pointer-events: none; }
.ui-btn svg, .ui-icon { width: 16px; height: 16px; flex: none; }

/* Toolbar — the dark floating pill of icon buttons */
.ui-toolbar { display: inline-flex; align-items: center; gap: 2px; padding: 4px; border-radius: var(--r-pill); background: var(--chrome); color: var(--on-chrome); box-shadow: var(--shadow-sm); }
.ui-toolbar .ui-btn { --btn-bg: transparent; --btn-fg: var(--on-chrome-muted); --btn-hover: rgb(255 255 255 / 0.1); --btn-shadow: none; border-radius: var(--r-pill); }
.ui-toolbar .ui-btn:hover, .ui-toolbar .ui-btn[aria-pressed='true'] { --btn-fg: var(--on-chrome); }
.ui-toolbar .ui-btn[aria-pressed='true'] { --btn-bg: rgb(255 255 255 / 0.14); }

/* ── Form fields ──────────────────────────────────────────────────────── */
.ui-field { display: flex; flex-direction: column; gap: var(--s-2); }
.ui-field > label { font-weight: var(--weight-ui); }
.ui-hint { font-size: var(--text-sm); color: var(--muted); }
.ui-field:has([aria-invalid='true']) .ui-hint { color: var(--danger); }

.ui-input, .ui-select {
  width: 100%; height: var(--h-md); padding: 0 var(--s-5);
  border: 0; border-radius: var(--r-md);
  background: var(--field, var(--tile)); color: var(--ink);
  font: var(--weight) var(--text-md) / var(--leading) var(--font); letter-spacing: var(--tracking);
  transition: background var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea.ui-input { height: auto; min-height: 96px; padding: var(--s-3) var(--s-5); resize: vertical; }
.ui-input::placeholder { color: var(--faint); }
.ui-input:hover, .ui-select:hover { background: var(--field-hover, var(--tile-hover)); }
.ui-input:focus-visible, .ui-select:focus-visible { outline: 0; background: var(--field-hover, var(--tile-hover)); box-shadow: inset 0 0 0 1.5px var(--ink); }
.ui-input[aria-invalid='true'] { box-shadow: inset 0 0 0 1.5px var(--danger); }
.ui-input:disabled, .ui-select:disabled { color: var(--faint); pointer-events: none; }
.ui-select {
  appearance: none; padding-right: var(--s-8); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23808286' stroke-width='1.5'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s-5) center;
}

/* Checkbox + radio: <label class="ui-check"><input type="checkbox"> Text</label>
   Empty = a recessed grey square, checked = a solid ink square — no tick, like the references. */
.ui-check { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.ui-check input {
  appearance: none; margin: 0; flex: none; width: 1.15em; height: 1.15em; min-width: 14px; min-height: 14px;
  border-radius: 28%; background: var(--field, var(--well)); cursor: pointer;
  display: grid; place-content: center;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease-pop);
}
.ui-check input:hover { background: var(--field-hover, var(--well-hover)); }
.ui-check input:active { transform: scale(0.85); }
.ui-check input[type='radio'] { border-radius: 50%; }
.ui-check input:checked { background: var(--ink); }
.ui-check input[type='radio']:checked::after { content: ''; width: 0.4em; height: 0.4em; border-radius: 50%; background: var(--bg); }
.ui-check:has(input:disabled) { color: var(--faint); pointer-events: none; }
.ui-check input:disabled { opacity: 0.5; }

/* Checklist — mono, airy rows; nest a <ul> to indent */
.ui-list { margin: 0; padding: 0; list-style: none; font: var(--weight) var(--text-sm) / var(--leading-list) var(--font-mono); letter-spacing: var(--tracking-mono); }
.ui-list ul { margin: 0; padding: 0 0 0 1.5em; list-style: none; }
.ui-list .ui-check { align-items: baseline; gap: 0.75em; }
.ui-list .ui-check input { transform: translateY(0.18em); }
.ui-list .ui-check input:active { transform: translateY(0.18em) scale(0.85); }

/* Switch: <input type="checkbox" role="switch" class="ui-switch"> */
.ui-switch {
  appearance: none; margin: 0; flex: none; position: relative; cursor: pointer;
  width: 40px; height: 24px; border-radius: var(--r-pill);
  background: var(--track);
  transition: background var(--base) var(--ease);
}
.ui-switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.22);
  transition: transform var(--base) var(--ease);
}
.ui-switch:checked { background: var(--ink); }
.ui-switch:checked::after { transform: translateX(16px); background: var(--bg); }

/* Segmented control — radios, no JS. Looks like the dark toolbar pill. */
.ui-segmented { display: inline-flex; padding: 4px; gap: 2px; border-radius: var(--r-pill); background: var(--chrome); }
.ui-segmented label { position: relative; }
.ui-segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ui-segmented span {
  display: flex; align-items: center; height: calc(var(--h-md) - 8px); padding: 0 var(--s-5);
  border-radius: var(--r-pill); color: var(--on-chrome-muted); font-weight: var(--weight-ui);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.ui-segmented label:hover span { color: var(--on-chrome); }
.ui-segmented input:checked + span { background: rgb(255 255 255 / 0.14); color: var(--on-chrome); }
.ui-segmented input:focus-visible + span { outline: 2px solid var(--on-chrome); outline-offset: -2px; }

/* ── Row — thumb + pair + trailing. Use inside a .ui-tile or as one. ─── */
.ui-row { display: flex; align-items: center; gap: var(--s-5); min-width: 0; }
.ui-row > .ui-pair { flex: 1; }
.ui-row > :last-child:not(.ui-pair):not(.ui-thumb) { margin-left: auto; flex: none; }
.ui-thumb {
  flex: none; width: var(--size, 64px); height: var(--size, 64px); border-radius: var(--r-md);
  background: var(--field, var(--well)); object-fit: cover; display: grid; place-items: center;
  font-weight: var(--weight-ui); overflow: hidden;
}
.ui-thumb[data-round] { border-radius: 50%; }

/* ── Badge — small rounded chips ("Today ⌄", "On Friday ⌄") ──────────── */
.ui-badge {
  display: inline-flex; align-items: center; gap: var(--s-1); height: 22px; padding: 0 var(--s-3);
  border-radius: 6px; background: var(--raised); color: var(--ink); box-shadow: var(--shadow-sm);
  font-size: var(--text-xs); font-weight: var(--weight-ui); white-space: nowrap;
}
.ui-tile .ui-badge { background: var(--field); box-shadow: none; }
.ui-badge[data-variant='accent']  { background: var(--accent); color: var(--on-accent); }
.ui-badge[data-variant='ink']     { background: var(--ink); color: var(--bg); }
.ui-badge[data-variant='success']::before, .ui-badge[data-variant='danger']::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--success);
}
.ui-badge[data-variant='danger']::before { background: var(--danger); }

/* ── Nav ──────────────────────────────────────────────────────────────── */
.ui-nav { display: flex; align-items: center; justify-content: space-between; gap: var(--s-6); padding: var(--s-5) 0; }
.ui-nav ul { display: flex; gap: var(--s-6); margin: 0; padding: 0; list-style: none; }

/* ── Empty state ──────────────────────────────────────────────────────── */
.ui-empty { display: grid; justify-items: center; gap: var(--s-5); padding: var(--s-9) var(--s-7); text-align: center; }
.ui-empty > p { margin: 0; max-width: 32ch; }
.ui-empty > p:not(.ui-title) { color: var(--muted); }

/* ── Dialog — native <dialog>; open with kit.js or dialog.showModal().
   Enters and leaves (transition + @starting-style); the desk behind whitens, it doesn't go dark.
   data-style="page" = a note opened into a full sheet. ── */
.ui-dialog {
  --field: var(--well); --field-hover: var(--well-hover);
  width: min(440px, calc(100vw - 32px)); padding: var(--s-7); border: 0; border-radius: calc(var(--r-lg) + 4px);
  background: var(--tile); color: var(--ink); box-shadow: var(--shadow-float);
  font: inherit;
  opacity: 0; transform: translateY(10px) scale(0.96);
  transition: opacity var(--base) var(--ease), transform var(--base) var(--ease), overlay var(--base) allow-discrete, display var(--base) allow-discrete;
}
.ui-dialog[open] { opacity: 1; transform: none; }
@starting-style { .ui-dialog[open] { opacity: 0; transform: translateY(10px) scale(0.96); } }
.ui-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); opacity: 0; transition: opacity var(--base) var(--ease), overlay var(--base) allow-discrete, display var(--base) allow-discrete; }
.ui-dialog[open]::backdrop { opacity: 1; }
@starting-style { .ui-dialog[open]::backdrop { opacity: 0; } }
.ui-dialog > form { display: flex; flex-direction: column; gap: var(--s-6); }
.ui-dialog[data-style='page'] {
  width: min(760px, calc(100vw - 24px)); max-width: none; height: calc(100dvh - 48px); max-height: none;
  margin: 24px auto 0; padding: clamp(var(--s-7), 7vw, 88px); border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--tile-hover); transform: translateY(24px) scale(0.9); transform-origin: 50% 30%;
  transition-duration: var(--slow);
}
.ui-dialog[data-style='page'][open] { transform: none; }
@starting-style { .ui-dialog[data-style='page'][open] { opacity: 0; transform: translateY(24px) scale(0.9); } }
.ui-dialog[data-style='page'] > form { gap: var(--s-7); max-width: 58ch; }
.ui-dialog [data-at='close'] { position: absolute; top: var(--s-5); right: var(--s-5); }

/* ── Toast — kit.js: ui.toast('Saved') — a dark chip like the toolbar ── */
.ui-toasts { position: fixed; inset: auto 0 var(--s-7) 0; display: grid; justify-items: center; gap: var(--s-3); pointer-events: none; z-index: 100; }
.ui-toast {
  display: flex; align-items: center; gap: var(--s-5); min-height: var(--h-lg); padding: 0 6px 0 var(--s-6);
  border-radius: var(--r-pill); background: var(--chrome); color: var(--on-chrome); box-shadow: var(--shadow-float);
  font-weight: var(--weight-ui); pointer-events: auto; animation: ui-pop var(--base) var(--ease-pop);
}
.ui-toast .ui-btn { border-radius: var(--r-pill); }
.ui-toast:not(:has(button)) { padding-right: var(--s-6); }
.ui-toast[data-leaving] { opacity: 0; transform: translateY(6px); transition: opacity var(--base) var(--ease), transform var(--base) var(--ease); }

/* ── Media — images are prints: almost square corners, casting a shadow on the desk
   <figure class="ui-media" data-ratio="portrait"><img src alt></figure>
   The paper colour shows while the image loads. Linked prints lift instead of zooming hard. */
.ui-media {
  position: relative; display: block; margin: 0; overflow: hidden; isolation: isolate;
  aspect-ratio: var(--ratio, auto);
  border-radius: var(--r-sm); background: var(--tile); color: #fff; text-decoration: none;
  box-shadow: var(--shadow-paper);
  transform: rotate(var(--rot, 0deg));
  transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease);
}
.ui-media[data-ratio='square']    { --ratio: 1 / 1; }
.ui-media[data-ratio='portrait']  { --ratio: 4 / 5; }
.ui-media[data-ratio='tall']      { --ratio: 3 / 4; }
.ui-media[data-ratio='landscape'] { --ratio: 3 / 2; }
.ui-media[data-ratio='wide']      { --ratio: 16 / 9; }
.ui-media > img, .ui-media > video {
  display: block; width: 100%; height: 100%; object-fit: cover;
  transition: transform var(--slow) var(--ease);
}
/* Object on a flat surface — packshots, logos, screenshots. Set the surface with style="background: …". */
.ui-media[data-fit='contain'] > img { object-fit: contain; padding: var(--inset, 12%); }
a.ui-media:hover { transform: translateY(-3px) rotate(var(--rot, 0deg)); box-shadow: var(--shadow-lift); }
a.ui-media:hover > img, a.ui-media:hover > video { transform: scale(1.02); }
a.ui-media:focus-visible { outline-offset: 3px; }
/* Inside a padded tile a print lies flat on the paper */
.ui-tile:not([data-pad='none']) .ui-media { border-radius: 3px; box-shadow: none; }
.ui-figure .ui-media, .ui-mosaic > .ui-media, .ui-masonry > .ui-media { box-shadow: var(--shadow-paper); }

/* Overlay caption — bottom of the image */
.ui-overlay {
  position: absolute; inset: auto 0 0 0; z-index: 1;
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-5);
  padding: var(--s-9) var(--s-5) var(--s-5);
  background: linear-gradient(transparent, rgb(10 12 14 / 0.52));
  color: #fff; font-weight: var(--weight-ui);
}
.ui-overlay .ui-pair > :not(:first-child) { color: rgb(255 255 255 / 0.76); }
/* Glass → here a paper label pinned on the print */
.ui-overlay[data-style='glass'] {
  inset: auto var(--s-3) var(--s-3) var(--s-3); padding: var(--s-3) var(--s-5); align-items: center;
  border-radius: var(--r-md); color: var(--ink);
  background: color-mix(in srgb, var(--tile) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-sm);
}
.ui-overlay[data-style='glass'] .ui-caption { color: var(--muted); }
.ui-overlay[data-style='glass'] .ui-pair > :not(:first-child) { color: var(--muted); }
/* Corner slot — badge or icon button on top of the image */
.ui-corner { position: absolute; z-index: 1; top: var(--s-3); left: var(--s-3); }
.ui-corner[data-at='tr'] { left: auto; right: var(--s-3); }
.ui-corner[data-at='br'] { top: auto; left: auto; right: var(--s-5); bottom: var(--s-5); }
/* Reveal on hover (always visible on touch) */
@media (hover: hover) {
  .ui-media [data-reveal='hover'] { opacity: 0; transform: translateY(6px); transition: opacity var(--base) var(--ease), transform var(--base) var(--ease); }
  .ui-media:hover [data-reveal='hover'], .ui-media:focus-visible [data-reveal='hover'] { opacity: 1; transform: none; }
}

/* Figure — image with caption below */
.ui-figure { display: grid; gap: var(--s-3); margin: 0; }
.ui-figure > figcaption { margin: 0; }

/* ── Image layouts ────────────────────────────────────────────────────── */
/* Mosaic — bento grid; children: data-span="wide | tall | big" */
.ui-mosaic {
  display: grid; gap: var(--s-4); grid-auto-flow: dense;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); grid-auto-rows: var(--row, 200px);
}
.ui-mosaic > * { aspect-ratio: auto; }
.ui-mosaic > [data-span='wide'], .ui-mosaic > [data-span='big'] { grid-column: span 2; }
.ui-mosaic > [data-span='tall'], .ui-mosaic > [data-span='big'] { grid-row: span 2; }
@media (max-width: 760px) { .ui-mosaic { --cols: 2; --row: 150px; } }

/* Masonry — columns of mixed heights; --cols is the maximum, --min the narrowest column */
.ui-masonry { columns: var(--cols, 3) var(--min, 220px); column-gap: var(--s-4); }
.ui-masonry > * { break-inside: avoid; margin-bottom: var(--s-4); }

/* Strip — horizontal scroll with snap; arrows: <button data-scroll="next" aria-controls="id">
   Padded so the shadows aren't cut. */
.ui-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--item, min(80%, 380px)); gap: var(--s-4);
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none;
  padding: 6px 0 36px; margin-bottom: -30px;
}
.ui-strip::-webkit-scrollbar { display: none; }
.ui-strip > * { scroll-snap-align: start; }

/* Lightbox — kit.js: <a href="large.jpg" data-lightbox><img …></a> */
.ui-lightbox { padding: 0; border: 0; background: none; overflow: visible; max-width: 92vw; max-height: 90vh; }
.ui-lightbox img { display: block; max-width: 92vw; max-height: 84vh; border-radius: var(--r-sm); box-shadow: var(--shadow-float); }
.ui-lightbox figcaption { margin-top: var(--s-5); text-align: center; color: var(--ink); font-weight: var(--weight-ui); }
.ui-lightbox .ui-btn { position: absolute; top: var(--s-4); right: var(--s-4); }
.ui-lightbox::backdrop { background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.ui-lightbox[open] { animation: ui-pop var(--slow) var(--ease); }
.ui-lightbox[open]::backdrop { animation: ui-fade var(--base) var(--ease); }

/* ── Kit-specific: objects on the desk ───────────────────────────────── */
/* Folder — back panel with a tab, sheets peeking out, a frosted front. data-tone="mint" etc. */
.ui-folder {
  --tab: 42%; --folder: color-mix(in srgb, var(--tile) 72%, var(--bg)); --sheet-a: var(--tile-hover); --sheet-b: color-mix(in srgb, var(--tile) 90%, var(--bg));
  position: relative; isolation: isolate; display: flex; flex-direction: column; justify-content: flex-end; gap: var(--s-4);
  min-height: 220px; padding: calc(30px + var(--s-7)) var(--s-7) var(--s-7);
  color: var(--ink); text-decoration: none;
  transition: transform var(--base) var(--ease);
}
.ui-folder::before, .ui-folder::after { content: ''; position: absolute; border-radius: var(--r-lg); transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease); }
.ui-folder::before { /* back + tab + two sheets */
  inset: 0; z-index: -2;
  background:
    linear-gradient(var(--sheet-a) 0 0) 18px 20px / 56% 60px no-repeat,
    linear-gradient(var(--sheet-b) 0 0) 40% 26px / 50% 60px no-repeat,
    color-mix(in srgb, var(--folder) 90%, #000 10%);
  -webkit-mask: linear-gradient(#000 0 0) 0 0 / var(--tab) 100% no-repeat, linear-gradient(to top right, #000 50%, #0000 51%) var(--tab) 0 / 30px 14px no-repeat, linear-gradient(#000 0 0) 0 14px / 100% 100% no-repeat;
  mask: linear-gradient(#000 0 0) 0 0 / var(--tab) 100% no-repeat, linear-gradient(to top right, #000 50%, #0000 51%) var(--tab) 0 / 30px 14px no-repeat, linear-gradient(#000 0 0) 0 14px / 100% 100% no-repeat;
}
@supports (clip-path: shape(from 0 0, line to 1px 1px)) { /* smooth tab where supported; the mask above is the fallback */
  .ui-folder::before {
    -webkit-mask: none; mask: none; border-radius: 0;
    clip-path: shape(from 0 var(--r-lg), curve to var(--r-lg) 0 with 0 0, hline to calc(var(--tab) - 10px), curve to calc(var(--tab) + 4px) 4px with var(--tab) 0,
      line to calc(var(--tab) + 20px) 12px, curve to calc(var(--tab) + 32px) 14px with calc(var(--tab) + 24px) 14px,
      hline to calc(100% - var(--r-lg)), curve to 100% calc(14px + var(--r-lg)) with 100% 14px,
      vline to calc(100% - var(--r-lg)), curve to calc(100% - var(--r-lg)) 100% with 100% 100%, hline to var(--r-lg), curve to 0 calc(100% - var(--r-lg)) with 0 100%, close);
  }
}
.ui-folder::after { /* front */
  inset: 30px 0 0; z-index: -1;
  background: color-mix(in srgb, var(--folder) 90%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.55), var(--shadow-paper);
  transform-origin: 50% 100%;
}
.ui-folder[data-tone] { --folder: var(--paper); --sheet-a: #fff; --sheet-b: #f1f2f3; }
a.ui-folder:hover::after, button.ui-folder:hover::after { transform: perspective(700px) rotateX(-9deg); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.55), var(--shadow-lift); }
a.ui-folder:hover, button.ui-folder:hover { transform: translateY(-2px); }

/* Pile — prints stacked on top of each other; they fan out into a row on hover / focus (video: 0.4 s) */
.ui-pile { display: flex; align-items: center; padding: 8px 0; }
.ui-pile > * { flex: 0 1 var(--item, 180px); min-width: 0; margin-left: calc(-1 * var(--item, 180px) + 10px); transition: margin var(--base) var(--ease), transform var(--base) var(--ease), box-shadow var(--base) var(--ease); }
.ui-pile > :first-child { margin-left: 0; }
.ui-pile > :nth-child(odd)  { --rot: calc(-0.8 * var(--tilt)); }
.ui-pile > :nth-child(even) { --rot: calc(0.8 * var(--tilt)); }
.ui-pile:hover > *, .ui-pile:focus-within > * { margin-left: var(--s-4); --rot: 0deg; }
.ui-pile:hover > :first-child, .ui-pile:focus-within > :first-child { margin-left: 0; }

/* Dim the rest — any container with data-dim: hovering one object fades the others back into the desk */
[data-dim] > * { transition: opacity var(--base) var(--ease), filter var(--base) var(--ease), transform var(--base) var(--ease), box-shadow var(--base) var(--ease), margin var(--base) var(--ease); }
@media (hover: hover) {
  [data-dim]:has(> :hover) > :not(:hover):not([data-at]) { opacity: 0.2; filter: saturate(0.3); }
}

/* Canvas — the desk as a window: objects inside, chrome pinned to the corners with data-at */
.ui-canvas { position: relative; overflow: hidden; padding: var(--s-9) var(--s-7); border-radius: calc(var(--r-lg) + 6px); background: var(--bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 6%, transparent); }
.ui-canvas > [data-at] { position: absolute; z-index: 2; }
.ui-canvas > [data-at='tl'] { top: var(--s-5); left: var(--s-5); }
.ui-canvas > [data-at='tr'] { top: var(--s-5); right: var(--s-5); }
.ui-canvas > [data-at='bl'] { bottom: var(--s-5); left: var(--s-5); }
.ui-canvas > [data-at='br'] { bottom: var(--s-5); right: var(--s-5); }
.ui-canvas > [data-at='bc'] { bottom: var(--s-5); left: 50%; translate: -50% 0; }

/* Pop in — a new object appears with a small overshoot: add data-enter to anything */
[data-enter] { animation: ui-pop var(--base) var(--ease-pop) both; }

@keyframes ui-pop { from { opacity: 0; transform: scale(0.7) rotate(var(--rot, 0deg)); } }
@keyframes ui-fade { from { opacity: 0; } }
