/* /metronome — the app's metronome as a browser utility.
 *
 * The palette is the app's Turf Night theme (Striped/Sources/Theme.swift),
 * not the marketing site's near-black, because this page IS the app's
 * control: field #0B140F -> #060A07, surface #122019, border #2B4134, ink
 * #EFFFF8, dim ink #A5B9AC, mint #17C97F (and #4CFFB0 only for focus).
 * Shapes follow the app's Practice tile: chevron pills 48 x 64 with radius 24
 * (ClubSelectorView.stepButton), a 48 pt rounded label (quickClubLabel), a
 * circular metronome button that fills when on (MetronomeButton; the app's
 * on colour is system blue, here it is the brand mint, per the site rule).
 */

:root {
  --bg: #0b140f;
  --bg-deep: #060a07;
  --surface: #122019;
  --raise: #1d3027;
  --border: #2b4134;
  --mint: #17c97f;
  --mint-hi: #4cffb0;
  --ink: #effff8;
  --ink-dim: #a5b9ac;
  --mute: #4d6657;
  --on-accent: #06180f;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;

  --go: 128px;
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--bg-deep);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--ink);
  font: 400 17px/1.4 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
button, select { font: inherit; color: inherit; }
button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  cursor: pointer;
}
:focus-visible { outline: 2px solid var(--mint-hi); outline-offset: 3px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------- layout */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  width: min(100%, 480px);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top, 0px)
    max(16px, env(safe-area-inset-right, 0px))
    max(20px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
  padding: 12px 0 28px;
}
.controls {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding-bottom: 12px;
}

/* First start on a phone: a quiet line above the practice selector, out of
   the layout flow, so nothing moves while it shows. It fades; it never
   slides (and under Reduce Motion it simply appears and goes). */
.lock-note {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(100% + 12px);
  margin: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--ink);
  font-size: 15px; font-weight: 500; letter-spacing: -0.01em;
  text-align: center;
  opacity: 0;
  transition: opacity 0.45s var(--ease);
  cursor: default;
}
.lock-note svg { flex: none; width: 16px; height: 16px; color: var(--mint); }
.lock-note.show { opacity: 1; }

/* ---------------------------------------------------------------- bar */

.bar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font-size: 1.1875rem; font-weight: 600; letter-spacing: -0.03em;
  border-radius: 8px;
}
.brand img { width: 28px; height: 28px; border-radius: 7px; }

.sound {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 2px 0 12px;
  color: var(--ink-dim);
  font-size: 15px; font-weight: 500;
  border-radius: 12px;
}
.sound svg { flex: none; }
.i-speaker { width: 20px; height: 20px; }
.i-updown { width: 12px; height: 12px; }
.sound-name { white-space: nowrap; }
.sound select, .pace-label select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; margin: 0; border: 0;
  font-size: 16px; /* 16 px: iOS does not zoom a focused control this size */
  -webkit-appearance: none; appearance: none;
  cursor: pointer;
}
.sound:hover { color: var(--ink); }
.sound:has(select:focus-visible) { outline: 2px solid var(--mint-hi); outline-offset: 2px; }

/* ---------------------------------------------------------------- pace */

.pace {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 12px;
}
.step {
  width: 48px; height: 64px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: var(--ink);
  transition: background-color 0.18s, opacity 0.18s;
}
.step svg { width: 22px; height: 22px; }
.step:disabled { opacity: 0.35; cursor: default; }
.step[hidden] { display: none; }
@media (hover: hover) { .step:not(:disabled):hover { background: var(--raise); } }
.step:not(:disabled):active { background: var(--raise); }

.pace-label {
  position: relative;
  grid-column: 2;
  min-height: 142px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px;
  text-align: center;
  border-radius: 28px;
}
.pace-name {
  font: 500 clamp(40px, 12.3vw, 48px)/1 var(--font-round);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.pace-ratio {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-dim);
  font-size: 15px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.i-down { width: 12px; height: 12px; }
.pace-label:not(.choosable) { grid-column: 1 / -1; }
.pace-label:not(.choosable) .i-down { display: none; }
.pace-label:not(.choosable) select { display: none; }
.pace-label:has(select:focus-visible) { outline: 2px solid var(--mint-hi); outline-offset: -2px; }

/* ---------------------------------------------------------------- beats */

/* The swing on a time axis: takeaway, top and impact marks, spaced by the
   pace's real backswing and downswing. The axis is fixed (Silky's 1.2 s fills
   it), so slower paces draw longer; the pattern is centred. */
.beats { padding: 0 12px; }
.pattern {
  --top: 75%;
  --w: 88.9%;
  position: relative;
  height: 52px;
  width: var(--w);
  margin-inline: auto;
}
.seg-line, .fill {
  position: absolute; top: 11px; height: 2px; border-radius: 1px;
}
.seg-line { background: var(--border); }
.seg-line.back { left: 0; width: var(--top); }
.seg-line.down { left: var(--top); right: 0; }
.fill {
  left: 0; right: 0;
  background: var(--mint);
  transform-origin: 0 50%;
  transform: scaleX(0);
  opacity: 0;
}
.mark {
  position: absolute; top: 6px;
  width: 12px; height: 12px; margin-left: -6px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: background-color 0.35s;
}
.m0 { left: 0; }
.m1 { left: var(--top); }
.m2 { left: 100%; }
.mark.lit { background: var(--mint); transition: none; }
.app.running .mark:not(.lit) { background: var(--mute); }
.dur {
  position: absolute; top: 28px;
  transform: translateX(-50%);
  color: var(--ink-dim);
  font-size: 13px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dur .u { margin-left: 1px; color: var(--mute); }
.dur.back { left: calc(var(--top) / 2); }
.dur.down { left: calc((var(--top) + 100%) / 2); }

/* -------------------------------------------------------------- practice */

.practice {
  position: relative;
  width: 100%;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  --i: 0;
}
.practice .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / 3);
  border-radius: 12px;
  background: var(--raise);
  transform: translateX(calc(var(--i) * 100%));
  transition: transform 0.22s var(--ease);
}
.practice button {
  position: relative;
  min-height: 44px;
  padding: 0 4px;
  border: 0; border-radius: 12px;
  background: none;
  color: var(--ink-dim);
  font-size: 15px; font-weight: 600; letter-spacing: -0.015em;
  white-space: nowrap;
  transition: color 0.18s;
}
.practice button[aria-checked="true"] { color: var(--ink); }
@media (hover: hover) { .practice button:hover { color: var(--ink); } }
.practice button:focus-visible { outline-offset: -2px; }

/* ------------------------------------------------------------------ go */

.go {
  position: relative;
  width: var(--go); height: var(--go);
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
  transition: background-color 0.18s, border-color 0.18s, color 0.18s, transform 0.18s var(--ease);
}
/* The app draws its 26 x 24 pt symbol aspect-fit into 24 of the button's
   60 pt (MetronomeButton.layoutSubviews), so the glyph is 0.4 of the
   circle's width here too, and its 2 pt stroke scales with it. */
.go .glyph { position: relative; width: calc(var(--go) * 0.4); height: auto; aspect-ratio: 26 / 24; overflow: visible; }
.go .glyph.on { display: none; }
.go[aria-pressed="true"] {
  background: var(--mint);
  border-color: var(--mint);
  color: var(--on-accent);
}
.go[aria-pressed="true"] .glyph.off { display: none; }
.go[aria-pressed="true"] .glyph.on { display: block; }
.go:active { transform: scale(0.97); }
@media (hover: hover) { .go[aria-pressed="false"]:hover { background: var(--raise); } }
.go:disabled { opacity: 0.4; cursor: default; }
/* The app's beat pulse: a white wash inside the circle (MetronomeBeatOverlay). */
.go .pulse {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.nojs, .note { color: var(--ink-dim); font-size: 15px; text-align: center; margin: 0 0 16px; }

/* ---------------------------------------------------------- breakpoints */

/* Short phones (an SE in Safari has ~550 px to work with). */
@media (max-height: 640px) {
  :root { --go: 108px; }
  .bar { height: 52px; }
  .stage { gap: 16px; padding: 4px 0 16px; }
  .pace-label { min-height: 112px; }
  .controls { gap: 20px; }
  .lock-note { bottom: calc(100% + 8px); font-size: 14px; }
}

/* Desktop and tablets: one centred column, a little larger, with the
   brand pinned to the corner instead of above the controls. */
@media (min-width: 720px) and (min-height: 600px) {
  :root { --go: 152px; }
  .app {
    width: min(100%, 520px);
    justify-content: center;
    gap: 40px;
    padding-top: 96px;
    padding-bottom: 72px;
  }
  .bar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 72px;
    padding: 0 clamp(24px, 4vw, 48px);
  }
  .stage { flex: none; gap: 36px; padding: 0; }
  .pace { grid-template-columns: 56px minmax(0, 1fr) 56px; gap: 16px; }
  .pace-name { font-size: 68px; }
  .pace-ratio { font-size: 17px; }
  .controls { gap: 36px; padding: 0; }
  .practice button { min-height: 48px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .go:active { transform: none; }
}

@media (forced-colors: active) {
  .go[aria-pressed="true"] { border: 3px solid Highlight; }
  .mark.lit { background: Highlight; }
}
