/*
 * Styles for the page furniture: welcome panel, bottom bar, messages.
 * The visuals themselves are not styled here; they are painted by the shaders
 * in /shaders onto the full-screen canvas.
 *
 * Contents
 *   1. Font and design tokens
 *   2. Page and canvas
 *   3. Welcome panel
 *   4. Buttons, chips, slider
 *   5. Bottom bar (now playing + controls)
 *   6. Messages
 *   7. States (loading, live, idle) and accessibility
 */

/* ── 1. Font and design tokens ─────────────────────────────────────────────── */

/* Unbounded, by The Unbounded Project Authors. Open Font License: /fonts/OFL.txt */
@font-face {
  font-family: 'Unbounded';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('/fonts/unbounded-latin-wght-normal.woff2') format('woff2-variations');
}

:root {
  --ink: #07040d;                          /* behind the canvas while it loads */
  --text: #f6f3fb;
  --text-dim: rgb(246 243 251 / 0.66);
  --glass: rgb(14 9 26 / 0.58);            /* translucent panel background */
  --glass-strong: rgb(14 9 26 / 0.78);
  --hairline: rgb(255 255 255 / 0.14);
  --accent: rgb(255 41 133);               /* replaced from JS with the palette's lead colour */
  --radius: 16px;
  --font-display: 'Unbounded', ui-sans-serif, system-ui, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

/* ── 2. Page and canvas ────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over display rules below. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font: 15px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ── 3. Welcome panel ──────────────────────────────────────────────────────── */

.intro {
  position: fixed;
  inset: 0;
  display: flex;
  padding: 20px 16px 110px; /* the bottom gap leaves room for the bar */
  overflow-y: auto; /* on very short screens the card can be scrolled */
  transition: opacity 0.5s ease, visibility 0.5s;
}

/* A frosted-glass card, so the text stays readable over any scene. */
.intro-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  /* Auto margins centre the card when there is room, and (unlike other ways of
     centring) never push its top off-screen when there isn't. */
  margin: auto;
  padding: clamp(24px, 5vw, 48px) clamp(20px, 5vw, 56px);
  border: 1px solid var(--hairline);
  border-radius: 32px;
  background: rgb(9 6 18 / 0.5);
  backdrop-filter: blur(26px) saturate(1.3);
  -webkit-backdrop-filter: blur(26px) saturate(1.3);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.45);
  text-align: center;
}

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.1rem, 8.4vw, 6.4rem);
  line-height: 1;
  letter-spacing: -0.035em;
  text-shadow: 0 0 60px color-mix(in srgb, var(--accent) 55%, transparent);
}

.accent {
  color: var(--accent);
  transition: color 1s ease;
}

.tagline {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(0.95rem, 2.2vw, 1.35rem);
  letter-spacing: 0.02em;
}

.hint {
  margin: 0;
  max-width: 34em;
  color: var(--text-dim);
}

.choices {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.fineprint {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.choices + .fineprint { margin-top: 14px; }

/* ── 4. Buttons, chips, slider ─────────────────────────────────────────────── */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.button {
  padding: 12px 22px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.button:hover {
  background: rgb(255 255 255 / 0.16);
  border-color: rgb(255 255 255 / 0.4);
}

.button:active { transform: scale(0.97); }

.button-primary {
  padding: 14px 30px;
  border-color: transparent;
  background: var(--text);
  color: var(--ink);
  font-size: 16px;
}

.button-primary:hover {
  background: #fff;
  border-color: transparent;
  box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 70%, transparent);
}

.button-quiet {
  background: transparent;
  color: var(--text-dim);
}

.button-small {
  padding: 7px 14px;
  font-size: 13px;
}

/* A chip is an on/off switch. `aria-pressed` holds its state. */
.chip {
  padding: 6px 13px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover { border-color: rgb(255 255 255 / 0.4); }

.chip[aria-pressed='true'] {
  border-color: transparent;
  background: var(--text);
  color: var(--ink);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition: background 0.15s ease;
}

.icon-button:hover { background: rgb(255 255 255 / 0.16); }

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.slider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.slider input {
  width: 96px;
  height: 18px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── 5. Bottom bar ─────────────────────────────────────────────────────────── */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  transition: opacity 0.6s ease;
}

.now-playing,
.controls {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.now-playing {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, 100%);
  padding: 10px 16px 13px 10px;
  overflow: hidden;
}

.track-art {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 4px;
  object-fit: cover;
}

.track-text {
  display: flex;
  flex-direction: column;
  min-width: 0; /* lets long titles be cut off with an ellipsis */
}

.track-title,
.track-artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-title {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.track-title[href]:hover { text-decoration: underline; }

.track-artist { color: var(--text-dim); }

.track-source {
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.track-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgb(255 255 255 / 0.12);
}

.track-progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
  transition: background 1s ease;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-left: auto;
  padding: 8px 10px;
}

.scene-picker {
  display: flex;
  align-items: center;
  gap: 2px;
}

.scene-name {
  min-width: 8.2em;
  text-align: center;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tempo {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 5.6em;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
}

.beat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  /* --beat is set from JS every frame: 1 on the beat, fading to 0. */
  opacity: calc(0.25 + 0.75 * var(--beat, 0));
  transform: scale(calc(0.7 + 0.6 * var(--beat, 0)));
}

/* ── 6. Messages ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  max-width: min(560px, calc(100% - 32px));
  padding: 11px 18px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  text-align: center;
  transform: translateX(-50%);
  animation: toast-in 0.25s ease;
  pointer-events: none; /* a message must never block a click on what's under it */
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
}

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 32px;
  text-align: center;
  font-size: 17px;
  background: var(--ink);
}

/* ── 7. States and accessibility ───────────────────────────────────────────── */

/* Until the scripts have started, keep the furniture out of sight. */
.is-loading .intro,
.is-loading .dock { opacity: 0; }

/* A sound source is running: the welcome panel steps aside. */
.is-live .intro {
  opacity: 0;
  visibility: hidden;
}

/* Nobody has moved the mouse for a while: fade the controls and the cursor. */
.is-idle .fades-when-idle {
  opacity: 0;
  pointer-events: none;
}

.is-idle,
.is-idle * { cursor: none; }

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

@media (max-width: 640px) {
  .dock { justify-content: center; }
  .controls { margin-left: 0; justify-content: center; }
  .slider span { display: none; }
  .intro { padding-bottom: 150px; }
  .intro-card { border-radius: 24px; }
}

/* Short screens, such as a phone held sideways: keep only the essentials, and
   keep the bottom bar out of the way until something is playing. */
@media (max-height: 560px) {
  body:not(.is-live) .dock { display: none; }
  .intro { padding-bottom: 20px; }
  .intro-card { gap: 8px; padding: 16px 24px; border-radius: 22px; }
  .wordmark { font-size: clamp(1.5rem, 11vh, 3.2rem); }
  .hint,
  .fineprint:last-child { display: none; }
  .choices { margin-top: 6px; }
  .choices + .fineprint { margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Links dressed as buttons (used on the 404 page). */
a.button {
  display: inline-block;
  text-decoration: none;
}
