/* The Chassis frame. Structure only: spacing, type sizes, floors, focus, motion timings.
   No colour and no typeface live here. Those come from the client's sheet (system/sheet.mjs writes
   theme.css with --cx-ground, --cx-ink, --cx-accent, --cx-font-display and so on).

   Use:  <body class="cx" data-cx="calder">  with frame.css then the client's theme.css.
   Everything sits in :where() so it has no weight: a client's own styles always win. */

:where(.cx) {
  /* Spacing, in steps of 4. Padding and gaps use these, never a one-off 13px. */
  --cx-1: 4px;  --cx-2: 8px;  --cx-3: 12px; --cx-4: 16px; --cx-5: 24px; --cx-6: 32px;
  --cx-7: 48px; --cx-8: 64px; --cx-9: 96px; --cx-10: 128px; --cx-11: 160px;
  --cx-gutter: clamp(20px, 5.556vw, 142px);            /* 20 at a phone, 80 at 1440, keeps pace to 2560 */
  --cx-section: clamp(48px, 6.111vw, 88px);            /* gap between sections: 48 to 88, never a blank band */
  --cx-measure: 65ch;                                  /* longest line of running text */

  /* Type sizes by role. Each grows in a straight line from a 390 phone to 1440, then gently to 2560,
     so nothing jumps at a breakpoint and nothing sits small on a wide monitor. The typeface is the client's. */
  --cx-size-display: clamp(2.75rem, 1.05rem + 6.86vw, max(6rem, min(6rem + (100vw - 90rem) / 35, 8rem)));   /* 44, 96 at 1440, 128 at 2560 */
  /* Display type also answers to the window's height, so a headline never pushes the subject off a short screen (1366 by 657). */
  --cx-size-display-fit: min(var(--cx-size-display), max(2.75rem, 17svh));
  --cx-size-h1: clamp(2.25rem, 1.6rem + 2.67vw, max(4rem, min(4rem + (100vw - 90rem) / 70, 5rem)));        /* 36, 64, 80 */
  --cx-size-h2: clamp(1.75rem, 1.47rem + 1.14vw, max(2.5rem, min(2.5rem + (100vw - 90rem) / 140, 3rem)));  /* 28, 40, 48 */
  --cx-size-h3: clamp(1.25rem, 1.16rem + 0.38vw, max(1.5rem, min(1.5rem + (100vw - 90rem) / 280, 1.75rem))); /* 20, 24, 28 */
  --cx-size-lead: clamp(1.0625rem, 0.99rem + 0.29vw, max(1.25rem, min(1.25rem + (100vw - 90rem) / 560, 1.375rem))); /* 17, 20, 22 */
  --cx-size-body: clamp(1rem, 0.977rem + 0.095vw, max(1.0625rem, min(1.0625rem + (100vw - 90rem) / 560, 1.1875rem))); /* 16, 17, 19 */
  --cx-size-small: 0.875rem;                           /* 14: the floor. Nothing a visitor reads is smaller. */
  --cx-line-display: 0.95; --cx-line-heading: 1.1; --cx-line-body: 1.6;

  /* Edges. The sheet sets --cx-radius (0 to 14, or a pill). A box inside a padded box takes the smaller one. */
  --cx-radius-inner: max(0px, calc(var(--cx-radius, 4px) - var(--cx-1)));

  /* Motion. The sheet sets --cx-tempo (calm 1.25, steady 1, brisk 0.8); every duration follows it. */
  --cx-dur-press: calc(100ms * var(--cx-tempo, 1));
  --cx-dur-ui: calc(200ms * var(--cx-tempo, 1));
  --cx-dur-reveal: calc(450ms * var(--cx-tempo, 1));   /* short, and it starts before the content is in view */
  --cx-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --cx-ease-move: cubic-bezier(0.77, 0, 0.175, 1);
  /* Fluid motion (rule fluid-motion): a change travels to its new place and settles, it never snaps. */
  --cx-dur-flow: calc(650ms * var(--cx-tempo, 1));     /* one thing travelling: a marker, a bar, a card */
  --cx-stagger: calc(70ms * var(--cx-tempo, 1));       /* the gap between items that arrive one after another */
  --cx-ease-glide: cubic-bezier(0.22, 1, 0.36, 1);     /* a long soft landing, no overshoot: text, photos, panels */
  --cx-ease-fluid: cubic-bezier(0.3, 1.25, 0.4, 1);    /* a small overshoot, then settle: markers, bars, buttons */

  /* Floors */
  --cx-target: 44px;                                   /* smallest thing a thumb has to hit */

  background: var(--cx-ground);
  color: var(--cx-ink);
  font-family: var(--cx-font-body);
  font-size: var(--cx-size-body);
  line-height: var(--cx-line-body);
  -webkit-font-smoothing: antialiased;
}

:where(.cx) :where(*, *::before, *::after) { box-sizing: border-box; }
:where(.cx) :where(h1, h2, h3) { font-family: var(--cx-font-display); line-height: var(--cx-line-heading); text-wrap: balance; margin: 0; }
:where(.cx) :where(p) { max-width: var(--cx-measure); margin: 0; }
:where(.cx) :where(img, video) { display: block; max-width: 100%; height: auto; }
:where(.cx) :where(button, input, select, textarea) { font: inherit; color: inherit; }
/* The thumb-size floor and the client's corner go on things a thumb presses, not on a checkbox, a radio or a slider. */
:where(.cx) :where(button, select, textarea, input:not([type='checkbox'], [type='radio'], [type='range'], [type='hidden'], [type='file'])) { min-height: var(--cx-target); border-radius: var(--cx-radius, 4px); }
:where(.cx) :where([hidden]) { display: none !important; }
:where(.cx) :where(a, button, [role='button']) { transition: color var(--cx-dur-ui) var(--cx-ease-out), background-color var(--cx-dur-ui) var(--cx-ease-out), transform var(--cx-dur-press) var(--cx-ease-out); }
/* The ring is always there. A client may restyle it; nobody may remove it. It has its own role (--cx-focus) because
   the accent vanishes on an accent button; the sheet test checks it against the ground and the accent. */
:where(.cx) :where(:focus-visible) { outline: 2px solid var(--cx-focus, var(--cx-accent)); outline-offset: 3px; }
/* A link to a section stops below the sticky bar, not under it. The site sets --cx-sticky to its bar's height. */
:where(.cx) :where([id]) { scroll-margin-top: calc(var(--cx-sticky, 0px) + var(--cx-4)); }
/* Figures line up in columns. */
:where(.cx) :where([data-cx-figure], time, table) { font-variant-numeric: tabular-nums; }
/* Words over a photo sit on the scrim colour, never on the photo itself. */
:where(.cx) :where([data-cx-on-photo]) { color: var(--cx-on-photo); background: var(--cx-photo-scrim); }
:where(.cx) :where(.cx-wrap) { padding-inline: var(--cx-gutter); }
:where(.cx) :where(.cx-section) { padding-block: var(--cx-section); }
:where(.cx) :where(.cx-hidden) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* The reveal (parts/motion.mjs arm()). Nothing is hidden until the script has run and set data-cx-armed, so a
   failed script still shows the page. Short, and it starts before the content is in view. */
:where(.cx)[data-cx-armed] :where([data-cx-reveal]), :where(.cx) :where([data-cx-armed] [data-cx-reveal]) { opacity: 0; transform: translateY(var(--cx-3)); }
/* The transition sits on the shown state only, so hiding is instant and never seen, and showing is the one move. */
:where(.cx)[data-cx-armed] :where([data-cx-reveal][data-cx-in]), :where(.cx) :where([data-cx-armed] [data-cx-reveal][data-cx-in]) {
  opacity: 1; transform: none;
  transition: opacity var(--cx-dur-reveal) var(--cx-ease-out), transform var(--cx-dur-reveal) var(--cx-ease-out);
}

/* Fluid patterns (parts/motion.mjs). All of them move transform, opacity or a stroke only, so they stay smooth
   while the page scrolls, and none of them is tied to the scroll position (rule native-scroll). */
@supports (transition-timing-function: linear(0, 1)) {
  /* A real spring where the browser can draw one: out fast, 4 percent past, back to rest. */
  :where(.cx) { --cx-ease-fluid: linear(0, 0.006, 0.025 2.8%, 0.101 6.1%, 0.539 18.9%, 0.721 25.3%, 0.849 31.5%, 0.937 38.1%, 0.968 41.8%, 0.991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%, 1.001); }
}
/* flow(): the children of [data-cx-flow] arrive one after another when the group is shown. */
:where(.cx) :where([data-cx-armed] [data-cx-flow] > *), :where(.cx)[data-cx-armed] :where([data-cx-flow] > *) { opacity: 0; transform: translateY(var(--cx-4)); }
:where(.cx) :where([data-cx-armed] [data-cx-flow][data-cx-in] > *), :where(.cx)[data-cx-armed] :where([data-cx-flow][data-cx-in] > *) {
  opacity: 1; transform: none;
  transition: opacity var(--cx-dur-flow) var(--cx-ease-glide) calc(var(--cx-i, 0) * var(--cx-stagger)), transform var(--cx-dur-flow) var(--cx-ease-glide) calc(var(--cx-i, 0) * var(--cx-stagger));
}
/* glide(): one marker that travels to whichever choice is on, instead of each choice switching its own colour. */
:where(.cx) :where([data-cx-glide]) {
  position: absolute; inset: 0 auto auto 0; width: var(--cx-gw, 0); height: var(--cx-gh, 0); pointer-events: none;
  transform: translate(var(--cx-gx, 0), var(--cx-gy, 0));
  transition: transform var(--cx-dur-flow) var(--cx-ease-fluid), width var(--cx-dur-flow) var(--cx-ease-fluid), height var(--cx-dur-flow) var(--cx-ease-fluid);
}
:where(.cx) :where([data-cx-glide]:not([data-cx-placed])) { transition: none; }
/* A line that draws itself: an SVG path with pathLength="1" and data-cx-draw, inside something that is revealed. */
:where(.cx) :where([data-cx-draw]) { stroke-dasharray: 1; stroke-dashoffset: 0; }
:where(.cx) :where([data-cx-armed] [data-cx-reveal]:not([data-cx-in]) [data-cx-draw]) { stroke-dashoffset: 1; }
:where(.cx) :where([data-cx-armed] [data-cx-reveal][data-cx-in] [data-cx-draw]) { transition: stroke-dashoffset calc(var(--cx-dur-flow) * 2) var(--cx-ease-glide) var(--cx-dur-ui); }
/* A card or tile that answers the pointer. Only where there is a real pointer, so a tap never sticks. */
@media (hover: hover) {
  :where(.cx) :where([data-cx-lift]) { transition: transform var(--cx-dur-flow) var(--cx-ease-fluid); }
  :where(.cx) :where([data-cx-lift]:hover) { transform: translateY(calc(var(--cx-1) * -1)); }
}
/* swap(): the old view fades into the new one; anything with a view-transition-name travels between them. */
::view-transition-group(*) { animation-duration: 0.5s; animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.3s; }

/* The form kit (parts/form.mjs). Structure only: where the error summary sits and that the sent card can take focus. */
:where(.cx) :where([data-cx-errors]) { margin: 0; max-width: none; }
:where(.cx) :where([data-cx-sent]:focus) { outline: none; }
:where(.cx) :where([data-cx-readback]) { display: grid; grid-template-columns: max-content 1fr; gap: var(--cx-2) var(--cx-5); margin: 0; }
:where(.cx) :where([data-cx-readback] dd) { margin: 0; overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  :where(.cx) :where(*, *::before, *::after) { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
