@property --cut {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 36%;
}
@property --head {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

.am {
  --ground: #f9e030;
  --ink: #1d1a0e;
  --red: #c4121f;
  --ease: cubic-bezier(0.3, 0, 0.2, 1);
  position: relative;
  isolation: isolate;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font-family: "Instrument Serif", serif;
  -webkit-font-smoothing: antialiased;
}

.am * {
  box-sizing: border-box;
}

/* the photographs: one on top of the other, the stalk on the frame's centre line, their paper
   backdrop let out into the page's own yellow at the sides and the bottom */
.am-photos {
  position: absolute;
  z-index: -1;
  left: 32px;
  top: -10px;
  width: 476px;
  height: 476px;
  mask-image:
    linear-gradient(to right, #0000, #000 9%, #000 91%, #0000),
    linear-gradient(to top, #0000, #000 6%);
  mask-composite: intersect;
}

/* a later photograph is let in from the bulb upwards behind a soft edge, which lengthens the
   stalk; above that edge it dissolves in over the day before, so one head turns into the next and
   the plant is never without one */
.am-photo {
  --cut: 36%;
  --head: 0;
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  mask-image: linear-gradient(
    to top,
    #000 calc(var(--cut) - 7%),
    rgb(0 0 0 / var(--head)) var(--cut)
  );
  transition:
    --cut 0.36s linear,
    --head 0.24s linear 0.1s;
}
.am-photo[data-shown] {
  --cut: calc(var(--top) + 10%);
  --head: 1;
}
.am-photo:first-child {
  mask-image: none;
}

/* the timeline: five events along the floor. Neither it nor an event is positioned, so an
   event's title and description can be set against the whole frame */
.am-line {
  display: grid;
  margin: 452px 0 0 20px;
  grid-template-columns: repeat(var(--timeline-count, 5), 1fr);
  width: 500px;
}

.am-item {
  display: grid;
  grid-template-rows: 26px auto;
  justify-items: center;
  outline: none;
  cursor: default;
}

/* from this marker's centre to the next one's */
.am-link {
  grid-area: 1 / 1;
  align-self: center;
  justify-self: start;
  width: 100%;
  height: 3px;
  margin-left: 50%;
  background:
    linear-gradient(var(--ink), var(--ink)) left / var(--done, 0%) 100%
      no-repeat,
    rgb(29 26 14 / 0.28);
  transition: background-size 0.3s var(--ease);
}
.am-link[data-complete] {
  --done: 100%;
}
.am-item[data-last] .am-link {
  display: none;
}

.am-marker {
  position: relative;
  grid-area: 1 / 1;
  align-self: center;
  width: 14px;
  height: 14px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--ground);
  transition:
    scale 0.3s cubic-bezier(0.3, 1.5, 0.5, 1),
    background-color 0.16s linear,
    border-color 0.16s linear;
}
.am-marker[data-complete] {
  background: var(--ink);
}
.am-marker[data-current] {
  scale: 1.6;
  border-color: var(--red);
  background: var(--red);
}
/* keyboard focus: a ring standing off the chosen marker */
.am-marker::after {
  content: "";
  position: absolute;
  inset: -7px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  opacity: 0;
  scale: 0.6;
  transition:
    opacity 0.12s linear,
    scale 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.am-item:focus-visible .am-marker::after {
  opacity: 1;
  scale: 1;
}

.am-time {
  grid-area: 2 / 1;
  margin-top: 7px;
  font-family: "Newsreader Variable", serif;
  font-size: 16px;
  font-weight: 500;
  line-height: 20px;
  font-variant-numeric: lining-nums;
  white-space: nowrap;
  opacity: 0.66;
  transition: opacity 0.2s linear;
}
.am-time[data-current] {
  opacity: 1;
}

/* the chosen event's title: the day, huge, left of the stalk. Every title stands in the same
   place and one dissolves into the next, so what two days share (the word, a first digit) holds
   still while the rest changes */
.am-title {
  position: absolute;
  left: 30px;
  top: 144px;
  display: grid;
}
.am-word {
  font-size: 30px;
  font-style: italic;
  line-height: 36px;
}
.am-title:not([data-current]) .am-word {
  visibility: hidden;
}
.am-number {
  margin-left: -4px;
  font-size: 168px;
  line-height: 128px;
  letter-spacing: -0.03em;
  font-variant-numeric: lining-nums;
  transition: opacity 0.1s linear;
}
.am-title:not([data-current]) .am-number {
  opacity: 0;
  transition: opacity 0.1s linear 0.02s;
}

/* and its description, right of the bulb on the same baseline */
.am-phrase {
  position: absolute;
  left: 330px;
  top: 271px;
  width: 190px;
  font-size: 34px;
  font-style: italic;
  line-height: 36px;
  transition:
    opacity 0.16s linear 0.13s,
    translate 0.38s cubic-bezier(0.2, 1, 0.3, 1) 0.1s;
}
/* days gone by have left upwards, days to come wait below */
.am-phrase[data-complete] {
  opacity: 0;
  translate: 0 -16px;
  transition:
    opacity 0.1s linear,
    translate 0.13s ease-in;
}
.am-phrase[data-upcoming] {
  opacity: 0;
  translate: 0 20px;
  transition:
    opacity 0.1s linear,
    translate 0.13s ease-in;
}
