:root {
  --bg:#05070b;
  --panel:#151617;
  --fg:#e8edf5;
  --accent-sub:#3b82f6;
  --accent-beat:#60a5fa;
  --accent-measure:#93c5fd;
  --subtle:#27292d;
  --radius-panel:1.6rem;
  --radius-ui:.9rem;
  overscroll-behavior: none;
}

* {
  box-sizing: border-box;
}

html {
 background-color: #05070b;
}

body {
  margin:0;
  min-height:100dvh;
  display:flex;
  align-items:center;
  justify-content:center;
  font-family:system-ui,sans-serif;
  background-color: #05070b;
  background:
    radial-gradient(circle at top, #1b2938 0, #05070b 55%),
    radial-gradient(circle at bottom, #05070b 0, #000 60%);
  color:var(--fg);
  overscroll-behavior-y: none;
}

/* === Panel === */
/* === Panel === */
.panel {
  position: relative;
  padding: 2.2rem 2.8rem 2rem;   /* increased horizontal padding */
  border-radius: var(--radius-panel);
  padding-bottom: env(safe-area-inset-bottom);
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.03) 0,
      rgba(255,255,255,0.03) 1px,
      transparent 1px,
      transparent 3px
    ),
    linear-gradient(135deg, #181a1f, #101115);
  box-shadow:
    0 28px 60px rgba(0,0,0,0.9),
    0 0 0 1px rgba(255,255,255,0.03);
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to bottom, rgba(255,255,255,0.14), transparent 30%);
  mix-blend-mode: screen;
  opacity: 0.18;
  pointer-events: none;
}

/* === Inner layout === */
.inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.3rem;
  min-width: 260px;
  max-width: 320px;             /* allow slightly more room inside */
}

h1 {
  margin:0 0 0.4rem;
  font-size:.9rem;
  letter-spacing:0.35em;
  text-transform:uppercase;
  color:rgba(232,237,245,0.65);
}

/* === BPM Display === */
.display {
  width:100%;
  max-width:260px;
  padding:1rem 1.2rem 1.2rem;
  border-radius:1rem;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.14), transparent 60%),
    #05060a;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.04),
    inset 0 -4px 12px rgba(0,0,0,0.9);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:.25rem;
  position: relative;
}

#tempoLabel {
  font-family:'Orbitron', system-ui, sans-serif;
  font-size:0.55rem;
  font-weight:500;
  letter-spacing:0.22em;
  text-transform:uppercase;
  user-select:none;
  margin-bottom:0.1rem;
  transition: color 0.4s ease, opacity 0.25s ease;
  opacity:0.8;
}
#tempoLabel.slow       { color:#7fb9ff; }
#tempoLabel.moderate   { color:#e0f0ff; }
#tempoLabel.fast       { color:#ffcf88; }
#tempoLabel.veryfast   { color:#ff8c70; }
#tempoLabel.updating   { opacity:0.55; }

#bpm {
  font-family:'Orbitron', system-ui, sans-serif;
  font-size:2.8rem;
  font-weight:700;
  border:none;
  outline:none;
  background:none;
  width:4ch;
  text-align:center;
  letter-spacing:0.18em;
  color:#7fd2ff;
  text-shadow:
    0 0 8px rgba(111,201,255,0.8),
    0 0 18px rgba(71,144,255,0.8);
  caret-color:var(--accent-measure);
  padding: 0;
}
#bpm::-webkit-inner-spin-button,
#bpm::-webkit-outer-spin-button { -webkit-appearance:none; margin:0; }

#bpmLabel {
  font-family:'Orbitron', system-ui, sans-serif;
  font-size:0.8rem;
  letter-spacing:.25em;
  text-transform:uppercase;
  color:rgba(232,237,245,0.9);
  margin-top:0.15rem;
}

/* === Slider === */
.slider-row {
  display:flex;
  align-items:center;
  justify-content:center;
  gap:.8rem;
  width:100%;
  max-width:260px;
}
.bpm-btn {
  font-size:1.4rem;
  width:2.4rem;
  height:2.4rem;
  border:none;
  border-radius:50%;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.25), transparent 55%),
    linear-gradient(145deg, #14161b, #05070a);
  color:var(--fg);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.8),
    0 0 0 1px rgba(255,255,255,0.06);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}
.bpm-btn:active {
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,0.85),
    0 0 0 1px rgba(255,255,255,0.08);
  transform:translateY(1px);
}
/* Prevent double-tap zoom on controls */
#bpmMinus,
#bpmPlus,
#tap,
button  {
  touch-action: manipulation;
}

input[type="range"] {
  flex:1;
  appearance:none;
  height:.4rem;
  border-radius:999px;
  background:linear-gradient(to right, #11151c, #05060a);
  box-shadow:inset 0 1px 3px rgba(0,0,0,0.9), 0 0 0 1px rgba(255,255,255,0.06);
}
input[type="range"]::-webkit-slider-thumb {
  appearance:none;
  width:1.2rem;
  height:1.2rem;
  border-radius:50%;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.32), transparent 60%),
    linear-gradient(145deg, #2a3340, #10141b);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.9),
    0 0 0 1px rgba(102,178,255,0.7),
    0 0 10px rgba(80,150,255,0.9);
  cursor:pointer;
}

/* === Controls (3-row layout) === */
#controls {
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.4rem;
}
#controls .row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
}

/* --- Start/Stop --- */
#startStop {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 3rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border: none;
  border-radius: 1rem;
  color: #fff;
  cursor: pointer;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.25), transparent 55%),
    linear-gradient(145deg, #16a085, #0e6655);
  box-shadow:
    0 3px 10px rgba(0,0,0,0.9),
    inset 0 0 0 1px rgba(200,255,240,0.3);
  transition: background .3s ease, box-shadow .3s ease, transform .1s ease;
}
#startStop.running {
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.25), transparent 55%),
    linear-gradient(145deg, #c0392b, #922b21);
  box-shadow:
    0 3px 10px rgba(0,0,0,0.9),
    inset 0 0 0 1px rgba(255,210,210,0.3);
}
#startStop:hover { transform: translateY(-1px); }
#startStop:active { transform: translateY(1px); }

/* --- Tap Tempo --- */
#tap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 3rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border: none;
  border-radius: 1rem;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.15), transparent 55%),
    linear-gradient(145deg, #2e3035, #0c0d10);
  box-shadow:
    0 3px 10px rgba(0,0,0,0.9),
    inset 0 0 0 1px rgba(255,255,255,0.08);
  transition: background .3s ease, transform .1s ease, box-shadow .3s ease;
}
#tap:hover {
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.25), transparent 55%),
    linear-gradient(145deg, #3b3d43, #111217);
  transform: translateY(-1px);
}
#tap:active {
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.9);
}

/* --- Dropdowns --- */
#controls select {
  flex: 1;
  font-size: 0.95rem;
  padding: 0.55rem 1.15rem;
  border: none;
  border-radius: var(--radius-ui);
  background:
    radial-gradient(circle at 30% 15%, rgba(255,255,255,0.2), transparent 55%),
    linear-gradient(145deg, #1b2027, #070a0e);
  color: var(--fg);
  box-shadow:
    0 3px 10px rgba(0,0,0,0.9),
    0 0 0 1px rgba(255,255,255,0.07);
  transition: transform .1s, box-shadow .2s;
}
#controls select:active {
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.85),
             0 0 0 1px rgba(255,255,255,0.09);
  transform: translateY(1px);
}

/* === Beat visualization === */
#visual {
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-items:center;
  gap:0.4rem;
  margin-top:0.7rem;
  width:100%;
}

.beat-group {
  display:flex;
  align-items:center;
  gap:0.4rem;
  transition:transform 0.1s;
}
.beat-group.active { transform:scale(1.05); }

.dot {
  border-radius:50%;
  background:var(--subtle);
  box-shadow:inset 0 0 3px rgba(0,0,0,0.8);
  transition:background 0.12s, transform 0.12s, box-shadow 0.12s;
  display:block;
}
.dot.sub { width:9px; height:9px; }
.dot.beat { width:17px; height:17px; }
.dot.measure { width:19px; height:19px; }

.active.sub {
  background:#3b82f6;
  box-shadow:0 0 4px rgba(59,130,246,0.8),0 0 10px rgba(59,130,246,0.6);
  transform:scale(1.2);
}
.active.beat {
  background:#60a5fa;
  box-shadow:0 0 6px rgba(96,165,250,0.9),0 0 16px rgba(96,165,250,0.7);
  transform:scale(1.35);
}
.active.measure {
  background:#93c5fd;
  box-shadow:0 0 8px rgba(147,197,253,1),0 0 20px rgba(147,197,253,0.9);
  transform:scale(1.5);
}

/* === Accessibility: Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  /* Hide all beat dots entirely for motion-sensitive users */
  #visual {
    display: none !important;
  }
}


/* === Footer / Maker mark === */
footer {
  margin-top: 1.6rem;
  margin-bottom: 1.6rem;
  font-size: 0.7rem;
  text-align: center;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.28);
  text-transform: uppercase;
  user-select: none;
  pointer-events: auto;
  text-shadow:
    0 1px 0 rgba(0,0,0,0.85),
    0 -1px 0 rgba(255,255,255,0.04);
  mix-blend-mode: soft-light;
}

footer a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,0.15);
  transition: color 0.2s ease, border-color 0.2s ease;
}

footer a:hover {
  color: rgba(255,255,255,0.45);
  border-color: rgba(255,255,255,0.45);
}

/* Visually hidden but readable by assistive tech */
.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;
}

/* === Small-screen optimization === */
@media (max-width: 480px) {
  body {
    margin: 0;
    padding: 0;
  }

  .panel {
    margin: 0 !important;
    border-radius: 0 !important;
    width: 100vw;
    min-height: 100dvh;
    box-shadow: none;
  }

  .inner {
    border-radius: 0;
    width: 100%;
  }
}

.display-actions {
  position: absolute;
  top: 0.55rem;
  left: 0.7rem;
  right: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 3;
}

.display-action {
  background: none;
  border: none;
  padding: 0;
  color: #7fd2ff;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.1s ease;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.display-action:hover,
.display-action:focus-visible {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(96,165,250,0.12);
  box-shadow: inset 0 0 0 1px rgba(147,197,253,0.25);
}
.display-action.active {
  color: #b5d8ff;
  text-shadow: 0 0 8px rgba(111,201,255,0.8);
  background: rgba(96,165,250,0.16);
  box-shadow: inset 0 0 0 1px rgba(147,197,253,0.3);
}
.display-action svg {
  stroke-width: 1.6;
  filter: drop-shadow(0 0 3px rgba(147,197,253,0.4));
  vertical-align: middle;
}

#volumeBtn .wave {
  opacity: 0;
  transition: opacity 0.2s ease;
}
#volumeBtn.volume-level-1 .wave-1,
#volumeBtn.volume-level-2 .wave-1,
#volumeBtn.volume-level-3 .wave-1 {
  opacity: 1;
}
#volumeBtn.volume-level-2 .wave-2,
#volumeBtn.volume-level-3 .wave-2 {
  opacity: 1;
}
#volumeBtn.volume-level-3 .wave-3 {
  opacity: 1;
}

.volume-panel {
  position: absolute;
  top: 2.7rem;
  right: 0.8rem;
  width: 150px;
  padding: 0.5rem 0.75rem 0.65rem;
  border-radius: 0.9rem;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.08), transparent 65%),
    rgba(5, 6, 10, 0.98);
  box-shadow:
    0 18px 30px rgba(0, 0, 0, 0.85),
    0 0 0 1px rgba(147,197,253,0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.volume-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.volume-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(232,237,245,0.8);
}
.volume-header label {
  cursor: pointer;
}

#volumeSlider {
  margin-top: 0.4rem;
  width: 100%;
  accent-color: var(--accent-beat);
}

dialog {
  background: #121417;
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.8rem;
  padding: 1.5rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  max-width: 600px;
  line-height: 1.5;
  animation: fadeInDialog 0.4s ease both;
}
dialog::backdrop {
  background: rgba(0,0,0,0.6);
}
dialog h2 {
  margin-top: 0;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

dialog h3 {
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
  margin-top: 1rem;
}

dialog button {
  margin-top: 1.2rem;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: var(--radius-ui);
  background: linear-gradient(145deg, #1b2027, #0a0b0d);
  color: var(--fg);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.8);
}
dialog button:hover {
  background: linear-gradient(145deg, #2b313a, #0f1014);
}

@keyframes fadeInDialog {
  from { opacity: 0; transform: translateY(-50px); }
  to { opacity: 1; transform: translateY(0); }
}
