@layer reset, tokens, base, layout, components, utilities, overrides;

@layer tokens {
  @property --art-ready {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
  }

  :root {
    --color-ink: oklch(15% 0.02 245);
    --color-ink-dot: oklch(15% 0.02 245 / 0.16);
    --color-cream: oklch(97% 0.025 90);
    --color-cream-dim: oklch(86% 0.03 90);
    --color-teal: oklch(52% 0.085 200);
    --color-cherry: oklch(58% 0.19 28);
    --color-mustard: oklch(81% 0.15 83);
    --font-sign: "Futura", "Century Gothic", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;

    --turquoise-400: oklch(72% 0.11 195);
    --steel-400: oklch(70% 0.02 235);
    --chrome-200: oklch(88% 0.02 225);
    --chrome-50: oklch(98% 0.01 220);

    --color-enamel-turquoise: var(--turquoise-400);
    --color-enamel-mustard: var(--color-mustard);
    --color-enamel-cherry: var(--color-cherry);
    --color-enamel-cream: var(--color-cream);
    --color-chrome-satin: var(--steel-400);
    --color-chrome-gleam: var(--chrome-200);
    --color-chrome-shine: var(--chrome-50);
    --color-floor-shadow: color-mix(in oklch, var(--color-ink) 45%, transparent);
    --pattern-glint: linear-gradient(100deg, transparent 0 20%, var(--color-chrome-shine) 20% 27%, transparent 27% 33%, var(--color-chrome-shine) 33% 36%, transparent 36%);

    --duration-paint: 400ms;
    --duration-pop: 480ms;
    --duration-settle: 300ms;
    --ease-pop: linear(0, 0.62 35%, 1.08 64%, 0.98 84%, 1);

    --crust-500: oklch(52% 0.11 55);
    --crumb-200: oklch(86% 0.08 82);
    --bakelite-900: oklch(22% 0.02 40);

    --color-toast-crust: var(--crust-500);
    --color-toast-crumb: var(--crumb-200);
    --color-bakelite: var(--bakelite-900);
  }
}

@layer components {
  .art {
    --u: calc(100cqi / var(--grid-w));
    --art-line: calc(3.5 * var(--line-scale, 1) * var(--u));
    --art-slip-x: calc(-5 * var(--line-scale, 1) * var(--u));
    --art-slip-y: calc(-4 * var(--line-scale, 1) * var(--u));
    --art-grain: radial-gradient(circle, var(--color-ink-dot) 32%, transparent 36%) 0 0 / calc(7 * var(--u)) calc(7 * var(--u));
    --paint: var(--enamel, var(--paint-default));
    --accent: var(--enamel-accent, var(--accent-default));
    --chrome: var(--trim, var(--color-chrome-satin));
    --glint: var(--trim-glint, none);

    position: relative;
    container-type: inline-size;
    isolation: isolate;
    inline-size: min(100%, var(--art-max-b, 200dvh) * var(--grid-w) / var(--grid-h));
    aspect-ratio: var(--grid-w) / var(--grid-h);
    margin-inline: auto;
    font-family: var(--font-sign);
    forced-color-adjust: none;

    & > :where(*) {
      position: absolute;
      inset-inline-start: calc(var(--x) * var(--u));
      inset-block-start: calc(var(--y) * var(--u));
      inline-size: calc(var(--w) * var(--u));
      block-size: calc(var(--h) * var(--u));
    }

    & :where(.shape) {
      background: var(--art-grain), var(--pattern, none), var(--fill, transparent);

      &::after {
        content: "";
        position: absolute;
        inset: var(--outline-inset, 0);
        border: var(--art-line) solid var(--color-ink);
        border-radius: inherit;
        translate: var(--art-slip-x) var(--art-slip-y);
        pointer-events: none;
      }
    }

    & :where(.cut) {
      &::before,
      &::after {
        content: "";
        position: absolute;
        clip-path: var(--shape);
      }

      &::before {
        inset: 0;
        background: var(--color-ink);
        translate: var(--art-slip-x) var(--art-slip-y);
      }

      &::after {
        inset: var(--art-line);
        background: var(--art-grain), var(--pattern, none), var(--fill);
      }
    }

    & :where(.type) {
      display: grid;
      place-items: center;
      color: var(--accent);
      font-size: calc(var(--type-size) * var(--u));
      font-style: italic;
      font-weight: 900;
      letter-spacing: 0.04em;
      line-height: 1;
      text-shadow: calc(-3 * var(--u)) calc(-2 * var(--u)) 0 var(--color-ink);
      text-transform: uppercase;
      white-space: nowrap;
    }

    & :where(.floor) {
      border-radius: 50%;
      background: var(--color-floor-shadow);
    }

    & :where(.pull) {
      --fill: var(--chrome);
      --pattern: var(--glint);

      border-radius: calc(8 * var(--u));
    }
  }

  .art[data-model="toaster"] {
    --grid-w: 480;
    --grid-h: 400;
    --paint-default: var(--color-enamel-cherry);
    --accent-default: var(--color-mustard);

    & :where(.floor) {
      --x: 36;
      --y: 346;
      --w: 408;
      --h: 24;
    }

    & :where(.foot) {
      --y: 342;
      --w: 46;
      --h: 16;
      --fill: var(--color-bakelite);

      border-radius: 0 0 calc(6 * var(--u)) calc(6 * var(--u));
    }

    & :where(.foot[data-n="1"]) {
      --x: 74;
    }

    & :where(.foot[data-n="2"]) {
      --x: 360;
    }

    & :where(.toast) {
      --y: 46;
      --w: 120;
      --h: 136;
      --fill: var(--color-toast-crumb);

      border-radius: 46% 46% 10% 10% / 34% 34% 8% 8%;
      box-shadow: inset 0 0 0 calc(9 * var(--u)) var(--color-toast-crust);
    }

    & :where(.toast[data-n="1"]) {
      --x: 106;
    }

    & :where(.toast[data-n="2"]) {
      --x: 254;

      opacity: var(--slot, 0);
      translate: 0 calc((1 - var(--slot, 0)) * 150 * var(--u));
    }

    & :where(.body) {
      --x: 60;
      --y: 120;
      --w: 360;
      --h: 214;
      --fill: var(--paint);

      border-radius: calc(54 * var(--u)) calc(54 * var(--u)) calc(18 * var(--u)) calc(18 * var(--u)) / calc(70 * var(--u)) calc(70 * var(--u)) calc(18 * var(--u)) calc(18 * var(--u));
    }

    & :where(.slot) {
      --y: 117;
      --w: 132;
      --h: 10;

      border-radius: calc(5 * var(--u));
      background: var(--color-ink);
    }

    & :where(.slot[data-n="1"]) {
      --x: 100;
    }

    & :where(.slot[data-n="2"]) {
      --x: 248;

      scale: var(--slot, 0) 1;
    }

    & :where(.band) {
      --x: 60;
      --y: 236;
      --w: 360;
      --h: 18;
      --fill: var(--chrome);
      --pattern: var(--glint);
    }

    & :where(.streak) {
      --x: 92;
      --h: 10;
      --fill: var(--accent);

      border-radius: calc(5 * var(--u));
    }

    & :where(.streak[data-n="1"]) {
      --y: 270;
      --w: 128;
    }

    & :where(.streak[data-n="2"]) {
      --y: 288;
      --w: 100;
    }

    & :where(.streak[data-n="3"]) {
      --y: 306;
      --w: 72;
    }

    & :where(.dial) {
      --x: 330;
      --y: 264;
      --w: 56;
      --h: 56;
      --fill: var(--color-cream);

      border-radius: 50%;
      box-shadow: inset 0 0 0 calc(6 * var(--u)) var(--chrome);
      scale: var(--dial, 0);

      &::before {
        content: "";
        position: absolute;
        inset-block-start: 16%;
        inset-inline-start: calc(50% - 2.5 * var(--u));
        inline-size: calc(5 * var(--u));
        block-size: 34%;
        border-radius: calc(3 * var(--u));
        background: var(--color-cherry);
        transform-origin: 50% 100%;
        rotate: 40deg;
      }
    }

    & :where(.lever) {
      --x: 404;
      --y: 168;
      --w: 50;
      --h: 22;
      --fill: var(--color-bakelite);

      border-radius: calc(11 * var(--u));
    }

    & :where(.base) {
      --x: 44;
      --y: 324;
      --w: 392;
      --h: 24;
      --fill: var(--chrome);
      --pattern: var(--glint);

      border-radius: calc(12 * var(--u));
    }
  }

  .art[data-enamel="turquoise"] {
    --enamel: var(--color-enamel-turquoise);
    --enamel-accent: var(--color-cherry);
  }

  .art[data-enamel="mustard"] {
    --enamel: var(--color-enamel-mustard);
    --enamel-accent: var(--color-teal);
  }

  .art[data-enamel="cherry"] {
    --enamel: var(--color-enamel-cherry);
    --enamel-accent: var(--color-mustard);
  }

  .art[data-enamel="cream"] {
    --enamel: var(--color-enamel-cream);
    --enamel-accent: var(--color-teal);
  }

  .art[data-trim="gleam"] {
    --trim: var(--color-chrome-gleam);
    --trim-glint: var(--pattern-glint);
  }

  .art[data-with~="second-slot"] {
    --slot: 1;
  }

  .art[data-with~="dial"] {
    --dial: 1;
  }

  @keyframes art-ready {
    from {
      --art-ready: 0;
    }

    to {
      --art-ready: 1;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .art {
      animation: art-ready 0s var(--duration-settle) both;
    }

    @container style(--art-ready: 1) {
      .art > :where(*) {
        transition:
          scale var(--duration-pop) var(--ease-pop),
          translate var(--duration-pop) var(--ease-pop),
          opacity var(--duration-paint) ease,
          color var(--duration-paint) ease,
          background-color var(--duration-paint) ease,
          box-shadow var(--duration-paint) ease;
      }
    }
  }
}
