:root {
  --hue: 190;
  --acc: hsl(var(--hue), 95%, 62%);
  --acc2: hsl(calc(var(--hue) + 60), 95%, 66%);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #07060d; color: #fff;
  font: 15px/1.4 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: currentColor; }

#viz { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }

/* ---------- intro ---------- */
#intro {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; text-align: center;
  background: radial-gradient(ellipse at center, rgba(34, 211, 238, .12), transparent 60%), rgba(7, 6, 13, .55);
  transition: opacity .8s, visibility .8s;
}
body.started #intro { opacity: 0; visibility: hidden; }
#intro h1 {
  margin: 0; font-size: clamp(56px, 12vw, 120px); font-weight: 900; letter-spacing: -.04em; line-height: 1;
}
#intro h1 span, .logo span {
  background: linear-gradient(90deg, #22d3ee, #f472b6); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag { font-size: clamp(16px, 2.4vw, 21px); color: #c9c6dc; margin: 18px 0 40px; }
.small { color: #7d7894; font-size: 13px; margin-top: 26px; }
#startBtn {
  width: 132px; height: 132px; border-radius: 50%; border: 0;
  background: linear-gradient(135deg, #22d3ee, #f472b6);
  color: #07060d; display: inline-grid; place-items: center;
  box-shadow: 0 0 0 0 rgba(244, 114, 182, .6), 0 20px 60px rgba(34, 211, 238, .35);
  animation: pulse 1.6s ease-out infinite;
  transition: transform .15s;
}
#startBtn:hover { transform: scale(1.06); }
#startBtn:active { transform: scale(.96); }
#startBtn svg { width: 56px; height: 56px; margin-left: 8px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(244, 114, 182, .55), 0 20px 60px rgba(34, 211, 238, .35); }
  100% { box-shadow: 0 0 0 38px rgba(244, 114, 182, 0), 0 20px 60px rgba(34, 211, 238, .35); }
}

/* ---------- live UI ---------- */
.ui { position: fixed; z-index: 5; opacity: 0; transition: opacity 1s .4s; pointer-events: none; }
body.started .ui { opacity: 1; }
body.started .ui button, body.started #ribbon { pointer-events: auto; }

#top { top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; }
.logo { font-size: 22px; font-weight: 900; letter-spacing: -.03em; }
.top-right { display: flex; align-items: center; gap: 14px; }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 800; letter-spacing: .15em; color: #ff6b8a; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #ff3b5c; box-shadow: 0 0 10px #ff3b5c; animation: blink 1.2s infinite; }
body.paused .live i { animation: none; opacity: .3; }
@keyframes blink { 50% { opacity: .25; } }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14);
  display: grid; place-items: center; backdrop-filter: blur(8px);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .i-play, body.paused .icon-btn .i-pause { display: none; }
body.paused .icon-btn .i-play { display: block; }

#hint {
  left: 50%; top: 64px; transform: translateX(-50%);
  display: flex; gap: 22px; font-size: 14px; color: rgba(255, 255, 255, .7);
  white-space: nowrap; transition: opacity 1.2s;
}
#hint b { color: #fff; }
body.hint-gone #hint { opacity: 0 !important; }

#buildMeter {
  left: 50%; top: 22%; transform: translateX(-50%);
  width: min(320px, 70vw); text-align: center;
  opacity: 0 !important; transition: opacity .2s;
}
body.building #buildMeter { opacity: 1 !important; }
#buildMeter div { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; position: relative; }
#buildMeter div::after {
  content: ""; position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--b, 0));
  background: linear-gradient(90deg, var(--acc), #fff);
}
#buildMeter span { display: block; margin-top: 8px; font-size: 12px; font-weight: 800; letter-spacing: .3em; }

#bottom {
  left: 0; right: 0; bottom: 0; padding: 22px; padding-bottom: max(22px, env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap;
  background: linear-gradient(transparent, rgba(7, 6, 13, .7));
}
.now-label { font-size: 11px; letter-spacing: .25em; text-transform: uppercase; color: rgba(255, 255, 255, .5); font-weight: 700; }
.now-title { font-size: clamp(24px, 4vw, 40px); font-weight: 900; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0; }
.now-title.swap { animation: swap .9s; }
@keyframes swap { from { opacity: 0; transform: translateY(10px); filter: blur(6px); } }
.now-meta { color: var(--acc); font-weight: 700; font-size: 14px; }
.sections { display: flex; gap: 6px; margin-top: 12px; }
.sections span {
  font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 99px; color: rgba(255, 255, 255, .35);
  border: 1px solid rgba(255, 255, 255, .12); transition: all .3s;
}
.sections span.on { color: #07060d; background: var(--acc); border-color: var(--acc); box-shadow: 0 0 16px var(--acc); }

.controls { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.vibes {
  display: flex; gap: 4px; padding: 4px; border-radius: 99px;
  background: rgba(20, 18, 32, .75); border: 1px solid rgba(255, 255, 255, .12);
}
.vibes button { border: 0; background: none; padding: 8px 15px; border-radius: 99px; font-weight: 700; font-size: 14px; color: rgba(255, 255, 255, .7); transition: all .2s; }
.vibes button:hover { color: #fff; }
.vibes button.on { background: #fff; color: #07060d; }
.next-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: none; border: 0; color: rgba(255, 255, 255, .75); font-weight: 700; padding: 6px 4px;
}
.next-btn:hover { color: #fff; }
.next-btn svg { width: 18px; height: 18px; }

@media (max-width: 720px) {
  #bottom { flex-direction: column; align-items: stretch; }
  .controls { align-items: stretch; }
  .vibes { justify-content: space-between; }
  .vibes button { padding: 8px 10px; font-size: 13px; }
  .next-btn { align-self: flex-end; }
  #hint { flex-direction: column; gap: 4px; text-align: center; font-size: 13px; top: 60px; }
}

/* ---------- tap FX popups & combo ---------- */
#combo {
  right: 24px; top: 50%; transform: translateY(-50%) scale(.8);
  text-align: center; opacity: 0 !important; transition: opacity .3s, transform .3s;
}
body.started #combo.show { opacity: 1 !important; transform: translateY(-50%) scale(1); }
#combo b {
  display: block; font-size: clamp(48px, 8vw, 84px); font-weight: 900; line-height: 1;
  background: linear-gradient(180deg, #fff, var(--acc)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
#combo span { font-size: 12px; font-weight: 800; letter-spacing: .35em; color: rgba(255, 255, 255, .8); }
#combo i { display: block; height: 4px; margin-top: 8px; border-radius: 2px; background: rgba(255, 255, 255, .15); position: relative; overflow: hidden; }
#combo i::after { content: ""; position: absolute; inset: 0; background: var(--acc); transform-origin: left; transform: scaleX(var(--fill, 0)); transition: transform .2s; }
@media (max-width: 720px) { #combo { right: 14px; top: 30%; } }

/* ---------- arpeggiator ribbon ---------- */
#ribbon {
  position: relative; flex: 1 0 100%; order: -1; height: 64px; border-radius: 18px; overflow: hidden;
  cursor: ew-resize; touch-action: none;
  background: linear-gradient(90deg, hsla(var(--hue), 90%, 55%, .10), hsla(calc(var(--hue) + 60), 90%, 60%, .16));
  border: 1px solid hsla(var(--hue), 90%, 70%, .35);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, .35);
  transition: border-color .2s, box-shadow .2s;
}
#ribbon .rb-marks {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(100% / 12 - 1px), rgba(255, 255, 255, .13) calc(100% / 12 - 1px) calc(100% / 12));
}
#ribbon .rb-glow {
  position: absolute; top: 0; bottom: 0; left: calc(var(--x, .5) * 100%); width: 160px; margin-left: -80px;
  background: radial-gradient(closest-side, hsla(var(--hue), 100%, 70%, calc(.25 + var(--hit, 0) * .6)), transparent);
  opacity: 0; transition: opacity .15s;
}
#ribbon .rb-dot {
  position: absolute; top: calc(var(--y, .5) * 100%); left: calc(var(--x, .5) * 100%);
  width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 18px var(--acc), 0 0 40px var(--acc);
  opacity: 0; transform: scale(calc(.8 + var(--hit, 0) * .6)); transition: opacity .15s;
}
#ribbon .rb-label {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 11px; font-weight: 800; letter-spacing: .3em; color: rgba(255, 255, 255, .45); transition: opacity .3s;
}
#ribbon.on { border-color: var(--acc); box-shadow: inset 0 0 24px rgba(0, 0, 0, .35), 0 0 24px hsla(var(--hue), 95%, 62%, .45); }
#ribbon.on .rb-glow, #ribbon.on .rb-dot { opacity: 1; }
#ribbon.on .rb-label { opacity: 0; }
@media (max-width: 720px) { #ribbon { flex: none; height: 72px; } }

/* ---------- step sequencer bar ---------- */
#seqBar { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 28px; }
#seqBar .sb-title { font-size: 11px; font-weight: 800; letter-spacing: .25em; color: rgba(255, 255, 255, .7); white-space: nowrap; overflow: hidden; }
#seqBar .sb-title em { font-style: normal; font-weight: 600; letter-spacing: .05em; color: rgba(255, 255, 255, .4); margin-left: 8px; }
#seqBar .sb-btns { display: flex; gap: 6px; }
#seqBar button {
  border: 1px solid rgba(255, 255, 255, .18); background: rgba(20, 18, 32, .75); color: rgba(255, 255, 255, .8);
  font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 99px;
}
#seqBar button:hover { color: #fff; border-color: var(--acc); }
@media (max-width: 720px) { #seqBar .sb-title em { display: none; } }
#tplBtn { color: #fff; border-color: var(--acc); }
#tplBtn i { font-style: normal; opacity: .7; }
#tplMenu {
  width: min(560px, calc(100vw - 28px)); max-height: 60vh; overflow-x: hidden; overflow-y: auto; padding: 12px 12px 6px;
  display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start;
  background: rgba(14, 12, 26, .96); border: 1px solid hsla(var(--hue), 90%, 70%, .35); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 30px hsla(var(--hue), 95%, 60%, .18);
  visibility: hidden; transform: translateY(8px); transition: opacity .18s, transform .18s, visibility .18s;
}
body.started.tpl-open #tplMenu { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
body.started:not(.tpl-open) #tplMenu { opacity: 0; }
#tplMenu .tm-group { flex: 1 0 100%; font-size: 10px; font-weight: 800; letter-spacing: .25em; text-transform: uppercase; color: rgba(255, 255, 255, .45); margin: 4px 2px 0; }
#tplMenu button {
  border: 1px solid rgba(255, 255, 255, .15); background: rgba(255, 255, 255, .05); color: rgba(255, 255, 255, .85);
  font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 99px;
}
#tplMenu button:hover { border-color: var(--acc); color: #fff; }
#tplMenu button.on { background: var(--acc); border-color: var(--acc); color: #07060d; }

/* ---------- section pills: how far into the current block ---------- */
.sections span { position: relative; overflow: hidden; isolation: isolate; }
.sections span.on::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, .55) 100%);
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .25s linear;
}
.sections span.on::before { /* thin hairline that runs along the bottom */
  content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: calc(var(--p, 0) * 100%);
  background: #fff; opacity: .8; box-shadow: 0 0 6px #fff; transition: width .25s linear;
}
.sections span.on.ending { animation: secEnd calc(60s / 124) ease-in-out infinite alternate; }
@keyframes secEnd { to { box-shadow: 0 0 26px var(--acc), 0 0 4px #fff; } }
