@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);

    --glass-800: oklch(30% 0.05 230);
    --coffee-700: oklch(34% 0.06 50);
    --bakelite-900: oklch(22% 0.02 40);

    --color-glass: var(--glass-800);
    --color-coffee: var(--coffee-700);
    --color-bakelite: var(--bakelite-900);
    --color-steam: var(--color-cream);
    --shape-spout: polygon(0 100%, 0 62%, 82% 0, 100% 10%, 36% 100%);
    --shape-pot: polygon(13% 0, 87% 0, 100% 100%, 0 100%);
    --shape-burst-16: polygon(50% 0%, 56.6% 16.7%, 69.1% 3.8%, 68.9% 21.7%, 85.4% 14.6%, 78.3% 31.1%, 96.2% 30.9%, 83.3% 43.4%, 100% 50%, 83.3% 56.6%, 96.2% 69.1%, 78.3% 68.9%, 85.4% 85.4%, 68.9% 78.3%, 69.1% 96.2%, 56.6% 83.3%, 50% 100%, 43.4% 83.3%, 30.9% 96.2%, 31.1% 78.3%, 14.6% 85.4%, 21.7% 68.9%, 3.8% 69.1%, 16.7% 56.6%, 0% 50%, 16.7% 43.4%, 3.8% 30.9%, 21.7% 31.1%, 14.6% 14.6%, 31.1% 21.7%, 30.9% 3.8%, 43.4% 16.7%);
  }
}

@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="percolator"] {
    --grid-w: 360;
    --grid-h: 520;
    --paint-default: var(--color-enamel-mustard);
    --accent-default: var(--color-teal);

    & :where(.floor) {
      --x: 34;
      --y: 458;
      --w: 292;
      --h: 22;
    }

    & :where(.tray) {
      --x: 20;
      --y: 452;
      --w: 320;
      --h: 34;
      --fill: var(--paint);

      border-radius: 50%;
      box-shadow: inset 0 0 0 calc(6 * var(--u)) var(--chrome);
      transform-origin: 50% 100%;
      scale: var(--tray, 0);
    }

    & :where(.handle) {
      --x: 30;
      --y: 180;
      --w: 96;
      --h: 190;
      --outline-inset: calc(-18 * var(--u));

      border: calc(18 * var(--u)) solid var(--color-bakelite);
      border-inline-end-width: 0;
      background: none;
      border-radius: calc(60 * var(--u)) 0 0 calc(60 * var(--u)) / 50% 0 0 50%;
    }

    & :where(.spout) {
      --x: 246;
      --y: 162;
      --w: 92;
      --h: 110;
      --shape: var(--shape-spout);
      --fill: var(--paint);
    }

    & :where(.pot) {
      --x: 78;
      --y: 148;
      --w: 204;
      --h: 276;
      --shape: var(--shape-pot);
      --fill: var(--paint);
      --pattern: linear-gradient(transparent 0 82%, var(--chrome) 82% 89%, transparent 89%);
    }

    & :where(.emblem) {
      --x: 146;
      --y: 226;
      --w: 68;
      --h: 68;
      --shape: var(--shape-burst-16);
      --fill: var(--accent);
    }

    & :where(.base) {
      --x: 64;
      --y: 414;
      --w: 232;
      --h: 54;
      --fill: var(--chrome);
      --pattern: var(--glint);

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

    & :where(.lid) {
      --x: 98;
      --y: 122;
      --w: 164;
      --h: 36;
      --fill: var(--chrome);
      --pattern: var(--glint);

      border-radius: 50% 50% calc(6 * var(--u)) calc(6 * var(--u)) / 100% 100% calc(6 * var(--u)) calc(6 * var(--u));
    }

    & :where(.collar) {
      --x: 156;
      --y: 112;
      --w: 48;
      --h: 14;
      --fill: var(--chrome);

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

    & :where(.cap) {
      --x: 164;
      --y: 88;
      --w: 32;
      --h: 26;
      --fill: var(--chrome);

      border-radius: 50% 50% calc(4 * var(--u)) calc(4 * var(--u)) / 80% 80% calc(4 * var(--u)) calc(4 * var(--u));
      transform-origin: 50% 100%;
      scale: calc(1 - var(--dome, 0));
    }

    & :where(.dome) {
      --x: 154;
      --y: 62;
      --w: 52;
      --h: 54;
      --fill: var(--color-glass);
      --pattern: linear-gradient(transparent 0 50%, var(--color-coffee) 50%);

      border-radius: 50% 50% calc(10 * var(--u)) calc(10 * var(--u)) / 60% 60% calc(10 * var(--u)) calc(10 * var(--u));
      transform-origin: 50% 100%;
      scale: var(--dome, 0);
    }

    & :where(.steam) {
      --y: 12;
      --w: 16;
      --h: 44;

      filter: drop-shadow(calc(-2 * var(--u)) calc(-2 * var(--u)) 0 var(--color-ink));
      transform-origin: 50% 100%;
      scale: var(--dome, 0);

      &::before,
      &::after {
        content: "";
        position: absolute;
        inline-size: 50%;
        block-size: 50%;
        border: 0 solid var(--color-steam);
      }

      &::before {
        inset-inline-start: 50%;
        inset-block-start: 0;
        border-inline-end-width: calc(4 * var(--u));
        border-radius: 0 100% 100% 0 / 0 50% 50% 0;
      }

      &::after {
        inset-inline-end: 50%;
        inset-block-end: 0;
        border-inline-start-width: calc(4 * var(--u));
        border-radius: 100% 0 0 100% / 50% 0 0 50%;
      }
    }

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

    & :where(.steam[data-n="2"]) {
      --x: 186;
      --y: 4;
    }
  }

  .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~="glass-top"] {
    --dome: 1;
  }

  .art[data-with~="tray"] {
    --tray: 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;
      }

      .art :where(.cut)::after {
        transition: background-color var(--duration-paint) ease;
      }
    }
  }
}
