/* Copyright 2026 Greg Fodor */
/* SPDX-License-Identifier: Apache-2.0 */

/* Palette + type lifted from the webspace-engine indigo UI (theme.scss):
   primary indigo scale, accent red/orange/sky, Lato + Inconsolata. */

:root {
  --indigo-sub0: #050e2e;
  --indigo-0: #061139;
  --indigo-1: #111749;
  --indigo-2: #19216c;
  --indigo-3: #2d3a8c;
  --indigo-4: #35469c;
  --indigo-5: #4055a8;
  --indigo-6: #4c63b6;
  --indigo-7: #647acb;
  --indigo-8: #7b93db;
  --indigo-9: #98aeeb;
  --indigo-10: #bed0f7;
  --indigo-11: #e0e8f9;
  --indigo-11b: #f0f4fc;
  --red: #e12d39;
  --red-bright: #ef4e4e;
  --orange: #f9703e;
  --sky: #40c3f7;
  --mono: "Inconsolata", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--indigo-11);
  background: var(--indigo-0);
  font-family: "Lato", Roboto, Helvetica, Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
}

/* ---------- full-screen acts ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.985);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

body[data-stage="record"] #screen-record,
body[data-stage="play"] #screen-play {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* ---------- act one · the booth ---------- */

.screen-record {
  color: var(--indigo-11);
  background:
    radial-gradient(circle at 50% 62%, rgba(76, 99, 182, 0.28), transparent 48%),
    radial-gradient(circle at 50% 120%, rgba(64, 195, 247, 0.14), transparent 60%),
    linear-gradient(180deg, var(--indigo-sub0), var(--indigo-1));
}

.screen-record::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.eyebrow,
.strip,
.readout,
.timer,
.status {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--sky);
}

.title {
  margin: 0;
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.title em {
  font-style: italic;
  color: var(--indigo-9);
}

/* the mic button */

.mic-zone {
  position: relative;
  margin-top: clamp(28px, 6vh, 56px);
  display: grid;
  justify-items: center;
  gap: 16px;
}

.mic {
  position: relative;
  width: clamp(96px, 15vmin, 128px);
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid var(--indigo-9);
  border-radius: 50%;
  background: rgba(25, 33, 108, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, border-color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.mic:hover {
  border-color: var(--indigo-11);
  transform: scale(1.05);
}

.mic:active {
  transform: scale(0.96);
}

.mic-core {
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--red);
  transition: border-radius 0.25s ease, transform 0.25s ease, background 0.25s ease;
}

.mic-ring {
  position: absolute;
  inset: -2px;
  border: 2px solid var(--red-bright);
  border-radius: 50%;
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
}

/* idle: slow beckoning pulse */
body[data-mode="idle"] .mic-ring {
  border-color: var(--indigo-7);
  animation: beckon 2.4s ease-out infinite;
}

@keyframes beckon {
  0% {
    opacity: 0.8;
    transform: scale(1);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.55);
  }
}

/* arming: anxious little throb while the model loads */
body[data-mode="arming"] .mic {
  cursor: progress;
  animation: throb 0.9s ease-in-out infinite;
}

@keyframes throb {
  50% {
    transform: scale(0.94);
  }
}

/* recording: core becomes a stop square, ring rides the live level */
body[data-mode="recording"] .mic {
  border-color: var(--red-bright);
}

body[data-mode="recording"] .mic-core {
  border-radius: 22%;
  transform: scale(0.82);
}

body[data-mode="recording"] .mic-ring {
  opacity: calc(0.15 + var(--level, 0) * 0.85);
  transform: scale(calc(1 + var(--level, 0) * 0.85));
  transition: transform 0.06s linear, opacity 0.12s linear;
}

.timer {
  min-height: 18px;
  margin: 0;
  color: var(--indigo-8);
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body[data-mode="recording"] .timer {
  color: var(--red-bright);
  opacity: 1;
}

.status {
  min-height: 20px;
  margin: 18px 0 0;
  color: var(--indigo-10);
  letter-spacing: 0.2em;
}

body[data-mode="recording"] .status {
  animation: flicker 1.6s steps(2) infinite;
}

@keyframes flicker {
  50% {
    opacity: 0.45;
  }
}

.strip {
  position: absolute;
  bottom: 22px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--indigo-7);
  font-size: 12px;
}

.strip strong {
  color: var(--sky);
}

.strip a,
.readout a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  transition: color 0.15s ease;
}

.strip a:hover,
.strip a:focus-visible {
  color: var(--sky);
}

/* ---------- act two · the reveal ---------- */

.screen-play {
  color: var(--indigo-1);
  background:
    radial-gradient(circle at 50% 30%, rgba(190, 208, 247, 0.55), transparent 55%),
    var(--indigo-11b);
}

.face-wrap {
  position: relative;
}

body[data-stage="play"] .face-wrap {
  animation: pop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes pop {
  0% {
    transform: scale(0.15) rotate(-8deg);
    opacity: 0;
  }
  55% {
    transform: scale(1.07) rotate(2deg);
    opacity: 1;
  }
  78% {
    transform: scale(0.97) rotate(-0.5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Jel avatar */

.face {
  position: relative;
  width: clamp(240px, 52vmin, 420px);
  aspect-ratio: 1;
  filter: drop-shadow(0 16px 28px rgba(6, 17, 57, 0.28));
}

.avatar {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--indigo-6);
}

body[data-mode="playing"] .face {
  animation: bob 0.44s ease-in-out infinite;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-7px) rotate(0.9deg);
  }
}

.avatar-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.4s infinite;
}

@keyframes blink {
  0%,
  93%,
  100% {
    transform: scaleY(1);
  }
  96% {
    transform: scaleY(0.06);
  }
}

/* Viseme mouths are drawn in a 128x127 box; the avatar mouth line sits at
   x 63-122, y 136 in the avatar's 186 box. Scale 59/43 maps one onto the other. */
#mouth {
  position: absolute;
  left: 2.89%;
  top: 25.21%;
  width: 94.42%;
  height: 93.67%;
  object-fit: contain;
  /* the viseme sprites are drawn vertically stretched; compress around the
     resting mouth line (y 64.94 of 127) so viseme-0 stays put */
  transform: scaleY(0.72);
  transform-origin: 50% 51.1%;
  pointer-events: none;
}

/* confetti */

.confetti {
  position: absolute;
  inset: -30% -40%;
  pointer-events: none;
  z-index: 2;
}

.confetti span {
  position: absolute;
  top: 42%;
  left: 50%;
  width: 10px;
  height: 15px;
  border-radius: 2px;
  opacity: 0;
}

.confetti.burst span {
  animation: toss 1.05s cubic-bezier(0.18, 0.6, 0.4, 1) var(--delay, 0s) forwards;
}

@keyframes toss {
  0% {
    transform: translate(-50%, 0) rotate(0deg) scale(0.5);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  55% {
    transform: translate(calc(-50% + var(--x, 0px) * 0.8), calc(var(--peak, -180px)))
      rotate(calc(var(--r, 360deg) * 0.6)) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--x, 0px)), 80px) rotate(var(--r, 360deg)) scale(0.9);
    opacity: 0;
  }
}

/* actions + readout */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: clamp(26px, 5.5vh, 48px);
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.actions.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.actions button {
  min-height: 54px;
  padding: 0 26px;
  border: 1px solid rgba(53, 70, 156, 0.63);
  border-radius: 12px;
  color: var(--indigo-3);
  background: #ffffff;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(6, 17, 57, 0.18);
}

.actions button.primary {
  color: var(--indigo-11);
  background: var(--indigo-6);
}

.actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(6, 17, 57, 0.24);
}

.actions button.primary:hover {
  background: var(--indigo-5);
}

.actions button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(6, 17, 57, 0.2);
}

.actions button.primary:active {
  background: var(--indigo-4);
}

.readout {
  position: absolute;
  bottom: 22px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--indigo-6);
  font-size: 12px;
}

.readout strong {
  color: var(--red);
}

.readout a:hover,
.readout a:focus-visible {
  color: var(--indigo-3);
}

/* ---------- small screens ---------- */

@media (max-width: 520px) {
  .actions button {
    flex: 1 1 100%;
  }
}

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

  .screen {
    transform: none;
  }
}
