/* CrowdMelody — hard-edged neon UI.
   Blue→purple signature, HUD panels, cut corners, scanlines.
   No webfonts on purpose: phones join over the LAN and may have no internet,
   so every face here is a system stack. */

:root {
  /* base */
  --bg: #04040c;
  --panel: rgba(13, 13, 32, 0.92);
  --panel-lit: rgba(22, 22, 52, 0.92);
  --ink: #ecebff;
  --muted: #8b89cc;

  /* the signature: blue → purple */
  --blue: #3b6bff;
  --indigo: #6d3bff;
  --purple: #a63bff;
  --grad: linear-gradient(100deg, var(--blue), var(--indigo) 45%, var(--purple));

  /* neons — instrument colours and state */
  --magenta: #ff2e7e;
  --cyan: #22e5ff;
  --lime: #6bff3b;
  --violet: #b388ff;
  --orange: #ff8a3d;

  --stroke: rgba(130, 130, 255, 0.2);
  --stroke-lit: rgba(150, 145, 255, 0.42);
  --radius: 2px;
  --cut: 12px; /* corner cut on filled controls */

  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background:
    /* engineering grid */
    linear-gradient(rgba(96, 110, 255, 0.05) 1px, transparent 1px) 0 0 / 100% 46px,
    linear-gradient(90deg, rgba(96, 110, 255, 0.05) 1px, transparent 1px) 0 0 / 46px 100%,
    /* neon blooms */
    radial-gradient(1100px 700px at 6% -14%, rgba(59, 107, 255, 0.34), transparent 62%),
    radial-gradient(900px 700px at 102% 2%, rgba(166, 59, 255, 0.3), transparent 58%),
    radial-gradient(1000px 600px at 50% 120%, rgba(34, 229, 255, 0.1), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* live rail across the top of every screen */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--grad);
  box-shadow: 0 0 24px rgba(109, 59, 255, 0.8);
  z-index: 998;
  pointer-events: none;
}

/* CRT scanlines */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 997;
  pointer-events: none;
  opacity: 0.45;
  background: repeating-linear-gradient(180deg, transparent 0 2px, rgba(0, 0, 0, 0.5) 2px 3px);
}
body.no-crt::after { display: none; }

::selection { background: var(--purple); color: #fff; }

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

/* ---------- type ---------- */

h1, h2, h3 {
  margin: 0 0 0.3em;
  line-height: 0.98;
  text-transform: uppercase;
}
h1 {
  font-size: clamp(2.4rem, 7vw, 4.6rem);
  font-weight: 900;
  letter-spacing: -0.035em;
}
h2 { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 800; letter-spacing: -0.02em; }
h3 {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink);
}

/* the wordmark: blue→purple, lit from behind */
.mark {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(109, 59, 255, 0.6));
}

.kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 0.6em;
}
.kicker::before {
  content: "";
  width: 26px;
  height: 2px;
  background: var(--grad);
  flex: 0 0 auto;
}

a { color: var(--cyan); text-underline-offset: 3px; }

/* ---------- layout ---------- */

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 20px 90px;
}

/* HUD panel: hairline box with lit corner brackets */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--panel-lit), var(--panel));
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
}
.card::before,
.card::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.card::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--blue);
  border-left: 2px solid var(--blue);
}
.card::after {
  right: -1px;
  bottom: -1px;
  border-right: 2px solid var(--purple);
  border-bottom: 2px solid var(--purple);
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

/* ---------- forms ---------- */

select, input, button {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}

select, input[type="text"], input[type="number"] {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--stroke-lit);
  border-radius: var(--radius);
  padding: 11px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:focus, input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 107, 255, 0.25), 0 0 22px -6px var(--blue);
}

/* drop the OS dropdown for a drawn chevron */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
select option { background: #0b0b1c; color: var(--ink); }

/* number inputs: no OS spinners — CM.stepper() adds −/+ controls instead */
input[type="number"] { appearance: textfield; -webkit-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--stroke-lit);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.stepper:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 107, 255, 0.25), 0 0 22px -6px var(--blue);
}
.stepper input[type="number"] {
  border: 0;
  background: none;
  text-align: center;
  padding: 10px 2px;
  width: 100%;
  min-width: 0;
  font-family: var(--mono);
  font-weight: 700;
}
.stepper input[type="number"]:focus { outline: none; box-shadow: none; }
.stepper .step {
  border: 0;
  background: rgba(109, 59, 255, 0.16);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  padding: 0 11px;
  cursor: pointer;
  user-select: none;
  transition: background 0.14s ease, color 0.14s ease;
}
.stepper .step:hover { background: var(--indigo); color: #fff; }
.stepper .step:active { background: var(--purple); }

/* ---------- buttons ---------- */

/* filled controls get a cut corner; outlined ones get an accent edge */
.btn {
  --c: var(--indigo);
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 0;
  padding: 13px 22px;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  text-decoration: none;
  color: #fff;
  background: var(--grad);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.18s ease, filter 0.18s ease;
}
/* light sweep on hover */
.btn::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -60%;
  width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-20deg);
  transition: left 0.45s ease;
}
.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.12);
  box-shadow: 0 10px 34px -10px var(--c), 0 0 26px -8px var(--c);
}
.btn:hover::after { left: 115%; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
.btn:disabled::after { display: none; }

.btn.big {
  font-size: 0.95rem;
  padding: 18px 32px;
  letter-spacing: 0.18em;
  --cut: 16px;
}

.btn.go {
  --c: var(--lime);
  background: linear-gradient(100deg, #14e08a, #6bff3b);
  color: #04120a;
}
.btn.stop {
  --c: var(--magenta);
  background: linear-gradient(100deg, #ff2e7e, #ff5a3d);
  color: #16030c;
}

/* secondary: hairline box with a lit leading edge, no cut */
.btn.ghost {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--stroke-lit);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius);
  clip-path: none;
  color: var(--ink);
  font-weight: 600;
}
.btn.ghost:hover {
  background: rgba(109, 59, 255, 0.16);
  border-left-color: var(--purple);
  box-shadow: 0 0 24px -10px var(--purple);
}
.btn.ghost::after { display: none; }

/* ---------- bits ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid var(--stroke-lit);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.35);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.45);
  background-size: cover;
}

/* ---------- count-in ---------- */
/* Re-triggered per digit by removing/re-adding .countin (see CM.punch).
   Fast and violent: chromatic split, skew jitter, HUD ring snapping shut. */
/* Transform/opacity only — these run on the compositor. Animating blur() or a
   big text-shadow here repaints a huge glyph every frame and stutters the
   falling notes, so the chromatic split is painted once and left alone. */
.countin {
  position: relative;
  will-change: transform, opacity;
  text-shadow: 3px 0 var(--magenta), -3px 0 var(--cyan), 0 0 60px var(--indigo);
  animation: countin 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.countin::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.25em;
  height: 1.25em;
  margin: -0.625em 0 0 -0.625em;
  border: 2px solid var(--purple);
  will-change: transform, opacity;
  animation: countring 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
  pointer-events: none;
}
@keyframes countin {
  0% { opacity: 0; transform: scale(2.3) skewX(-16deg); }
  16% { opacity: 1; transform: scale(1.08) skewX(7deg); }
  30% { transform: scale(0.97) skewX(-4deg) translateX(6px); }
  44% { transform: scale(1.02) skewX(2deg) translateX(-4px); }
  60%, 100% { opacity: 1; transform: none; }
}
@keyframes countring {
  0% { opacity: 0; transform: scale(2.2) rotate(-8deg); }
  18% { opacity: 0.9; transform: scale(1.25) rotate(3deg); }
  55% { opacity: 0.5; transform: scale(1) rotate(0deg); }
  100% { opacity: 0; transform: scale(0.82); }
}

.muted { color: var(--muted); }
.hidden { display: none !important; }
.center { text-align: center; }
canvas { display: block; }

@media (prefers-reduced-motion: reduce) {
  .btn, .btn::after { transition: none; }
  .countin, .countin::after { animation: none; }
  .countin::after { opacity: 0; }
}
