/*
  Thrum web player styles.

  Brand tokens (dark-first):
    Pulse Coral        #FF5C7A  primary
    Deep Hum Violet    #7C5CFF  secondary
    Spark Amber        #FFD15C  accent
    Warm Black         #141017  dark bg
    Warm Paper         #F7F4F2  light bg
    Soft White         #F4EFF2  text on dark
    Felt Green         #4ADE9E  success
    Warm Alert         #FF8A5C  error
    Signature gradient linear violet -> coral
    Fonts: display "Space Grotesk", body "Inter", mono "JetBrains Mono"
           (family names only with sane fallbacks; no webfont fetches)
*/

:root {
  --coral: #ff5c7a;
  --violet: #7c5cff;
  --amber: #ffd15c;
  --warm-black: #141017;
  --warm-paper: #f7f4f2;
  --soft-white: #f4eff2;
  --felt-green: #4ade9e;
  --warm-alert: #ff8a5c;

  --bg: var(--warm-black);
  --text: var(--soft-white);
  --muted: rgba(244, 239, 242, 0.66);
  --gradient: linear-gradient(120deg, var(--violet), var(--coral));

  --font-display: "Space Grotesk", "Inter", system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas,
    monospace;

  --radius: 18px;
  --maxw: 560px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(
      120% 80% at 50% -10%,
      rgba(124, 92, 255, 0.22),
      transparent 60%
    ),
    radial-gradient(
      100% 70% at 50% 120%,
      rgba(255, 92, 122, 0.16),
      transparent 60%
    ),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Avoid horizontal scroll on any viewport. */
  overflow-x: hidden;
}

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(20px, 5vw, 40px) clamp(16px, 5vw, 32px) 48px;
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 4vw, 32px);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- top bar / wordmark ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  letter-spacing: -0.02em;
  /* lowercase wordmark with gradient ink */
  text-transform: lowercase;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* ---------- stage ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 4vw, 28px);
  flex: 1;
  justify-content: center;
}

.scope-wrap {
  width: 100%;
  border-radius: var(--radius);
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(244, 239, 242, 0.08);
  box-shadow: 0 18px 50px -28px rgba(124, 92, 255, 0.5);
}

.scope {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 280;
  border-radius: 12px;
  /* Inner well so the trace reads like an instrument. */
  background:
    radial-gradient(
      130% 120% at 50% 0%,
      rgba(124, 92, 255, 0.1),
      transparent 70%
    ),
    #0e0b12;
}

/* ---------- feel button ---------- */
.feel-btn {
  position: relative;
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.15rem, 4.5vw, 1.4rem);
  letter-spacing: 0.01em;
  color: #fff;
  padding: clamp(16px, 3.5vw, 20px) clamp(40px, 10vw, 64px);
  border-radius: 999px;
  background: var(--gradient);
  box-shadow:
    0 14px 40px -12px rgba(255, 92, 122, 0.6),
    0 0 0 0 rgba(124, 92, 255, 0.5);
  transition:
    transform 0.12s ease,
    box-shadow 0.25s ease,
    filter 0.2s ease;
}

.feel-btn:hover {
  filter: brightness(1.06);
}

.feel-btn:active {
  transform: translateY(1px) scale(0.99);
}

/* "Held pulse" idle breathing ring to invite the tap. */
.feel-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  border: 2px solid rgba(255, 92, 122, 0.45);
  opacity: 0;
  pointer-events: none;
  animation: pulse-ring 2.4s ease-out infinite;
}

.feel-btn.is-playing {
  filter: brightness(1.08);
}

.feel-btn.is-playing::after {
  animation-duration: 0.9s;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.92);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.18);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

/* ---------- status line ---------- */
.status {
  margin: 0;
  text-align: center;
  max-width: 42ch;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.status.is-error {
  color: var(--warm-alert);
}

.status.is-good {
  color: var(--felt-green);
}

/* ---------- install CTA ---------- */
.cta {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.cta__btn {
  display: inline-block;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--soft-white);
  padding: 13px 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 209, 92, 0.55);
  background: rgba(255, 209, 92, 0.08);
  transition:
    background 0.2s ease,
    transform 0.12s ease;
}

.cta__btn:hover {
  background: rgba(255, 209, 92, 0.16);
}

.cta__btn:active {
  transform: translateY(1px);
}

.cta__sub {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- footer + held-pulse glyph ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.footer p {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/*
  "Held pulse" logo glyph: rounded-capsule bars stepping DOWN in height
  (sharp attack, exponential decay) — left tall to right short.
*/
.held-pulse {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
}

.held-pulse i {
  display: block;
  width: 4px;
  border-radius: 4px;
  background: var(--gradient);
}

.held-pulse i:nth-child(1) {
  height: 18px;
}
.held-pulse i:nth-child(2) {
  height: 12px;
}
.held-pulse i:nth-child(3) {
  height: 8px;
}
.held-pulse i:nth-child(4) {
  height: 5px;
}
.held-pulse i:nth-child(5) {
  height: 3px;
}

/* ---------- stage actions (Feel it + Share) ---------- */
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* ---------- share button ---------- */
.share-btn {
  appearance: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.01em;
  color: var(--soft-white);
  padding: 13px 26px;
  border-radius: 999px;
  border: 1px solid rgba(124, 92, 255, 0.55);
  background: rgba(124, 92, 255, 0.1);
  transition:
    background 0.2s ease,
    transform 0.12s ease;
}

.share-btn:hover {
  background: rgba(124, 92, 255, 0.2);
}

.share-btn:active {
  transform: translateY(1px);
}

.share-btn[hidden] {
  display: none;
}

/* ---------- preset gallery ---------- */
.gallery {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 3vw, 22px);
}

.gallery[hidden] {
  display: none;
}

.gallery__title {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
}

.gallery__title-lead {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.15rem, 4.5vw, 1.5rem);
  letter-spacing: -0.01em;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gallery__title-sub {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.92rem;
  color: var(--muted);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(98px, 1fr));
  gap: clamp(10px, 2.5vw, 14px);
}

.preset-card {
  appearance: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 104px;
  padding: 14px 10px;
  border-radius: var(--radius);
  color: var(--text);
  border: 1px solid rgba(244, 239, 242, 0.1);
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.05),
      rgba(255, 255, 255, 0.015)
    );
  box-shadow: 0 14px 36px -28px rgba(124, 92, 255, 0.5);
  transition:
    transform 0.14s ease,
    border-color 0.2s ease,
    box-shadow 0.25s ease,
    background 0.2s ease;
}

.preset-card__glyph {
  font-size: clamp(1.9rem, 7vw, 2.4rem);
  line-height: 1;
  /* Keep emoji from triggering selection / drag on long-press. */
  -webkit-user-select: none;
  user-select: none;
}

.preset-card__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.005em;
  text-align: center;
  color: var(--text);
  /* Avoid awkward overflow on long names. */
  max-width: 100%;
  overflow-wrap: anywhere;
}

.preset-card:hover {
  transform: translateY(-2px);
  border-color: transparent;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    var(--gradient);
  box-shadow: 0 18px 44px -22px rgba(255, 92, 122, 0.6);
}

.preset-card:active {
  transform: translateY(0) scale(0.98);
}

.preset-card.is-active {
  border-color: transparent;
  box-shadow:
    0 0 0 2px rgba(255, 92, 122, 0.55),
    0 18px 44px -22px rgba(124, 92, 255, 0.6);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--gradient);
}

/*
  Layout modes set by player.js:
    body.mode-gallery — URL has no buzz: gallery is the hero, the single-buzz
      stage de-emphasizes (the canvas + Feel it still work once a card loads).
    body.mode-player  — a buzz is loaded: stage is primary, gallery is the
      secondary "or try these" strip below.
*/
body.mode-gallery .stage {
  flex: 0 0 auto;
  justify-content: flex-start;
}

body.mode-gallery .gallery {
  order: 2;
}

/* ---------- a11y helpers ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Visible, high-contrast focus for keyboard users. */
:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
  border-radius: 8px;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .feel-btn::after {
    animation: none;
  }
  .feel-btn,
  .cta__btn,
  .share-btn,
  .preset-card {
    transition: none;
  }
  .preset-card:hover,
  .preset-card:active {
    transform: none;
  }
}
