/* The Kundt's tube button: a glass tube with brass caps on a black page, lit from above, with a bed of fine golden
   powder along its bottom. The powder and the dust are drawn by script.js on the canvas (their colours come from
   here); the glass, its reflections, the caps and the words printed on the glass are CSS. */
:root {
  --page: #000000;          /* the page */
  --glass: #040605;         /* the inside of the tube, black with a hint of green glass */
  --rim: #b9d3c8;           /* the edges of the glass, where it is seen thickest */
  --powder: #c4862a;        /* the powder, in the light of the lamp */
  --powder-lit: #f3cd76;    /* the powder where the lamp falls on it */
  --powder-deep: #4c2e0a;   /* the powder in the shade, at the bottom of the tube */
  --brass: #b88a3c;         /* the caps */
  --brass-lit: #f6e1a2;     /* the light on the caps */
  --brass-deep: #3b2607;    /* the shade under the caps */
  --print: #f2e9d5;         /* the words and the scale printed on the glass */
  --focus: #f3cd76;         /* the ring of the keyboard's focus */
  --cap: 30px;              /* how long the brass caps are */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--print);
  font-family: 'Saira Variable', 'Saira', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 72px 16px;
}

.kundt {
  display: grid;
  justify-items: center;
}

/* ---------------------------------------------------------------- the tube */
.kundt__btn {
  position: relative;
  display: block;
  width: min(340px, calc(100vw - 32px));
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  /* the glass seen edge on: a bright line along the top, a fainter one along the bottom, and its green edge */
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--rim) 55%, transparent),
    inset 0 -1px 0 color-mix(in srgb, var(--rim) 22%, transparent),
    inset 0 0 0 1px color-mix(in srgb, var(--rim) 14%, transparent),
    0 0 0 1px rgba(0, 0, 0, 0.9);
  color: var(--print);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  /* a finger drawn along the glass hums it; up and down still scrolls the page */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}

.kundt__btn:active {
  transform: scale(0.97);
}

.kundt__btn[aria-busy='true'] {
  cursor: progress;
}

.kundt__btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 5px;
}

html[data-using='pointer'] .kundt__btn:focus-visible {
  outline: none;
}

/* the warm light the lit powder throws on the back of the glass, just above it */
.kundt__haze {
  position: absolute;
  left: var(--cap);
  right: var(--cap);
  bottom: 2px;
  height: 30px;
  background:
    radial-gradient(60% 100% at 50% 100%, color-mix(in srgb, var(--powder) 16%, transparent), transparent 75%);
  pointer-events: none;
}

.kundt__canvas {
  position: absolute;
  top: 0;
  left: var(--cap);
  width: calc(100% - var(--cap) * 2);
  height: 100%;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the glass, over everything inside */
/* the glass is thicker to the eye at the top and the bottom, where it is seen edge on: a green shade there */
.kundt__glass {
  position: absolute;
  inset: 0 var(--cap);
  pointer-events: none;
  overflow: hidden;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--rim) 16%, transparent),
      color-mix(in srgb, var(--rim) 4%, transparent) 5px,
      transparent 11px,
      transparent 49px,
      color-mix(in srgb, var(--rim) 5%, transparent) 55px,
      color-mix(in srgb, var(--rim) 14%, transparent));
}

/* the lamp caught on the top of the tube, a sharp line with a soft band under it, and the room caught low on its
   curve; both fade out towards the caps */
.kundt__glass::before,
.kundt__glass::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent);
}

.kundt__glass::before {
  top: 0;
  height: 18px;
  background:
    linear-gradient(180deg, transparent 2.4px, rgba(255, 252, 240, 0.62) 3px, rgba(255, 252, 240, 0.62) 3.7px, transparent 4.5px),
    linear-gradient(180deg, transparent 3.5px, rgba(255, 250, 235, 0.12) 6px, rgba(255, 250, 235, 0.04) 11px, transparent 17px);
}

.kundt__glass::after {
  bottom: 0;
  height: 8px;
  background: linear-gradient(0deg, transparent 1.6px, rgba(255, 244, 220, 0.2) 2.2px, rgba(255, 244, 220, 0.2) 2.7px, transparent 3.6px);
}

/* the light that slides along the top of the glass to meet the pointer */
.kundt__glint {
  position: absolute;
  left: 0;
  top: 1px;
  width: 96px;
  height: 12px;
  margin-left: -48px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 252, 238, 0.62), rgba(255, 252, 238, 0.14) 55%, rgba(255, 252, 238, 0));
  opacity: 0;
}

/* a scale printed along the bottom of the glass, for measuring the heaps: a short tick every 5 pixels, a longer one
   every 25 */
.kundt__scale {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 3px;
  height: 3.5px;
  background:
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--print) 40%, transparent) 0 1px, transparent 1px 25px) 0 0 / 100% 3.5px no-repeat,
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--print) 24%, transparent) 0 1px, transparent 1px 5px) 0 100% / 100% 1.6px no-repeat;
  opacity: 0.75;
}

/* ---------------------------------------------------------------- the caps */
/* turned brass: lit on top like a cylinder, rounded off at the end, with three grooves cut near the glass and a dark
   seam where it holds it */
.kundt__cap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--cap);
  background:
    radial-gradient(9px 6px at var(--shine-x) 15px, rgba(255, 252, 235, 0.75), rgba(255, 252, 235, 0)),
    linear-gradient(var(--dome), rgba(30, 18, 2, 0.6), rgba(30, 18, 2, 0) 9px),
    linear-gradient(180deg,
      var(--brass-deep) 0%,
      color-mix(in srgb, var(--brass) 80%, var(--brass-lit)) 8%,
      var(--brass-lit) 19%,
      color-mix(in srgb, var(--brass) 70%, var(--brass-lit)) 34%,
      var(--brass) 52%,
      color-mix(in srgb, var(--brass) 55%, var(--brass-deep)) 74%,
      var(--brass-deep) 100%);
  pointer-events: none;
}

.kundt__cap::before,
.kundt__cap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
}

/* the grooves */
.kundt__cap::before {
  width: 11px;
  background: repeating-linear-gradient(90deg,
    rgba(40, 24, 4, 0.55) 0 1px,
    rgba(255, 240, 200, 0.28) 1px 1.6px,
    transparent 1.6px 3.6px);
}

/* the seam: a dark line where the brass grips the glass, and a lit bevel just before it */
.kundt__cap::after {
  width: 3px;
}

.kundt__cap--left {
  --dome: 90deg;
  --shine-x: 15px;
  left: 0;
  border-radius: 999px 0 0 999px;
}

.kundt__cap--left::before {
  right: 4px;
}

.kundt__cap--left::after {
  right: 0;
  background: linear-gradient(90deg, rgba(255, 238, 190, 0.45), rgba(20, 12, 2, 0.9) 70%);
}

.kundt__cap--right {
  --dome: 270deg;
  --shine-x: calc(100% - 15px);
  right: 0;
  border-radius: 0 999px 999px 0;
}

.kundt__cap--right::before {
  left: 4px;
}

.kundt__cap--right::after {
  left: 0;
  background: linear-gradient(270deg, rgba(255, 238, 190, 0.35), rgba(20, 12, 2, 0.9) 70%);
}

/* ---------------------------------------------------------------- the words, printed on the glass */
.kundt__print {
  position: absolute;
  inset: 0 var(--cap);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 14px;
  pointer-events: none;
}

.kundt__label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 20px;
  font-size: 15px;
  font-weight: 560;
  font-stretch: 112%;
  line-height: 1;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: var(--print);
}

.kundt__words {
  display: block;
}

/* the frequency of the sweep, in figures that keep their width */
.kundt__hz {
  display: none;
  text-align: left;
  font-weight: 460;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--print) 62%, transparent);
}

.kundt__hz[data-on] {
  display: block;
}

/* the tuning fork, and the tick that takes its place once the powder has settled */
.kundt__icons {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  flex: none;
}

.kundt__icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.kundt__icon--done {
  opacity: 0;
}

@media (max-width: 359px) {
  :root {
    --cap: 26px;
  }

  .kundt__label {
    font-size: 14px;
    font-stretch: 106%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kundt__btn,
  .kundt__btn:active {
    transform: none;
  }

  .kundt__btn:active {
    filter: brightness(0.9);
  }
}
