/* --cm-lz is the natural log of the magnification on screen. It is a registered number, so the zoom is
   one transition in log space: every layer, the crossfades and the scale bar are computed from it. */
@property --cm-lz {
  syntax: "<number>";
  inherits: true;
  initial-value: 2.302585;
}

@property --cm-blur {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

@property --cm-l {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

@property --cm-r {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

.cm {
  --mint: #b9f1dc;
  --ink: #0a3a30;
  --stain: #d3117d;
  --glass: #ecefe9;
  /* a longer jump across the turret takes a little longer */
  --cm-time: calc(760ms + var(--cm-span) * 170ms);
  position: relative;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: var(--mint);
  color: var(--ink);
  font-family: "Instrument Sans Variable", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  transition: --cm-lz var(--cm-time) cubic-bezier(0.6, 0, 0.3, 1);
}

/* Focus pull: the image goes soft as the turret leaves its detent, comes sharp when the new objective
   seats, runs a little past focus and settles. Two identical animations, alternated to restart. */
.cm[data-pull="a"] { animation: cm-pull-a calc(var(--cm-time) + 520ms) linear; }
.cm[data-pull="b"] { animation: cm-pull-b calc(var(--cm-time) + 520ms) linear; }

@keyframes cm-pull-a {
  0% { --cm-blur: 0; animation-timing-function: cubic-bezier(0.3, 0, 0.4, 1); }
  24% { --cm-blur: 1; animation-timing-function: cubic-bezier(0.5, 0, 0.5, 1); }
  46% { --cm-blur: 0.8; animation-timing-function: cubic-bezier(0.5, 0, 0.3, 1); }
  70% { --cm-blur: 0; animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1); }
  84% { --cm-blur: 0.2; animation-timing-function: cubic-bezier(0.4, 0, 0.3, 1); }
  100% { --cm-blur: 0; }
}

@keyframes cm-pull-b {
  0% { --cm-blur: 0; animation-timing-function: cubic-bezier(0.3, 0, 0.4, 1); }
  24% { --cm-blur: 1; animation-timing-function: cubic-bezier(0.5, 0, 0.5, 1); }
  46% { --cm-blur: 0.8; animation-timing-function: cubic-bezier(0.5, 0, 0.3, 1); }
  70% { --cm-blur: 0; animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1); }
  84% { --cm-blur: 0.2; animation-timing-function: cubic-bezier(0.4, 0, 0.3, 1); }
  100% { --cm-blur: 0; }
}

/* ---- readouts in the two top corners ---- */

.cm-slide,
.cm-fov {
  position: absolute;
  top: 16px;
  margin: 0;
}

.cm-slide { left: 18px; }
.cm-fov { right: 18px; text-align: right; }

.cm dt {
  font-size: 12px;
  line-height: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.66;
}

.cm dd {
  margin: 3px 0 0;
  font-size: 16px;
  line-height: 18px;
  font-weight: 600;
  font-stretch: 94%;
  letter-spacing: -0.005em;
}

.cm-fov dd {
  margin-top: 0;
  font-size: 29px;
  line-height: 32px;
  font-weight: 600;
  font-stretch: 100%;
  letter-spacing: -0.025em;
  animation: cm-swap 420ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

@keyframes cm-swap {
  from { opacity: 0; transform: translateY(7px); filter: blur(3px); }
}

/* ---- the field of view ---- */

.cm-field {
  position: absolute;
  left: 84px;
  top: 40px;
  width: 372px;
  height: 372px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--glass);
  isolation: isolate;
}

.cm-stack {
  position: absolute;
  inset: 0;
  filter: blur(calc(var(--cm-blur) * (3.4px + var(--cm-span) * 1.5px)));
}

/* Each level is a photograph 7/6 the width of the field at its own objective, centred on the same point
   of the section, and scaled by the magnification on screen over its own. */
.cm-layer {
  position: absolute;
  left: -31px;
  top: -31px;
  /* The page resets images to `max-width: 100%`, which would squeeze this 434 px
     plate into the 372 px field and push the section off to the left. */
  width: 434px;
  max-width: none;
  height: 434px;
  user-select: none;
  -webkit-mask-image: radial-gradient(circle closest-side, #000 88%, transparent 100%);
  mask-image: radial-gradient(circle closest-side, #000 88%, transparent 100%);
}

/* A sharper level fades in over the one below while the lower one still has pixels to spare. */
.cm-layer[data-level="4"] {
  transform: scale(calc(exp(var(--cm-lz)) / 4));
  -webkit-mask-image: none;
  mask-image: none;
}

.cm-layer[data-level="10"] {
  transform: scale(calc(exp(var(--cm-lz)) / 10));
  opacity: clamp(0, (var(--cm-lz) - 1.4816) / 0.2412, 1);
}

.cm-layer[data-level="40"] {
  transform: scale(calc(exp(var(--cm-lz)) / 40));
  opacity: clamp(0, (var(--cm-lz) - 2.6391) / 0.3566, 1);
}

.cm-layer[data-level="100"] {
  transform: scale(calc(exp(var(--cm-lz)) / 100));
  opacity: clamp(0, (var(--cm-lz) - 3.912) / 0.4055, 1);
}

/* the field darkens a touch towards the stop, as it does through an eyepiece */
.cm-field::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent 76%, rgb(10 58 48 / 0.1) 100%);
  box-shadow: inset 0 0 0 1px rgb(10 58 48 / 0.3);
  pointer-events: none;
}

/* The bar is always as long as its label says at the magnification on screen: 2/9 of the field at rest,
   shorter or longer than that while the zoom is still travelling. */
.cm-scale {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 1;
  display: grid;
  justify-items: center;
  width: 112px;
  margin-left: -56px;
  padding: 5px 0 9px;
  border-radius: 12px;
  overflow: hidden;
  background: rgb(255 255 255 / 0.92);
  box-shadow: 0 0 0 1px rgb(10 58 48 / 0.1);
}

.cm-scale span {
  font-size: 13px;
  line-height: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
  animation: cm-swap 320ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

.cm-scale i {
  width: calc(82.667px * exp(var(--cm-lz)) / var(--cm-power));
  height: 7px;
  margin-top: 3px;
  border: solid var(--ink);
  border-width: 0 2px;
  background: linear-gradient(var(--ink), var(--ink)) center / 100% 3px no-repeat;
  box-sizing: border-box;
}

/* ---- the turret ring ---- */

.cm-turret {
  position: absolute;
  left: 50px;
  top: 6px;
  width: 440px;
  height: 440px;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 14px 16px rgb(10 80 62 / 0.2));
}

/* a quarter turn per objective, seating into its detent with a small overshoot */
.cm-ring {
  transform: rotate(calc(var(--cm-turn) * -90deg));
  transition: transform var(--cm-time) cubic-bezier(0.5, 0, 0.2, 1.22);
}

.cm-ring-body {
  fill: none;
  stroke: #fff;
  stroke-width: 26;
}

.cm-ring-knurl {
  fill: none;
  stroke: rgb(10 58 48 / 0.22);
  stroke-width: 4;
  stroke-dasharray: 1 2.674;
}

.cm-band {
  fill: none;
  stroke-width: 3;
}

/* the white band of the 100x is drawn as an outline on the white ring; the black one marks oil immersion */
.cm-band[data-band="100"] {
  stroke: rgb(10 58 48 / 0.28) !important;
  stroke-width: 1;
}

.cm-band-oil {
  stroke: #111;
}

.cm-engraving {
  fill: var(--ink);
  font-size: 11.5px;
  font-weight: 650;
  font-stretch: 88%;
  letter-spacing: 0.085em;
  text-anchor: middle;
  opacity: 0.4;
  transition: opacity 300ms linear;
}

[data-on] > .cm-engraving {
  opacity: 1;
  transition-delay: calc(var(--cm-time) - 320ms);
}

.cm-stop {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
}

.cm-index {
  fill: none;
  stroke: var(--stain);
  stroke-width: 3;
  stroke-linecap: round;
}

/* ---- the control ---- */

.cm-control {
  position: absolute;
  left: 20px;
  bottom: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 500px;
  height: 68px;
  border-radius: 34px;
  background: #fff;
  box-shadow: 0 12px 22px -14px rgb(10 80 62 / 0.55);
  font-size: 31px;
  line-height: 36px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.cm-item,
.cm-over span {
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 15px 0 0;
  white-space: nowrap;
}

.cm-item {
  border: 0;
  border-radius: 34px;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  outline: none;
  cursor: pointer;
}

.cm-control small {
  margin-left: 4px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

/* The pill moves like a cell: the edge on the side it is heading for reaches out first, the other edge
   lets go late, so it stretches across the gap and rounds up again on arrival. */
.cm-indicator {
  --cm-l: var(--segmented-control-indicator-left);
  --cm-r: calc(500px - var(--segmented-control-indicator-left) - var(--segmented-control-indicator-width));
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 34px;
  background: var(--stain);
  clip-path: inset(5px calc(var(--cm-r) + 5px) 5px calc(var(--cm-l) + 5px) round 29px);
  pointer-events: none;
  transition:
    --cm-l 500ms cubic-bezier(0.6, 0, 0.2, 1) 70ms,
    --cm-r 300ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.cm[data-dir="down"] .cm-indicator {
  transition:
    --cm-l 300ms cubic-bezier(0.2, 0.7, 0.2, 1),
    --cm-r 500ms cubic-bezier(0.6, 0, 0.2, 1) 70ms;
}

.cm-over {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  color: #fff;
}

.cm-control:has(.cm-item:focus-visible) .cm-indicator::after {
  content: "";
  position: absolute;
  inset: 9px calc(var(--cm-r) + 9px) 9px calc(var(--cm-l) + 9px);
  border: 2.5px solid #fff;
  border-radius: 25px;
}
