:root {
  color-scheme: light;
  --ink: #221b16;
  --ink-soft: #57483b;
  --paper: #f6f1e8;
  --paper-strong: #efe7da;
  --surface: rgba(255, 251, 244, 0.82);
  --surface-solid: #fffaf2;
  --border: rgba(62, 45, 30, 0.2);
  --border-strong: rgba(62, 45, 30, 0.36);
  --accent: #8c3b2f;
  --accent-strong: #6f1f16;
  --gold: #b27a37;
  --shadow-soft: 0 10px 30px rgba(34, 27, 22, 0.1);
  --shadow-strong: 0 18px 45px rgba(34, 27, 22, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  line-height: 1.55;
  background:
    radial-gradient(circle at 85% 8%, rgba(178, 122, 55, 0.16), transparent 35%),
    radial-gradient(circle at 12% 22%, rgba(140, 59, 47, 0.1), transparent 34%),
    repeating-linear-gradient(
      180deg,
      rgba(57, 43, 31, 0.035) 0,
      rgba(57, 43, 31, 0.035) 1px,
      transparent 1px,
      transparent 36px
    ),
    linear-gradient(180deg, #fcf7ef 0%, #f3eadb 100%);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.6rem 1.1rem 3.4rem;
  display: grid;
  gap: 1.35rem;
}

.hero {
  text-align: center;
  position: relative;
  padding: 1.4rem 0.7rem 0.1rem;
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  left: 50%;
  width: min(520px, 78vw);
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(62, 45, 30, 0.46), transparent);
}

.hero::before {
  top: 0.3rem;
}

.hero::after {
  bottom: -0.2rem;
}

.eyebrow {
  margin: 0;
  font-family: "Marck Script", "Brush Script MT", cursive;
  font-size: clamp(1.2rem, 2.6vw, 1.7rem);
  color: var(--accent);
}

.hero h1 {
  margin: 0.2rem 0 0.55rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(2.4rem, 5.2vw, 4rem);
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: #2d221b;
}

.metronome {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  border-radius: 1.05rem;
  padding: 1.2rem;
  display: grid;
  gap: 1rem;
}

.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;
}

.visual-stage {
  position: relative;
  min-height: 172px;
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.35rem;
}

.visual-element {
  grid-area: 1 / 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.pulse {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: linear-gradient(165deg, #b67a35, #8a5627);
  box-shadow: 0 0 0 rgba(140, 59, 47, 0.35);
  transform: scale(0.96);
  transition: transform 100ms ease-out, box-shadow 120ms ease-out, background 120ms ease-out, opacity 180ms ease;
}

.number-display {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(4.2rem, 11vw, 6.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  transform: scale(0.87);
  text-shadow: 0 6px 18px rgba(80, 48, 25, 0.18);
  transition: transform 120ms ease, color 120ms ease, opacity 180ms ease;
}

.pendulum {
  --pendulum-carriage-offset: 0px;
  width: min(240px, 68vw);
  aspect-ratio: 4 / 5;
  height: auto;
  position: relative;
}

.metronome[data-visual-mode="pendulum"] .visual-stage {
  min-height: 348px;
  padding-top: 0;
}

.pendulum-device {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.device-shadow {
  fill: rgba(61, 31, 15, 0.16);
}

.device-case {
  filter: drop-shadow(0 8px 14px rgba(61, 31, 15, 0.2));
}

.scale-ticks line {
  stroke: rgba(246, 241, 232, 0.24);
  stroke-width: 1.5;
  stroke-linecap: round;
}

/* Rotation is set directly on the SVG transform attribute from script.js
   (rotate(angle, 120, 246), matching the pivot near the base) rather than
   through this CSS custom property. transform-box/transform-origin on SVG
   elements is inconsistently implemented across browsers — notably mobile
   Safari — and produced an erratic, off-axis swing; a native SVG rotate()
   is universally reliable and needs no transform-box at all. */

.pendulum-rod,
.pendulum-pivot {
  fill: #f6f1e8;
}

.pendulum-carriage {
  transform: translateY(var(--pendulum-carriage-offset));
  transition: transform 220ms ease;
}

.pendulum-weight {
  fill: var(--gold);
  transition: fill 110ms ease;
}

.pendulum-weight-highlight {
  fill: rgba(255, 248, 235, 0.45);
}

.pendulum.tick .pendulum-weight {
  fill: #e2a24f;
}

.metronome[data-visual-mode="pulse"] .pulse,
.metronome[data-visual-mode="numbers"] .number-display,
.metronome[data-visual-mode="pendulum"] .pendulum {
  opacity: 1;
}

.pulse.active {
  transform: scale(1.08);
  box-shadow: 0 0 30px rgba(140, 59, 47, 0.42);
}

.pulse.accent {
  background: linear-gradient(160deg, #a13828, #7d2215);
}

.pendulum.accent .pendulum-weight {
  fill: var(--accent);
}

.number-display.accent {
  color: var(--accent-strong);
}

.number-display.active {
  transform: scale(1);
}

.beat-label {
  grid-area: 2 / 1;
  margin: 0;
  color: var(--ink-soft);
  font-weight: 600;
  text-align: center;
}

.beat-label.is-hidden {
  display: none;
}

.toggle-btn {
  width: min(228px, 100%);
  justify-self: center;
  border: 1px solid rgba(123, 71, 32, 0.65);
  border-radius: 999px;
  padding: 0.85rem 1rem;
  background: linear-gradient(145deg, #b57a38, #885123);
  color: #fffdf8;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 700;
  font-size: 1.22rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 7px 18px rgba(82, 47, 20, 0.25);
}

.toggle-btn:hover {
  filter: brightness(1.04);
}

.beat-indicators {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.beat-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(60, 44, 31, 0.28);
  transition: transform 100ms ease, background 100ms ease;
}

.beat-dot.active {
  transform: scale(1.2);
  background: #92522a;
}

.beat-dot.accent {
  background: #9b3224;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.control-block {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.9rem;
  display: grid;
  gap: 0.7rem;
  align-content: start;
}

label,
legend {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

input,
select,
button {
  font: inherit;
}

input[type="number"],
select {
  width: 100%;
  border-radius: 0.65rem;
  border: 1px solid var(--border-strong);
  background: #fffcf8;
  color: var(--ink);
  padding: 0.58rem 0.65rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* ---- tempo hero: the primary, unboxed control beneath the visual ---- */
.tempo-hero {
  display: grid;
  grid-template-columns: auto auto auto;
  justify-content: center;
  align-items: center;
  gap: 0.9rem;
}

.bpm-readout {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.bpm-readout input {
  width: 4.6ch;
  border: none;
  background: none;
  padding: 0;
  text-align: right;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(3rem, 9vw, 4.2rem);
  font-weight: 700;
  color: var(--accent-strong);
}

.bpm-unit {
  color: var(--ink-soft);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bpm-slider {
  width: min(360px, 88%);
  margin: 0 auto;
}

.transport-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
}

.tap-status {
  text-align: center;
  min-height: 1.1em;
}

.small-btn {
  border: 1px solid var(--border-strong);
  background: #fff9f1;
  color: var(--ink);
  border-radius: 0.65rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.small-btn:hover {
  background: #fff3e3;
}

.tap-btn {
  font-weight: 700;
}

/* ---- pill toggles: shared component for visual mode, subdivision,
   count display, and the audio/haptics switches ---- */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  position: relative;
  display: block;
  cursor: pointer;
}

.pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.pill span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border-strong);
  background: #fffdf9;
  color: #2f2218;
  font-size: 0.85rem;
  font-weight: 600;
  transition: transform 100ms ease, border-color 100ms ease, background 100ms ease, color 100ms ease;
}

.pill input:checked + span {
  background: linear-gradient(140deg, #b67a35, #8d5524);
  border-color: rgba(115, 68, 29, 0.7);
  color: #fffdf7;
  transform: translateY(-1px);
}

.pill input:focus-visible + span,
.toggle-btn:focus-visible,
.small-btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(163, 86, 34, 0.9);
  outline-offset: 2px;
}

.pill-sm span {
  min-height: 32px;
  min-width: 32px;
  padding: 0 0.55rem;
  font-size: 0.78rem;
}

.display-toggle {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
}

.sound-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: center;
}

.sound-row input[type="range"] {
  width: auto;
}

.hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.footer {
  text-align: center;
  color: var(--ink-soft);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.22rem;
}

.footer-links,
.footer-contact {
  margin: 0.3rem 0 0;
  font-family: Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 0.85rem;
}

.footer-links a,
.footer-contact a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.05rem;
  transition: color 120ms ease, border-color 120ms ease;
}

.footer-links a:hover,
.footer-contact a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 820px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .page {
    padding-top: 2rem;
  }

  .metronome,
  .content-section {
    padding: 1rem;
  }

  .metronome[data-visual-mode="pendulum"] .visual-stage {
    min-height: 306px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
