/*
 * MeetFolks PWA -- the residual global layer.
 *
 * This file is what renders when the bundle does not. Component styling lives in the kit's
 * Tailwind utilities (see `src/styles/tailwind.css`); what is left is everything that has
 * to work without that bundle, for three audiences:
 *
 *  - **The static pages.** `/privacy/`, `/terms/`, `/support/` and `/home/` are copied into
 *    the build untouched and link this stylesheet and `legal.css` and nothing else: the
 *    tokens, the faces, the body and the focus ring come from here, their own look from
 *    `legal.css`.
 *  - **The first paint.** `index.html` links this in `<head>`; the boot overlay it styles
 *    is on screen before any JavaScript runs.
 *  - **The static shell.** The boot overlay and the update toast live in `index.html`
 *    outside the React root -- they survive every screen change and, in the toast's case,
 *    exist to announce that the bundle is being replaced.
 *
 * The faces are vendored, self-hosted woff2 subsets under `/fonts/`, variable-weight.
 * Self-hosting is a constraint, not a preference: the server sends COEP `require-corp`,
 * so a cross-origin font silently fails to load.
 */

/* Declared here as well as in the bundle so the order holds on the static pages, where
   this is the only stylesheet besides `legal.css`. Everything below sits in `base`, which
   is why a utility in the bundle can override it without `!important` -- and why the
   tokens are left out of any layer, so they beat both. */
@layer base, theme, components, utilities;

/* The design tokens are generated from `contract/tokens/tokens.json` into `/tokens.css`
   and imported here, so the static pages that link this stylesheet see the same values as
   the bundle. Nothing below may restate a token. */
@import url("/tokens.css");

@layer base {
  /* Inter: one file, variable weight across the whole range. `font-display: swap` because
     the shell must paint even on a cold cache. */
  @font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/inter-latin-var.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  /* Newsreader, the UI rethink's serif (#1406): roman and italic, each a variable latin
     subset with `opsz` (the browser sets it from the size) and weights 400 to 600. It is
     fetched only once a rule asks for it. Other scripts fall through to the body stack
     (`--ui-font-serif`), never a synthesised serif or italic. */
  @font-face {
    font-family: "Newsreader";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("/fonts/newsreader-latin-var.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  @font-face {
    font-family: "Newsreader";
    font-style: italic;
    font-weight: 400 600;
    font-display: swap;
    src: url("/fonts/newsreader-italic-latin-var.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  * {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    /* The paper, the ground of every light screen (#1411), behind scrolling content too. */
    background: var(--ui-paper);
    color: var(--ui-ink);
    font: 16px/1.5 var(--ui-font-sans);
    -webkit-font-smoothing: antialiased;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  /*
   * The font inheritance a reset normally supplies. Tailwind's preflight is deliberately
   * not loaded (see `src/styles/tailwind.css`), and without something saying this a form
   * control renders in the UA's own 13.333px sans.
   *
   * An element rule and not a utility, because it is a reset: a utility would sit in the
   * same layer as the type utilities that have to beat it, and `font` is a shorthand, so
   * losing that race silently wipes a component's family, size, weight and leading at once.
   */
  input,
  button,
  textarea,
  select {
    font: inherit;
    /* Without preflight a control keeps the browser's own text color -- system blue on
       iOS Safari -- so a label with no color class would ignore the ink. */
    color: inherit;
  }

  /* `hidden` means hidden, whatever else an element is styled as.
   *
   * The UA stylesheet's `[hidden] { display: none }` is beaten by any author rule that
   * sets `display` -- a `flex` or `grid` utility is exactly such a rule, and utilities sit
   * in a later layer than this. `!important` because it has to outrank the layout rules it
   * exists to correct: important declarations invert layer order, so this beats a utility
   * despite living in the earliest layer. */
  [hidden] {
    display: none !important;
  }

  /* -- focus ------------------------------------------------------------ */

  /* One rule for every focusable thing, kept a base rule on purpose: a focus ring applied
     per component is one that gets forgotten on the next component, and these have to work
     on the static pages too. */
  a:focus-visible,
  input:focus-visible,
  button:focus-visible,
  summary:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  /* -- update toast ----------------------------------------------------- */

  /* Shown for about a second while the page reloads itself onto a new shell.
   *
   * Bundle-independent by necessity: the thing it announces is the bundle being
   * replaced, and it is static markup in `index.html` for the same reason. Bottom, clear
   * of the home indicator. */
  .toast {
    position: fixed;
    left: 50%;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translate(-50%, 0.6rem);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: calc(100vw - 2rem);
    padding: 0.7rem 1rem;
    border-radius: 1rem;
    background: var(--ui-card);
    box-shadow: var(--ui-shadow-floating);
    color: var(--ui-ink);
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 180ms ease, transform 180ms ease;
  }

  .toast[hidden] {
    display: none;
  }

  .toast.in {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  /* The one spot of accent. */
  .toast-dot {
    width: 0.5rem;
    height: 0.5rem;
    flex: none;
    border-radius: 50%;
    background: var(--ui-accent);
  }

  /* -- boot ------------------------------------------------------------ */

  .boot {
    position: fixed;
    inset: 0;
    /* The overlay is on screen before the bundle: the paper, the ground of every light
       screen (#1398), so the launch never flashes another colour on its way in. */
    background: var(--ui-paper);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    padding: 2rem;
    text-align: center;
    /* Over every layer the app draws (#1478): Home mounts beneath it while boot still checks
       the account, and its button dock (`z-30`) and the sheets (`z-50`) must not show
       through. The update toast sits under it, which is fine: it only shows after boot. */
    z-index: 60;
  }

  .boot[hidden] {
    display: none;
  }

  /* Empty until boot stops short (#1066), and then out of the layout, so the mark alone
     sits at the centre with no gap held for a line that is not there. */
  #boot-text:empty {
    display: none;
  }

  /* Ready (#1066): the overlay leaves at once, wherever the loop is -- the mark shrinks to
     0.9 as the overlay fades over 0.24 s, onto the screen already drawn beneath it.
     `releaseBootOverlay` in `src/boot-overlay.ts` sets this and hides it after. */
  .boot.leaving {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease-out;
  }

  .boot.leaving .boot-mark {
    transform: scale(0.9);
    transition: transform 0.24s ease-out;
  }

  /* Onto the first-run intro (#1095): its mark is this one, same size, same place, so this
     one fades where it is rather than shrinking over it. */
  .boot.leaving.to-welcome .boot-mark {
    transform: none;
  }

  /* The boot screen's mark: the folded mark at 96px, the plate and three planes (#1066), in
     the accent `index.html` sets before the first paint. */
  .boot-mark {
    width: 96px;
    height: 96px;
    flex: none;
    display: block;
  }

  /* The mark in the person's accent (#1398), as the first-run opening and the screens after
     it draw it (`kit-mark` in `src/styles/kit.css`), so the hand-off does not change colour. */
  .boot-mark > use:nth-of-type(1) {
    color: color-mix(in srgb, var(--ui-accent) 37.65%, var(--ui-on-accent));
  }

  .boot-mark > use:nth-of-type(2) {
    color: color-mix(in srgb, var(--ui-accent) 12.16%, var(--ui-on-accent));
  }

  .boot-mark > use:nth-of-type(3) {
    color: color-mix(in srgb, var(--ui-accent) 56.86%, var(--ui-on-accent));
  }

  /* Fold together (#1066): the two people draw apart and fold back, and the overlap where
     they meet fades as they part and returns as they meet. 2.2 s a cycle, ease-in-out,
     transform and opacity only, so the apps play the same thing. */
  .boot-plane {
    /* Each plane turns about its own centre, and its translation is in the mark's 1254
       viewBox (a px in an SVG child's transform is a user unit), so the same numbers
       mean the same thing at every size. */
    transform-box: fill-box;
    transform-origin: center;
    animation-duration: 2.2s;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
  }

  .boot-main {
    animation-name: fold-main;
  }

  .boot-light {
    animation-name: fold-light;
  }

  /* From its left edge, the seam the two planes fold over, and a beat behind them. */
  .boot-overlap {
    animation-name: fold-overlap;
    transform-origin: left center;
    animation-delay: 0.12s;
  }

  /* Boot stopped short: one line (and Try again where there is one) under a mark that
     holds still. The loop says "still working", and nothing is (#643). */
  .boot.failed .boot-plane {
    animation: none;
  }

  /* Still used by the inline `?reset=` hatch in index.html, which injects its own
     markup and must depend on nothing else. Do not remove. */
  .spinner {
    width: 26px;
    height: 26px;
    border: 2px solid var(--ui-hairline);
    border-top-color: var(--ui-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
}

/* Keyframes are not layerable and do not need to be -- they are named, not cascaded. */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Fold together (#1066), in the mark's 1254 viewBox. Half a cycle out, half back: the
   light plane draws back and down, the main one up and right, each turning 5° about its
   own centre, while the overlap between them fades and shrinks. */
@keyframes fold-main {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  50% {
    transform: translate(120px, -34px) rotate(5deg);
  }
}

@keyframes fold-light {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  50% {
    transform: translate(-120px, 34px) rotate(-5deg);
  }
}

@keyframes fold-overlap {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.86);
    opacity: 0.15;
  }
}

/* Someone who has asked not to be moved still gets the toast, just without it
 * sliding in. The reload is what matters and it happens either way. */
@media (prefers-reduced-motion: reduce) {
  @layer base {
    .toast {
      transition: none;
      transform: translate(-50%, 0);
    }

    .spinner {
      animation-duration: 2.4s;
    }

    /* The mark holds still and the overlay leaves without fading (`releaseBootOverlay`
       hides it at once). */
    .boot-plane {
      animation: none;
    }
  }
}

/* Native search controls draw their own decorations in WebKit. The kit's search field
   supplies its own icon and clear button. */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
}
