/* VibeOhm Metronome — brand tokens from the VibeOhm Identity Book v2.0.
   Light = "Soft Neomorphic Web Canvas", dark = "Cyber Resilient Canvas". */

:root {
  color-scheme: light;
  --bg: #F3F4F9;           /* Soft Alabaster */
  --surface: #FFFFFF;      /* Pure White */
  --surface-2: #E8EBF4;
  --shadow: #D1D6E6;       /* Muted Shadow */
  --highlight: #FFFFFF;
  --ink: #0B0F19;          /* Deep Ink */
  --ink-2: #4A5168;
  --line: #B9BFD3;
  --accent: #7F00FF;       /* Electric Violet */
  --on-accent: #FFFFFF;
  --focus: #7F00FF;
  --dot-accent: #7F00FF;
  --dot-normal: #5E6684;
  --glow: rgb(127 0 255 / .45);
  --pulse-accent: rgb(127 0 255 / .16);
  --pulse-normal: rgb(127 0 255 / .07);
  --logo-side: #7F00FF;
  --logo-mid: #00F2FE;     /* Neon Cyan */
  --logo-glow: none;
  --raised: 10px 10px 24px var(--shadow), -10px -10px 24px var(--highlight);
  --raised-sm: 4px 4px 10px var(--shadow), -4px -4px 10px var(--highlight);
  --inset: inset 3px 3px 8px var(--shadow), inset -3px -3px 8px var(--highlight);
  --backdrop: rgb(11 15 25 / .45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0B0F19;         /* Deep Obsidian */
    --surface: #141A29;    /* Card Surface */
    --surface-2: #1C2438;  /* Glow Matrix */
    --shadow: #04060B;
    --highlight: #1C2438;
    --ink: #FFFFFF;
    --ink-2: #A9B1C7;
    --line: #3A4560;
    --accent: #00F2FE;
    --on-accent: #0B0F19;
    --focus: #00F2FE;
    --dot-accent: #00F2FE;
    --dot-normal: #8A93AD;
    --glow: rgb(0 242 254 / .55);
    --pulse-accent: rgb(127 0 255 / .30);
    --pulse-normal: rgb(0 242 254 / .09);
    --logo-side: #00F2FE;
    --logo-mid: #7F00FF;
    --logo-glow: drop-shadow(0 0 6px rgb(0 242 254 / .6));
    --raised: 0 0 0 1px #1C2438, 0 14px 36px rgb(0 0 0 / .55);
    --raised-sm: 0 0 0 1px #1C2438, 0 6px 16px rgb(0 0 0 / .45);
    --inset: inset 0 0 0 1px #1C2438, inset 0 4px 12px rgb(0 0 0 / .45);
    --backdrop: rgb(0 0 0 / .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0F19;
  --surface: #141A29;
  --surface-2: #1C2438;
  --shadow: #04060B;
  --highlight: #1C2438;
  --ink: #FFFFFF;
  --ink-2: #A9B1C7;
  --line: #3A4560;
  --accent: #00F2FE;
  --on-accent: #0B0F19;
  --focus: #00F2FE;
  --dot-accent: #00F2FE;
  --dot-normal: #8A93AD;
  --glow: rgb(0 242 254 / .55);
  --pulse-accent: rgb(127 0 255 / .30);
  --pulse-normal: rgb(0 242 254 / .09);
  --logo-side: #00F2FE;
  --logo-mid: #7F00FF;
  --logo-glow: drop-shadow(0 0 6px rgb(0 242 254 / .6));
  --raised: 0 0 0 1px #1C2438, 0 14px 36px rgb(0 0 0 / .55);
  --raised-sm: 0 0 0 1px #1C2438, 0 6px 16px rgb(0 0 0 / .45);
  --inset: inset 0 0 0 1px #1C2438, inset 0 4px 12px rgb(0 0 0 / .45);
  --backdrop: rgb(0 0 0 / .6);
}

@media (prefers-contrast: more) {
  :root { --ink-2: var(--ink); --dot-normal: var(--ink); --line: var(--ink); }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
/* iOS: follow the Dynamic Type text size from system settings. */
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  html { font: -apple-system-body; font-family: system-ui, -apple-system, sans-serif; }
}

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Main screen: one big gesture surface ---------- */

.stage {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    max(.75rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(.75rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}

.pulse {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 45%, var(--pulse-normal) 0, transparent 70%);
}
.pulse[data-kind="accent"] {
  background: radial-gradient(ellipse at 50% 45%, var(--pulse-accent) 0, transparent 70%);
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-size: 1.125rem; }
.logo { width: 2rem; height: 2rem; filter: var(--logo-glow); }
.logo path { fill: none; stroke-width: 4; stroke-linecap: round; }
.logo-side { stroke: var(--logo-side); }
.logo-mid { stroke: var(--logo-mid); }
.wordmark { letter-spacing: -.01em; }
.wordmark b { font-weight: 700; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 3rem; height: 3rem;
  min-width: 48px; min-height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--raised-sm);
}
.icon-btn svg {
  width: 1.5rem; height: 1.5rem;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}

.center {
  position: relative;
  display: grid;
  grid-template-areas: "readout" "beats" "play";
  align-content: center;
  justify-items: center;
  gap: clamp(.75rem, 3vh, 2rem);
  min-height: 0;
}

.readout-wrap, .beats-wrap { position: relative; border-radius: 1.5rem; }
.readout-wrap { grid-area: readout; padding: 0 1.5rem; }
.beats-wrap { grid-area: beats; padding: .25rem .75rem; }

/* Native sliders for screen readers and keyboards. They sit over the
   visual readout (so a screen reader's focus ring lands on it) but never
   take touches away from the gesture surface. */
.overlay-input {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.readout-wrap:has(.overlay-input:focus-visible),
.beats-wrap:has(.overlay-input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}
.bpm {
  font-size: clamp(4rem, min(30vw, 22vh), 12rem);
  font-weight: 700;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  margin: .25rem 0 .1em;
}
.bpm-meta {
  font-size: 1rem;
  color: var(--ink-2);
  letter-spacing: .04em;
}
.chev {
  width: 1.75rem; height: .875rem;
  fill: none; stroke: var(--ink-2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  opacity: .55;
}
.readout .chev:last-child { margin-top: .6rem; }
.chev-h { width: .875rem; height: 1.75rem; flex: none; }

.beats { display: flex; align-items: center; gap: .75rem; }
.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .6rem;
  max-width: min(78vw, 22rem);
  margin: 0;
  padding: .6rem .9rem;
  list-style: none;
  border-radius: 999px;
  box-shadow: var(--inset);
}
.dot {
  width: 1.1rem; height: 1.1rem;
  border-radius: 50%;
  border: 2px solid var(--dot-normal);
  transition: transform .08s ease-out, background-color .08s;
}
.dot.accent { background: var(--dot-accent); border-color: var(--dot-accent); }
.dot.mute { border-style: dashed; opacity: .55; }
.dot.on { transform: scale(1.35); background: var(--dot-normal); box-shadow: 0 0 10px var(--glow); }
.dot.accent.on { background: var(--dot-accent); box-shadow: 0 0 14px var(--glow); }
.dot.mute.on { background: transparent; box-shadow: none; }
.beats-label {
  margin: .5rem 0 0;
  text-align: center;
  font-size: 1rem;
  color: var(--ink-2);
}

.play {
  grid-area: play;
  --size: clamp(6rem, min(32vw, 19vh), 9.5rem);
  width: var(--size); height: var(--size);
  display: grid;
  place-items: center;
  align-content: center;
  gap: .2rem;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--raised);
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.play svg { width: 42%; height: auto; fill: currentColor; }
.play .icon-stop { display: none; }
.play-label { font-size: 1rem; font-weight: 600; color: var(--ink); }
.is-playing .play { background: var(--accent); color: var(--on-accent); box-shadow: 0 0 0 .5rem var(--surface), 0 0 34px var(--glow); }
.is-playing .play .icon-play { display: none; }
.is-playing .play .icon-stop { display: block; }
.is-playing .play-label { color: var(--on-accent); }

.hints {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .35rem 1rem;
  max-width: 36rem;
  width: 100%;
  margin: 0 auto;
  padding: 0;
  list-style: none;
  font-size: .875rem;
  color: var(--ink-2);
  text-align: center;
}
.hints b { color: var(--ink); font-weight: 600; }
.hint-keys { grid-column: 1 / -1; display: none; }
@media (hover: hover) and (pointer: fine) { .hint-keys { display: block; } }
.hints-off .hints { display: none; }

/* Short screens and very large text: drop the tips, keep the controls. */
@media (max-height: 36em) { .hints { display: none; } }
@media (orientation: landscape) and (max-height: 34em) {
  .center {
    grid-template-areas: "readout play" "beats play";
    grid-template-columns: auto auto;
    justify-content: center;
    column-gap: clamp(1.5rem, 8vw, 5rem);
  }
  .bpm { font-size: clamp(3.5rem, 26vh, 9rem); }
  .play { --size: clamp(5.5rem, 34vh, 9rem); }
}

/* ---------- Settings sheet ---------- */

.settings {
  width: min(100% - 2rem, 38rem);
  max-height: min(100% - 2rem, 54rem);
  padding: 0;
  border: 0;
  border-radius: 1.5rem;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / .35);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.settings::backdrop { background: var(--backdrop); }
@media (max-width: 40em) {
  .settings {
    width: 100%;
    max-width: 100%;
    max-height: 94dvh;
    margin: auto 0 0;
    border-radius: 1.5rem 1.5rem 0 0;
  }
}

.sheet { padding: 0 1.25rem max(1.25rem, env(safe-area-inset-bottom)); }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 -1.25rem;
  padding: 1rem 1.25rem .75rem;
  background: var(--bg);
}
.sheet-head h2 { margin: 0; font-size: 1.5rem; }

.group {
  margin: 0 0 1rem;
  padding: 1rem;
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--raised-sm);
}
.group h3 { margin: 0 0 .75rem; font-size: 1.125rem; }
.fieldset { margin: 1rem 0 0; padding: 0; border: 0; min-width: 0; }
.fieldset legend, .field-label { display: block; padding: 0; margin: 0 0 .4rem; font-weight: 600; }
.field-label { margin-top: 1rem; }
.group h3 + .field-label, .group h3 + .fieldset { margin-top: 0; }
.help { margin: .4rem 0 0; font-size: .875rem; color: var(--ink-2); }

.stepper { display: flex; align-items: stretch; gap: .5rem; }
.step-btn {
  flex: none;
  width: 3.25rem; min-height: 3.25rem;
  border: 0;
  border-radius: 1rem;
  background: var(--bg);
  box-shadow: var(--raised-sm);
  font-size: 1.75rem;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.stepper input {
  flex: 1;
  min-width: 0;
  min-height: 3.25rem;
  padding: .25rem .75rem;
  border: 2px solid var(--line);
  border-radius: 1rem;
  background: var(--bg);
  text-align: center;
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stepper input:focus-visible { outline-offset: 1px; }

.wide-btn, .primary-btn, .text-btn {
  min-height: 3rem;
  padding: .6rem 1.25rem;
  border-radius: 1rem;
  font-weight: 600;
  touch-action: manipulation;
}
.wide-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  width: 100%;
  margin-top: 1rem;
  min-height: 4rem;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--ink);
  font-size: 1.125rem;
  user-select: none;
  -webkit-user-select: none;
}
.wide-btn:active { background: var(--surface-2); }
.tap-readout { font-variant-numeric: tabular-nums; color: var(--accent); }
.primary-btn { border: 0; background: var(--accent); color: var(--on-accent); min-width: 8rem; }
.text-btn { border: 2px solid var(--line); background: transparent; }

.pattern { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.beat-btn {
  width: 3rem; height: 3rem;
  border-radius: 50%;
  border: 2px solid var(--dot-normal);
  background: transparent;
  font-weight: 700;
  touch-action: manipulation;
}
.beat-btn.accent { background: var(--dot-accent); border-color: var(--dot-accent); color: var(--on-accent); }
.beat-btn.mute { border-style: dashed; color: var(--ink-2); text-decoration: line-through; }

.choices { display: grid; gap: .5rem; }
.choices-row { grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.choice {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 3rem;
  padding: .5rem .9rem;
  border: 2px solid var(--line);
  border-radius: 1rem;
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice input { width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--accent); flex: none; }
.choice-text { flex: 1; }
.choice-glyph { color: var(--ink-2); letter-spacing: .1em; white-space: nowrap; font-size: .875rem; }

.check {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 3rem;
  margin-top: .25rem;
  cursor: pointer;
}
.check input { width: 1.5rem; height: 1.5rem; margin: 0; flex: none; accent-color: var(--accent); }
.check[hidden] { display: none; }

.range { width: 100%; height: 2.5rem; margin: 0; accent-color: var(--accent); }
.select {
  width: 100%;
  min-height: 3rem;
  padding: .5rem .75rem;
  border: 2px solid var(--line);
  border-radius: 1rem;
  background: var(--bg);
}

.help-list { margin: 0; display: grid; gap: .6rem; }
.help-list div { display: grid; gap: .1rem; }
.help-list dt { font-weight: 600; }
.help-list dd { margin: 0; color: var(--ink-2); }

.sheet-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .75rem;
  padding-top: .25rem;
}

/* ---------- Motion, Windows High Contrast ---------- */

@media (prefers-reduced-motion: reduce) {
  .dot, .play { transition: none; }
  .dot.on { transform: none; }
}

@media (forced-colors: active) {
  .pulse { display: none; }
  .icon-btn, .play, .step-btn, .group, .dots { border: 2px solid ButtonText; }
  .dot { border-color: CanvasText; }
  .dot.accent { background: CanvasText; }
  .dot.on { forced-color-adjust: none; background: Highlight; border-color: Highlight; }
  .is-playing .play { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .is-playing .play-label { color: HighlightText; }
  .logo path { stroke: CanvasText; }
}
