:root {
  --bg: #0b0d17;
  --panel: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef0ff;
  --muted: #8b90b0;
  --accent: #ff4f8b;
  --accent2: #5ee7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, #1a1d3a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.7em 1.4em;
  transition: transform 0.08s, background 0.2s, border-color 0.2s;
}
button:hover { border-color: rgba(255, 255, 255, 0.25); }
button:active { transform: scale(0.96); }
button.primary {
  background: linear-gradient(135deg, var(--accent), #ff7a59);
  border: none;
  font-weight: 600;
  min-width: 8em;
}
button.small { padding: 0.35em 0.9em; font-size: 0.85rem; }
button.big { font-size: 1.2rem; padding: 1em 2em; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem max(1rem, env(safe-area-inset-left));
}
.brand { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.9rem; color: var(--muted); }

.session-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.session-bar[hidden], #new-session[hidden] { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f5a524; }
.dot.ok { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }
.muted { color: var(--muted); }

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1rem 2rem;
}

.viz-wrap {
  width: min(78vw, 52vh, 460px);
  aspect-ratio: 1;
}
#viz { width: 100%; height: 100%; display: block; }

.controls {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  margin-top: 1rem;
}

.tempo { display: flex; align-items: center; gap: 1.5rem; }
.round { width: 3rem; height: 3rem; padding: 0; font-size: 1.5rem; line-height: 1; }
.bpm { display: flex; flex-direction: column; align-items: center; min-width: 5.5rem; }
.bpm span { font-size: 3.2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.bpm small { color: var(--muted); letter-spacing: 0.2em; font-size: 0.75rem; margin-top: 0.25rem; }

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; border: none;
  background: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); cursor: pointer;
}

.buttons { display: flex; gap: 0.75rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0; }
@media (hover: none) { .hint { display: none; } }

dialog {
  background: #151830;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.5rem;
  width: min(92vw, 380px);
  text-align: center;
}
dialog::backdrop { background: rgba(5, 6, 15, 0.75); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 1rem; }
.qr { background: #fff; border-radius: 12px; padding: 0.75rem; }
.qr svg { width: 100%; height: auto; display: block; }
.join-link { display: block; margin: 0.9rem 0 0.4rem; color: var(--accent2); word-break: break-all; font-size: 0.9rem; }
.dialog-buttons { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1rem; }

.overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(5, 6, 15, 0.8);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.overlay[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: #151830; border: 1px solid var(--border);
  padding: 0.6rem 1.1rem; border-radius: 999px; font-size: 0.9rem;
  z-index: 20;
}
.toast[hidden] { display: none; }
#viz { cursor: pointer; }
