/* Sizes follow --ring-radius, which ring.js sets to suit the screen */
:root {
  --ring-radius: 18vmin;
}

html, body {
  height: 100%;
  margin: 0;
  background: #02031a;
  overflow: hidden;
}

main {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Covers the page, so a click or tap anywhere stops Ayra while it's talking or thinking */
.stop {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.stop:focus-visible {
  outline: 2px solid #4b4a8a;
  outline-offset: -8px;
}

/* The title and status sit together inside the ring, clear of the ribbons when they stretch */
.center {
  position: relative;
  display: grid;
  justify-items: center;
  gap: calc(var(--ring-radius) * 0.07);
  pointer-events: none;
}

h1 {
  position: relative;
  margin: 0;
  /* --breath and --glow are set by ring.js every frame, in time with the ring */
  transform: scale(var(--breath, 1));
  text-shadow:
    0 0 calc(var(--glow, 0.25) * var(--ring-radius) * 0.09) rgba(22, 242, 230, calc(var(--glow, 0.25) * 0.55)),
    0 0 calc(var(--glow, 0.25) * var(--ring-radius) * 0.2) rgba(164, 79, 242, calc(var(--glow, 0.25) * 0.35));
  color: #d9d4f5;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: calc(var(--ring-radius) * 0.28);
  font-weight: 100;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Status pill: a small animated indicator and a label for what Ayra is doing */
.status {
  --dot: #6f7bd8;
  display: inline-flex;
  align-items: center;
  gap: 0.7em;
  margin: 0;
  padding: 0.5em 1em 0.5em 0.85em;
  border: 1px solid rgba(160, 150, 255, 0.16);
  border-radius: 999px;
  background: rgba(120, 110, 230, 0.07);
  color: #aeb0dc;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: clamp(10px, calc(var(--ring-radius) * 0.072), 14px);
  font-weight: 400;
  letter-spacing: 0.22em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.4s ease;
  box-shadow: 0 0 calc(var(--glow, 0.25) * 18px) rgba(120, 110, 230, calc(var(--glow, 0.25) * 0.25));
}

.status.changing {
  opacity: 0;
  transform: translateY(0.35em);
}

.status[data-state="listening"] { --dot: #16f2e6; border-color: rgba(22, 242, 230, 0.22); }
.status[data-state="thinking"] { --dot: #a44ff2; border-color: rgba(164, 79, 242, 0.25); }
.status[data-state="speaking"] { --dot: #7f8cff; border-color: rgba(127, 140, 255, 0.28); }
.status[data-state="on_call"] { --dot: #5fe39a; border-color: rgba(95, 227, 154, 0.22); }
.status[data-state="offline"] { --dot: #5b5f7a; color: #7c7fa0; }

.indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 1.5em;
  height: 1.1em;
}

.indicator i {
  width: 0.36em;
  height: 0.36em;
  border-radius: 50%;
  background: var(--dot);
  transition: background 0.4s ease;
}

/* One dot for the calm states */
.status:is([data-state="listening"], [data-state="starting"], [data-state="on_call"], [data-state="offline"]) .indicator i:not(:first-child) {
  display: none;
}

/* Listening: a soft pulse with a ripple */
.status[data-state="listening"] .indicator i {
  width: 0.46em;
  height: 0.46em;
  animation: pulse 1.6s ease-in-out infinite;
}

/* Waking up: a slow fade */
.status[data-state="starting"] .indicator i {
  animation: fade 1.4s ease-in-out infinite;
}

/* Working: three dots taking turns */
.status[data-state="thinking"] .indicator i {
  animation: bounce 1.1s ease-in-out infinite;
}
.status[data-state="thinking"] .indicator i:nth-child(2) { animation-delay: 0.15s; }
.status[data-state="thinking"] .indicator i:nth-child(3) { animation-delay: 0.3s; }

/* Speaking: three moving sound bars */
.status[data-state="speaking"] .indicator i {
  width: 0.2em;
  height: 1em;
  border-radius: 0.1em;
  transform-origin: center;
  animation: bars 0.9s ease-in-out infinite;
}
.status[data-state="speaking"] .indicator i:nth-child(2) { animation-delay: 0.2s; }
.status[data-state="speaking"] .indicator i:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 100% { transform: scale(0.85); box-shadow: 0 0 0 0 rgba(22, 242, 230, 0.45); }
  50% { transform: scale(1); box-shadow: 0 0 0 0.45em rgba(22, 242, 230, 0); }
}

@keyframes fade {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-0.35em); opacity: 1; }
}

@keyframes bars {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}

/* Camera mode: the camera fills the screen, the ring shrinks to a glow at the bottom (ring.js moves it),
   the title steps aside and the status moves to the top, so nothing covers what the user is pointing at */
.camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.camera.mirrored {
  transform: scaleX(-1);  /* The front camera looks like a mirror, as people expect */
}

.camera-on .camera {
  opacity: 1;
}

/* Darkens the bottom, so the ring and buttons stand out against a bright scene */
.camera-on main::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 38%;
  background: linear-gradient(transparent, rgba(2, 3, 26, 0.75));
  pointer-events: none;
}

/* A small crosshair marks the middle, which is what "this" means */
.aim {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 12px rgba(22, 242, 230, 0.5);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.aim::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #fff;
}

.camera-on .aim {
  opacity: 1;
  transform: scale(1);
}

canvas {
  z-index: 1;
}

.center {
  z-index: 1;
  transition: opacity 0.4s ease;
}

.camera-on .center {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
}

.camera-on h1 {
  display: none;
}

.camera-on .status {
  background: rgba(2, 3, 26, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stop {
  z-index: 2;
}

/* Round buttons in the bottom corner, above the stop area that covers the page */
.controls {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  gap: 12px;
}

.control {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid rgba(160, 150, 255, 0.25);
  border-radius: 50%;
  background: rgba(20, 22, 60, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #d9d4f5;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
}

.control[hidden] {
  display: none;
}

.control:hover {
  border-color: rgba(22, 242, 230, 0.5);
}

.control:active {
  transform: scale(0.94);
}

.control:focus-visible {
  outline: 2px solid #16f2e6;
  outline-offset: 3px;
}

.control svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control[aria-pressed="true"] {
  border-color: rgba(22, 242, 230, 0.6);
  background: rgba(22, 242, 230, 0.18);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .status, .indicator i { transition: none; animation: none !important; }
  .camera, .aim, .center, .control { transition: none; }
}

/* Start screen: browsers only allow the mic and sound after a tap */
.start {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding-top: calc(var(--ring-radius) * 1.25);  /* Below the title, inside the ring */
  background: rgba(2, 3, 26, 0.35);
}

.start[hidden] {
  display: none;
}

.start-button,
.login button {
  padding: 0.85em 1.8em;
  border: 1px solid rgba(22, 242, 230, 0.5);
  border-radius: 999px;
  background: rgba(22, 242, 230, 0.12);
  color: #e6e3ff;
  font: 400 15px "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(22, 242, 230, 0.18);
  transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.15s ease;
}

.start-button:hover,
.login button:hover {
  background: rgba(22, 242, 230, 0.2);
  box-shadow: 0 0 32px rgba(22, 242, 230, 0.3);
}

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

.start-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.start-button:focus-visible,
.login button:focus-visible,
.login input:focus-visible {
  outline: 2px solid #16f2e6;
  outline-offset: 3px;
}

.start-note {
  margin: 0;
  max-width: 20em;
  color: #8d90bf;
  font: 400 13px "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-align: center;
}

/* Sign-in page */
.login-page main {
  background: radial-gradient(circle at 50% 45%, rgba(63, 111, 230, 0.16), transparent 55%);
}

.login {
  display: grid;
  gap: 12px;
  width: min(320px, 86vw);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.login h1 {
  margin-bottom: 18px;
  font-size: 44px;
  text-align: center;
  transform: none;
}

.login label {
  color: #8d90bf;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.login input {
  padding: 0.8em 1em;
  border: 1px solid rgba(160, 150, 255, 0.25);
  border-radius: 12px;
  background: rgba(20, 22, 60, 0.6);
  color: #e6e3ff;
  font-size: 16px;  /* 16px stops phones zooming in on the field */
}

.login-error {
  margin: 0;
  color: #ff8fa3;
  font-size: 14px;
}

.login button {
  margin-top: 8px;
}
