:root {
  color-scheme: dark;
  --bg: #101214;
  --bg-soft: #171a1d;
  --text: #f1f4f4;
  --muted: #8d969b;
  --cool: #b8ecff;
  --cool-strong: #66d8ff;
  --warm: #f5c478;
  --danger: #ef7e72;
  --focus: rgba(184, 236, 255, 0.62);
  --panel: rgba(17, 20, 22, 0.86);
  --panel-border: rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 45%, rgba(42, 49, 53, 0.72), transparent 34rem),
    linear-gradient(145deg, #0f1113 0%, var(--bg-soft) 52%, #0d0f10 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: 4rem 1rem;
  isolation: isolate;
}

.app-shell::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(circle at center, black, transparent 72%);
}

.signal-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.activation-stage {
  display: grid;
  width: min(92vw, 34rem);
  place-items: center;
  text-align: center;
}

.settings-button {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 20;
  display: grid;
  width: 2.75rem;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(184, 236, 255, 0.14);
  border-radius: 50%;
  background: rgba(14, 17, 19, 0.58);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 1rem 2.4rem rgba(0, 0, 0, 0.25);
  color: rgba(241, 244, 244, 0.84);
  cursor: pointer;
  line-height: 1;
  backdrop-filter: blur(16px);
  transition:
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.settings-button span {
  display: block;
  font-size: 1.18rem;
  transform: translateY(-0.02rem);
}

.settings-button:hover,
.settings-button[aria-expanded="true"] {
  border-color: rgba(184, 236, 255, 0.34);
  background: rgba(20, 25, 28, 0.72);
  color: var(--text);
  transform: translateY(-1px);
}

.settings-button:focus-visible,
.settings-close:focus-visible,
.setting-range:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 21;
  background: rgba(4, 6, 7, 0.4);
  backdrop-filter: blur(2px);
}

.settings-panel {
  position: fixed;
  top: max(4.5rem, calc(env(safe-area-inset-top) + 4.5rem));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 22;
  display: grid;
  width: min(24rem, calc(100vw - 2rem));
  gap: 1.35rem;
  padding: 1.15rem;
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 36%),
    var(--panel);
  box-shadow:
    0 1.5rem 4rem rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(255, 255, 255, 0.025) inset;
  backdrop-filter: blur(24px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.35rem) scale(0.985);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.settings-panel[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.settings-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 620;
}

.settings-close {
  display: grid;
  width: 2.2rem;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.setting-row {
  display: grid;
  gap: 0.72rem;
}

.setting-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 560;
}

.setting-title output {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 520;
}

.setting-range {
  width: 100%;
  accent-color: var(--cool);
  cursor: pointer;
}

.range-labels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  color: rgba(184, 192, 195, 0.72);
  font-size: 0.72rem;
  line-height: 1.25;
}

.range-labels span:nth-child(2) {
  text-align: center;
}

.range-labels span:nth-child(3) {
  text-align: right;
}

.voice-core {
  position: relative;
  display: grid;
  width: clamp(12rem, 32vw, 18rem);
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(184, 236, 255, 0.18);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 43%, rgba(255, 255, 255, 0.16), transparent 18%),
    radial-gradient(circle, rgba(102, 216, 255, 0.16), rgba(16, 18, 20, 0.96) 62%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.035) inset,
    0 2rem 5rem rgba(0, 0, 0, 0.42),
    0 0 5rem rgba(102, 216, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.voice-core:hover {
  transform: translateY(-2px) scale(1.012);
  border-color: rgba(184, 236, 255, 0.34);
}

.voice-core:focus-visible {
  box-shadow:
    0 0 0 3px var(--focus),
    0 2rem 5rem rgba(0, 0, 0, 0.42),
    0 0 5rem rgba(102, 216, 255, 0.16);
}

.voice-core::before,
.voice-core::after {
  position: absolute;
  inset: -1.2rem;
  content: "";
  border: 1px solid rgba(184, 236, 255, 0.16);
  border-radius: inherit;
  animation: breathe 5.4s ease-in-out infinite;
}

.voice-core::after {
  inset: -2.5rem;
  border-color: rgba(245, 196, 120, 0.12);
  animation-duration: 7.2s;
  animation-delay: -1.6s;
}

.core-glow {
  position: absolute;
  inset: 18%;
  border-radius: inherit;
  background: radial-gradient(circle, rgba(184, 236, 255, 0.14), transparent 62%);
  filter: blur(0.3rem);
}

.core-name {
  position: relative;
  font-size: clamp(2.7rem, 8vw, 5.8rem);
  font-weight: 620;
  line-height: 1;
}

.core-state {
  position: absolute;
  bottom: 25%;
  color: var(--muted);
  font-size: clamp(0.86rem, 2vw, 1rem);
  font-weight: 520;
  letter-spacing: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell[data-state="listening"] .voice-core {
  border-color: rgba(102, 216, 255, 0.5);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 2rem 5rem rgba(0, 0, 0, 0.42),
    0 0 7rem rgba(102, 216, 255, 0.25);
}

.app-shell[data-state="thinking"] .voice-core {
  border-color: rgba(245, 196, 120, 0.42);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 2rem 5rem rgba(0, 0, 0, 0.42),
    0 0 7rem rgba(245, 196, 120, 0.2);
}

.app-shell[data-state="speaking"] .voice-core {
  border-color: rgba(184, 236, 255, 0.58);
}

.app-shell[data-state="error"] .voice-core {
  border-color: rgba(239, 126, 114, 0.52);
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.42;
    transform: scale(0.98);
  }

  50% {
    opacity: 0.92;
    transform: scale(1.04);
  }
}

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

@media (max-width: 560px) {
  .app-shell {
    padding: 3rem 1rem;
  }

  .settings-button {
    top: max(0.85rem, env(safe-area-inset-top));
    right: max(0.85rem, env(safe-area-inset-right));
    width: 2.65rem;
  }

  .settings-backdrop {
    background: rgba(4, 6, 7, 0.34);
  }

  .settings-panel {
    top: auto;
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    left: max(0.75rem, env(safe-area-inset-left));
    width: auto;
    padding: 1rem;
    border-radius: 1rem;
    transform: translateY(1rem);
  }

  .settings-panel[data-open="true"] {
    transform: none;
  }
}
