@import url("https://fonts.googleapis.com/css2?family=Caveat:wght@500;700&display=swap");

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

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

  @property --light {
    syntax: "<number>";
    inherits: true;
    initial-value: 1;
  }

  :root {
    color-scheme: dark;

    --color-void: oklch(7% 0.006 60);
    --color-plaster: oklch(17% 0.012 65);
    --color-wax-edge: oklch(46% 0.1 62);
    --color-wax: oklch(70% 0.13 76);
    --color-wax-lit: oklch(84% 0.11 86);
    --color-wax-shade: oklch(55% 0.11 66);
    --color-paint: oklch(40% 0.13 28);
    --color-iron: oklch(30% 0.015 45);
    --color-iron-dark: oklch(12% 0.008 40);
    --color-pewter: oklch(52% 0.014 78);
    --color-pewter-lit: oklch(72% 0.035 82);
    --color-pewter-dark: oklch(24% 0.01 70);
    --color-oak: oklch(25% 0.035 58);
    --color-oak-dark: oklch(15% 0.025 52);
    --color-brass: oklch(72% 0.11 85);
    --color-brass-dark: oklch(44% 0.08 68);
    --color-chalk: oklch(90% 0.015 85);
    --color-text: oklch(90% 0.01 80);
    --color-muted: oklch(70% 0.015 75);

    --font-chalk: "Caveat", "Segoe Print", "Bradley Hand", cursive;
    --font-plate: Georgia, "Times New Roman", serif;
    --type-s: 0.85rem;
    --leading: 1.35;

    /* The burn finishes at this share of the scroll; the rest is the flame going out. */
    --span: 92%;
  }
}

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

  body,
  figure,
  h1,
  ol,
  p {
    margin: 0;
  }

  ol {
    padding: 0;
    list-style: none;
  }
}

@layer base {
  body {
    background: var(--color-void);
    color: var(--color-text);
    font: 1rem / var(--leading) system-ui, sans-serif;
  }

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

  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }
}

@layer layout {
  .wall {
    container-type: size;
    position: fixed;
    inset: 0;
    overflow: clip;

    /* Geometry. Each value resolves inside the wall, so cqb is the wall's height. */
    --w: clamp(1.4rem, 5cqb, 3.2rem);
    --top: 11cqb;
    --wax: 59cqb;
    --stub: 3.5cqb;
    --L: calc(var(--wax) - var(--stub));
    --base: calc(var(--top) + var(--wax));
    --ground: calc(var(--base) + var(--D) * 0.76);
    --surface: calc(var(--ground) - 5cqb);
    --edge: calc(var(--ground) + 2.5cqb);
    --cx: max(5.5rem, 50cqi - 3rem);
    --D: calc(var(--w) * 3.8);
    --Dh: calc(var(--D) * 0.24);
    --lip: calc(var(--w) * 0.32);
    --cut: calc(var(--burn) * var(--L));
    --fy: calc(var(--top) + var(--cut) - var(--w) * 1.05);
    --note-x: calc(var(--cx) + var(--w) * 1.9 + 0.6rem);
  }

  .rig,
  .clock,
  .note {
    position: absolute;
    inset: 0;
  }

  .note {
    z-index: 4;
  }
}

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

    .p-dark { stop-color: var(--color-pewter-dark); }
    .p-mid { stop-color: var(--color-pewter); }
    .p-lit { stop-color: var(--color-pewter-lit); }
    .core { stop-color: oklch(99% 0.03 98); }
    .yellow { stop-color: oklch(95% 0.12 95); }
    .orange { stop-color: oklch(84% 0.16 72); }
    .edge { stop-color: oklch(70% 0.19 52); stop-opacity: 0.35; }
  }

  /* The room: a limewashed wall, an oak table, and the light the flame throws on both. */
  .room {
    position: absolute;
    inset: 0;
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.55' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 .95  0 0 0 0 .85  .3 0 0 0 -.13'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E") 0 0 / 240px,
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1000' height='1000'%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.006 .012' numOctaves='4' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  1.5 0 0 0 -.55'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23b)'/%3E%3C/svg%3E") center / cover no-repeat,
      var(--color-plaster);
  }

  .table {
    position: absolute;
    inset: var(--surface) 0 0;
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='180'%3E%3Cfilter id='o'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.004 .22' numOctaves='3' seed='5' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  1.4 0 0 0 -.52'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23o)'/%3E%3C/svg%3E") 0 0 / 700px 180px,
      linear-gradient(
        var(--color-oak-dark) 0,
        var(--color-oak) calc(var(--edge) - var(--surface) - 0.4cqb),
        oklch(42% 0.05 62) calc(var(--edge) - var(--surface)),
        oklch(20% 0.03 55) calc(var(--edge) - var(--surface) + 0.5cqb),
        oklch(13% 0.02 50) calc(var(--edge) - var(--surface) + 7cqb),
        var(--color-void) calc(var(--edge) - var(--surface) + 7.3cqb)
      );
  }

  .pool {
    position: absolute;
    inset: 0;
    mix-blend-mode: screen;
    opacity: var(--light);
    pointer-events: none;

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      background: radial-gradient(
        circle at var(--cx) var(--fy),
        oklch(74% 0.11 76 / 0.62) 0,
        oklch(56% 0.1 66 / 0.4) 8cqb,
        oklch(40% 0.075 58 / 0.2) 24cqb,
        oklch(28% 0.045 55 / 0.07) 46cqb,
        transparent 72cqb
      );
      animation: breathe 3.1s ease-in-out infinite;
    }
  }

  .dark {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--color-void);
    opacity: calc((1 - var(--light)) * 0.55);
    pointer-events: none;
  }

  /* Pewter pricket stand: one turned piece under the dish, from the bowl to the foot. */
  .stand {
    position: absolute;
    inset-inline-start: calc(var(--cx) - var(--D) / 2);
    inset-block-start: var(--base);
    inline-size: var(--D);
    overflow: visible;
    filter: brightness(calc(0.55 + 0.45 * var(--light) * (0.6 + 0.4 * var(--burn))));

    .metal { fill: url(#pewter); }
    .foot-top { fill: var(--color-pewter-lit); }
    .shine { fill: oklch(88% 0.01 240 / 0.55); }
    .shadow { fill: oklch(4% 0.01 50 / 0.7); filter: url(#soft); }
  }

  /* Wax that has run down and pooled round the base. It spreads as the candle burns. */
  .puddle {
    position: absolute;
    inset-inline-start: var(--cx);
    inset-block-start: calc(var(--base) + var(--Dh) * 0.3);
    inline-size: calc(var(--w) * (1.5 + 0.5 * var(--burn)));
    block-size: calc(var(--w) * (0.4 + 0.08 * var(--burn)));
    translate: -50% -50%;
    border-radius: 48% 52% 50% 50% / 55% 50% 50% 45%;
    background: radial-gradient(closest-side, var(--color-wax-shade) 55%, oklch(60% 0.09 70 / 0.75) 80%, oklch(60% 0.06 70 / 0));
    filter: brightness(calc(0.5 + 0.45 * var(--light) * (0.5 + 0.5 * var(--burn))));
  }

  .dish-back,
  .dish-front {
    position: absolute;
    inset-inline-start: calc(var(--cx) - var(--D) / 2);
    inline-size: var(--D);
    filter: brightness(calc(0.6 + 0.5 * var(--light) * (0.5 + 0.5 * var(--burn))));
  }

  .dish-back {
    inset-block-start: calc(var(--base) - var(--Dh) / 2);
    block-size: var(--Dh);
    border-radius: 50%;
    border: max(1px, calc(var(--w) * 0.05)) solid var(--color-pewter-lit);
    background:
      radial-gradient(calc(var(--w) * 1.05) calc(var(--Dh) * 0.32) at 50% 72%, oklch(8% 0.01 240 / 0.6), transparent),
      radial-gradient(ellipse at 50% 30%, oklch(56% 0.03 80), oklch(36% 0.014 74) 60%, var(--color-pewter-dark));
    box-shadow: inset 0 calc(var(--Dh) * 0.14) calc(var(--Dh) * 0.2) oklch(0% 0 0 / 0.45);
  }

  .dish-front {
    z-index: 3;
    inset-block-start: var(--base);
    block-size: calc(var(--Dh) / 2 + var(--lip));
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    background:
      radial-gradient(calc(var(--D) / 2) calc(var(--Dh) / 2) at 50% 0, transparent 96%, var(--color-pewter-lit) 98%, var(--color-pewter-lit) 106%, transparent 116%),
      linear-gradient(90deg, var(--color-pewter-dark), var(--color-pewter) 28%, var(--color-pewter-lit) 42%, var(--color-pewter) 58%, var(--color-pewter-dark));
    mask: radial-gradient(calc(var(--D) / 2) calc(var(--Dh) / 2) at 50% 0, transparent 97%, #000 99%);
  }

  /* The candle. Nothing here sets a z-index on .candle, so its parts layer between the dish halves. */
  .candle {
    position: absolute;
    inset-inline-start: calc(var(--cx) - var(--w) / 2);
    inset-block-start: var(--top);
    inline-size: var(--w);
    block-size: var(--wax);
  }

  .wax {
    position: absolute;
    inset: 0 0 calc(var(--Dh) * -0.5 - var(--lip) * 0.6);
    z-index: 1;
    border-radius: 0 0 50% 50% / 0 0 calc(var(--w) * 0.12) calc(var(--w) * 0.12);
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.12 .2' numOctaves='3' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .25  0 0 0 0 .12  0 0 0 0 0  .45 0 0 0 -.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E") 0 0 / 100% 160px,
      linear-gradient(90deg, var(--color-wax-edge), var(--color-wax-shade) 12%, var(--color-wax-lit) 32%, var(--color-wax) 50%, var(--color-wax-shade) 78%, var(--color-wax-edge));
    clip-path: inset(var(--cut) -60% 0 -60%);

    /* Glow where the flame shines through the wax, and the dark lower down. */
    &::before,
    &::after {
      content: "";
      position: absolute;
      inset-inline: 0;
      pointer-events: none;
    }

    &::before {
      inset-block-start: var(--cut);
      block-size: calc(var(--w) * 3.2);
      z-index: 1;
      background: linear-gradient(oklch(93% 0.12 86 / 0.85), oklch(84% 0.16 72 / 0.45) calc(var(--w) * 0.7), oklch(76% 0.15 66 / 0.14) calc(var(--w) * 1.8), transparent);
      mix-blend-mode: screen;
      opacity: var(--light);
    }

    &::after {
      inset-block: var(--cut) 0;
      background: linear-gradient(transparent 10%, oklch(10% 0.03 50 / calc(0.35 + 0.25 * (1 - var(--light)))));
      border-radius: inherit;
    }
  }

  .band {
    position: absolute;
    inset-inline: 0;
    inset-block-start: calc(var(--f) * var(--L) - var(--w) * 0.12);
    block-size: calc(var(--w) * 0.12);
    border-block-end: max(1.5px, calc(var(--w) * 0.07)) solid var(--color-paint);
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    opacity: 0.9;
  }

  /* Physical top and left: logical ones would follow the vertical writing mode. */
  .year {
    position: absolute;
    left: 50%;
    top: calc((var(--f) + 0.125) * var(--L));
    translate: -50% -50%;
    writing-mode: vertical-rl;
    color: var(--color-paint);
    font: 700 calc(var(--w) * 0.34) / 1 var(--font-plate);
    letter-spacing: 0.08em;
    opacity: 0.9;
  }

  .ticks {
    position: absolute;
    inset-inline-start: 12%;
    inset-block-start: 0;
    inline-size: 14%;
    block-size: var(--L);
    background: repeating-linear-gradient(var(--color-paint) 0 max(1px, calc(var(--w) * 0.035)), transparent 0 calc(var(--L) / 48));
    opacity: 0.75;
  }

  .drip {
    position: absolute;
    inset-block-start: calc(var(--f) * var(--L));
    inset-inline-start: calc(50% + var(--side) * var(--w) * 0.5 - var(--w) * 0.08);
    inline-size: calc(var(--w) * 0.16);
    block-size: var(--len);
    border-radius: 0 0 999px 999px;
    background: linear-gradient(90deg, var(--color-wax-lit), var(--color-wax) 60%, var(--color-wax-shade));
    transform-origin: top;

    &::after {
      content: "";
      position: absolute;
      inset-inline-start: 50%;
      inset-block-end: calc(var(--w) * -0.06);
      translate: -50% 0;
      inline-size: calc(var(--w) * 0.24);
      aspect-ratio: 1 / 1.1;
      border-radius: 50%;
      background: radial-gradient(circle at 38% 35%, var(--color-wax-lit), var(--color-wax) 55%, var(--color-wax-shade));
    }
  }

  .pool-wax {
    position: absolute;
    z-index: 1;
    inset-inline: calc(var(--w) * -0.03);
    inset-block-start: calc(var(--cut) - var(--w) * 0.14);
    block-size: calc(var(--w) * 0.28);
    border-radius: 50%;
    background: radial-gradient(ellipse at 50% 42%, oklch(82% 0.15 76), oklch(70% 0.16 66) 62%, oklch(62% 0.14 60));
    box-shadow:
      inset 0 0 0 max(1px, calc(var(--w) * 0.055)) oklch(90% 0.09 86 / 0.9),
      inset 0 calc(var(--w) * 0.05) calc(var(--w) * 0.06) oklch(40% 0.1 55 / 0.55);
    filter: brightness(calc(0.5 + 0.5 * var(--light)));

    /* The flame reflected in the liquid wax. */
    &::after {
      content: "";
      position: absolute;
      inset-inline-start: 50%;
      inset-block-start: 18%;
      translate: -50% 0;
      inline-size: 22%;
      block-size: 36%;
      border-radius: 50%;
      background: radial-gradient(closest-side, oklch(99% 0.04 95), oklch(92% 0.12 88 / 0.6) 60%, transparent);
      opacity: var(--light);
    }
  }

  /* Iron nails pushed in sideways. Each falls when the wax around it melts. */
  .nail {
    --nail-h: max(4px, calc(var(--w) * 0.15));
    --fall: calc(var(--wax) - var(--f) * var(--L) + var(--land-y) * var(--Dh));

    position: absolute;
    z-index: 2;
    inset-inline-start: calc(var(--w) * 0.7);
    inset-block-start: calc(var(--f) * var(--L) - var(--nail-h) / 2);
    inline-size: calc(var(--w) * 1.2);
    block-size: var(--nail-h);
    background: linear-gradient(oklch(62% 0.05 55), oklch(40% 0.045 45) 30%, oklch(28% 0.035 40) 55%, var(--color-iron-dark));
    clip-path: polygon(0 30%, 88% 12%, 88% 0, 100% 0, 100% 100%, 88% 100%, 88% 88%, 0 70%);
    filter: drop-shadow(0 calc(var(--w) * 0.05) calc(var(--w) * 0.04) oklch(0% 0 0 / 0.55));

    /* The forged head, taller than the shank. */
    &::before {
      content: "";
      position: absolute;
      inset-inline-end: 0;
      inset-block: 0;
      inline-size: 12%;
      background: linear-gradient(90deg, oklch(64% 0.03 55), var(--color-iron-dark));
    }
  }

  .wick {
    position: absolute;
    inset-inline-start: 50%;
    inset-block-start: var(--cut);
    inline-size: max(2px, calc(var(--w) * 0.07));
    block-size: calc(var(--w) * 0.34);
    translate: -50% calc(-100% + var(--w) * 0.06);
    border-radius: 40% 40% 20% 20%;
    background: linear-gradient(90deg, oklch(14% 0.01 40), oklch(34% 0.02 50) 45%, oklch(10% 0 0));

    /* Once the flame is out the top of the wick keeps glowing, with an ember at the tip. */
    &::before {
      content: "";
      position: absolute;
      inset: -1px -1px 45%;
      border-radius: inherit;
      background: linear-gradient(oklch(70% 0.2 42), oklch(45% 0.16 35 / 0.6) 60%, transparent);
      opacity: calc(1 - var(--light));
    }

    &::after {
      content: "";
      position: absolute;
      z-index: 6;
      inset-inline-start: 50%;
      inset-block-start: -1px;
      translate: -50% 0;
      inline-size: max(3px, calc(var(--w) * 0.09));
      aspect-ratio: 1;
      border-radius: 50%;
      background: oklch(78% 0.18 48);
      box-shadow: 0 0 calc(var(--w) * 0.15) oklch(65% 0.22 35);
      opacity: calc((1 - var(--light)) * 0.9);
    }
  }

  .fire {
    position: absolute;
    z-index: 6;
    inset-inline-start: 50%;
    inset-block-end: calc(var(--w) * -0.04);
    inline-size: calc(var(--w) * 0.55);
    overflow: visible;
    translate: -50% 0;
    scale: var(--light);
    transform-origin: 50% 94%;
    animation: flicker 2.6s ease-in-out infinite;

    .outer {
      fill: oklch(82% 0.15 70 / 0.4);
      filter: url(#soft);
    }

    .body {
      fill: url(#flame-fill);
    }

    .dim {
      fill: oklch(48% 0.07 58 / 0.4);
      filter: url(#soft);
    }

    .blue {
      fill: oklch(58% 0.16 255 / 0.65);
      filter: url(#soft);
    }

    .wick-in {
      fill: none;
      stroke: oklch(12% 0.01 40 / 0.85);
      stroke-width: 0.9;
      stroke-linecap: round;
    }

    .ember-in {
      fill: oklch(80% 0.17 50);
    }
  }

  .glow {
    position: absolute;
    z-index: 5;
    inset-inline-start: 50%;
    inset-block-end: calc(var(--w) * 0.9);
    inline-size: calc(var(--w) * 5);
    aspect-ratio: 1;
    translate: -50% 50%;
    border-radius: 50%;
    background: radial-gradient(closest-side, oklch(92% 0.1 88 / 0.5), oklch(82% 0.13 72 / 0.16) 42%, transparent);
    mix-blend-mode: screen;
    opacity: var(--light);
    pointer-events: none;
    animation: pulse 2.3s ease-in-out infinite;
  }

  .smoke {
    position: absolute;
    z-index: 6;
    inset-inline-start: 50%;
    inset-block-end: 100%;
    opacity: calc(1 - var(--light));

    i {
      position: absolute;
      inset-inline-start: calc(var(--w) * -0.035);
      inset-block-end: 0;
      inline-size: calc(var(--w) * 0.07);
      block-size: calc(var(--w) * 1.5);
      border-radius: 50%;
      background: linear-gradient(transparent, oklch(78% 0.01 70 / 0.45) 30%, oklch(78% 0.01 70 / 0.3) 80%, transparent);
      filter: blur(1.5px);
      opacity: 0;
      animation: rise 3.6s linear infinite;

      &:nth-child(2) { animation-delay: -1.2s; }
      &:nth-child(3) { animation-delay: -2.4s; }
    }
  }

  /* The brass plate on the table edge. */
  .plate {
    position: absolute;
    inset-inline-start: max(var(--cx), 6.5rem);
    inset-block-start: calc(var(--edge) + 3.4cqb);
    translate: -50% -50%;
    display: grid;
    padding: 0.4em 1.8em;
    border-radius: 0.2em;
    background:
      radial-gradient(circle at 0.7em 50%, var(--color-brass-dark) 0 0.17em, transparent 0.21em),
      radial-gradient(circle at calc(100% - 0.7em) 50%, var(--color-brass-dark) 0 0.17em, transparent 0.21em),
      linear-gradient(var(--color-brass), oklch(58% 0.1 76) 55%, var(--color-brass-dark));
    box-shadow: inset 0 1px 0 oklch(90% 0.1 90 / 0.6), 0 0.15em 0.35em oklch(0% 0 0 / 0.6);
    color: oklch(27% 0.05 68);
    font: 700 clamp(0.7rem, 2cqb, 1.05rem) / 1.15 var(--font-plate);
    letter-spacing: 0.14em;
    text-align: center;
    text-shadow: 0 1px 0 oklch(86% 0.1 86 / 0.5);
    text-transform: uppercase;
    white-space: nowrap;
    filter: brightness(calc(0.45 + 0.55 * var(--light)));

    small {
      font: 500 0.66em / 1.3 ui-monospace, "SF Mono", Menlo, monospace;
      letter-spacing: 0.06em;
      text-transform: none;
    }
  }

  .hint,
  .notes {
    color: var(--color-chalk);
    font-family: var(--font-chalk);
  }

  .hint {
    position: absolute;
    inset-inline-start: var(--note-x);
    inset-block-start: 4.5cqb;
    font-size: clamp(1rem, 2.8cqb, 1.4rem);
    opacity: 0.7;
    filter: url(#chalk);
  }

  /* The timeline, chalked on the wall beside each nail. Light from the flame decides how well it reads. */
  .notes {
    position: absolute;
    inset: 0;
    font-size: clamp(1rem, 3cqb, 1.55rem);
    font-weight: 500;
    line-height: 1.05;
    mask: radial-gradient(circle at var(--cx) var(--fy), #000 20cqb, oklch(0% 0 0 / 0.42) 60cqb);

    li {
      position: absolute;
      inset-inline-start: var(--note-x);
      inset-block-start: calc(var(--top) + var(--f) * var(--L));
      inline-size: min(19rem, 100cqi - var(--note-x) - 1rem);
      translate: 0 -0.6em;
      rotate: -1.5deg;
      filter: url(#chalk);

      &::before {
        content: "";
        position: absolute;
        inset-inline-end: calc(100% + 0.3rem);
        inset-block-start: 0.6em;
        inline-size: 0.8rem;
        block-size: 2px;
        background: currentColor;
        rotate: 8deg;
      }
    }

    strong {
      display: block;
      font-size: 1.45em;
      font-weight: 700;
    }

    span {
      display: block;
      opacity: 0.85;
    }

    em {
      display: inline-block;
      margin-block-start: 0.25em;
      padding: 0.05em 0.5em 0.1em;
      border: 2px solid currentColor;
      border-radius: 50%;
      font-size: 1.2em;
      font-style: normal;
      font-weight: 700;
      rotate: -4deg;
    }
  }

  .relight {
    position: absolute;
    z-index: 7;
    inset-inline-start: 50%;
    inset-block-end: 1.6cqb;
    translate: -50% 0;
    padding: 0.2em 0.6em;
    color: var(--color-brass);
    font: 700 clamp(1rem, 2.6cqb, 1.3rem) / 1 var(--font-chalk);
    text-underline-offset: 0.2em;
  }

  .no-timeline {
    display: none;
    position: absolute;
    z-index: 7;
    inset-inline-start: 50%;
    inset-block-start: 1.5cqb;
    translate: -50% 0;
    inline-size: min(40ch, 100% - 2rem);
    color: var(--color-muted);
    font-size: var(--type-s);
    text-align: center;
  }
}

@layer overrides {
  /* Older browsers: a still candle, part burned, with the first nail already in the dish. */
  @supports not (animation-timeline: scroll()) {
    :root {
      --burn: 0.45;
    }

    .no-timeline {
      display: block;
    }

    .relight,
    .hint {
      display: none;
    }

    .nail:first-of-type {
      translate: calc(var(--land-x) * var(--w)) var(--fall);
      rotate: var(--land-r);
    }
  }

  @supports (animation-timeline: scroll()) {
    body {
      block-size: 700svh;
    }

    :root {
      animation: burn linear both;
      animation-timeline: scroll(root);
    }

    .nail {
      animation: drop linear both;
      animation-timeline: scroll(root);
      animation-range: calc(var(--f) * var(--span)) calc(var(--f) * var(--span) + 4%);
    }

    .notes li {
      animation: write linear both;
      animation-timeline: scroll(root);
      animation-range: calc(var(--f) * var(--span) + 2.5%) calc(var(--f) * var(--span) + 7%);
    }

    .drip {
      animation: drip linear both;
      animation-timeline: scroll(root);
      animation-range: calc(var(--f) * var(--span) - 1%) calc(var(--f) * var(--span) + 3%);
    }

    .hint {
      animation: fade linear both reverse;
      animation-timeline: scroll(root);
      animation-range: 0% 5%;
    }

    .relight {
      animation: fade linear both;
      animation-timeline: scroll(root);
      animation-range: 96% 100%;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .fire,
    .glow,
    .pool::before {
      animation: none;
    }

    .drip,
    .smoke {
      display: none;
    }
  }

  @keyframes burn {
    0% { --burn: 0; --light: 1; }
    92% { --burn: 1; --light: 1; }
    94% { --light: 0.5; }
    95% { --light: 0.8; }
    96.5% { --light: 0.15; }
    97.5%, 100% { --burn: 1; --light: 0; }
  }

  @keyframes drop {
    0% {
      translate: 0 0;
      rotate: 0deg;
      animation-timing-function: ease-out;
    }

    14% {
      translate: calc(var(--w) * 0.04) calc(var(--w) * 0.12);
      rotate: 12deg;
      animation-timing-function: ease-in;
    }

    62% {
      translate: calc(var(--land-x) * var(--w)) var(--fall);
      rotate: var(--land-r);
      animation-timing-function: ease-out;
    }

    76% {
      translate: calc(var(--land-x) * var(--w) + var(--w) * 0.1) calc(var(--fall) - var(--w) * 0.35);
      rotate: calc(var(--land-r) + 8deg);
      animation-timing-function: ease-in;
    }

    88%, 100% {
      translate: calc(var(--land-x) * var(--w)) var(--fall);
      rotate: var(--land-r);
    }
  }

  @keyframes write {
    0% {
      opacity: 0;
      clip-path: inset(-1em 100% -1em -2rem);
    }

    15% {
      opacity: 1;
    }

    100% {
      opacity: 1;
      clip-path: inset(-1em -1em -1em -2rem);
    }
  }

  @keyframes drip {
    from { scale: 1 0; }
    to { scale: 1 1; }
  }

  @keyframes fade {
    from { opacity: 0; visibility: hidden; }
    to { opacity: 1; visibility: visible; }
  }

  @keyframes flicker {
    0%, 100% { transform: scale(1, 1) skewX(0deg); }
    20% { transform: scale(0.98, 1.03) skewX(-1deg); }
    45% { transform: scale(1.01, 0.98) skewX(0.8deg); }
    63% { transform: scale(0.99, 1.05) skewX(-0.4deg); }
    82% { transform: scale(1.01, 0.99) skewX(1.2deg); }
  }

  @keyframes pulse {
    0%, 100% { scale: 1; }
    35% { scale: 0.95; }
    70% { scale: 1.03; }
  }

  @keyframes breathe {
    0%, 100% { opacity: 1; }
    30% { opacity: 0.9; }
    55% { opacity: 0.97; }
    80% { opacity: 0.86; }
  }

  @keyframes rise {
    0% { opacity: 0; translate: 0 0; scale: 0.6 0.8; }
    20% { opacity: 0.8; }
    100% { opacity: 0; translate: calc(var(--w) * 0.5) calc(var(--w) * -4.5); scale: 2 1.6; rotate: 18deg; }
  }
}
