/* Sound Experiences: Welcome screen.
   All styling for index.html lives here (no inline CSS anywhere in the page). */

:root {
  --css-build: "10";       /* shown by ?debug=1 so a stale stylesheet is easy to spot */
  --ink: #1f1029;          /* deep aubergine, top of the sky */
  --plum: #34183f;
  --mulberry: #4b2249;     /* bottom of the sky */
  --apricot: #ff9f68;      /* warm glow behind the listening disc */
  --rose: #f0728f;
  --bone: #fff4e8;         /* type and disc */
  --bone-dim: rgba(255, 244, 232, 0.7);
  --bone-faint: rgba(255, 244, 232, 0.16);
  --accent: var(--apricot);   /* replaced by the matched experience's colour */
  --accent2: var(--rose);
  --font: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--bone);
  background:
    radial-gradient(120% 60% at 50% 112%, rgba(240, 114, 143, 0.22), transparent 70%),
    linear-gradient(180deg, var(--ink) 0%, var(--plum) 52%, var(--mulberry) 100%);
  background-color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Film grain, so the gradient never bands on a big screen. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

img { display: block; max-width: 100%; }

/* ---------- Side rulers: a tick scale on each edge, quiet until the phone is listening ---------- */

.ruler {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: clamp(16px, 4.2vw, 44px);
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(255, 244, 232, 0.3) 0 1px, transparent 1px 10px) left center / 36% 100% no-repeat,
    repeating-linear-gradient(180deg, rgba(255, 244, 232, 0.55) 0 1.5px, transparent 1.5px 50px) left center / 72% 100% no-repeat;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 16%, #000 84%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 16%, #000 84%, transparent);
}
.ruler--left  { left: max(8px, env(safe-area-inset-left)); }
.ruler--right { right: max(8px, env(safe-area-inset-right)); transform: scaleX(-1); }

.ruler::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22%;
  opacity: 0;
  background: linear-gradient(180deg, transparent, rgba(255, 190, 140, 0.55), transparent);
}
body[data-state="listening"] .ruler::after {
  opacity: 1;
  animation: scan 2.4s ease-in-out infinite alternate;
}
@keyframes scan { from { transform: translateY(0); } to { transform: translateY(350%); } }

/* ---------- Stage ---------- */

.stage {
  position: relative;
  z-index: 2;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  /* The rings and glow around the Listen button are larger than the screen. Clip them here: on Android,
     Chrome widens its layout viewport to fit any overflow, which pushes fixed elements off-screen. */
  overflow: hidden;
  overflow: clip;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(14px, 3vh, 32px);
  gap: clamp(14px, 3dvh, 32px);
  padding:
    max(24px, env(safe-area-inset-top))
    clamp(40px, 10vw, 84px)
    max(24px, env(safe-area-inset-bottom));
  text-align: center;
  transition: opacity 0.5s var(--ease-out), filter 0.5s var(--ease-out);
}
body[data-state="experience"] .stage { opacity: 0; filter: blur(8px); }

.masthead { display: flex; flex-direction: column; align-items: center; }

.title {
  margin: clamp(8px, 2vh, 20px) 0 0;
  margin: clamp(8px, 2dvh, 20px) 0 0;
  font-weight: 300;
  font-size: clamp(2.1rem, 8.6vw, 3.7rem);
  letter-spacing: -0.035em;
  line-height: 1.02;
}
.lede {
  margin: clamp(10px, 1.8vh, 18px) auto 0;
  margin: clamp(10px, 1.8dvh, 18px) auto 0;
  max-width: 34ch;
  text-wrap: balance;
  font-size: clamp(0.95rem, 3.9vw, 1.1rem);
  line-height: 1.5;
  color: var(--bone-dim);
}

/* ---------- Listener: disc, time arc, seven lamps ---------- */

.listener {
  --size: 200px;                                  /* safe default: a custom property that fails to parse would leave the disc unsized */
  --ring: calc(var(--size) + 60px);
  --window: 5s;
  position: relative;
  flex: none;
  width: var(--ring);
  height: var(--ring);
  display: grid;
  place-items: center;
}
@supports (width: min(1px, 2px)) {
  .listener { --size: clamp(168px, min(56vw, 33vh), 300px); }
}
@supports (height: 1dvh) {
  .listener { --size: clamp(168px, min(56vw, 33dvh), 300px); }
}

/* Warm glow and concentric ripple texture, always centred on the disc. */
.listener::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: 190vmax;
  height: 190vmax;
  transform: translate(-50%, -50%);
  pointer-events: none;
  background:
    radial-gradient(closest-side, rgba(255, 159, 104, 0.38), rgba(255, 159, 104, 0.12) 22%, transparent 36%),
    repeating-radial-gradient(circle at 50% 50%, rgba(255, 244, 232, 0.075) 0 1px, transparent 1px 30px);
  -webkit-mask-image: radial-gradient(closest-side, #000 0%, #000 18%, transparent 62%);
  mask-image: radial-gradient(closest-side, #000 0%, #000 18%, transparent 62%);
  animation: breathe 5.5s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.78; } 50% { opacity: 1; } }
body[data-state="matched"] .listener::before {
  background:
    radial-gradient(closest-side, color-mix(in srgb, var(--accent) 45%, transparent), color-mix(in srgb, var(--accent) 14%, transparent) 22%, transparent 36%),
    repeating-radial-gradient(circle at 50% 50%, rgba(255, 244, 232, 0.075) 0 1px, transparent 1px 30px);
}

.arc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  overflow: visible;
}
.arc circle { fill: none; stroke-width: 1.5; }
.arc__track { stroke: var(--bone-faint); }
.arc__fill {
  stroke: var(--bone);
  stroke-linecap: round;
  stroke-dasharray: 596.9;
  stroke-dashoffset: 596.9;
  transition: stroke 0.5s;
}
body[data-state="listening"] .arc__fill { animation: sweep var(--window) linear forwards; }
body[data-state="matched"]   .arc__fill { stroke-dashoffset: 0; stroke: var(--accent); stroke-width: 2.5; }
@keyframes sweep { to { stroke-dashoffset: 0; } }

.beads { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; }
.bead {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: rgba(255, 244, 232, 0.12);
  border: 1px solid rgba(255, 244, 232, 0.42);
  transform: rotate(calc(var(--i) * 51.4286deg)) translateY(calc(var(--ring) * -0.475));
  transition: background 0.35s, box-shadow 0.35s, border-color 0.35s, scale 0.45s var(--ease-spring);
}
.bead:nth-child(1) { --i: 0; } .bead:nth-child(2) { --i: 1; } .bead:nth-child(3) { --i: 2; }
.bead:nth-child(4) { --i: 3; } .bead:nth-child(5) { --i: 4; } .bead:nth-child(6) { --i: 5; }
.bead:nth-child(7) { --i: 6; }
.bead.is-lit {
  background: var(--bone);
  border-color: var(--bone);
  box-shadow: 0 0 14px 3px rgba(255, 200, 150, 0.75);
  scale: 1.35;
}
body[data-state="matched"] .bead.is-lit {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 18px 4px color-mix(in srgb, var(--accent) 70%, transparent);
}

.listen {
  position: relative;
  width: var(--size);
  height: var(--size);
  aspect-ratio: 1 / 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.7rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  font: 600 1.125rem/1 var(--font);
  letter-spacing: 0.01em;
  background: radial-gradient(120% 120% at 30% 18%, #fffaf3 0%, #ffe8d1 52%, #ffd0a8 100%);
  box-shadow:
    0 20px 44px -14px rgba(255, 150, 90, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -14px 34px rgba(255, 150, 90, 0.2);
  transition: transform 0.3s var(--ease-out), box-shadow 0.5s, background 0.6s, color 0.4s;
}
.listen:hover  { transform: scale(1.025); }
.listen:active { transform: scale(0.965); }
.listen:focus-visible { outline: 2px solid var(--bone); outline-offset: 10px; }

.listen__icon {
  width: clamp(34px, 7vh, 46px);
  height: clamp(34px, 7vh, 46px);
  width: clamp(34px, 7dvh, 46px);
  height: clamp(34px, 7dvh, 46px);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Ripples leave the disc while the phone is listening. */
.listen::before, .listen::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 244, 232, 0.55);
  opacity: 0;
  pointer-events: none;
}
body[data-state="listening"] .listen::before { animation: ripple 2.4s ease-out infinite; }
body[data-state="listening"] .listen::after  { animation: ripple 2.4s ease-out 1.2s infinite; }
@keyframes ripple {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(1.7); opacity: 0; }
}

body[data-state="connecting"] .listen { transform: scale(0.97); }
body[data-state="listening"]  .listen { box-shadow: 0 22px 48px -10px rgba(255, 150, 90, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.85), inset 0 -14px 34px rgba(255, 150, 90, 0.2); }

/* The one orchestrated moment: the disc takes on the experience's colour. */
body[data-state="matched"] .listen {
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--accent2));
  box-shadow: 0 22px 48px -10px color-mix(in srgb, var(--accent) 80%, transparent), inset 0 2px 8px rgba(255, 255, 255, 0.3);
  transform: scale(1.04);
  cursor: default;
}
body[data-state="nomatch"] .listen,
body[data-state="error"]   .listen { animation: nudge 0.5s var(--ease-out); }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  60% { transform: translateX(5px); }
}

.bloom {
  position: fixed;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  background: radial-gradient(circle, var(--accent) 0%, color-mix(in srgb, var(--accent2) 55%, transparent) 45%, transparent 70%);
  transform: translate(-50%, -50%) scale(0);
}
.bloom.is-on { animation: bloom 1.5s var(--ease-out) forwards; }
@keyframes bloom {
  0%   { opacity: 0.55; transform: translate(-50%, -50%) scale(0); }
  100% { opacity: 0;    transform: translate(-50%, -50%) scale(90); }
}

/* ---------- Status copy and brand ---------- */

.footing { display: flex; flex-direction: column; align-items: center; }
.status {
  margin: 0;
  min-height: 2.8em;
  max-width: 28ch;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
}
.detail {
  margin: 0.45em 0 0;
  min-height: 2.8em;
  max-width: 30ch;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--bone-dim);
}
.footing__brand { width: clamp(124px, 34vw, 170px); height: auto; margin-top: clamp(8px, 2vh, 22px); margin-top: clamp(8px, 2dvh, 22px); opacity: 0.95; }

/* ---------- Experience overlay ---------- */

.experience {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #0b0711;
  opacity: 0;
  transform: scale(1.025);
  transition: opacity 0.5s ease, transform 0.6s var(--ease-out);
}
.experience[hidden] { display: none; }
.experience.is-open { opacity: 1; transform: none; }

/* A slim bar keeps Exit clear of whatever the experience draws in its own corners. */
.experience__bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  height: calc(44px + env(safe-area-inset-top));
  background: #0b0711;
}
.experience__bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.experience__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--bone);
}
.experience__frame { display: block; flex: 1 1 auto; min-height: 0; width: 100%; border: 0; background: #06070d; }

.exit {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px 0 10px;
  border: 1px solid rgba(255, 244, 232, 0.35);
  border-radius: 999px;
  color: var(--bone);
  background: rgba(255, 244, 232, 0.08);
  font: 600 0.8125rem/1 var(--font);
  cursor: pointer;
  transition: transform 0.25s var(--ease-out), background 0.25s;
}
.exit:hover  { background: rgba(255, 244, 232, 0.18); }
.exit:active { transform: scale(0.94); }
.exit:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }
.exit svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* ---------- Debug panel (add ?debug=1 to the address) ---------- */

.debug {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 80;
  max-height: 42vh;
  max-height: 42dvh;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(10, 5, 14, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #e9dfe6;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.debug[hidden] { display: none; }
.debug__row { margin: 0 0 6px; word-break: break-all; }
.debug__log { margin: 6px 0 0; padding: 0; list-style: none; opacity: 0.8; }
.debug__launch { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.debug__launch button {
  padding: 5px 9px;
  border: 1px solid rgba(255, 244, 232, 0.3);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

/* ---------- Short screens and wide screens ---------- */

@media (max-height: 640px) {
  .footing__brand { display: none; }
  .lede { font-size: 0.875rem; }
  .detail { min-height: 2.2em; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .title { font-size: 1.6rem; margin-top: 0; }
}
@media (min-width: 900px) {
  .ruler { width: 44px; left: auto; right: auto; }
  .ruler--left  { left: clamp(24px, 6vw, 120px); }
  .ruler--right { right: clamp(24px, 6vw, 120px); }
}

/* ---------- Reduced motion: keep the time arc (it carries information), drop the decoration ---------- */

@media (prefers-reduced-motion: reduce) {
  .listener::before,
  .listen::before, .listen::after,
  .ruler::after { animation: none !important; }
  .bloom.is-on { animation: none; opacity: 0; }
  .bead, .listen, .stage, .experience { transition-duration: 0.01ms; }
  body[data-state="nomatch"] .listen, body[data-state="error"] .listen { animation: none; }
}
