/*
Design tokens and base styles. They sit in `base`, before Remix's `rmx` layer,
so css(...) mixins override them.
https://guides.remix.run/rendering-ui/#theme-tokens-and-cascade-layers
*/
@layer base, rmx, app;

/*
The fonts are subsets: printable ASCII and the symbols the design uses (© ° · ¾
× – ’ “ ” • −), with Shopify Inter limited to weights 400–500. Other characters
render in the fallback font.
*/
@font-face {
  font-family: 'Shopify Inter';
  src: url('/fonts/shopify-inter.woff2') format('woff2');
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

/*
Shopify Inter for long copy, which waits for the font rather than showing the
fallback: lines set in the fallback break elsewhere, so a late swap moves
everything after them. The file is the same, so it downloads once.
*/
@font-face {
  font-family: 'Shopify Inter Copy';
  src: url('/fonts/shopify-inter.woff2') format('woff2');
  font-weight: 400 500;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: Monoform;
  src: url('/fonts/shopify-monoform.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/*
A title's cap height, registered so that it is measured in the title's font and
inherited as a length, for what is set from the title's caps in smaller type.
*/
@property --title-cap {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}

/*
The count of months the Hero's colour has walked through, registered as a
number so that its walk moves between them, which mixes each month's colour over
the last as the count passes. Only the wash reads it.
*/
@property --hero-month {
  syntax: '<number>';
  inherits: false;
  initial-value: 0;
}

@layer base {
  :root {
    /*------ COLOR TOKENS ------*/
    --ink: #121212;
    --paper: #fbfbf9;
    --bg: var(--paper);
    --fg: var(--ink);
    /* The theme's --bg and --fg on any surface, for what keeps the theme's
       colours there, such as the toast: declared on :root, so that they
       resolve to the theme's before a surface sets its own, and again on a
       surface that keeps the theme's */
    --theme-bg: var(--bg);
    --theme-fg: var(--fg);
    --accent: #96dd2c;
    --accent-ink: #0b1a00;
    --error: #e0574b;
    --dot-grid: #d6d6cf;
    /* Collections */
    --c-dev-mode: #e7cdff;
    --c-entrepreneur: #875329;
    --c-performance-pack: #02a867;
    --c-collabs: #c6dcf9;
    --c-nik-bentel: #77b7ff;
    /* The new drop (app/ui/public/drop.ts): the band atop the menu and the
       Hero's ground, and the Hero's sticker and the New pill on the drop's
       page */
    --c-bfcm: #8db9ec;
    --c-bfcm-new: #3cd36e;
    /* Collaborations' product pages: Dad Gang's quote's ground, Nik Bentel
       Studio's letters in the handbag's interactive hero, and the Keyboard
       hero's type, the dark theme's blurb over the ink, its pixel field, and
       its diagrams' switch stem, backlight and links */
    --c-dad-gang: #e2b9c4;
    --c-nik-red: #ff3a3f;
    --c-nik-blue: #72b4f7;
    --c-nik-green: #3fae4e;
    --c-keyboard-text: #c5c5c0;
    --c-keyboard-shade: #557a20;
    --c-keyboard-lime: #c4f02f;
    --c-keyboard-red: #e0574b;
    --c-keyboard-blue: #72b4f7;
    --c-keyboard-sky: #c6dcf9;
    /* Reserved: the sticker folder, the Buy with Shop button, the Editions
       sock's ground */
    --c-folder: #9bc746;
    --c-folder-light: #c2f46c;
    --c-shop-pay: #5433eb;
    --c-editions-sock: #051daa;
    /* Shadow colors: on the page, on a colored surface, on ink, and under a
       thing that floats over the Hero's ground */
    --shade: rgba(0, 0, 0, 0.13);
    --shade-on-color: rgba(0, 0, 0, 0.22);
    --shade-on-ink: rgba(0, 0, 0, 0.4);
    --shade-float: rgba(0, 0, 0, 0.2);
    /* Neutrals, as shares of --fg */
    --a-blurb: 80%;
    --a-muted: 60%;
    --a-line: 15%;
    --a-soft: 5%;
    --a-underline: 28%;
    /* Glass, and the scrim under a window, as shares of --bg. The scrim
       dims the page a touch more than --opacity-dim would */
    --a-glass: 86%;
    --a-solid: 94%;
    --a-scrim: 92%;

    /*------ TYPE TOKENS ------*/
    --font-sans: 'Shopify Inter', Haas, 'Helvetica Neue', Arial, sans-serif;
    /* The same, for long copy, which waits for it */
    --font-copy:
      'Shopify Inter Copy', Haas, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: Monoform, 'SF Mono', Menlo, monospace;
    --font-size-display: clamp(56px, 10.5vw, 176px);
    /* The display beside an open page: 17% of the room the page leaves */
    --font-size-display-half: min(
      var(--font-size-display),
      calc((100vw - var(--pdp-width) - var(--frame-pad) * 3) * 0.17)
    );
    --font-size-headline: clamp(28px, 2.5vw, 40px);
    --font-size-title: 28px;

    /*------ SPACE AND SIZE TOKENS ------*/
    /* One scale for every gap, padding and margin */
    --space-4: 4px;
    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-20: 20px;
    --space-24: 24px;
    --space-32: 32px;
    --space-40: 40px;
    /* The frame's margin (the page's edge), and every window's inset */
    --frame-pad: var(--space-20);
    --window-pad: var(--frame-pad);
    /* Sizes, on the same 4px grid: glyphs, three control heights, a tile */
    --icon: 12px;
    --icon-lg: 16px;
    --icon-hit: 24px;
    --control-sm: 28px;
    --control-md: 40px;
    --control-lg: 48px;
    --tile: 56px;
    /* Layout: the header, the card, and the product page, half the window */
    --header-height: 56px;
    --card-width: 340px;
    --pdp-width: calc(50vw - var(--frame-pad) * 1.5);
    /* Radii */
    --radius-control: 6px;
    --radius-window: 12px;
    --radius-sheet: 16px;
    --radius-pill: 999px;
    --underline-offset: 3px;

    /*------ SHADOW, BLUR AND MOTION TOKENS ------*/
    /* A window's shadow: a 1px contact and a 36px ambient; darker on ink */
    --shadow-contact: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* The contact as a hairline, round a panel that casts no shadow */
    --window-edge: rgba(0, 0, 0, 0.06);
    --shadow-ambient: 0 12px 36px rgba(0, 0, 0, 0.11);
    --shadow-window-ink:
      0 1px 2px rgba(0, 0, 0, 0.18), 0 12px 36px rgba(0, 0, 0, 0.22);
    /* Under a window's glass */
    --blur: blur(12px);
    /* The page behind a window, a thing or button that's off, a control at rest */
    --opacity-dim: 0.12;
    --opacity-off: 0.5;
    --opacity-quiet: 0.7;
    /* One curve, one that overshoots, and four durations */
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-pop: cubic-bezier(0.2, 1.35, 0.3, 1);
    --duration-fast: 0.2s;
    --duration-fade: 0.3s;
    --duration-move: 0.5s;
    --duration-slow: 0.9s;

    /*------ LAYER TOKENS ------*/
    /* Back to front. Stacking inside a component (0, 1, 2, -1) stays in it */
    --z-table: 1;
    --z-thing-near: 3;
    --z-thing-open: 4;
    --z-hero: 5;
    --z-count: 6;
    --z-folder: 7;
    --z-scrim: 50;
    --z-page: 55;
    --z-page-top: 56;
    --z-page-bar: 58;
    --z-furniture: 60;
    --z-windows: 70;
    --z-folder-open: 75;
    --z-consent: 80;
    --z-over-shell: 190;
    --z-toast: 300;
  }

  @media (min-width: 721px) and (max-width: 1024px) {
    /* A footer page's window (PAGE_WINDOW_ID), and what stands beside it,
       widen on a tablet; the product page keeps half the window */
    :root:has(#page-window) {
      /*------ SPACE AND SIZE TOKENS ------*/
      --pdp-width: calc(70vw - var(--frame-pad) * 1.5);
    }
  }

  @media (max-width: 720px) {
    :root {
      /*------ TYPE TOKENS ------*/
      --font-size-display: clamp(40px, 12vw, 72px);
      --font-size-title: 24px;

      /*------ SPACE AND SIZE TOKENS ------*/
      --frame-pad: var(--space-16);
      --tile: 48px;
      /* A sheet's height: the bag opens to it, and the product page's to the
         foot of its image (product-sheet.ts). Phone only; a wider window has
         no sheets */
      --sheet-height: 56vh;
      --card-width: auto;
    }
  }

  /* Dark theme: when the system prefers dark and light isn't chosen, or when
     dark is chosen (app/ui/public/theme.ts), on a page in no collection's
     colours, and on a surface that keeps the theme's on one; and whatever the
     theme on a page that wears it, and on a surface that keeps it, such as
     that page's own as it leaves for one in other colours. Keep the two
     blocks in sync */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']):not([data-collection]),
    :root[data-collection]:not([data-theme='light']) [data-surface='theme'] {
      color-scheme: dark;

      /*------ COLOR TOKENS ------*/
      --bg: #14140f;
      --fg: #f2f2ec;
      --dot-grid: #606058;
      --shade: rgba(0, 0, 0, 0.55);

      /*------ SHADOW, BLUR AND MOTION TOKENS ------*/
      /* A shadow is lost on ink, so the contact is a faint light rim */
      --window-edge: rgba(255, 255, 255, 0.07);
      --shadow-contact: 0 0 0 1px var(--window-edge);
      --shadow-ambient: 0 12px 36px rgba(0, 0, 0, 0.55);
    }
  }

  :root[data-theme='dark']:not([data-collection]),
  :root[data-collection][data-theme='dark'] [data-surface='theme'],
  :root[data-dark]:not([data-collection]),
  [data-surface='dark'] {
    color-scheme: dark;

    /*------ COLOR TOKENS ------*/
    --bg: #14140f;
    --fg: #f2f2ec;
    --dot-grid: #606058;
    --shade: rgba(0, 0, 0, 0.55);

    /*------ SHADOW, BLUR AND MOTION TOKENS ------*/
    /* A shadow is lost on ink, so the contact is a faint light rim */
    --window-edge: rgba(255, 255, 255, 0.07);
    --shadow-contact: 0 0 0 1px var(--window-edge);
    --shadow-ambient: 0 12px 36px rgba(0, 0, 0, 0.55);
  }

  /* Keeps light-dark() and native controls in step with a chosen theme */
  :root[data-theme='light'] {
    color-scheme: light;
  }

  /* A collection's page, in its colours whatever the theme
     (app/ui/public/table/collections.ts): the light theme's, on the
     collection's colour, lightened toward the paper until ink reads on it as
     the design's is, the dots a shade deeper, and the muted type darker,
     which at the paper's share fails contrast on each colour. The theme's
     own colours stay the paper and the ink */
  :root[data-collection] {
    color-scheme: light;
    --theme-bg: var(--paper);
    --dot-grid: color-mix(in srgb, var(--bg) 82%, black);
    --a-muted: 72%;
  }

  :root[data-collection='dev-mode'] {
    --bg: var(--c-dev-mode);
  }

  :root[data-collection='entrepreneur'] {
    --bg: color-mix(in srgb, var(--c-entrepreneur), var(--paper) 50%);
  }

  :root[data-collection='performance-pack'] {
    --bg: color-mix(in srgb, var(--c-performance-pack), var(--paper) 40%);
  }

  :root[data-collection='collabs'] {
    --bg: var(--c-collabs);
  }

  /* A surface that keeps the theme's colours on a collection's page, such as
     a product's page leaving for one, which wears the collection's from the
     navigation's start: the light theme's here, the dark theme's in its
     blocks above, which outrank this */
  :root[data-collection] [data-surface='theme'] {
    --bg: var(--paper);
    --a-muted: 60%;
  }

  /* And one that keeps the dark theme there, its muted type's share too */
  :root[data-collection] [data-surface='dark'] {
    --a-muted: 60%;
  }

  [data-surface='theme'],
  [data-surface='dark'] {
    --theme-bg: var(--bg);
    --theme-fg: var(--fg);
    color: var(--fg);
  }

  @media (prefers-reduced-motion: reduce) {
    :root {
      /*------ SHADOW, BLUR AND MOTION TOKENS ------*/
      /* Moves become jumps; fades and hovers stay. 0.01ms, not 0, so
         transitionend still fires */
      --duration-move: 0.01ms;
      --duration-slow: 0.01ms;
    }
  }

  /* On :root, and again on an element marked data-surface, which sets its own
     --fg, --bg, --shade or share (--a-muted), so that these follow it. Not on
     every element: each would hold its own copies, resolved anew at every
     restyle. To change one, set its input or its share on a surface, not the
     name itself. */
  :root,
  [data-surface] {
    --blurb: color-mix(in srgb, var(--fg) var(--a-blurb), transparent);
    --muted: color-mix(in srgb, var(--fg) var(--a-muted), transparent);
    --line: color-mix(in srgb, var(--fg) var(--a-line), transparent);
    --soft: color-mix(in srgb, var(--fg) var(--a-soft), transparent);
    --underline: color-mix(in srgb, var(--fg) var(--a-underline), transparent);
    --glass: color-mix(in srgb, var(--bg) var(--a-glass), transparent);
    --solid: color-mix(in srgb, var(--bg) var(--a-solid), transparent);
    --scrim: color-mix(in srgb, var(--bg) var(--a-scrim), transparent);
    --shadow-window: var(--shadow-contact), var(--shadow-ambient);
    --shadow-thing: drop-shadow(0 14px 12px var(--shade));
    --shadow-thing-2x: drop-shadow(0 28px 24px var(--shade));
    --ring: inset 0 0 0 1.5px var(--fg);
  }

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

  /* The page behind an open window, the bag or the page window, does not
     scroll. */
  :root:has(dialog[open]) {
    overflow: hidden;
  }

  :focus-visible {
    outline: 2px solid var(--fg);
    outline-offset: 2px;
  }

  body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--fg);
    /* From the paper to a collection's colour and back, as the table
       regroups, and from one theme to the other */
    transition: background-color var(--duration-move) var(--ease);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    /* Slashed zero. `title` repeats this list, since it sets its own. */
    font-feature-settings: 'kern', 'zero';
    /* Bold text uses weight 500, the heaviest the fonts have, unsynthesized. */
    font-synthesis-weight: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Unstyled buttons that inherit their font and color */
  button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
  }

  /* The type styles set no margins. */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p {
    margin: 0;
  }
}
