.lm {
  --amber: #ffb01f;
  --red: #ff3d26;
  --off-amber: #2a1c07;
  --off-red: #2d0e09;
  --print: #8d877b;
  position: relative;
  width: 540px;
  height: 540px;
  box-sizing: border-box;
  background: #0b0a09;
  color: var(--amber);
  font-family: "Doto", monospace;
  overflow: hidden;
}

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

/* Message: 16 characters to a line, three lines. The real input sits on top, invisible. */
.lm-msg {
  position: absolute;
  inset: 26px 32px auto;
  height: 180px;
  display: block;
}

.lm-input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  border: 0;
  outline: none;
}

.lm-text {
  display: block;
  font-size: 49px;
  font-weight: 700;
  line-height: 60px;
  white-space: pre-wrap;
  text-shadow: 0 0 10px #ff9a0a99, 0 0 2px #ffd27a;
}

/* The cursor is a full 5 × 7 cell of the same dots (pitch 0.1em, dot 0.075em). */
.lm-cur {
  display: inline-block;
  width: 0.475em;
  height: 0.675em;
  margin-left: 0.0625em;
  translate: 0 -0.5px;
  filter: drop-shadow(0 0 5px #ff9a0a99);
}

.lm-cur b {
  display: block;
  height: 100%;
  background: var(--amber);
  -webkit-mask:
    linear-gradient(90deg, #000 75%, transparent 0) 0 0 / 0.1em 100%,
    linear-gradient(#000 75%, transparent 0) 0 0 / 100% 0.1em;
  -webkit-mask-composite: source-in;
  mask:
    linear-gradient(90deg, #000 75%, transparent 0) 0 0 / 0.1em 100%,
    linear-gradient(#000 75%, transparent 0) 0 0 / 100% 0.1em;
  mask-composite: intersect;
}

.lm-meter {
  position: absolute;
  inset: auto 32px 30px;
  height: 262px;
  display: block;
}

/* Printed legend, as on a front panel. */
.lm-label {
  position: absolute;
  left: 0;
  top: 50px;
  color: var(--print);
  font-family: "JetBrains Mono Variable", monospace;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.16em;
  line-height: 16px;
  text-transform: uppercase;
}

.lm-value {
  position: absolute;
  right: -9.5px; /* the cell's side bearing: the last dot column lands on the bar's right edge */
  top: 0;
  font-size: 76px;
  font-weight: 700;
  line-height: 76px;
  text-shadow: 0 0 14px #ff9a0a99, 0 0 2px #ffd27a;
}

/* Forty 8 px segments on a 12 px pitch: 476 px across. The first 32 are amber, the last 8 red. */
.lm-bar {
  position: absolute;
  inset: 92px 0 auto;
  height: 134px;
}

.lm-track {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--off-amber) 0 384px, var(--off-red) 384px);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 8px, transparent 8px 12px);
  mask: repeating-linear-gradient(90deg, #000 0 8px, transparent 8px 12px);
}

.lm-fill {
  height: 100%;
  background:
    linear-gradient(#0000 0, #fff3 38%, #fff3 62%, #0000) left / 476px 100% no-repeat,
    linear-gradient(90deg, #ffb829 0 384px, #ff4a2e 384px) left / 476px 100% no-repeat;
}

/* A segment takes a moment to come up to full brightness. */
.lm-rise {
  position: absolute;
  top: 0;
  width: 8px;
  height: 100%;
  background: var(--off-amber);
  opacity: 0;
  animation: lm-rise 190ms cubic-bezier(0.3, 0, 0.6, 1);
}

.lm-rise[data-zone="red"] { background: var(--off-red); }

@keyframes lm-rise {
  from { opacity: 1; }
  to { opacity: 0; }
}

.lm-glow {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--meter-value);
  background: linear-gradient(90deg, var(--amber) 0 384px, var(--red) 384px) left / 476px 100% no-repeat;
  filter: blur(14px);
  opacity: 0.38;
  transition: width 190ms linear;
}

.lm-scale {
  position: absolute;
  inset: auto 0 0;
  height: 16px;
  color: var(--print);
  font-family: "JetBrains Mono Variable", monospace;
  font-size: 15px;
  font-weight: 500;
  line-height: 16px;
}

.lm-scale span { position: absolute; top: 0; translate: -50% 0; }
.lm-scale span[data-end="start"] { translate: 0 0; }
.lm-scale span[data-end="end"] { translate: -100% 0; }

/* The meter's LEDs, wider than sRGB on a wide-gamut display, with the lit
   segments and their glow allowed past SDR white where there is headroom.
   The sRGB rules above stay the fallback. */
@media (color-gamut: p3) {
  .lm {
    --amber: color(display-p3 1 0.62 0.06);
    --red: color(display-p3 1 0.16 0.06);
    --off-amber: color(display-p3 0.19 0.1 0.01);
    --off-red: color(display-p3 0.2 0.03 0.01);
  }
  .lm-fill {
    background:
      linear-gradient(#0000 0, #fff3 38%, #fff3 62%, #0000) left / 476px 100% no-repeat,
      linear-gradient(90deg, color(display-p3 1 0.64 0.08) 0 384px, color(display-p3 1 0.2 0.08) 384px) left / 476px 100% no-repeat;
  }
  .lm-text,
  .lm-value {
    text-shadow: 0 0 10px color(display-p3 1 0.52 0.01 / 0.6), 0 0 2px color(display-p3 1 0.83 0.46);
  }
}

@media (color-gamut: p3) and (dynamic-range: high) {
  .lm-text,
  .lm-value {
    text-shadow: 0 0 10px color(display-p3 1.1 0.55 0.01), 0 0 3px color(display-p3 1.15 0.9 0.55);
  }
  .lm-glow {
    opacity: 0.5;
  }
  .lm-fill {
    background:
      linear-gradient(#0000 0, #fff4 38%, #fff4 62%, #0000) left / 476px 100% no-repeat,
      linear-gradient(90deg, color(display-p3 1.1 0.66 0.06) 0 384px, color(display-p3 1.1 0.2 0.06) 384px) left / 476px 100% no-repeat;
  }
}
