:root {
  color-scheme: dark;
  --bg: #070812;
  --panel: rgba(18, 20, 39, 0.7);
  --text: #f8f8ff;
  --muted: #a4a6bb;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --pink: #f43f9e;
  --lime: #b9f227;
  --safe-top: max(24px, env(safe-area-inset-top));
  --safe-bottom: max(22px, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

.app {
  isolation: isolate;
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 110%, rgba(139, 92, 246, 0.24), transparent 46%),
    linear-gradient(145deg, #090a17 0%, #050610 58%, #090718 100%);
}

.grain {
  position: absolute;
  z-index: -1;
  inset: 0;
  opacity: 0.16;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

.ambient {
  position: absolute;
  z-index: -2;
  width: min(56vw, 620px);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  pointer-events: none;
}

.ambient--one {
  top: -30%;
  left: -12%;
  background: var(--violet);
}

.ambient--two {
  right: -14%;
  bottom: -34%;
  background: var(--cyan);
}

.meter-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 0.9fr) minmax(180px, 1.15fr) auto;
  gap: clamp(12px, 2.2vh, 28px);
  width: min(100%, 1280px);
  height: 100%;
  margin: 0 auto;
  padding: var(--safe-top) clamp(24px, 5vw, 72px) var(--safe-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #dcdeef;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand__mark {
  display: flex;
  align-items: end;
  gap: 3px;
  width: 24px;
  height: 24px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 7px;
}

.brand__mark i {
  width: 3px;
  border-radius: 4px;
  background: linear-gradient(to top, var(--violet), var(--cyan));
}

.brand__mark i:nth-child(1) { height: 45%; }
.brand__mark i:nth-child(2) { height: 100%; }
.brand__mark i:nth-child(3) { height: 70%; }

.live-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 148px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  color: #c7c8d8;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.live-badge__dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 0 5px rgba(185, 242, 39, 0.1), 0 0 14px var(--lime);
}

[data-state="COUNTDOWN"] .live-badge,
[data-state="ACTIVE"] .live-badge {
  border-color: rgba(244, 63, 158, 0.26);
  background: rgba(244, 63, 158, 0.1);
}

[data-state="COUNTDOWN"] .live-badge__dot,
[data-state="ACTIVE"] .live-badge__dot {
  background: var(--pink);
  box-shadow: 0 0 0 5px rgba(244, 63, 158, 0.12), 0 0 16px var(--pink);
  animation: blink 0.65s ease-in-out infinite alternate;
}

.hero-copy {
  align-self: end;
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: #b3a1ff;
  font-size: clamp(10px, 1.15vw, 13px);
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 72px);
  font-weight: 850;
  letter-spacing: -0.055em;
  line-height: 0.92;
}

.hero-copy h1 span {
  color: transparent;
  background: linear-gradient(100deg, #c4a8ff 0%, #7ddfff 56%, #f78dce 100%);
  background-clip: text;
  -webkit-background-clip: text;
}

.instruction {
  max-width: 660px;
  margin: clamp(12px, 2vh, 22px) auto 0;
  color: var(--muted);
  font-size: clamp(14px, 1.6vw, 19px);
  line-height: 1.4;
}

.meter {
  align-self: stretch;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 1fr;
  gap: clamp(24px, 4vw, 60px);
  min-height: 0;
  padding: clamp(16px, 2.8vh, 34px) clamp(18px, 3vw, 40px) clamp(12px, 2vh, 24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: clamp(22px, 3vw, 42px);
  background: linear-gradient(135deg, rgba(27, 29, 53, 0.72), rgba(12, 13, 28, 0.58));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.06), 0 28px 80px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(16px);
}

.equalizer-stage {
  align-self: stretch;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(8px, 1vw, 14px);
  min-height: 0;
}

.equalizer {
  align-self: end;
  display: flex;
  align-items: end;
  gap: clamp(4px, 0.8vw, 12px);
  width: 100%;
  height: 100%;
  min-height: 100px;
}

.bar {
  position: relative;
  flex: 1 1 0;
  min-width: 3px;
  height: 8%;
  min-height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(to top, var(--violet) 0%, var(--pink) 48%, #ffc554 100%);
  box-shadow: 0 0 18px rgba(139, 92, 246, 0.22);
  transform-origin: bottom;
  will-change: height;
}

.bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3), transparent);
  opacity: 0.55;
}

.reading {
  align-self: center;
  display: flex;
  align-items: flex-end;
  min-width: clamp(150px, 18vw, 240px);
  line-height: 0.78;
}

.reading__value {
  display: inline-block;
  min-width: 2ch;
  color: var(--text);
  font-size: clamp(74px, 11vw, 154px);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: -0.095em;
  text-shadow: 0 0 46px rgba(139, 92, 246, 0.16);
}

.reading__unit {
  margin: 0 0 0.15em 0.25em;
  color: #8f91a8;
  font-size: clamp(16px, 2vw, 25px);
  font-weight: 750;
  letter-spacing: 0.08em;
}

.level-axis {
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 8px;
  padding-block: 1px;
  color: #666a82;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.11em;
}

.level-axis i {
  position: relative;
  width: 1px;
  height: 100%;
  min-height: 52px;
  background: linear-gradient(to top, rgba(139, 92, 246, 0.2), rgba(244, 63, 158, 0.58));
}

.level-axis i::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 6px;
  height: 6px;
  border-top: 1px solid rgba(244, 63, 158, 0.8);
  border-left: 1px solid rgba(244, 63, 158, 0.8);
  transform: translate(-50%, -1px) rotate(45deg);
}

.footer-actions {
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 9px;
}

.start-round-button {
  visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 34px;
  min-width: clamp(180px, 22vw, 240px);
  min-height: 54px;
  padding: 8px 11px 8px 25px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 999px;
  opacity: 0;
  color: #090a13;
  background: linear-gradient(105deg, var(--lime), #72ecde);
  box-shadow: 0 14px 38px rgba(185, 242, 39, 0.15);
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}

.start-round-button i {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(7, 8, 18, 0.13);
  font-size: 20px;
  font-style: normal;
}

[data-state="IDLE"] .start-round-button {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.start-round-button:focus-visible {
  outline: 3px solid white;
  outline-offset: 4px;
}

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

.footer-hint {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #8f91a5;
  font-size: clamp(11px, 1.2vw, 14px);
}

.footer-hint__icon {
  position: relative;
  width: 14px;
  height: 19px;
  border: 1.5px solid #777b92;
  border-radius: 8px;
}

.footer-hint__icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 4px;
  width: 2px;
  height: 5px;
  border-radius: 2px;
  background: #777b92;
  transform: translateX(-50%);
}

.overlay {
  visibility: hidden;
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) clamp(24px, 7vw, 90px) max(28px, env(safe-area-inset-bottom));
  opacity: 0;
  text-align: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(139, 92, 246, 0.25), transparent 35%),
    rgba(5, 6, 16, 0.97);
  transform: scale(1.02);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0s linear 0.45s;
}

.overlay--visible {
  visibility: visible;
  opacity: 1;
  transform: scale(1);
  transition-delay: 0s;
}

.start-screen {
  cursor: pointer;
}

.prep-screen {
  z-index: 9;
  background:
    radial-gradient(circle at 50% 45%, rgba(139, 92, 246, 0.3), transparent 34%),
    rgba(5, 6, 16, 0.96);
}

.prep-screen strong {
  color: transparent;
  background: linear-gradient(135deg, #fff, #bca7ff 48%, #72ecde);
  background-clip: text;
  -webkit-background-clip: text;
  font-size: clamp(150px, 30vmin, 340px);
  font-weight: 950;
  letter-spacing: -0.09em;
  line-height: 0.8;
  text-shadow: 0 0 80px rgba(139, 92, 246, 0.22);
  font-variant-numeric: tabular-nums;
}

.prep-screen h2 {
  margin: clamp(30px, 5vh, 56px) 0 0;
  font-size: clamp(32px, 5vw, 68px);
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 1;
}

.prep-screen > p:not(.eyebrow) {
  margin: 16px 0 0;
  color: #aeb0c1;
  font-size: clamp(14px, 1.7vw, 20px);
}

.start-screen__orb {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(150px, 23vmin, 250px);
  aspect-ratio: 1;
  margin-bottom: clamp(24px, 4vh, 44px);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(105, 72, 220, 0.52), rgba(23, 19, 57, 0.58) 55%, rgba(10, 10, 24, 0.2) 70%);
  box-shadow: 0 0 90px rgba(139, 92, 246, 0.25), inset 0 0 40px rgba(125, 223, 255, 0.08);
}

.start-screen__orb > span {
  position: absolute;
  inset: -11%;
  border: 1px solid rgba(139, 92, 246, 0.23);
  border-radius: 48% 52% 45% 55%;
  animation: orbit 8s linear infinite;
}

.start-screen__orb > span:nth-child(2) {
  inset: -20%;
  border-color: rgba(34, 211, 238, 0.12);
  animation-duration: 12s;
  animation-direction: reverse;
}

.start-screen__orb > span:nth-child(3) {
  inset: 8%;
  border-color: rgba(244, 63, 158, 0.19);
  animation-duration: 6s;
}

.start-screen__mic {
  position: relative;
  width: 54px;
  height: 82px;
}

.start-screen__mic-head {
  position: absolute;
  top: 0;
  left: 12px;
  width: 30px;
  height: 50px;
  border: 4px solid white;
  border-radius: 18px;
}

.start-screen__mic::before {
  content: "";
  position: absolute;
  top: 23px;
  left: 4px;
  width: 46px;
  height: 38px;
  border: 4px solid white;
  border-top: 0;
  border-radius: 0 0 26px 26px;
}

.start-screen__mic-stem {
  position: absolute;
  left: 25px;
  bottom: 0;
  width: 4px;
  height: 22px;
  border-radius: 4px;
  background: white;
}

.start-screen__mic-stem::after {
  content: "";
  position: absolute;
  left: -11px;
  bottom: 0;
  width: 26px;
  height: 4px;
  border-radius: 4px;
  background: white;
}

.start-screen h2,
.error-screen h2 {
  margin: 0;
  font-size: clamp(42px, 7vw, 92px);
  font-weight: 900;
  letter-spacing: -0.065em;
  line-height: 0.92;
}

.start-screen > p:not(.eyebrow) {
  margin: clamp(20px, 3vh, 34px) 0 0;
  color: #b1b3c5;
  font-size: clamp(16px, 2vw, 24px);
}

.tap-cue {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-top: clamp(24px, 4vh, 46px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
}

.tap-cue span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 0 0 9px rgba(255, 255, 255, 0.06);
  animation: tap 1.65s ease-out infinite;
}

.result-screen {
  background:
    radial-gradient(circle at 50% 32%, rgba(244, 63, 158, 0.24), transparent 32%),
    radial-gradient(circle at 50% 70%, rgba(34, 211, 238, 0.1), transparent 38%),
    rgba(5, 6, 16, 0.95);
}

.result-screen__emoji {
  margin: 0 0 clamp(4px, 1vh, 12px);
  font-size: clamp(68px, 11vmin, 132px);
  line-height: 1;
  filter: drop-shadow(0 16px 30px rgba(244, 63, 158, 0.22));
  animation: result-pop 0.7s cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}

.result-screen__score {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  line-height: 0.78;
}

.result-screen__score strong {
  color: transparent;
  background: linear-gradient(115deg, #fff 8%, #bca7ff 43%, #6ee7ff 70%, #ff86c7);
  background-clip: text;
  -webkit-background-clip: text;
  font-size: clamp(105px, 22vmin, 250px);
  font-weight: 950;
  letter-spacing: -0.1em;
}

.result-screen__score span {
  margin: 0 0 0.14em 0.25em;
  color: #a8aabb;
  font-size: clamp(20px, 3vmin, 36px);
  font-weight: 800;
}

.result-screen h2 {
  margin: clamp(18px, 3vh, 32px) 0 0;
  font-size: clamp(36px, 5.5vw, 76px);
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 0.98;
}

.result-screen__caption {
  margin: 14px 0 0;
  color: #a4a6b9;
  font-size: clamp(14px, 1.7vw, 20px);
}

.countdown {
  position: absolute;
  left: 50%;
  bottom: var(--safe-bottom);
  display: grid;
  width: min(520px, calc(100% - 48px));
  gap: 11px;
  color: #7f8298;
  font-size: 12px;
  transform: translateX(-50%);
}

.countdown__track {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
}

.countdown__track i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(to right, var(--violet), var(--cyan), var(--pink));
  transform-origin: left;
}

.result-screen.overlay--visible .countdown__track i {
  animation: countdown var(--result-duration, 5000ms) linear forwards;
}

.error-screen__icon {
  display: grid;
  place-items: center;
  width: clamp(90px, 15vmin, 150px);
  aspect-ratio: 1;
  margin-bottom: clamp(22px, 4vh, 44px);
  border: 1px solid rgba(244, 63, 158, 0.32);
  border-radius: 50%;
  color: #ff9acc;
  background: rgba(244, 63, 158, 0.08);
  box-shadow: 0 0 70px rgba(244, 63, 158, 0.18);
  font-size: clamp(48px, 8vmin, 82px);
  font-weight: 250;
}

.error-screen h2 {
  max-width: 900px;
  font-size: clamp(38px, 6vw, 74px);
}

.error-screen > p:not(.eyebrow) {
  max-width: 700px;
  margin: 20px 0 0;
  color: #aeb0c1;
  font-size: clamp(15px, 1.8vw, 21px);
  line-height: 1.45;
}

.retry-label {
  margin-top: clamp(28px, 5vh, 52px);
  padding: 13px 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: #d4d5e1;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
  font-weight: 700;
}

@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes tap { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.22); } 70%, 100% { box-shadow: 0 0 0 20px rgba(255, 255, 255, 0); } }
@keyframes blink { to { opacity: 0.45; transform: scale(0.82); } }
@keyframes result-pop { from { opacity: 0; transform: scale(0.5) rotate(-12deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes countdown { to { transform: scaleX(0); } }

@media (orientation: portrait) {
  .meter-screen {
    grid-template-rows: auto minmax(0, 0.86fr) minmax(230px, 1.25fr) auto;
  }

  .meter {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(130px, 1fr) auto;
    gap: 8px;
  }

  .equalizer-stage { grid-row: 1; }
  .reading { grid-row: 2; justify-self: center; }
}

@media (max-width: 560px) {
  .meter-screen {
    gap: 10px;
    padding-inline: 15px;
  }

  .brand { font-size: 9px; gap: 8px; }
  .live-badge { min-width: auto; padding: 9px 11px; font-size: 10px; }
  .hero-copy h1 { font-size: clamp(32px, 11vw, 48px); }
  .instruction { margin-top: 10px; font-size: 12px; }
  .meter { border-radius: 22px; padding: 14px 13px 10px; }
  .equalizer-stage { gap: 6px; }
  .equalizer { gap: 3px; }
  .level-axis { font-size: 7px; }
  .reading__value { font-size: clamp(68px, 23vw, 110px); }
  .start-round-button { min-height: 48px; }
  .footer-hint { font-size: 10px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .meter-screen {
    grid-template-columns: minmax(260px, 0.7fr) minmax(420px, 1.3fr);
    grid-template-rows: auto 1fr auto;
    gap: 12px 26px;
    padding-top: 16px;
    padding-bottom: 14px;
  }

  .topbar { grid-column: 1 / -1; }
  .hero-copy { align-self: center; text-align: left; }
  .hero-copy h1 { font-size: clamp(34px, 5vw, 58px); }
  .hero-copy .instruction { margin-left: 0; font-size: 13px; }
  .meter { align-self: stretch; min-height: 0; }
  .footer-actions { grid-column: 1 / -1; grid-template-columns: auto auto; align-items: center; gap: 18px; }
  .start-round-button { min-width: 160px; min-height: 46px; padding-left: 20px; }
  .start-round-button i { width: 32px; height: 32px; }
  .start-screen__orb { width: 112px; margin-bottom: 16px; }
  .start-screen h2 { font-size: 48px; }
  .start-screen > p:not(.eyebrow) { margin-top: 12px; font-size: 15px; }
  .tap-cue { width: 42px; height: 42px; margin-top: 14px; }
  .prep-screen strong { font-size: 116px; }
  .prep-screen h2 { margin-top: 14px; font-size: 38px; }
  .prep-screen > p:not(.eyebrow) { margin-top: 8px; font-size: 13px; }
  .result-screen__emoji { font-size: 58px; }
  .result-screen__score strong { font-size: 112px; }
  .result-screen h2 { margin-top: 10px; font-size: 40px; }
  .result-screen__caption { margin-top: 8px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
