/* @gestalt/core/gestalt.css */

@layer aufbau.tokens, aufbau.reset, aufbau.elements, aufbau.skin, aufbau.utilities;

/*////// 2. IMPORTS //////*/
@import url('./functions.css');
@import url('./reset.css') layer(aufbau.reset);
@import url('./palettes.css');
@import url('./animate/functions.css');
@import url('./animate/keyframes.css');
@import url('./animate/animations.css');
@import url('./layouts/landing.css');
@import url('./shorthands/typo.css') layer(aufbau.utilities);

/*
document.body.style.setProperty('--bg', 'var(--color-bg)');
document.body.style.setProperty('--fg', 'var(--color-fg)');
document.body.style.setProperty('--ink', 'var(--color-ink)');

document.body.style.setProperty('background-color', 'var(--color-bg)');
document.body.style.setProperty('color', 'var(--color-fg)');
document.body.style.setProperty('accent-color', 'var(--color-ink)');


the axes of the design system and the shorthand properties.

axes, each writes its own raw tokens:

--palette  :: <preset> | <color>                      -> --color-bg, --color-fg, --color-ink (palettes.css)
--scheme   :: auto | light | dark                     -> color-scheme (the palettes use light-dark())
--geometry :: sharp | soft | round | pill             -> --radius()
--density  :: compact | normal | comfortable | touch  (not used yet)
--skin     :: monochrome | …                          -> the decoration of the elements (skins/)
--typo     :: system | humanist | mono | editorial    -> --font-body, --font-heading, --font-mono, --ratio
--motion   :: <number>, 0 turns every duration off

shorthands, set on an element to style that element only.
they do not inherit: a child of an element with --bg keeps its own transparent background.
the colors of the palette are --color-bg, --color-fg, --color-ink, read those.

--bg  : <color>                  background-color
--fg  : <color>                  color
--ink : <color>                  accent-color
--gap : <number> | tiny … huge   gap     (through --space())
--pad : <number> | tiny … huge   padding (through --space())
--mgn : <number> | tiny … huge   margin  (through --space())
--rad : <length> | auto | none   border-radius, auto is --radius() of the geometry
*/

/*///////////////// TOKENS | CUSTOM PROPERTIES /////////////////*/

/* ===== axes ===== */
@property --density  { inherits: true; initial-value: normal;     syntax: "compact | normal | comfortable | touch"; }
@property --geometry { inherits: true; initial-value: soft;       syntax: "sharp | soft | round | pill"; }
@property --palette  { inherits: true; initial-value: zombie;     syntax: "<color> | <custom-ident>"; }
@property --scheme   { inherits: true; initial-value: auto;       syntax: "auto | light | dark"; }
@property --skin     { inherits: true; initial-value: monochrome; syntax: "<custom-ident>"; }

/* ===== shorthands ===== */
@property --bg  { inherits: false; initial-value: transparent; syntax: "<color>"; }
@property --fg  { inherits: false; initial-value: none;        syntax: "<color> | none"; }
@property --ink { inherits: false; initial-value: none;        syntax: "<color> | none"; }
@property --gap { inherits: false; initial-value: none; syntax: "none | <number> | tiny | small | normal | large | huge"; }
@property --mgn { inherits: false; initial-value: none; syntax: "none | <number> | tiny | small | normal | large | huge"; }
@property --pad { inherits: false; initial-value: none; syntax: "none | <number> | tiny | small | normal | large | huge"; }         
@property --rad { inherits: false; initial-value: none; syntax: "none | auto | <length-percentage>"; }

/*///////////////// ... /////////////////*/

/*//////////// AXES AS ATTRIBUTES ////////////*/

/*
every axis can be set as an attribute, plain or with data-:

  <html palette='zombie' geometry='round' scheme='dark' a11y='reduced-motion high-contrast'>

closed keyword sets (scheme, geometry, density) go through attribute selectors: every
browser, and an unknown value simply matches nothing. open values (palette, skin: a preset
name or any color) need attr() with type(), chromium only so far, so it sits in @supports.
both can address the same axis: the selector first, attr() after it overrides where it
works. for a closed set that would only repeat the selector, so each axis uses one.
a11y is a token list, attr() cannot test a token in it, so ~= selectors.
*/

:root {
  --a11y-contrast : off;
  --a11y-motion   : off;

  --density  : normal;
  --geometry : soft;
  --palette  : zombie;
  --scheme   : auto;
  --skin     : monochrome;
}

:is([density='compact'],     [data-density='compact'])     { --density: compact; }
:is([density='normal'],      [data-density='normal'])      { --density: normal; }
:is([density='comfortable'], [data-density='comfortable']) { --density: comfortable; }
:is([density='touch'],       [data-density='touch'])       { --density: touch; }

:is([geometry='sharp'], [data-geometry='sharp']) { --geometry: sharp; }
:is([geometry='soft'],  [data-geometry='soft'])  { --geometry: soft; }
:is([geometry='round'], [data-geometry='round']) { --geometry: round; }
:is([geometry='pill'],  [data-geometry='pill'])  { --geometry: pill; }

:is([scheme='auto'],  [data-scheme='auto'])  { --scheme: auto; }
:is([scheme='light'], [data-scheme='light']) { --scheme: light; }
:is([scheme='dark'],  [data-scheme='dark'])  { --scheme: dark; }

@supports (width: attr(x type(*))) {
  :root[palette]      { --palette : attr(palette      type(<color> | <custom-ident>), zombie); }
  :root[data-palette] { --palette : attr(data-palette type(<color> | <custom-ident>), zombie); }
  :root[skin]         { --skin    : attr(skin         type(<custom-ident>), monochrome); }
  :root[data-skin]    { --skin    : attr(data-skin    type(<custom-ident>), monochrome); }
}

:root, :is([scheme], [data-scheme]) {
  color-scheme : if(
    style(--scheme: light) : light;
    style(--scheme: dark)  : dark;
    else                   : light dark
  );
}

/*//////////// A11Y ////////////*/

/* the user's system settings switch them on, the attribute switches them on for the page */
@media (prefers-reduced-motion: reduce) { :root { --a11y-motion: on; } }
@media (prefers-contrast: more)         { :root { --a11y-contrast: on; } }

:is([a11y~='reduced-motion'], [data-a11y~='reduced-motion']) { --a11y-motion: on; --motion: 0; }
:is([a11y~='high-contrast'],  [data-a11y~='high-contrast'])  { --a11y-contrast: on; }

/* high contrast: the text turns black or white, whichever stands against the background,
   lines lose their transparency */
body {
  @container style(--a11y-contrast: on) {
    --color-fg : oklch(from var(--color-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
    --line     : currentColor;
  }
}

/*//////////// GEOMETRY ////////////*/

/* the radius of the geometry: --rad: auto, or border-radius: --radius() */
@function --radius() returns <length> {
  result: if(
    style(--geometry: sharp) : 0px;
    style(--geometry: round) : 0.75rem;
    style(--geometry: pill)  : 999px;
    else                     : 0.25rem;
  );
}

/*//////////// COLORS ////////////*/

:root {
  --color-danger  : red;
  --color-error   : red;
  --color-success : green;
  --color-warning : yellow;
}

/*//////////// SHORTHANDS ////////////*/


/* a layer below the elements and skins, specificity 0: an element, a skin or any rule of the page that sets the property itself wins */
@layer aufbau.reset {
  :where(*) {
    background-color : var(--bg);
    color            : if(style(--fg:  none): inherit; else: var(--fg));
    accent-color     : if(style(--ink: none): inherit; else: var(--ink));

    gap     : if(style(--gap: none): normal; else: --space(var(--gap)));
    padding : if(style(--pad: none): 0;      else: --space(var(--pad)));
    margin  : if(style(--mgn: none): 0;      else: --space(var(--mgn)));

    /* none steps back, so the radius an element gives itself (:host included) stays */
    border-radius : if(style(--rad: none): revert-layer; style(--rad: auto): --radius(); else: var(--rad));
  }
}

/* the page paints the palette */
html {
  background-color : var(--color-ink, purple);
}
body {
  --bg  : var(--color-bg);
  --fg  : var(--color-fg);
  --ink : var(--color-ink);
}

/*//////////// CONFIG ////////////*/

@property --factor-space { inherits: false; initial-value: 0.25rem; syntax: "<length>"; }

:root {
  --factor-space : 0.25rem;
}

