/* ============================================================================
   FOUNDATION -- how every page moves, settles and answers the hand.

   Both looks, every page: linked from _theme_head.html, ahead of each page's
   own CSS, so a page can still say something more specific. Nothing here
   sets a colour but the scrim; Modern and Original keep theirs.

   The rules it holds, from Apple's interface guidelines:
     - Motion is a spring, not a timed curve. A spring settles from wherever
       the thing is now, so a transition caught mid-flight turns around
       without a jump. Critically damped (no overshoot) by default; a little
       bounce only where a gesture threw something.
     - Feedback arrives on the press, not on the release.
     - Glass is for chrome that floats, and turns solid for anyone who asks
       the system for less transparency.
   ========================================================================= */


/* ── Springs ────────────────────────────────────────────────────────────────
   Generated by scripts/spring_easing.py; do not edit by hand. A spring's
   shape depends only on its damping, so one curve serves every duration:
   a transition of D ms on --spring is a spring with response 0.743 * D.

     --dur-press   100 ms   the press itself: immediate
     --dur-pop     270 ms   response 0.20  chips, popovers, small fades
     --dur-panel   400 ms   response 0.30  menus, panels, sheets
     --dur-move    470 ms   response 0.35  things moving across the screen

   Before linear() a browser falls back to the curve the app used before. */
:root {
    --spring:        cubic-bezier(0.23, 1, 0.32, 1);
    --spring-bounce: cubic-bezier(0.23, 1, 0.32, 1);
    --dur-press: 100ms;
    --dur-pop:   270ms;
    --dur-panel: 400ms;
    --dur-move:  470ms;
}
@supports (transition-timing-function: linear(0, 1)) {
    :root {
        /* damping 1.0: arrives and stops, never overshoots */
        --spring: linear(0, 0.006 1.35%, 0.0256 2.9%, 0.0609 4.7%, 0.1194 7%, 0.2279 10.65%, 0.4083 16.55%, 0.5122 20.3%, 0.5977 23.8%, 0.6714 27.3%, 0.7362 30.95%, 0.7924 34.8%, 0.8414 39%, 0.8836 43.7%, 0.9188 49.05%, 0.9476 55.4%, 0.97 63.3%, 0.9861 74%, 0.9961 91%, 0.998 99.95%, 1);
        /* damping 0.8: a 1.5% overshoot, for momentum only */
        --spring-bounce: linear(0, 0.0059 1.4%, 0.0247 2.95%, 0.058 4.7%, 0.1109 6.8%, 0.194 9.55%, 0.484 18.25%, 0.5917 21.8%, 0.6789 25.05%, 0.7531 28.25%, 0.8164 31.5%, 0.8697 34.85%, 0.9148 38.45%, 0.9512 42.35%, 0.9796 46.75%, 1 51.9%, 1.0121 58.4%, 1.0148 68.05%, 1.002 99.95%, 1);
    }
}


/* ── The scrim ──────────────────────────────────────────────────────────────
   One dim for every dialog that asks for the whole of someone's attention:
   the page behind recedes, it is not frosted. There used to be five, from
   a clear .32 to a heavy .65, each with its own blur. */
:root { --scrim: rgba(12, 31, 28, .45); }


/* ── The ground ─────────────────────────────────────────────────────────────
   A girih lattice under every page, barely there: Hankin's star pattern on
   the 4.6.12 tiling -- twelve-point rosettes ringed by six- and four-point
   stars -- after a carved screen, with its holes toned and its bands left
   as the page. girih.svg is one seamless tile (scripts/girih_tile.py) used
   as a mask, so the tone is a colour each look sets per mode in
   --ground-ink, and the same file serves light and dark.

   It sits on its own layer over the page's background and under everything
   on the page (`isolation` keeps it there), fixed to the window, so it never
   scrolls into a seam. The tile grows with the screen, between 180 and
   280 px wide, so a phone and a wall display both see the same few stars
   rather than a dense weave or three giant ones. Gone for print and for
   anyone who asks the system for more contrast.

   The defaults are in :where(), at no specificity, on the same elements
   as each page's dark switch, so a look's own value wins on that element
   rather than being shadowed by an inherited one. */
:where(:root) {
    --ground-ink: rgba(12, 31, 28, .035);
    --ground-size: clamp(180px, 16vmax, 280px);
}
:where(body.theme-dark, :root.dark, body:has(#darkModeToggle:checked)) {
    --ground-ink: rgba(0, 0, 0, .26);
}
body { isolation: isolate; }
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: var(--ground-ink);
    -webkit-mask: url("girih.77aaad8bf6f4.svg") 50% 0 / var(--ground-size) auto repeat;
    mask: url("girih.77aaad8bf6f4.svg") 50% 0 / var(--ground-size) auto repeat;
}
@media print, (prefers-contrast: more) {
    body::after { content: none; }
}


/* ── Response ───────────────────────────────────────────────────────────────
   No double-tap zoom on anything a finger presses, so a tap is answered the
   moment it lands rather than 300 ms later. */
:where(a, button, input, select, textarea, label, summary, [role="button"], [role="tab"]) {
    touch-action: manipulation;
}


/* ── Type ───────────────────────────────────────────────────────────────────
   Arabic is joined script: tracking pulls its letters apart at the joins.
   Wherever a heading, label or badge was given letter-spacing for Latin
   capitals, an Arabic page takes it back out. */
html[lang|="ar"] :is(h1, h2, h3, h4, h5, h6, th, label, button, .badge,
    [class*="tracking-"], [class*="-label"], [class*="-title"], [class*="title-"],
    [class*="eyebrow"], [class*="-badge"], [class*="-header"]) {
    letter-spacing: 0 !important;
}


/* ── The press ──────────────────────────────────────────────────────────────
   Anything that can be pressed gives a little the moment it is pressed:
   97%, the size of the give in a real key. It is the individual `scale`
   property, so it adds to a control's own transform instead of replacing
   it, and it sits in :where() at no specificity, so a control with its own
   press (a deeper one, a row that dims instead) simply says so. Tabs, menu
   items and options are list-like; they highlight rather than shrink. */
:where(button, .btn, [role="button"], input:is([type="submit"], [type="button"], [type="reset"])):where(
        :active:not(:disabled, [aria-disabled="true"], [role="tab"], [role="menuitem"], [role="option"], .dropdown-item)) {
    scale: .97;
}


/* ── Dialogs ────────────────────────────────────────────────────────────────
   Bootstrap drops a dialog 50 px from above. Here it settles in place from
   just smaller, on the spring, and leaves the same way: a dialog is about
   the page it sits on, not something that falls onto it. */
.modal.fade .modal-dialog {
    transform: scale(.97);
    transition: transform var(--dur-panel) var(--spring);
}
.modal.show .modal-dialog { transform: none; }
.modal.fade { transition: opacity var(--dur-pop) var(--spring); }
.modal-backdrop.fade { transition: opacity var(--dur-pop) var(--spring); }


/* ── A change of look ───────────────────────────────────────────────────────
   reveal.js grows the new look out of the control that asked for it; the
   browser's own cross-fade is turned off only for that, so a reduced-motion
   switch still fades rather than cutting. Clicks go through to the page
   while it plays: nobody waits for an animation to finish. */
html.vt-reveal::view-transition-old(root),
html.vt-reveal::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.vt-reveal::view-transition-old(root) { z-index: 0; }
html.vt-reveal::view-transition-new(root) { z-index: 1; }
::view-transition { pointer-events: none; }
::view-transition-group(root) { animation-duration: var(--dur-panel); }

/* Native controls -- scrollbars, date pickers, selects, checkboxes -- drawn
   for the mode the page is in, whichever of its switches the page uses. */
:root:has(body.theme-dark),
:root:has(#darkModeToggle:checked),
:root.dark { color-scheme: dark; }


/* ── Less transparency ──────────────────────────────────────────────────────
   Asked for in the system settings: no frosted glass anywhere. Each page
   makes its translucent surfaces solid under the same query. */
@media (prefers-reduced-transparency: reduce) {
    *, *::before, *::after {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
}

/* ── More contrast ──────────────────────────────────────────────────────────
   A heavier focus ring everywhere; each page firms up its own borders and
   faint text under the same query. */
@media (prefers-contrast: more) {
    :focus-visible { outline-width: 3px !important; }
}
