/* Enlarger timer under a ruby safelight. Two colours only: black and ruby.
   The safelight hangs up and to the left, out of frame. */

@property --dk-turn {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

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

.dk {
  --film: #ff2139;
  --ink: #0b0002;
  --paint: #b4132b;
  --spec: 255, 38, 62;
  --move: 500ms cubic-bezier(0.4, 0, 0.3, 1.16);
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(90% 90% at 0% 0%, #0d0003 0%, #030001 60%);
  font-family: "Barlow Condensed", sans-serif;
  font-weight: 500;
  color: var(--paint);
  -webkit-font-smoothing: antialiased;
}

/* ---- the moulded body ---- */

.dk-body {
  position: absolute;
  inset: 14px;
  border-radius: 50px;
  background:
    radial-gradient(64% 46% at 10% 0%, rgba(168, 8, 32, 0.4) 0%, rgba(104, 3, 20, 0.16) 42%, rgba(60, 0, 10, 0) 76%),
    #060102;
  box-shadow:
    inset 9px 9px 14px -9px rgba(var(--spec), 0.5),
    inset -10px -12px 18px -8px #000;
}

/* the rolled edge: one long crimson specular, hottest at the lit corner */
.dk-body::before,
.dk-bezel::before,
.dk-bezel::after,
.dk-key::before,
.dk-key::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px;
  pointer-events: none;
  mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
}

.dk-body::before {
  background: linear-gradient(
    135deg,
    rgba(var(--spec), 1) 0%,
    rgba(var(--spec), 0.9) 9%,
    rgba(214, 16, 42, 0.62) 24%,
    rgba(130, 4, 24, 0.34) 44%,
    rgba(60, 0, 10, 0.22) 66%,
    rgba(96, 2, 18, 0.34) 100%
  );
}

.dk-group {
  position: absolute;
  inset: 0;
}

/* ---- scale window ---- */

.dk-bezel {
  position: absolute;
  left: 20px;
  top: 20px;
  width: 472px;
  height: 268px;
  border-radius: 36px;
  background:
    radial-gradient(60% 80% at 4% 0%, rgba(150, 6, 28, 0.34), rgba(60, 0, 10, 0) 64%),
    #070102;
  box-shadow:
    inset 6px 6px 9px -6px rgba(var(--spec), 0.62),
    inset -7px -8px 12px -6px #000,
    9px 11px 18px rgba(0, 0, 0, 0.95),
    0 0 44px 4px rgba(200, 10, 36, 0.09);
}

.dk-bezel::before {
  padding: 1.5px;
  background: linear-gradient(
    135deg,
    rgba(var(--spec), 0.9) 0%,
    rgba(214, 16, 42, 0.6) 12%,
    rgba(120, 4, 22, 0.24) 30%,
    rgba(40, 0, 8, 0) 50%
  );
}

/* inner lip of the opening: the far walls face the lamp, and all of it
   catches a little of the scale's own light */
.dk-bezel::after {
  inset: 11px;
  border-radius: 25px;
  padding: 2.5px;
  background: linear-gradient(
    315deg,
    rgba(var(--spec), 0.9) 0%,
    rgba(206, 14, 40, 0.56) 14%,
    rgba(120, 4, 22, 0.3) 34%,
    rgba(70, 1, 12, 0.14) 56%,
    rgba(40, 0, 8, 0) 80%
  );
}

.dk-window {
  position: absolute;
  inset: 14px;
  border-radius: 22px;
  overflow: hidden;
  background: #020001;
  isolation: isolate;
}

/* the gate behind the strip: dark, with a little of the lamp's spill */
.dk-roller {
  position: absolute;
  inset: 0;
  background: radial-gradient(48% 62% at 50% 50%, rgba(120, 4, 22, 0.34), rgba(60, 0, 10, 0.12) 60%, rgba(40, 0, 8, 0) 90%);
}

/* the strip runs over a roller of 250 px radius whose axis stands upright
   behind the slot. --dk-v is the value under the index; each piece sits
   --dk-s seconds along the film and turns (s - v) x 48 degrees about the axis. */
.dk-strip {
  position: absolute;
  left: 50%;
  top: 0;
  width: 0;
  height: 100%;
  transition: --dk-v var(--move);
}

.dk-num,
.dk-film {
  position: absolute;
  display: block;
  backface-visibility: hidden;
}

/* the film: a translucent ruby base, lit from behind, narrower than the slot
   so both of its cut edges show. Each piece is a tenth of a second long and
   carries its share of the emulsion, one tick and one perforation. */
.dk-film {
  left: -11.2px;
  top: 6px;
  width: 22.4px;
  height: 228px;
  transform-origin: 50% 114px;
  transform: perspective(1500px) translateZ(-250px) rotateY(calc((var(--dk-s) - var(--dk-v)) * 48deg)) translateZ(250px);
  background:
    linear-gradient(var(--ink), var(--ink)) center bottom 8px / 1.5px 12px no-repeat,
    linear-gradient(var(--ink), var(--ink)) center bottom 8px / 100% 1.5px no-repeat,
    var(--dk-emulsion) var(--dk-grain-x) 0 / 419px 240px repeat,
    linear-gradient(#ff2e48, #ff2e48) top / 100% 1.25px no-repeat,
    linear-gradient(#ff2e48, #ff2e48) bottom / 100% 1.25px no-repeat,
    var(--film);
}

.dk-film.half {
  background-size:
    2px 20px,
    100% 1.5px,
    419px 240px,
    100% 1.25px,
    100% 1.25px,
    auto;
}

.dk-film.major {
  background-size:
    3px 30px,
    100% 1.5px,
    419px 240px,
    100% 1.25px,
    100% 1.25px,
    auto;
}

.dk-film::before {
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  top: 3.5px;
  width: 10px;
  height: 6.5px;
  border-radius: 2px;
  background: #050001;
}

/* the print: dense black emulsion on the lit base */
.dk-num {
  left: -130px;
  top: -6px;
  width: 260px;
  height: 200px;
  transform-origin: 50% 126px;
  transform: perspective(1500px) translateZ(-250px) rotateY(calc((var(--dk-s) - var(--dk-v)) * 48deg)) translateZ(252px) translateX(var(--dk-dx, 0px));
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: 500 230px/200px "Barlow Condensed", sans-serif;
  letter-spacing: 0;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
}

.dk-field {
  appearance: none;
  outline: none;
  caret-color: transparent;
  cursor: default;
  border-radius: 0;
}

.dk-field::selection {
  background: transparent;
}

/* one lamp behind the middle of the slot: the strip is hottest there and
   falls away to the slot's ends */
.dk-falloff {
  position: absolute;
  inset: 0;
  mix-blend-mode: multiply;
  background: radial-gradient(56% 170% at 50% 50%, #fff 0%, #f2f2f2 20%, #b4b4b4 48%, #626262 74%, #2c2c2c 100%);
  pointer-events: none;
}

/* fixed index: a hairline scribed on the cover, black against the lit strip */
.dk-hair {
  position: absolute;
  left: calc(50% - 1px);
  top: 191px;
  bottom: 0;
  width: 2px;
  background: var(--ink);
  pointer-events: none;
}

.dk-recess {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px #000,
    inset 4px 5px 9px 1px rgba(0, 0, 0, 0.7),
    inset -2px -2px 6px 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.dk-notch {
  position: absolute;
  left: calc(50% - 6px);
  bottom: 1.5px;
  width: 12px;
  height: 8px;
  background: var(--paint);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

/* ---- engraved and filled legends ---- */

.dk-legend {
  position: absolute;
  left: 34px;
  top: 304px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.16em;
  color: var(--paint);
}

/* ---- push keys ---- */

.dk-key {
  position: absolute;
  top: 360px;
  width: 88px;
  height: 88px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  appearance: none;
  outline: none;
  cursor: pointer;
  isolation: isolate;
  background: #070102;
  box-shadow:
    0 0 0 4px #010000,
    6px 8px 12px 2px rgba(0, 0, 0, 0.9);
}

.dk-minus {
  left: 54px;
}

.dk-plus {
  left: 370px;
}

/* rim of the cap */
.dk-key::before {
  padding: 1.5px;
  background: conic-gradient(
    from 315deg,
    rgba(var(--spec), 0.95) 0deg,
    rgba(206, 14, 40, 0.5) 34deg,
    rgba(90, 2, 16, 0.18) 80deg,
    rgba(40, 0, 8, 0) 150deg,
    rgba(40, 0, 8, 0) 210deg,
    rgba(90, 2, 16, 0.18) 280deg,
    rgba(206, 14, 40, 0.5) 326deg,
    rgba(var(--spec), 0.95) 360deg
  );
}

/* far wall of the well the cap sits in */
.dk-key::after {
  inset: -5.5px;
  padding: 1.5px;
  background: conic-gradient(
    from 135deg,
    rgba(var(--spec), 0.7) 0deg,
    rgba(170, 8, 32, 0.3) 36deg,
    rgba(40, 0, 8, 0) 84deg,
    rgba(40, 0, 8, 0) 276deg,
    rgba(170, 8, 32, 0.3) 324deg,
    rgba(var(--spec), 0.7) 360deg
  );
}

.dk-key:active {
  transform: translateY(1px) scale(0.985);
}

.dk-glyph,
.dk-plus .dk-glyph::after {
  position: absolute;
  left: calc(50% - 16px);
  top: calc(50% - 2.5px);
  width: 32px;
  height: 5px;
  border-radius: 0.5px;
  background: var(--paint);
  box-shadow: inset 1px 1px 1px rgba(30, 0, 6, 0.75);
}

.dk-plus .dk-glyph::after {
  content: "";
  left: 0;
  top: 0;
  transform: rotate(90deg);
}

/* the cap is dished for the fingertip: the far side of the dish faces the lamp */
.dk-glyph::before {
  content: "";
  position: absolute;
  left: calc(50% - 37px);
  top: calc(50% - 37px);
  width: 74px;
  height: 74px;
  border-radius: 50%;
  z-index: -1;
  background: radial-gradient(circle at 30% 28%, #020001 0%, #030001 60%, rgba(96, 3, 18, 0.45) 80%, rgba(214, 18, 44, 0.8) 100%);
  box-shadow: inset 2px 2px 3px #000;
}

/* ---- knob ---- */

.dk-knob {
  position: absolute;
  left: 164px;
  top: 312px;
  width: 184px;
  height: 184px;
  transition: --dk-turn var(--move);
}

.dk-index {
  position: absolute;
  inset: -4px;
  width: 192px;
  height: 192px;
}

.dk-index line {
  stroke: var(--paint);
  stroke-width: 2.5;
}

.dk-index line.zero {
  stroke-width: 3.5;
}

.dk-skirt {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  filter: drop-shadow(6px 8px 6px rgba(0, 0, 0, 0.95));
}

/* the moulded outline: 24 ribs, turning with the knob */
.dk-ribs {
  position: absolute;
  inset: 0;
  width: 160px;
  height: 160px;
  transform: rotate(var(--dk-turn));
}

.dk-ribs path {
  fill: #060102;
}

/* the same outline again as a bare edge: it turns, and the lamp picks it out
   on the near side only */
.dk-rim {
  position: absolute;
  inset: 0;
  mask-image: conic-gradient(
    from 315deg,
    #000 0deg,
    rgba(0, 0, 0, 0.6) 40deg,
    rgba(0, 0, 0, 0.2) 100deg,
    rgba(0, 0, 0, 0.12) 180deg,
    rgba(0, 0, 0, 0.2) 260deg,
    rgba(0, 0, 0, 0.6) 320deg,
    #000 360deg
  );
}

.dk-rim path {
  fill: none;
  stroke: rgba(var(--spec), 0.9);
  stroke-width: 1.25;
}

/* fluted skirt. The ribs turn with the knob; the light does not. Each layer
   is one face of a rib (its crest, and the two flanks), lit as far as that
   face looks toward the lamp, and cut out by a mask that turns. Every crest
   keeps a thin line of red all the way round: gloss black mirrors the room. */
.dk-flute {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  mask-composite: intersect;
}

.dk-flute.crest {
  background: conic-gradient(
    from 318deg,
    rgba(var(--spec), 1) 0deg,
    rgba(232, 22, 48, 0.8) 34deg,
    rgba(176, 10, 34, 0.52) 78deg,
    rgba(140, 6, 26, 0.4) 130deg,
    rgba(140, 6, 26, 0.4) 230deg,
    rgba(176, 10, 34, 0.52) 282deg,
    rgba(232, 22, 48, 0.8) 326deg,
    rgba(var(--spec), 1) 360deg
  );
  mask-image:
    radial-gradient(circle, transparent 55px, rgba(0, 0, 0, 0.6) 56px, #000 76.6px, transparent 77.8px),
    repeating-conic-gradient(from calc(var(--dk-turn) - 0.8deg), #000 0deg 1.6deg, transparent 2.3deg 14.3deg, #000 15deg);
}

.dk-flute.ccw {
  background: conic-gradient(
    from 12deg,
    rgba(var(--spec), 0.85) 0deg,
    rgba(190, 12, 38, 0.4) 26deg,
    rgba(60, 0, 10, 0) 60deg,
    rgba(60, 0, 10, 0) 300deg,
    rgba(190, 12, 38, 0.4) 334deg,
    rgba(var(--spec), 0.85) 360deg
  );
  mask-image:
    radial-gradient(circle, transparent 55px, rgba(0, 0, 0, 0.6) 56px, #000 75px, transparent 76.4px),
    repeating-conic-gradient(from calc(var(--dk-turn) - 3.2deg), transparent 0deg, #000 0.6deg 2.6deg, transparent 2.6deg 15deg);
}

.dk-flute.cw {
  background: conic-gradient(
    from 262deg,
    rgba(var(--spec), 0.85) 0deg,
    rgba(190, 12, 38, 0.4) 26deg,
    rgba(60, 0, 10, 0) 60deg,
    rgba(60, 0, 10, 0) 300deg,
    rgba(190, 12, 38, 0.4) 334deg,
    rgba(var(--spec), 0.85) 360deg
  );
  mask-image:
    radial-gradient(circle, transparent 55px, rgba(0, 0, 0, 0.6) 56px, #000 75px, transparent 76.4px),
    repeating-conic-gradient(from calc(var(--dk-turn) + 0.6deg), transparent 0deg, #000 0deg 2deg, transparent 2.6deg 15deg);
}

/* the dome: gloss black. A soft sheen toward the lamp, and a little of the
   lit body thrown back up into its far shoulder. */
.dk-dome {
  position: absolute;
  inset: 40px;
  border-radius: 50%;
  background:
    radial-gradient(48% 48% at 33% 31%, rgba(184, 10, 36, 0.5), rgba(110, 3, 20, 0.2) 54%, rgba(60, 0, 10, 0) 84%),
    radial-gradient(circle at 36% 34%, rgba(60, 0, 10, 0) 56%, rgba(150, 6, 28, 0.34) 78%),
    radial-gradient(circle, #0b0103 0%, #050102 62%, #020001 100%);
  box-shadow:
    0 0 0 1.5px #000,
    5px 6px 8px 1px rgba(0, 0, 0, 0.9);
}

/* the dome's shoulder: a long arc from the lamp, a shorter one above it from
   the lit slot */
.dk-dome::before,
.dk-dome::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.dk-dome::before {
  background: conic-gradient(
    from 315deg,
    rgba(var(--spec), 1) 0deg,
    rgba(214, 16, 42, 0.7) 28deg,
    rgba(120, 4, 22, 0.2) 62deg,
    rgba(60, 0, 10, 0) 92deg,
    rgba(60, 0, 10, 0) 268deg,
    rgba(120, 4, 22, 0.2) 298deg,
    rgba(214, 16, 42, 0.7) 332deg,
    rgba(var(--spec), 1) 360deg
  );
  mask-image: radial-gradient(circle, transparent 47.4px, #000 48.4px, #000 50.2px, transparent 51.2px);
}

.dk-dome::after {
  background: conic-gradient(
    from 0deg,
    rgba(var(--spec), 0.62) 0deg,
    rgba(190, 12, 38, 0.3) 20deg,
    rgba(60, 0, 10, 0) 36deg,
    rgba(60, 0, 10, 0) 324deg,
    rgba(190, 12, 38, 0.3) 340deg,
    rgba(var(--spec), 0.62) 360deg
  );
  mask-image: radial-gradient(circle, transparent 40px, #000 41.2px, #000 43.2px, transparent 44.4px);
}

.dk-pointer {
  position: absolute;
  left: calc(50% - 2.5px);
  top: 4px;
  width: 5px;
  height: 22px;
  border-radius: 1px;
  background: var(--paint);
  box-shadow: inset 1px 1px 1px rgba(30, 0, 6, 0.75);
  transform-origin: 50% 48px;
  transform: rotate(var(--dk-turn));
}

/* the lamp itself, mirrored small and sharp in the dome */
.dk-gloss {
  position: absolute;
  left: 28.4px;
  top: 36.4px;
  width: 26px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(var(--spec), 1) 0%, rgba(var(--spec), 1) 84%, rgba(var(--spec), 0) 100%);
  transform: rotate(-45deg);
}

/* The safelight is a pure emitter, so its ruby goes wider than sRGB on a
   display that can show it, and the lamp's gloss can beat SDR white. The
   sRGB rules above stay the fallback. */
@media (color-gamut: p3) {
  .dk {
    --film: color(display-p3 1 0.05 0.15);
    --paint: color(display-p3 0.72 0.01 0.1);
  }
}

@media (color-gamut: p3) and (dynamic-range: high) {
  .dk-body {
    background:
      radial-gradient(64% 46% at 10% 0%, color(display-p3 0.72 0.01 0.1 / 0.45) 0%, color(display-p3 0.4 0 0.04 / 0.18) 42%, transparent 76%),
      #060102;
  }
  .dk-gloss {
    background: radial-gradient(closest-side, color(display-p3 1.25 0.12 0.2) 0%, color(display-p3 1 0.05 0.14) 84%, transparent 100%);
  }
}
