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

@layer tokens {
  @property --hue { syntax: "<number>"; inherits: true; initial-value: 310; }
  @property --phase { syntax: "<number>"; inherits: false; initial-value: 0.4; }
  @property --blob { syntax: "<length>"; inherits: false; initial-value: 44px; }
  @property --period { syntax: "<time>"; inherits: false; initial-value: 17s; }
  @property --offset { syntax: "<time>"; inherits: false; initial-value: -6s; }
  @property --trip { syntax: "<integer>"; inherits: false; initial-value: 0; }
  @property --column { syntax: "<number>"; inherits: false; initial-value: 0.5; }

  :root {
    color-scheme: dark;

    --hue: mod(random(--lamp-hue, 170, 425, 1), 360);

    --color-wall: oklch(22% 0.003 270);
    --color-wall-light: oklch(31% 0.004 270);
    --color-wall-dark: oklch(13% 0.003 270);
    --color-table: oklch(16% 0.003 270);
    --color-table-dark: oklch(9% 0.003 270);
    --color-matte: oklch(15% 0.002 270);
    --color-matte-light: oklch(27% 0.003 270);
    --color-matte-dark: oklch(7% 0.002 270);
    --color-tint: oklch(60% 0.28 var(--hue));
    --color-light: oklch(68% 0.27 var(--hue));
    --color-cord: oklch(14% 0.01 270);
    --color-cord-twist: oklch(22% 0.015 var(--hue));
    --color-text: oklch(90% 0.004 270);

    --space-xs: 0.35rem;
    --space-m: 1rem;
    --type-xs: 0.8rem;
    --type-s: 0.95rem;
    --lamp-w: min(16rem, 52vw, 25dvh);
    --glass-shape: shape(
      from 19% 0%,
      line to 81% 0%,
      curve to 100% 88% with 88% 36% / 100% 62%,
      curve to 97% 100% with 100% 94% / 99% 98%,
      line to 3% 100%,
      curve to 0% 88% with 1% 98% / 0% 94%,
      curve to 19% 0% with 0% 62% / 12% 36%,
      close
    );
  }
}

@layer reset {
  * {
    box-sizing: border-box;
  }

  body,
  p {
    margin: 0;
  }

  i,
  b {
    display: block;
  }
}

@layer base {
  body {
    background: var(--color-wall-dark);
    color: var(--color-text);
    font: var(--type-s) / 1.3 system-ui, sans-serif;
  }

  a:focus-visible {
    outline: 2px solid var(--color-text);
    outline-offset: 3px;
  }
}

@layer layout {
  .room {
    position: relative;
    display: grid;
    grid-template-rows: 1fr auto;
    justify-items: center;
    align-items: end;
    gap: var(--space-xs);
    min-block-size: 100dvh;
    padding-block-start: var(--space-m);
    overflow: clip;
    background: radial-gradient(ellipse 70% 62% at 50% 44%, var(--color-wall-light), var(--color-wall) 52%, var(--color-wall-dark));
  }

  .table {
    position: absolute;
    inset-inline: 0;
    inset-block-end: 0;
    block-size: 23dvh;
    border-block-start: 1px solid oklch(26% 0.003 270);
    background: linear-gradient(var(--color-table), var(--color-table-dark));
  }

  .lamp {
    container-type: inline-size;
    position: relative;
    inline-size: var(--lamp-w);
    aspect-ratio: 1 / 3.25;
  }

  .foot-note {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-m) var(--space-m);
    text-align: center;
  }
}

@layer components {
  .defs {
    position: absolute;
    inline-size: 0;
    block-size: 0;
  }

  .aura {
    position: absolute;
    inset: -8% -130% 16%;
    background: radial-gradient(ellipse closest-side, color-mix(in oklch, var(--color-light) 24%, transparent), transparent);
  }

  .spill {
    position: absolute;
    inset-block-end: -4.5%;
    inset-inline: -70%;
    block-size: 12%;
    background:
      radial-gradient(ellipse 34% 26% at 50% 42%, oklch(3% 0 0 / 0.9), transparent),
      radial-gradient(ellipse closest-side, color-mix(in oklch, var(--color-light) 30%, transparent), transparent);
  }

  .cord {
    position: absolute;
    inset-block-end: 2.2%;
    inset-inline-end: 92%;
    inline-size: 100vw;
    block-size: 10cqi;
    overflow: visible;
    fill: none;
    stroke-linecap: butt;
  }

  .cord-body {
    stroke: var(--color-cord);
    stroke-width: 11;
    vector-effect: non-scaling-stroke;
  }

  .cord-twist {
    stroke: var(--color-cord-twist);
    stroke-width: 11;
    stroke-dasharray: 7 7;
    vector-effect: non-scaling-stroke;
  }

  .cap {
    position: absolute;
    inset-block: 0 82.6%;
    inset-inline: 18%;
    border-radius: 0.2rem 0.2rem 0 0;
    background: linear-gradient(90deg, var(--color-matte-dark), var(--color-matte-light) 24%, var(--color-matte) 48%, var(--color-matte-dark) 92%);
    clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%);
  }

  .glass {
    position: absolute;
    inset-block: 17.3% 37.5%;
    inset-inline: 0;
    isolation: isolate;
    overflow: clip;
    clip-path: polygon(19% 0, 81% 0, 100% 88%, 97% 100%, 3% 100%, 0 88%);
    clip-path: var(--glass-shape);
  }

  .refract {
    position: absolute;
    inset: 0;
    isolation: isolate;
    filter: url(#lens);
  }

  .liquid {
    position: absolute;
    inset: 0;
    background:
      radial-gradient(ellipse 66% 34% at 50% 100%, oklch(72% 0 0), transparent),
      linear-gradient(oklch(10% 0 0), oklch(19% 0 0) 48%, oklch(33% 0 0));
  }

  .far {
    position: absolute;
    inset: 0;
    opacity: 0.32;
    filter: blur(6px);
    scale: 0.85;
  }

  .blobs {
    position: absolute;
    inset: -5%;
    filter: url(#wax);
  }

  .pool {
    position: absolute;
    inset-inline: -4%;
    inset-block-end: -2%;
    block-size: 11%;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    background: white;

    & + & {
      inset-block: -2% auto;
      inset-inline: 28%;
      block-size: 4%;
      border-radius: 0 0 50% 50% / 0 0 100% 100%;
    }
  }

  :is(.blobs, .far) i {
    --phase: random(0, 1000);
    --blob: random(13cqi, 34cqi, 0.5cqi);
    --period: random(12s, 28s, 0.5s);
    --offset: random(-28s, 0s, 0.5s);
    --column: mod(sin(var(--phase) * 0.137 + var(--trip) * 12.9898) * 43758.5453, 1);
    --travel: 132cqi;

    position: absolute;
    inset-block-end: calc(var(--blob) * -0.3 + 6%);
    inset-inline-start: calc(32% + var(--column) * 36%);
    inline-size: var(--blob);
    aspect-ratio: 1;
    translate: -50% calc(var(--travel) * -1 * mod(var(--phase), 1));
    border-radius: 50%;
    background: white;
  }

  .heat {
    position: absolute;
    inset: 0;
    mix-blend-mode: soft-light;
    background: linear-gradient(oklch(26% 0 0), oklch(60% 0 0) 56%, white);
  }

  .tint {
    position: absolute;
    inset: 0;
    mix-blend-mode: color;
    background: var(--color-tint);
  }

  .curve {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, oklch(0% 0 0 / 0.62), transparent 15%, transparent 83%, oklch(0% 0 0 / 0.66));
  }

  .sheen {
    position: absolute;
    inset: 0;
    opacity: 0.55;
    mix-blend-mode: screen;
    filter: url(#bulb);

    b {
      block-size: 100%;
      background: white;
      clip-path: polygon(19% 0, 81% 0, 100% 88%, 97% 100%, 3% 100%, 0 88%);
      clip-path: var(--glass-shape);
    }
  }

  .streak {
    position: absolute;
    inset-block: 3% 11%;
    inline-size: 4.5%;
    border-radius: 50%;
    background: linear-gradient(oklch(100% 0 0 / 0.5), oklch(100% 0 0 / 0.2) 58%, transparent);

    &:nth-last-child(2) {
      inset-inline-start: 13%;
      rotate: 7deg;
    }

    &:last-child {
      inset-inline-start: 86%;
      inline-size: 1.8%;
      rotate: -7deg;
      background: linear-gradient(oklch(100% 0 0 / 0.42), oklch(100% 0 0 / 0.12) 70%, transparent);
    }
  }

  .collar {
    position: absolute;
    inset-block: 62% 16.4%;
    inset-inline: 0;
    background:
      linear-gradient(color-mix(in oklch, var(--color-light) 52%, transparent), transparent 12%),
      linear-gradient(90deg, var(--color-matte-dark), var(--color-matte-light) 22%, var(--color-matte) 46%, var(--color-matte-dark) 90%);
    clip-path: polygon(3% 0, 97% 0, 70% 100%, 30% 100%);
  }

  .foot {
    position: absolute;
    inset-block: 83.3% 0;
    inset-inline: 0;
    background:
      radial-gradient(ellipse 34% 14% at 50% 0%, oklch(0% 0 0 / 0.75), transparent),
      linear-gradient(90deg, var(--color-matte-dark) 8%, var(--color-matte-light) 30%, var(--color-matte) 50%, var(--color-matte-dark) 86%);
    clip-path: polygon(30% 0, 70% 0, 95% 92%, 50% 100%, 5% 92%);
    clip-path: shape(
      from 30% 0%,
      line to 70% 0%,
      line to 95% 90%,
      curve to 5% 90% with 80% 104% / 20% 104%,
      close
    );
  }

  .next {
    padding: var(--space-xs) 0.6rem;
    color: var(--color-text);
    text-underline-offset: 0.2em;
  }

  .no-random {
    display: none;
    font-size: var(--type-xs);
  }

  @supports not (order: random(1, 2)) {
    .no-random {
      display: block;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    @keyframes float {
      0% {
        translate: -50% 0;
        scale: 1.1 0.84;
      }

      45% {
        scale: 0.86 1.2;
      }

      100% {
        translate: -50% calc(var(--travel) * -1);
        scale: 1.04 0.96;
      }
    }

    @keyframes trips {
      to {
        --trip: 1000;
      }
    }

    :is(.blobs, .far) i {
      animation:
        float var(--period) ease-in-out var(--offset) infinite alternate,
        trips calc(var(--period) * 2000) steps(1000) var(--offset) infinite;
    }
  }
}
