:root {
  color-scheme: light;
  --sand: #e8d8bd;
  --sand-deep: #d8c29f;
  --ink: #244b4a;
  --warm-green: #78b998;
  --soft-amber: #c88a32;
  --progress: 0deg;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--sand);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.44), transparent 48%),
    var(--sand);
  outline: none;
}

.card {
  position: relative;
  display: grid;
  width: min(76vmin, 34rem);
  height: min(76vmin, 34rem);
  place-items: center;
  border-radius: 50%;
  font-size: clamp(8rem, 40vmin, 22rem);
  line-height: 1;
  filter: drop-shadow(0 1.1rem 1.4rem rgba(70, 55, 35, 0.12));
  transform: translateZ(0);
  transition: filter 240ms ease, opacity 240ms ease;
  cursor: pointer;
}

.tap-hint {
  position: absolute;
  left: 50%;
  bottom: max(7vh, calc(env(safe-area-inset-bottom) + 1.5rem));
  width: 1.05rem;
  height: 1.05rem;
  border: 0.18rem solid rgba(36, 75, 74, 0.55);
  border-radius: 50%;
  transform: translateX(-50%);
  animation: hint-pulse 2.2s ease-out infinite;
}

.is-listening .card {
  animation: breathe 1.65s ease-in-out infinite;
}

.is-listening .card::before,
.is-did-not-hear .card::before {
  position: absolute;
  inset: 1.5%;
  border: clamp(0.32rem, 1.3vmin, 0.58rem) solid rgba(36, 75, 74, 0.72);
  border-radius: 50%;
  box-shadow:
    0 0 0 clamp(0.35rem, 1.5vmin, 0.75rem) rgba(120, 185, 152, 0.18),
    0 0 clamp(1.4rem, 6vmin, 3rem) rgba(36, 75, 74, 0.32);
  content: "";
  pointer-events: none;
  animation: listening-ring 1.2s ease-out infinite;
}

.is-did-not-hear .card::before {
  animation: did-not-hear-ring 650ms ease-out both;
}

.listening-meter {
  position: absolute;
  left: 50%;
  bottom: max(8vh, calc(env(safe-area-inset-bottom) + 2rem));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.35rem, 1.6vmin, 0.72rem);
  width: min(44vmin, 13rem);
  height: clamp(2.6rem, 11vmin, 4.8rem);
  opacity: 0;
  transform: translateX(-50%) translateY(0.7rem);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}

.is-listening .listening-meter {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.listening-bar {
  --level: 0.16;
  width: clamp(0.48rem, 2.1vmin, 0.88rem);
  height: 100%;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 0 0.7rem rgba(36, 75, 74, 0.26);
  transform: scaleY(var(--level));
  transition: transform 70ms linear;
  transform-origin: center;
}

.result-cue {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  opacity: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Symbol", sans-serif;
  font-weight: 700;
  line-height: 1;
  transform: scale(0.72);
  pointer-events: none;
}

.result-cue.is-visible {
  animation: result-cue 900ms cubic-bezier(.2, .85, .3, 1) both;
}

.result-cue.is-pass {
  color: #3d9a68;
  font-size: clamp(11rem, 48vmin, 25rem);
  text-shadow:
    0 0 1.7rem rgba(83, 177, 124, 0.9),
    0 0 5rem rgba(120, 185, 152, 0.58);
}

.result-cue.is-miss {
  color: var(--soft-amber);
  font-size: clamp(10rem, 43vmin, 23rem);
  text-shadow:
    0 0 1.5rem rgba(200, 138, 50, 0.48),
    0 0 4.5rem rgba(219, 173, 101, 0.34);
}

.is-playing .tap-hint,
.is-listening .tap-hint,
.is-scoring .tap-hint,
.is-did-not-hear .tap-hint,
.is-result .tap-hint,
.is-celebrating .tap-hint,
.is-neutral .tap-hint {
  opacity: 0;
}

.is-celebrating .card {
  animation: happy-bounce 720ms cubic-bezier(.22, .9, .3, 1.2);
  filter:
    drop-shadow(0 0 2.8rem rgba(83, 177, 124, 0.92))
    drop-shadow(0 0 6rem rgba(120, 185, 152, 0.6));
}

.is-neutral .card {
  animation: neutral-fade 480ms ease-in-out both;
}

.is-sunset {
  background: radial-gradient(circle at 50% 68%, #f6b66c 0 8%, #df8d68 24%, #8a789a 72%, #53617c 100%) !important;
  animation: sunset-arrive 1.2s ease-out both;
}

.is-sunset .card {
  animation: sunset-float 3s ease-in-out infinite;
}

.mic-help {
  position: absolute;
  display: none;
  place-items: center;
  width: 100%;
  height: 100%;
  background: var(--sand);
  font-size: clamp(6rem, 28vmin, 15rem);
  cursor: pointer;
}

.needs-mic .card,
.needs-mic .tap-hint {
  display: none;
}

.needs-mic .mic-help {
  display: grid;
}

.cache-progress {
  position: absolute;
  z-index: 8;
  display: none;
  width: min(25vmin, 8rem);
  aspect-ratio: 1;
  border: 0.35rem solid rgba(36, 75, 74, 0.2);
  border-radius: 50%;
  background: conic-gradient(var(--ink) var(--progress), rgba(255, 255, 255, 0.35) 0);
  box-shadow: 0 0 0 100vmax rgba(232, 216, 189, 0.94);
}

.is-caching .cache-progress {
  display: block;
}

.maintenance {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: none;
  grid-template-rows: auto auto auto 1fr;
  gap: 2rem;
  padding: max(9vh, calc(env(safe-area-inset-top) + 2rem)) 7vw max(6vh, calc(env(safe-area-inset-bottom) + 1rem));
  background: var(--sand);
}

.maintenance.is-open {
  display: grid;
}

.maintenance-tools {
  display: flex;
  justify-content: center;
  gap: clamp(1rem, 6vw, 3.5rem);
}

.maintenance button {
  display: grid;
  width: clamp(4.8rem, 19vmin, 8rem);
  aspect-ratio: 1;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0.6rem 1.4rem rgba(70, 55, 35, 0.12);
  font: inherit;
  font-size: clamp(2.2rem, 10vmin, 4.2rem);
  cursor: pointer;
}

.maintenance button:active {
  transform: scale(0.93);
}

.version-dots {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
}

.version-dot {
  width: 0.45rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.72;
}

.attempt-diagnostics {
  min-height: 5.5em;
  direction: ltr;
  color: rgba(35, 28, 20, 0.72);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: clamp(0.58rem, 2.2vmin, 0.72rem);
  line-height: 1.1;
  text-align: center;
}

.progress-grid {
  align-self: center;
  display: grid;
  grid-template-columns: repeat(19, minmax(0.35rem, 1fr));
  gap: clamp(0.2rem, 0.8vmin, 0.45rem);
  max-width: 38rem;
  width: 100%;
  margin: auto;
}

.progress-dot {
  aspect-ratio: 1;
  border: 1px solid rgba(36, 75, 74, 0.28);
  border-radius: 50%;
}

.progress-dot.is-mastered {
  border-color: var(--ink);
  background: var(--ink);
}

@keyframes hint-pulse {
  0% { opacity: 0.72; transform: translateX(-50%) scale(0.62); }
  75%, 100% { opacity: 0; transform: translateX(-50%) scale(2.5); }
}

@keyframes breathe {
  0%, 100% { transform: scale(0.93); }
  50% { transform: scale(1.05); }
}

@keyframes listening-ring {
  0% { opacity: 0.44; transform: scale(0.9); }
  48% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.12); }
}

@keyframes did-not-hear-ring {
  0% { opacity: 0; transform: scale(0.86); }
  42% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0; transform: scale(1.16); }
}

@keyframes result-cue {
  0% { opacity: 0; transform: scale(0.72); }
  18% { opacity: 1; transform: scale(1.06); }
  36%, 72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.96); }
}

@keyframes happy-bounce {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-5vh) scale(1.08); }
  65% { transform: translateY(0) scale(0.96); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes neutral-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.28; }
}

@keyframes sunset-arrive {
  from { filter: brightness(1.25); }
  to { filter: brightness(1); }
}

@keyframes sunset-float {
  0%, 100% { transform: translateY(1vh); }
  50% { transform: translateY(-2vh); }
}

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

  .is-listening .card::before,
  .is-did-not-hear .card::before {
    opacity: 1;
    transform: none;
  }

  .result-cue.is-visible {
    animation: none !important;
    opacity: 1;
    transform: none;
  }
}
