/* The online metronome (/metronome/ and /ja/metronome), after the app's one screen:
   the beat dots, the circle, the tempo. Loaded after style.css. */

.tool-head { text-align: center; }
.tool-head h1 { margin-bottom: 4px; }
.tool-head .note { margin: 0; }

.metronome {
  /* The circle: about half the width of a phone, smaller on a short screen. */
  --d: clamp(150px, min(56vw, 38vh), 280px);
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 12px auto 8px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.metronome :focus { outline: none; }
.metronome :focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }

/* The dots: one per beat, the downbeat larger; the beat being heard lights up.
   The whole row is the control, as wide as the page. */
.mm-beats {
  width: 100%;
  height: 56px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border-radius: 12px;
  cursor: pointer;
  touch-action: pan-y;
}
.mm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text); opacity: 0.25; }
.mm-dot.mm-downbeat { width: 14px; height: 14px; }
.mm-dot.mm-lit { opacity: 1; }

/* Room for the circle to swell by a quarter. */
.mm-stage { width: calc(var(--d) * 1.28); height: calc(var(--d) * 1.28); display: grid; place-items: center; }

.mm-circle {
  position: relative;
  width: var(--d);
  height: var(--d);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.mm-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.15;
  will-change: transform, opacity;
}
.mm-play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  /* Optically centred: the triangle sits a little right of the middle. */
  transform: translate(calc(-50% + var(--d) * 0.02), -50%);
  transition: opacity 0.2s ease-out;
}
.is-playing .mm-play { opacity: 0; }

/* The tempo: − / +, and the number, which can be dragged. */
.mm-tempo { display: flex; align-items: center; gap: 4px; }
.mm-step {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.mm-step svg { width: 26px; height: 26px; }
.mm-step:disabled { opacity: 0.3; cursor: default; }
.mm-number { min-width: 170px; text-align: center; border-radius: 12px; cursor: ew-resize; touch-action: none; }
.mm-bpm-value {
  display: block;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 80px;
  font-weight: 200;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.mm-bpm-unit { display: block; font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--muted); }

/* A short screen, such as a small phone under the browser's bars: the whole
   metronome stays in view. */
@media (max-height: 700px) {
  main.tool { padding-top: 16px; }
  main.tool nav { margin-bottom: 16px; }
  .metronome { --d: clamp(140px, min(56vw, 34vh), 280px); margin-top: 4px; }
  .mm-beats { height: 48px; }
  .mm-stage { width: calc(var(--d) * 1.25); height: calc(var(--d) * 1.25); }
  .mm-bpm-value { font-size: 72px; }
}

/* A narrow phone: the tempo row fits between the gutters. */
@media (max-width: 360px) {
  .mm-step { width: 52px; }
  .mm-number { min-width: 136px; }
  .mm-bpm-value { font-size: 68px; }
}

/* The Space key is for a keyboard; on a touch screen the ▶ says enough. */
@media (hover: none) { .mm-key-hint { display: none; } }

/* Until the script has set it up, or without one, the controls cannot be used. */
.metronome:not(.is-ready) .mm-beats,
.metronome:not(.is-ready) .mm-circle,
.metronome:not(.is-ready) .mm-tempo { pointer-events: none; }
.mm-message { margin: 8px 0 0; text-align: center; }

/* Under the metronome: the iPhone app. */
.mm-app { text-align: center; margin-top: 16px; }
.mm-app p:first-child { max-width: 30rem; margin: 0 auto; }
.mm-app .badge { margin: 16px 0 6px; }
