/* Happy 90th Birthday, ULI: one dark, camera-first theme on every device.
   Tokens first, then the layout, the viewfinder, the controls, the states and the motion. */

/* ---------- Tokens ---------- */

/* Brand colours. Source: the ULI Style Guide 2025, "ULI Color | Core Colors" (page 35).
   Every brand colour on the page is one of these core colours or White. The page uses the
   approved pairing "Emerald + White" (page 38): a flat Emerald ground with white text. */
:root {
  --emerald: #004617;     /* Emerald: the ground */
  --uli-green: #78A22F;   /* ULI Green: the primary colour, for the CTA button (page 110) */
  --moss: #9CB865;        /* Moss: the hover of the CTA button */
  --dew: #BACD92;         /* Dew: the accent on Emerald (link, icons, focus ring). 6.5:1 on Emerald */
  --on-primary: #FFFFFF;  /* White */
  /* White with transparency, for quiet text, lines and fills on Emerald. */
  --on-primary-strong: rgba(255, 255, 255, 0.92);
  --on-primary-muted: rgba(255, 255, 255, 0.85);
  --on-primary-subtle: rgba(255, 255, 255, 0.70);
  --on-primary-border: rgba(255, 255, 255, 0.50);
  --on-primary-border-subtle: rgba(255, 255, 255, 0.28);
  --on-primary-frost: rgba(255, 255, 255, 0.24);
  --on-primary-fill: rgba(255, 255, 255, 0.14);
  --on-primary-panel: rgba(255, 255, 255, 0.08);
  --on-primary-accent: var(--dew);
  /* Text over the camera picture sits on an Emerald screen of 80 %. The guide asks for a tinted
     screen of at least 75 % over a photo (page 19). White text on it keeps at least 6:1 even over
     a white wall (AA). */
  --glass: rgba(0, 70, 23, 0.8);
  --glass-solid: #004617;
  --focus: var(--on-primary-accent);

  /* Functional colours, no brand meaning. They are not in the guide's palette. */
  --rec: #FF3B30;        /* record red, the camera convention */
  --letterbox: #000000;  /* behind the picture */
}

/* Type. The guide: websites use Roboto (pages 32 and 110). Headlines and CTA buttons are bold
   ALL CAPS; body text is sentence case. The sizes and line heights are the myULI type scale
   (myuli-admin-console-site/styles/tokens.css).
   Roboto is self-hosted (site/vendor/fonts, Latin subset, SIL OFL 1.1). */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("./vendor/fonts/roboto-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Arial, adjusted to Roboto's metrics, so the swap does not move the layout. */
@font-face {
  font-family: "Roboto Fallback";
  src: local("Arial"), local("ArialMT"), local("Helvetica");
  ascent-override: 92.77%;
  descent-override: 24.41%;
  line-gap-override: 0%;
  size-adjust: 100.3%;
}
:root {
  --font: "Roboto", "Roboto Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace; /* --font-family-mono */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-bold: 700;
  --size-meta: 12px;   --leading-meta: 16px;   /* --font-size-meta */
  --size-sm: 13px;     --leading-sm: 19px;     /* --font-size-sm */
  --size-note: 14px;   --leading-note: 20px;   /* --font-size-note */
  --size-base: 15px;   --leading-base: 22px;   /* --font-size-base, .text-body-tight */
  --size-body-lg: 16px; --leading-body-lg: 24px; /* --font-size-body-large */
  --size-md: 17px;     --leading-md: 22px;     /* --font-size-md */
  --size-lg: 20px;     --leading-lg: 26px;     /* --font-size-lg */
  --size-xl: 24px;     --leading-xl: 30px;     /* --font-size-xl */
  --size-xxl: 32px;    --leading-xxl: 38px;    /* --font-size-xxl */
  --tracking-tighter: -0.7px;
  --tracking-tight: -0.4px;
  --tracking-snug: -0.2px;
  --tracking-caps: 0.03em;   /* ALL CAPS text needs a little more space between letters */
}

/* Space, radii, sizes. Source: tokens.css (Space, radius, borders; Sizes and layout). */
:root {
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 20px;
  --space-xl: 24px;
  --space-xxl: 32px;
  --space-xxxl: 48px;
  --radius-xs: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 999px;
  --touch: 44px;                 /* --size-touch-target */
  --control-md: 52px;            /* --size-control-md */
  --mark-w: 22px;                /* the mark is 44:52; desktop uses --size-mark-sm (34 x 40) */
  --mark-h: 26px;
  --shutter: 76px;               /* camera shutter: ring + core */
  --frame-max: 1280px;
}

/* Shadows. Geometry from tokens.css (--shadow-raised, --shadow-float). On the dark ground a
   green-tinted shadow disappears, so the colour is black. */
:root {
  --shadow-frame: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-frame-lg: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 20px 24px rgba(0, 0, 0, 0.25), 0 30px 80px rgba(0, 0, 0, 0.45);
  --shadow-control: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Motion. Source: tokens.css (Motion). */
:root {
  --duration-micro: 160ms;
  --duration-standard: 240ms;
  --duration-blink: 1000ms;
  --ease-decelerate: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-accelerate: cubic-bezier(0.4, 0, 1, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --press: 100ms;
}

/* The viewfinder takes the camera's shape (app.js sets body[data-shape] from the picture size).
   Before the camera starts: a guess from the screen orientation. */
:root { --cam-r: 0.5625; }
@media (orientation: landscape) { :root { --cam-r: 1.7778; } }
body[data-shape="16-9"] { --cam-r: 1.7778; }
body[data-shape="3-2"] { --cam-r: 1.5; }
body[data-shape="4-3"] { --cam-r: 1.3333; }
body[data-shape="1-1"] { --cam-r: 1; }
body[data-shape="3-4"] { --cam-r: 0.75; }
body[data-shape="2-3"] { --cam-r: 0.6667; }
body[data-shape="9-16"] { --cam-r: 0.5625; }

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--emerald);
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "top" "stage" "controls";
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--emerald);
  color: var(--on-primary);
  font-family: var(--font);
  font-size: var(--size-base);
  line-height: var(--leading-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  overflow: hidden;
}

button, a { touch-action: manipulation; }
button {
  font: inherit;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
/* The error title takes focus only so a screen reader reads it. It is not a control. */
#error-title:focus { outline: none; }

/* A sentence that wraps as a whole, so a line never breaks mid-sentence. */
.keep { display: inline-block; }

/* ---------- Header ---------- */

/* The ULI Logomark, white on Emerald (an approved variation, guide pages 17 and 19).
   Clear space (page 21): half the height of the mark on each side, free of text. --mark-clear is
   that distance: it is the gap to the title, the least padding above, and the gap to the line below. */
.top {
  --mark-clear: calc(var(--mark-h) / 2);
  grid-area: top;
  padding: max(var(--space-sm), var(--mark-clear)) var(--space-md) var(--space-sm);
  text-align: center;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--mark-clear);
  max-width: 100%;
}
.mark {
  display: block;
  flex: none;
  width: var(--mark-w);
  height: var(--mark-h);
}
/* The headline: bold ALL CAPS (guide pages 32 and 110). The HTML keeps the sentence-case text. */
h1 {
  margin: 0;
  font-size: var(--size-lg);
  line-height: var(--leading-lg);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  text-wrap: balance;
}
/* The status slot: every line and the timer share one grid cell, and only visibility changes,
   so the slot keeps the height of its tallest line in every state. */
.status {
  display: grid;
  justify-items: center;
  align-items: center;
  margin: var(--mark-clear) auto 0;   /* the mark's clear space */
  max-width: 34em;
}
.status > *, .lede > * { grid-area: 1 / 1; }
.lede {
  display: grid;
  justify-items: center;
  align-items: center;
  margin: 0;
  font-size: var(--size-sm);
  line-height: 18px;
  color: var(--on-primary-subtle);
  text-wrap: balance;
}
.lede-text { visibility: hidden; }
body[data-state="loading"] .lede-record,
body[data-state="ready"] .lede-record,
body[data-state="countdown"] .lede-record,
body[data-state="review"] .lede-review,
body[data-state="error"] .lede-error { visibility: visible; }

.timer {
  display: flex;
  visibility: hidden;
  align-items: center;
  gap: var(--space-xs);
  margin: 0;
  padding: 5px 14px 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--on-primary-fill);
  color: var(--on-primary);
  font-size: var(--size-base);
  line-height: 20px;
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}
body[data-state="recording"] .timer { visibility: visible; animation: fade var(--duration-micro) ease both; }
.timer .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rec);
  animation: pulse var(--duration-blink) ease-in-out infinite;
}

/* ---------- Viewfinder ---------- */

.stage-wrap {
  grid-area: stage;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 var(--space-sm);
  container-type: size;
  /* The hat picker's geometry (see "Hat picker" below). --stage-pad-top follows the top padding. */
  --stage-pad-top: 0px;
  --pk-pad: var(--space-xxs);                          /* pill padding around the thumbnails */
  --pk-row: calc(var(--touch) + 2 * var(--pk-pad));    /* pill height: 52 px */
  --pk-inset: var(--space-sm);                         /* over the picture: up from its bottom edge */
  --pk-gap: var(--space-sm);                           /* under the picture: down from its bottom edge */
}
@supports (width: 1cqw) {
  .stage-wrap {
    /* The viewfinder's size (same formula as .frame) and the free room under it. */
    --frame-w: min(100cqw, 100cqh * var(--cam-r), var(--frame-max));
    --frame-h: calc(var(--frame-w) / var(--cam-r));
    --frame-spare: calc(50cqh - var(--frame-h) / 2);
    /* Negative when the picker cannot fit under the picture, a large length when it can. */
    --pk-room: calc((var(--frame-spare) - var(--pk-row) - var(--pk-gap)) * 1000);
    /* Steps made with clamp(). --pk-drop: 0 over the picture, else the distance down to under it. */
    --pk-drop: clamp(0px, var(--pk-room), var(--pk-row) + var(--pk-inset) + var(--pk-gap));
    /* --pk-end: the picker-wrap's right padding. Equal to the left padding: the pill is centred. */
    --pk-end: var(--pk-inset);
  }
  /* A landscape picture (a laptop camera) puts the face in the middle and low: over the picture,
     the pill goes to the bottom-left corner. The full-width right padding pushes it there. */
  body[data-shape="16-9"] .stage-wrap,
  body[data-shape="3-2"] .stage-wrap,
  body[data-shape="4-3"] .stage-wrap {
    --pk-end: clamp(var(--pk-inset), var(--frame-w) - var(--pk-room), var(--frame-w));
  }
}

/* The raw camera feed stays in the page for iOS, but out of sight. */
#camera {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

.frame {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--on-primary-panel);   /* a flat panel, a little lighter than the Emerald ground */
  box-shadow: var(--shadow-frame);
  isolation: isolate;
}
@supports (width: 1cqw) {
  .frame {
    height: auto;
    width: min(100cqw, 100cqh * var(--cam-r), var(--frame-max));
    aspect-ratio: var(--cam-r);
  }
}
/* An error card needs the room, not the camera's shape. */
body[data-state="error"] .frame {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  max-width: 720px;
}

#stage, #playback {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  display: block;
  background: var(--letterbox);
  border-radius: inherit;
}
/* Explicit layers in the viewfinder: picture 0, review video 1, countdown dim 2, overlays 3. */
#stage { position: relative; z-index: 0; }
#playback { position: relative; z-index: 1; }
.loading { position: relative; z-index: 3; }
.hint, .error { z-index: 3; }

/* Loading */
.loading {
  grid-area: 1 / 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-xl);
  text-align: center;
}
.loading p {
  margin: 0;
  font-size: var(--size-base);
  line-height: var(--leading-base);
  font-weight: var(--weight-medium);
  color: var(--on-primary-muted);
}
.loading-bar {
  position: relative;
  display: block;
  width: 120px;
  height: 3px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--on-primary-fill);
}
.loading-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: inherit;
  background: var(--uli-green);
  animation: slide 1400ms var(--ease-in-out) infinite;
}

/* Video off: a calm panel in the frame, in the language of the loading and error panels. */
.video-off {
  position: relative;
  z-index: 3;
  grid-area: 1 / 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-xl);
  text-align: center;
}
.video-off h2 {
  margin: 0;
  font-size: var(--size-lg);
  line-height: var(--leading-lg);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-snug);
}
.video-off p {
  margin: 0;
  max-width: 22em;
  color: var(--on-primary-muted);
  font-size: var(--size-base);
  line-height: var(--leading-base);
  text-wrap: balance;
}

/* The hint, on the picture */
.hint {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: max-content;
  max-width: calc(100% - 2 * var(--space-sm));
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  color: var(--on-primary);
  text-align: center;
  pointer-events: none;
  --hint-bottom: var(--space-sm);
  bottom: var(--hint-bottom);
  padding: 9px 16px;
  border-radius: var(--radius-lg);
  font-size: var(--size-base);
  line-height: 20px;
  font-weight: var(--weight-medium);
  text-wrap: balance;
}
.hint:empty { display: none; }
/* In 'ready' the hint sits above the hat picker when the picker overlays the picture. */
body[data-state="ready"]:has(.picker:not([hidden])) .hint {
  bottom: max(var(--hint-bottom), calc(var(--pk-inset) + var(--pk-row) + var(--space-xs) - var(--pk-drop, 0px)));
}

/* Hat picker: round thumbnails in a glass pill, like the lens row of a phone camera. It is DOM,
   never drawn into the canvas, and it never moves or resizes the viewfinder. Where it goes costs
   no height:
   - over the bottom of the picture when the picture fills the stage (a phone in portrait, a laptop
     window): centred on a portrait picture, in the bottom-left corner of a landscape one;
   - just under the picture, centred, when the room there can hold it.
   .picker-wrap spans the picture's width at the picker's height; .picker is the pill. */
.picker-wrap {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: var(--pk-inset);   /* fallback without container units: the frame fills the stage */
  display: none;
  padding: 0 var(--pk-inset);
  pointer-events: none;
}
@supports (width: 1cqw) {
  .picker-wrap {
    right: auto;
    bottom: auto;
    left: calc(50% - var(--frame-w) / 2);
    width: var(--frame-w);
    top: calc(var(--stage-pad-top) + 50cqh + var(--frame-h) / 2 - var(--pk-inset) - var(--pk-row) + var(--pk-drop));
    padding: 0 var(--pk-end) 0 var(--pk-inset);
  }
}
.picker {
  display: flex;
  flex: none;
  gap: var(--space-xxs);
  margin: 0 auto;   /* centred; at the left padding edge when the wrap's right padding fills it */
  padding: var(--pk-pad);
  border-radius: var(--radius-pill);
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  box-shadow: var(--shadow-control);
  pointer-events: auto;
}
.picker[hidden] { display: none; }
/* Each hat: a 44 px target. The visible chip is smaller until it is the chosen hat. */
.hat-option {
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.hat-chip {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 50%;
  background: var(--on-primary-fill);
  transform: scale(0.84);
  transition: transform var(--duration-micro) var(--ease-decelerate), background-color var(--duration-micro) ease;
}
.hat-chip img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(0.84);   /* the whole hat, brim included, inside the circle */
  pointer-events: none;
  -webkit-user-drag: none;
}
/* The ring sits over the picture of the hat. */
.hat-chip::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--on-primary-border-subtle);
  transition: box-shadow var(--duration-micro) ease;
}
.hat-option[aria-checked="true"] .hat-chip { transform: none; background: var(--on-primary-frost); }
.hat-option[aria-checked="true"] .hat-chip::after { box-shadow: inset 0 0 0 2.5px var(--on-primary); }
.hat-option:focus-visible { outline-offset: 1px; }
.hat-option:active .hat-chip { transform: scale(0.8); }
.hat-option[aria-checked="true"]:active .hat-chip { transform: scale(0.94); }

/* The countdown dim is its own layer, so it fades in and out with the state instead of popping. */
.frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.38), rgba(0, 0, 0, 0.12));
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-standard) var(--ease-decelerate);
}
body[data-state="countdown"] .frame::before { opacity: 1; }

.countdown {
  position: absolute;
  inset: 0;
  z-index: 3;
  place-items: center;
  color: var(--on-primary);
  font-size: 120px;
  font-size: clamp(88px, 32cqmin, 200px);
  line-height: 1;
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tighter);
  /* A tight shadow for the edge and a wide one for the body: legible over a pale face or wall. */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 4px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown span { display: block; animation: count 1000ms linear both; }

/* Error */
.error {
  position: absolute;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--space-xl) var(--space-lg);
}
.error-card {
  margin: auto;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  text-align: center;
}
.error-icon, .panel-icon {
  box-sizing: content-box;
  padding: 14px;
  margin-bottom: var(--space-xxs);
  border-radius: 50%;
  background: var(--on-primary-fill);
  color: var(--on-primary-accent);
}
.error h2 {
  margin: 0;
  font-size: var(--size-lg);
  line-height: var(--leading-lg);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-snug);
  text-wrap: balance;
}
.error p {
  margin: 0;
  color: var(--on-primary-muted);
  font-size: var(--size-base);
  line-height: var(--leading-base);
}
.error-link {
  max-width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  background: var(--on-primary-fill);
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  line-height: var(--leading-sm);
  overflow-wrap: anywhere;
  -webkit-user-select: all;
  user-select: all;
}
.error-link:empty { display: none; }
.error .btn { margin-top: var(--space-xs); min-width: 160px; }

/* ---------- Controls ---------- */

.controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-md) var(--space-sm);
}

/* One fixed-height deck for the shutter and the review buttons, so the viewfinder never jumps. */
/* Three columns: an empty cell, the shutter, the video toggle. The two side cells are equal, so the
   shutter stays optically centred, as in a phone camera app. The review area spans all three. */
.deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  justify-items: center;
  align-items: start;
  width: 100%;
  max-width: 440px;
  min-height: 112px;
}
/* The upload link is not in the deck: it has its own row under the deck, in every state. */
/* No shutter in the error state: give the room to the error card. */
body[data-state="error"] .deck { min-height: 0; }
.deck > * { grid-area: 1 / 2; }
.deck > .review { grid-area: 1 / 1 / 2 / 4; }
.deck > .vtoggle { grid-area: 1 / 3; }

/* The shutter: #record and #stop share one place and read as one control. */
.shutter {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: none;
  cursor: pointer;
  outline: none;
}
.shutter-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--shutter);
  height: var(--shutter);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px var(--on-primary-strong), var(--shadow-control);
  transition: transform var(--press) var(--ease-decelerate), opacity var(--duration-micro) ease;
}
.shutter-core {
  width: calc(var(--shutter) - 16px);
  height: calc(var(--shutter) - 16px);
  border-radius: 50%;
  background: var(--rec);
  transition: transform var(--duration-standard) var(--ease-decelerate);
}
.shutter-label {
  font-size: var(--size-sm);
  line-height: 16px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.2px;
  color: var(--on-primary-muted);
}
.shutter:focus-visible .shutter-ring { outline: 3px solid var(--focus); outline-offset: 3px; }
.shutter:active .shutter-ring { transform: scale(0.94); }
.shutter:disabled { cursor: default; }
.shutter:disabled .shutter-ring { box-shadow: inset 0 0 0 4px var(--on-primary-border-subtle); }
.shutter:disabled .shutter-core { background: var(--on-primary-fill); }
.shutter:disabled .shutter-label { color: var(--on-primary-subtle); }

/* While counting down, the Record shutter stays, armed. */
body[data-state="countdown"] .shutter-record .shutter-ring { box-shadow: inset 0 0 0 4px var(--on-primary-strong), var(--shadow-control); }
body[data-state="countdown"] .shutter-record .shutter-core { background: var(--rec); transform: scale(0.86); }
body[data-state="countdown"] .shutter-record .shutter-label { color: var(--on-primary-muted); }

/* Stop: the core becomes a rounded square; the ring shows the 30 seconds. */
/* Track at --on-primary-border: about 5:1 on the ground (3:1 needed for a non-text element). */
.shutter-stop .shutter-ring { box-shadow: inset 0 0 0 4px var(--on-primary-border), var(--shadow-control); }
.shutter-stop .shutter-core {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  animation: to-square var(--duration-standard) var(--ease-decelerate) both;
}
.shutter-progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  overflow: visible;
}
.progress-arc {
  fill: none;
  stroke: var(--on-primary);
  stroke-width: 5.3;
  stroke-linecap: butt;   /* a round cap draws a dot at 0:00 */
  transition: stroke-dashoffset 200ms linear;
}

/* The video toggle: a smaller frosted disc beside the shutter. Its centre sits on the shutter's
   centre line and its label on the same line as "Record". */
.vtoggle {
  --vt: var(--control-md);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: calc((var(--shutter) - var(--vt)) / 2 + var(--space-xs));
  min-width: var(--touch);
  margin-top: calc((var(--shutter) - var(--vt)) / 2);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: none;
  cursor: pointer;
  outline: none;
}
.vtoggle-disc {
  display: grid;
  place-items: center;
  width: var(--vt);
  height: var(--vt);
  border-radius: 50%;
  background: var(--on-primary-fill);
  color: var(--on-primary);
  box-shadow: inset 0 0 0 1px var(--on-primary-border);
  transition: transform var(--press) var(--ease-decelerate), background-color var(--duration-micro) ease, color var(--duration-micro) ease;
}
.vtoggle-icon { display: block; width: 24px; height: 24px; }
.vtoggle-label {
  font-size: var(--size-sm);
  line-height: 16px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.2px;
  color: var(--on-primary-muted);
  white-space: nowrap;
}
.vtoggle-icon-off { display: none; }
/* Off: the disc turns solid, like a switched-on camera-off key in a call app. */
body[data-video="off"] .vtoggle-disc { background: var(--on-primary); color: var(--emerald); box-shadow: var(--shadow-control); }
body[data-video="off"] .vtoggle-icon-on { display: none; }
body[data-video="off"] .vtoggle-icon-off { display: block; }
.vtoggle:focus-visible .vtoggle-disc { outline: 3px solid var(--focus); outline-offset: 3px; }
.vtoggle:active .vtoggle-disc { transform: scale(0.94); }

/* Review */
.review {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  padding-top: 12px;   /* centres the buttons on the shutter's centre line */
}
.review-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  max-width: 400px;
}
.btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch);
  height: var(--control-md);
  padding: 0 var(--space-md);
  border: 0;
  border-radius: var(--radius-pill);
  /* CTA buttons: bold ALL CAPS (guide page 110). 19 px bold is "large text", so the 3.7:1 of
     Emerald on ULI Green passes AA. Do not make this text smaller. */
  font-size: 19px;
  line-height: var(--leading-md);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--press) var(--ease-decelerate), background-color var(--duration-micro) ease;
}
.btn:active { transform: scale(0.97); }
/* The primary CTA: ULI Green, the guide's colour for CTA buttons, with Emerald text (the approved
   pairing "ULI Green + Emerald", page 38). White text on ULI Green is only 3.0:1. */
.btn-primary {
  background: var(--uli-green);
  color: var(--emerald);
}
.btn-secondary {
  background: var(--on-primary-fill);
  color: var(--on-primary);
  box-shadow: inset 0 0 0 1px var(--on-primary-border);
}
.error .btn { flex: none; }

.save-note {
  margin: 0;
  max-width: 400px;
  font-size: var(--size-sm);
  line-height: 18px;
  color: var(--on-primary-subtle);
  text-align: center;
  overflow-wrap: normal;
}
.save-note:empty { display: none; }
/* The file name on its own line, never broken; cut with an ellipsis only if it cannot fit. */
.save-file {
  display: block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--size-meta);
  line-height: var(--leading-meta);
  color: var(--on-primary-subtle);
}
/* The link to the team folder: a tinted text button with an upload icon and a new-tab arrow.
   It shows in every state, in its own row between the deck and the privacy line.
   Lighter than Retake, so "Save video" stays the one primary button. */
.upload-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: var(--touch);
  padding: 0 var(--space-md);
  color: var(--on-primary-accent);
  font-size: var(--size-base);
  line-height: 20px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.1px;
  text-decoration: none;
  text-wrap: balance;
  border-radius: var(--radius-pill);
  transition: background-color var(--duration-micro) ease, color var(--duration-micro) ease;
}
.upload-icon { flex: none; width: 20px; height: 20px; }
/* The new-tab arrow follows the last word and never wraps to a line of its own. */
.upload-end { white-space: nowrap; }
.upload-out { display: inline-block; width: 12px; height: 12px; margin-left: 6px; vertical-align: 0; opacity: 0.85; }
/* Countdown and recording (app.js sets aria-disabled): the link stays in place, dimmed, and a tap
   does nothing. A new tab in the middle of a clip can stop the camera. */
.upload-link[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.privacy {
  margin: 0;
  font-size: var(--size-meta);
  line-height: var(--leading-meta);
  color: var(--on-primary-subtle);
  text-align: center;
  text-wrap: balance;
}
.privacy-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 5px;
  vertical-align: -1px;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--moss); }
  .btn-secondary:hover { background: var(--on-primary-frost); }
  .shutter-record:not(:disabled):not([aria-disabled="true"]):hover .shutter-ring { box-shadow: inset 0 0 0 4px var(--on-primary), var(--shadow-control); }
  .shutter-record:not(:disabled):not([aria-disabled="true"]):hover .shutter-core { transform: scale(0.94); }
  .shutter-stop:hover .shutter-ring { box-shadow: inset 0 0 0 4px var(--on-primary-strong), var(--shadow-control); }
  .upload-link:hover { color: var(--on-primary); background: var(--on-primary-fill); }
  body[data-video="on"] .vtoggle:hover .vtoggle-disc { background: var(--on-primary-frost); }
  body[data-video="off"] .vtoggle:hover .vtoggle-disc { background: var(--on-primary-strong); }
  .hat-option:hover .hat-chip { background: var(--on-primary-frost); }
}

/* ---------- What each state shows ---------- */

#record, #stop, .review, #playback, #countdown, #error, #loading-note { display: none; }
body[data-state="loading"] #loading-note { display: flex; }
body[data-state="loading"] #record,
body[data-state="ready"] #record,
body[data-state="countdown"] #record { display: flex; }
body[data-state="countdown"] #countdown:not(:empty) { display: grid; }
body[data-state="recording"] #stop { display: flex; }
/* Review: the last camera frame stays under the video while the video fades in (no flash). */
body[data-state="review"] #playback { display: block; background: transparent; }
body[data-state="review"] .review { display: flex; }
body[data-state="review"] #hint,
body[data-state="error"] #hint,
body[data-state="loading"] #hint { display: none; }
body[data-state="error"] #error { display: flex; }
body[data-state="error"] #stage,
body[data-state="loading"] #stage { visibility: hidden; }
/* The video toggle exists only in 'ready'. Video off (ready only): no picture, no hint, the panel.
   display: none on the canvas restarts its fade when the picture comes back. */
#video-toggle, #video-off { display: none; }
body[data-state="ready"] #video-toggle { display: flex; }
body[data-state="ready"][data-video="off"] #video-off { display: flex; }
body[data-state="ready"][data-video="off"] #stage,
body[data-state="ready"][data-video="off"] #hint { display: none; }
/* The hat picker exists only in 'ready' with the picture on. With the video off there is no
   picture to show the hat on, so the picker hides too. */
body[data-state="ready"][data-video="on"] .picker-wrap { display: flex; }

/* State changes cross-fade in rather than jump. */
.review, .error-card { animation: enter var(--duration-standard) var(--ease-decelerate) both; }
/* The shutter scales in at full colour: a red fading over the green ground reads brown. */
#record, #stop { animation: shutter-in var(--duration-standard) var(--ease-decelerate) both; }
.hint, .loading, #playback, .video-off, .vtoggle, .picker-wrap { animation: fade var(--duration-micro) ease both; }
/* The picture fades in once, when the first camera frame is drawn (app.js waits for it). */
body:not([data-state="loading"]) #stage { animation: fade var(--duration-standard) ease both; }

/* ---------- Sizes ---------- */

/* Short phones (360 x 640 class): give the picture the height. */
@media (max-height: 700px) and (orientation: portrait) {
  :root { --shutter: 68px; }
  .top { padding-bottom: 10px; }
  .lede { font-size: var(--size-meta); line-height: var(--leading-meta); }
  .timer { font-size: var(--size-note); padding-top: 3px; padding-bottom: 3px; }
  .controls { padding-top: var(--space-sm); padding-bottom: 10px; gap: 6px; }
  .deck { min-height: 102px; }
  .review { padding-top: 8px; }
  .btn { height: 48px; }
}

/* Very short portrait screens (also 200 % zoom on a phone): scroll rather than clip, and keep
   the title and the timer in view at the top. */
@media (max-height: 540px) and (orientation: portrait) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .top {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--emerald);
    box-shadow: 0 8px 16px var(--emerald);
  }
  .stage-wrap { height: 320px; }
}
/* Narrow phones (320 px class): a smaller headline, so the ALL CAPS title stays on one line
   beside the mark. */
@media (max-width: 350px) and (orientation: portrait) {
  h1 { font-size: 18px; line-height: 24px; }
}
/* Very narrow (200 % zoom on a phone): the review buttons stack. */
@media (max-width: 300px) {
  .review-actions { flex-direction: column; align-items: stretch; }
  .btn { flex: none; }
}

/* Tablets and wide phones in portrait */
@media (min-width: 600px) and (min-height: 701px) {
  :root { --mark-w: 29px; --mark-h: 34px; --shutter: 80px; }  /* --size-mark-xs */
  .top { padding: var(--space-xl) var(--space-xl) var(--space-lg); }
  h1 { font-size: var(--size-xl); line-height: var(--leading-xl); }
  .lede { font-size: var(--size-base); line-height: var(--leading-base); }
  .stage-wrap { padding: 0 var(--space-xl); }
  .frame { border-radius: var(--radius-xl); box-shadow: var(--shadow-frame-lg); }
  .controls { padding: var(--space-xl) var(--space-xl) var(--space-lg); gap: var(--space-sm); }
  .deck { min-height: 120px; }
  .review { padding-top: 14px; }
  .privacy { font-size: var(--size-sm); line-height: 18px; }
  .privacy-icon { width: 13px; height: 13px; }
  .hint { font-size: var(--size-md); line-height: var(--leading-md); --hint-bottom: var(--space-lg); padding: 10px 18px; }
}

/* Desktop: a centred composition that fits the window. */
@media (min-width: 1024px) and (min-height: 600px) {
  :root { --mark-w: 34px; --mark-h: 40px; }  /* --size-mark-sm */
  .top { padding: var(--space-xxl) var(--space-xxl) var(--space-xl); }
  h1 { font-size: var(--size-xxl); line-height: var(--leading-xxl); }
  .lede { font-size: var(--size-md); line-height: var(--leading-md); }
  .stage-wrap { padding: 0 var(--space-xxl); }
  .controls { padding: var(--space-xl) var(--space-xxl) var(--space-xl); }
  /* The error card at desktop scale, so the panel does not look empty. */
  .error-card { max-width: 440px; gap: var(--space-md); }
  .error-icon { width: 32px; height: 32px; padding: 16px; }
  .error h2 { font-size: var(--size-xl); line-height: var(--leading-xl); }
  .error p { font-size: var(--size-md); line-height: var(--leading-md); }
  .error .error-link { font-size: var(--size-note); line-height: var(--leading-note); }
  /* The video-off panel at the same scale as the error card. */
  .video-off { gap: var(--space-md); }
  .video-off .panel-icon { width: 32px; height: 32px; padding: 16px; }
  .video-off h2 { font-size: var(--size-xl); line-height: var(--leading-xl); }
  .video-off p { font-size: var(--size-md); line-height: var(--leading-md); }
}
/* On a desktop the error card keeps the viewfinder's shape: a full-height slab looks empty. */
@supports (width: 1cqw) {
  @media (min-width: 1024px) and (min-height: 600px) {
    body[data-state="error"] .frame {
      height: auto;
      width: min(100cqw, 100cqh * var(--cam-r), var(--frame-max));
      max-width: none;
      aspect-ratio: var(--cam-r);
    }
  }
}

/* Phone held sideways: the picture on the left, the title and the shutter on the right. */
@media (orientation: landscape) and (max-height: 520px) {
  body {
    grid-template-columns: minmax(0, 1fr) 232px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "stage top" "stage controls";
  }
  .top { padding: var(--space-md) var(--space-md) 0 0; text-align: left; }
  .brand { align-items: flex-start; }
  h1 { font-size: var(--size-md); line-height: var(--leading-md); }
  /* No room for the instruction line here (as before); the slot keeps the timer. */
  .lede { display: none; }
  .status { justify-items: start; margin: var(--mark-clear) 0 0; }
  .stage-wrap { padding: var(--space-sm) var(--space-md) var(--space-sm) var(--space-sm); --stage-pad-top: var(--space-sm); }
  .controls { justify-content: center; padding: var(--space-xs) var(--space-md) var(--space-sm) 0; gap: var(--space-sm); }
  .deck { min-height: 0; align-items: center; }
  .review { padding-top: 0; }
  .review-actions { flex-direction: column; gap: var(--space-xs); }
  .btn { flex: none; height: 46px; }
  .privacy, .save-note { text-align: left; }
  .review { align-items: stretch; }
  .upload-link { align-self: flex-start; padding: 0; }
  /* Review: room for the save note from the start, so Save does not move when the note appears. */
  body[data-state="review"] .deck { min-height: 142px; align-items: start; }
}

/* ---------- Motion ---------- */

@keyframes enter {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes shutter-in {
  from { transform: scale(0.9); }
  to { transform: none; }
}
@keyframes to-square {
  from { transform: scale(2.14); border-radius: 14px; }
  to { transform: none; border-radius: var(--radius-xs); }
}
@keyframes count {
  0% { opacity: 0; transform: scale(1.35); animation-timing-function: var(--ease-decelerate); }
  24% { opacity: 1; transform: scale(1); }
  84% { opacity: 1; transform: scale(1); animation-timing-function: var(--ease-accelerate); }
  100% { opacity: 0; transform: scale(0.92); }
}
@keyframes count-fade {
  0% { opacity: 0; }
  16% { opacity: 1; }
  100% { opacity: 1; }
}
@keyframes pulse {
  50% { opacity: 0.6; }
}
@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

/* Reduced motion: no scale or slide. Short opacity fades stay, because they explain the change. */
@media (prefers-reduced-motion: reduce) {
  .review, .error-card { animation-name: fade; }
  #record, #stop { animation: none; }
  .frame::before { transition-duration: var(--duration-micro); }
  .countdown span { animation-name: count-fade; }
  .shutter-stop .shutter-core { animation: none; }
  .timer .dot, .loading-bar::after { animation: none; }
  .loading-bar::after { left: 30%; }
  .shutter-ring, .shutter-core, .btn, .progress-arc, .vtoggle-disc, .hat-chip, .hat-chip::after { transition: none; }
  .shutter:active .shutter-ring, .btn:active, .vtoggle:active .vtoggle-disc { transform: none; }
}

/* Reduced transparency: solid glass. */
@media (prefers-reduced-transparency: reduce) {
  .hint, .picker {
    background: var(--glass-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
