/* The first screen: the copy, and the skapa demo with its bar (control, numerals the pen marks, caption; direction.css) above the window. The window's height budget lives on .hero-grid, so the copy can be centred on the window; every other media rule is scoped to [data-hero-media]. */

/* Layout: copy above the media on a phone, beside it from 1240 px */
.hero { overflow: clip; }
/* --hero-room: paper under the window for its long shadow (66 px below it, 50 px at 0.75), which .hero would cut at its foot. It is not in the height budget (--hero-air counts the paddings only) */
.hero-grid { --hero-room: 56px; display: grid; gap: 28px; padding-top: var(--hero-pad-top, 28px); padding-bottom: calc(var(--hero-pad-bottom, 40px) + var(--hero-room)); }
[data-hero-copy] { container: hero-copy / inline-size; min-width: 0; display: flex; flex-direction: column; }
.hero-for { margin-bottom: 14px; color: var(--ink-2); font: 400 17px/1.4 var(--serif); max-width: 26em; }
.hero-for > span { display: block; }   /* one sentence a line: it never fits one line in the copy column, and a break inside a sentence read as a stray wrap */
.hero h1 {
  font-size: min(61px, calc(100cqi / 10.4)); font-weight: 500; line-height: 1.04; letter-spacing: -0.02em; font-variation-settings: 'opsz' 72;
}
.hero h1 span { display: block; white-space: nowrap; }   /* one sentence a line, sized to the column, so a late font cannot re-break it */
.lede { margin-top: 20px; max-width: 26em; font: 400 clamp(18px, 4.7vw, var(--t-1))/1.45 var(--serif); text-wrap: balance; }   /* pretty left "i ord." alone on the last line at 1440 and 320; balance keeps the line count */
.hero .actions { margin-top: 28px; }
.hero .fine { margin-top: 20px; }

@media (prefers-reduced-motion: no-preference) {
  .hero h1 span { animation: settle 0.6s var(--ease-out) both; }
  .hero h1 span:nth-child(2) { animation-delay: 0.1s; }
}
@keyframes settle { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 599.98px) {
  .hero-grid { gap: 24px; --hero-pad-top: 24px; }
  .hero-for { margin-bottom: 12px; font-size: 16px; line-height: 1.35; }
  .hero .actions { flex-wrap: wrap; gap: 8px; margin-top: 22px; }
  .hero .button { min-height: 46px; padding: 0 14px; }   /* the pilot's two buttons (323 px) stay on one row at 360 px, where the gutter leaves 320 */
}

@media (max-width: 374.98px) {   /* 340 to 374 px: at 15 px the first caption (322 px) takes two lines in the 320 px of 360 px and pushes the window 22 px down (README section 11) */
  [data-hero-media] .dk-demo > .dk-steps { font-size: 14px; }
}

@media (min-width: 1240px) {
  /* Copy on columns 1 to 5, media on 6 to 12. The copy block is centred on the media: its box is as high as the bar plus the window (--hero-v, and --hero-above where there is a bar) and starts level with the bar. */
  .hero-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--s3); --hero-pad-top: 24px; --hero-pad-bottom: 24px; --hero-room: 48px; }
  [data-hero-copy] { grid-column: 1 / span 5; align-self: start; justify-content: center; min-height: var(--hero-v); }
  .hero-media { grid-column: 6 / span 7; }
  .hero-for { margin-bottom: 10px; font-size: 18px; line-height: 28px; }
  .lede { margin-top: 28px; font-size: var(--t-1); line-height: 1.5; max-width: 24em; }
  .hero .actions { margin-top: 36px; }
  .hero .fine { margin-top: 24px; }
}

/* Media: the skapa figure beside the copy (from 1240 px) or under it */
.hero-media { position: relative; }
.hero-grid {
  --hero-h: 700px;               /* tallest window on screen while the stage is wider than 760 px */
  --hero-h-phone: 580px;         /* tallest window on screen in the phone layout (stage up to 760 px) */
  --hero-scale: 0.75;            /* beside the copy: the replica is laid out at the column's width / this and shown at this scale at most, like the app at 75 % in a browser */
  --hero-smax: 1;                /* the largest scale of the layout in use (--hero-scale from 1240 px) */
  --hero-a: var(--hero-h);       /* the authored window height in the replica's own pixels: --hero-h / --hero-smax (the fit rule, direction.css) */
  --hero-vmin: calc(var(--hero-a) / 2);   /* the window never gets shorter than this on screen: below it the page scrolls instead of the picture shrinking */
  --hero-air: 8px;               /* what the budget leaves free besides header, gap and bar */
  --hero-row: 40px;              /* the bar's row, fixed (the control is 36 px, a caption of two lines 44 px and centred); in the phone layout both lines, the caption two lines long */
  --hero-row-phone: calc(44px + 6px + 44px);
  --hero-above: calc(var(--hero-row) + var(--bar-gap));   /* what the bar takes above the window */
  --hero-copy-h-phone: calc(500px + var(--hero-above));   /* phone: header + copy + gaps + bar above the media; the window is at most twice what is left */
}
@media (pointer: coarse) { .hero-grid { --hero-row: 48px; } }   /* the control is 44 px high */
[data-hero-media] { container: hero-media demo / inline-size; min-width: 0; }
/* The room variables again on the grid (the kit sets them on the figure), so that the one budget formula below gives the same window height there. --hero-v is the window's height on screen */
.hero-grid { --dk-header: var(--header-h, 64px); }
@media (max-height: 420px) { .hero-grid { --dk-header: 0px; } }
.hero-grid, [data-hero-media] .dk-demo {
  --hero-cap: calc(min(100svh - var(--dk-header) - var(--hero-air), 90svh) - var(--bar-gap) - var(--hero-row));
  --hero-v: clamp(var(--hero-vmin), var(--hero-cap), var(--hero-h));
}
/* The fit rule (direction.css) with the hero's own numbers */
[data-hero-media] .dk-demo { --fit-a: var(--hero-a); --fit-smax: var(--hero-smax); --fit-v: var(--hero-v); }
@media (max-width: 1239.98px) {
  @container hero-media (max-width: 760px) {
    [data-hero-media] .dk-demo {
      --hero-row: var(--hero-row-phone);
      --hero-a: var(--hero-h-phone);
      --hero-vmin: 360px;   /* the bar takes two lines above the window: at 360 x 740 a shorter window would not matter, a taller one would push its top half off the first screen (the rule below) */
      --hero-cap: calc(min(100svh - var(--dk-header) - var(--hero-air), 90svh) - var(--bar-gap) - var(--hero-row));
      --hero-v: clamp(var(--hero-vmin), min(var(--hero-cap), 2 * (100svh - var(--hero-copy-h-phone))), var(--hero-h-phone));
    }
  }
}

/* The bar's room above the window is held while the demo is not live (the kit makes it live in a deferred script), so the window does not move when the bar arrives */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  [data-hero-media] .dk-demo:not(.dk-live) { padding-top: var(--hero-above); }
  @media (max-width: 1239.98px) {
    @container hero-media (max-width: 760px) { [data-hero-media] .dk-demo:not(.dk-live) { padding-top: calc(var(--hero-row-phone) + var(--bar-gap)); } }
  }
}
/* The bar's rows are fixed, so the budget above is exact whatever the caption */
[data-hero-media] .dk-demo.dk-live { grid-template-rows: var(--hero-row); }
@media (max-width: 1239.98px) { @container hero-media (max-width: 760px) { [data-hero-media] .dk-demo.dk-live { grid-template-rows: 44px auto; } } }

@media (min-width: 1240px) {
  @media (scripting: enabled) and (prefers-reduced-motion: no-preference) { [data-hero-copy] { min-height: calc(var(--hero-above) + var(--hero-v)); } }   /* without script, or in reduced motion, there is no bar: the window starts at the top of the column and the block is centred on it alone */
  .hero-grid {
    --hero-air: calc(var(--hero-pad-top, 24px) + var(--hero-pad-bottom, 24px));
    --hero-smax: var(--hero-scale); --hero-a: calc(var(--hero-h) / var(--hero-smax));   /* 933 px: 700 px on screen at 0.75 */
  }
}

/* The drag picture of the demo hangs on the pointer and can leave the window: clip it outside the stage (.hero clips at the page's edge, so the page never scrolls sideways).
   The sides are the window's shadow plus a margin: it reaches 36 px out in the stage's own pixels (60 blur - 24 spread), 27 px on screen at 0.75; 10 px cut it in a hard edge */
[data-hero-media] .dk-stage { clip-path: inset(-140px -48px -140px -48px); }

/* The cards dropped into the box arrive in a tray at its top; its room is held from the first frame, so nothing below it moves. The tray is 560 px wide: two cards always fit it and
   three never do, so they sit in two rows (126 px) whatever font the page falls back to. On a phone they are the kit's one row that scrolls sideways (58 px) */
[data-hero-media] .rp-hem-prompt { --tray: 126px; position: relative; padding-top: calc(18px + var(--tray) + 6px); }
[data-hero-media] .rp-hem-attachments { position: absolute; top: 18px; left: 22px; right: 14px; max-width: 560px; }
@container rp (max-width: 640px) {
  [data-hero-media] .rp-hem-prompt { --tray: 58px; }
  [data-hero-media] .rp-hem-attachments { left: 16px; right: 10px; max-width: none; }
}

/* Until the kit has made the demo live nothing of it is shown: not its sky (a window with no app in it read as loading), not its captions or its bar. The scripts are deferred and run after the whole page is parsed,
   which can come after the first paint. Then the figure arrives whole, a 0.4 s fade. After 3 s everything is shown, kit or not */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  [data-hero-media] .dk-demo:not(.dk-live) { opacity: 0; animation: hero-show 0s 3s both; }
  [data-hero-media] .dk-demo.dk-live { animation: hero-arrive 0.4s var(--ease-out) backwards; }
  [data-hero-media] .dk-demo:not(.dk-live) .rp-window > * { visibility: hidden; animation: hero-reveal 0s 3s both; }
  [data-hero-media] .dk-demo:not(.dk-live) > .dk-steps { max-height: var(--hero-row); overflow: hidden; visibility: hidden; animation: hero-reveal-steps 0s 3s both; }
  /* The kit fades every caption but the first out when it goes live. From 0 they are never seen stacked */
  [data-hero-media] .dk-demo:not(.dk-live) > .dk-steps > li { opacity: 0; animation: hero-reveal-caption 0s 3s both; }
}
@keyframes hero-show { to { opacity: 1; } }
@keyframes hero-arrive { from { opacity: 0; } }
@keyframes hero-reveal { to { visibility: visible; } }
@keyframes hero-reveal-steps { to { visibility: visible; max-height: none; } }
@keyframes hero-reveal-caption { to { opacity: 1; } }
/* No caption fades at step 0 (the kit's 0.3 s opacity transition would show whatever opacity they had before it went live as a fade); the crossfade is back from step 1 */
@media (scripting: enabled) {
  [data-hero-media] .dk-demo.dk-live:is([data-dk-step="0"], [data-dk-state="static"]) > .dk-steps > li { transition: none; }
}
