html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
  user-select: none;
}

#screen-cloak {
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#screen-cloak:not([hidden]) {
  display: flex;
}

/* ---------- LLM subtitle (kept for JS echo detection, hidden from view) ----- */

#llm-text {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90vw;
  min-height: 1.2em;
  color: #555;
  font-size: 12px;
  font-family: system-ui, sans-serif;
  text-align: center;
  line-height: 1.4;
  overflow-wrap: break-word;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
}

/* ---------- Center breathing orb ------------------------------------------ */

#orb-stage {
  flex: 1;
  display: grid;
  place-items: center;
  width: 100%;
}

#status-orb {
  position: relative;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

#status-orb .orb-halo,
#status-orb .orb-ring,
#status-orb .orb-core {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

#status-orb .orb-halo {
  width: 100%;
  height: 100%;
  opacity: 0.55;
  filter: blur(18px);
  transition: background 600ms ease, opacity 600ms ease;
}

#status-orb .orb-ring {
  width: 72%;
  height: 72%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  transition: border-color 600ms ease;
}

#status-orb .orb-core {
  width: 44%;
  height: 44%;
  filter: blur(6px);
  transition: background 600ms ease, opacity 600ms ease;
  animation: orb-breathe 5.5s ease-in-out infinite;
}

@keyframes orb-breathe {
  0%, 100% {
    transform: scale(0.86);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.85;
  }
}

/* idle / disconnected — almost invisible, dim warm gray */
#status-orb[data-state="idle"] .orb-halo {
  background: radial-gradient(circle, rgba(60, 50, 46, 0.35), transparent 70%);
}
#status-orb[data-state="idle"] .orb-core {
  background: radial-gradient(circle, rgba(80, 64, 56, 0.5), transparent 70%);
}

/* connecting — subtle warm pulse */
#status-orb[data-state="connecting"] .orb-halo {
  background: radial-gradient(circle, rgba(120, 96, 36, 0.4), transparent 70%);
  animation: orb-pulse 2.4s ease-in-out infinite;
}
#status-orb[data-state="connecting"] .orb-core {
  background: radial-gradient(circle, rgba(150, 116, 44, 0.6), transparent 70%);
}

/* listening — low-luminance blue-green, slow breath */
#status-orb[data-state="listening"] .orb-halo {
  background: radial-gradient(circle, rgba(32, 86, 74, 0.5), transparent 70%);
  animation: orb-pulse 3.2s ease-in-out infinite;
}
#status-orb[data-state="listening"] .orb-core {
  background: radial-gradient(circle, rgba(58, 128, 108, 0.7), transparent 70%);
}
#status-orb[data-state="listening"] .orb-ring {
  border-color: rgba(58, 128, 108, 0.18);
}

/* recording — brighter blue-green, faster breath (speech detected) */
#status-orb[data-state="recording"] .orb-halo {
  background: radial-gradient(circle, rgba(44, 110, 94, 0.62), transparent 70%);
  animation: orb-pulse 1.6s ease-in-out infinite;
}
#status-orb[data-state="recording"] .orb-core {
  background: radial-gradient(circle, rgba(80, 158, 132, 0.82), transparent 70%);
}
#status-orb[data-state="recording"] .orb-ring {
  border-color: rgba(80, 158, 132, 0.26);
}

/* processing — gentle amber, inner pulse */
#status-orb[data-state="processing"] .orb-halo {
  background: radial-gradient(circle, rgba(120, 80, 28, 0.45), transparent 70%);
  animation: orb-pulse 2s ease-in-out infinite;
}
#status-orb[data-state="processing"] .orb-core {
  background: radial-gradient(circle, rgba(156, 108, 40, 0.7), transparent 70%);
}
#status-orb[data-state="processing"] .orb-ring {
  border-color: rgba(156, 108, 40, 0.2);
  animation: orb-rotate 6s linear infinite;
}

/* speaking — soft warm violet */
#status-orb[data-state="speaking"] .orb-halo {
  background: radial-gradient(circle, rgba(74, 54, 108, 0.5), transparent 70%);
  animation: orb-pulse 2.6s ease-in-out infinite;
}
#status-orb[data-state="speaking"] .orb-core {
  background: radial-gradient(circle, rgba(120, 86, 156, 0.7), transparent 70%);
}
#status-orb[data-state="speaking"] .orb-ring {
  border-color: rgba(120, 86, 156, 0.2);
}

/* error — brief dim red blink, not harsh */
#status-orb[data-state="error"] .orb-halo {
  background: radial-gradient(circle, rgba(120, 28, 28, 0.5), transparent 70%);
  animation: orb-blink 1.4s ease-in-out infinite;
}
#status-orb[data-state="error"] .orb-core {
  background: radial-gradient(circle, rgba(160, 44, 44, 0.7), transparent 70%);
}
#status-orb[data-state="error"] .orb-ring {
  border-color: rgba(160, 44, 44, 0.22);
}

@keyframes orb-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.8; }
}

@keyframes orb-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes orb-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.75; }
}

/* ---------- Bottom control panel ------------------------------------------- */

#control-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 44px;
}

#connect-button {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 20, 22, 0.7);
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
}

#connect-button:hover {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(28, 28, 30, 0.8);
}

#connect-button:active {
  transform: scale(0.96);
}

#connect-button .btn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  transition: background 200ms ease;
  pointer-events: none;
}

#connect-button[data-connected="true"] .btn-dot {
  background: rgba(80, 140, 120, 0.55);
}

#connect-button .press-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

#connect-button.is-pressing .press-ring {
  opacity: 1;
}

#connect-button .ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 2;
}

#connect-button .ring-fill {
  fill: none;
  stroke: rgba(180, 120, 120, 0.6);
  stroke-width: 2;
  stroke-linecap: round;
  /* r=36 → circumference ≈ 226.19 */
  stroke-dasharray: 226.19;
  stroke-dashoffset: 226.19;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 2000ms linear;
}

#connect-button.is-pressing .ring-fill {
  stroke-dashoffset: 0;
}

#status-text {
  margin: 0;
  min-width: 96px;
  text-align: center;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.02em;
}

/* ---------- Mobile adjustments -------------------------------------------- */

@media (max-width: 640px) {
  #status-orb {
    width: 156px;
    height: 156px;
  }

  #connect-button {
    width: 72px;
    height: 72px;
  }

  #control-panel {
    margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 32px);
  }

  #status-text {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #status-orb .orb-core,
  #status-orb[data-state="connecting"] .orb-halo,
  #status-orb[data-state="listening"] .orb-halo,
  #status-orb[data-state="recording"] .orb-halo,
  #status-orb[data-state="processing"] .orb-halo,
  #status-orb[data-state="speaking"] .orb-halo,
  #status-orb[data-state="error"] .orb-halo,
  #status-orb[data-state="processing"] .orb-ring {
    animation: none;
  }
}
