:root {
  --bg: #05070a;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --accent: #2f81f7;
  --purple: #a371f7;
  --pink: #f778ba;
  --gold: #ffd700;
  --red: #f85149;
  --green: #3fb950;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}

.ui-layer > * { pointer-events: auto; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(13, 17, 23, 0.72);
  border: 1px solid rgba(47, 129, 247, 0.25);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 0.3s ease, color 0.3s ease;
}

.status-pill[data-state="listening"] { border-color: rgba(63, 185, 80, 0.45); color: #7ee787; }
.status-pill[data-state="thinking"] { border-color: rgba(163, 113, 247, 0.45); color: #d2a8ff; }
.status-pill[data-state="speaking"] { border-color: rgba(247, 120, 186, 0.45); color: #ffaed7; }
.status-pill[data-state="error"] { border-color: rgba(248, 81, 73, 0.55); color: #ff7b72; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.status-pill[data-state="listening"] .status-dot,
.status-pill[data-state="speaking"] .status-dot {
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.65; }
}

.fps-badge {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(13, 17, 23, 0.72);
  border-radius: 999px;
  padding: 6px 10px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fps-badge.visible { opacity: 1; }

.permission-sheet,
.notice-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(5, 7, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.permission-sheet.active,
.notice-sheet.active {
  opacity: 1;
  pointer-events: auto;
}

.sheet-card {
  width: min(360px, 100%);
  background: rgba(13, 17, 23, 0.95);
  border: 1px solid rgba(47, 129, 247, 0.22);
  border-radius: 18px;
  padding: 26px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.sheet-card h2 {
  font-size: 20px;
  margin-bottom: 10px;
  font-weight: 600;
}

.sheet-card p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.sheet-card .btn {
  width: 100%;
  margin-top: 8px;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding-bottom: 24px;
}

.mic-button {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, #3b91ff, #1f6feb 55%, #0d3a85 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(47, 129, 247, 0.45),
              0 12px 34px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, box-shadow 0.3s ease;
}

.mic-button:active { transform: scale(0.94); }

.mic-button.active {
  background: radial-gradient(circle at 30% 30%, #ff8ec8, #f778ba 55%, #a3306e 100%);
  box-shadow: 0 0 0 10px rgba(247, 120, 186, 0.18),
              0 0 40px rgba(247, 120, 186, 0.35),
              0 12px 34px rgba(0, 0, 0, 0.45);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(247, 120, 186, 0.12), 0 0 30px rgba(247, 120, 186, 0.25), 0 12px 34px rgba(0, 0, 0, 0.45); }
  50% { box-shadow: 0 0 0 16px rgba(247, 120, 186, 0.04), 0 0 50px rgba(247, 120, 186, 0.4), 0 12px 34px rgba(0, 0, 0, 0.45); }
}

.mic-button svg {
  width: 34px;
  height: 34px;
  fill: currentColor;
}

.hint {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.45;
  max-width: 280px;
}

.hint strong { color: var(--text); font-weight: 500; }

.bottom-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(230, 237, 243, 0.12);
  background: rgba(13, 17, 23, 0.72);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn:hover { background: rgba(33, 41, 58, 0.85); border-color: rgba(230, 237, 243, 0.22); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #388bfd; border-color: #388bfd; }

.error-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 40;
  background: rgba(248, 81, 73, 0.14);
  border: 1px solid rgba(248, 81, 73, 0.45);
  color: #ff7b72;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.error-toast.show { transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .status-pill[data-state="listening"] .status-dot,
  .status-pill[data-state="speaking"] .status-dot,
  .mic-button.active {
    animation: none;
  }
}

@media (max-width: 380px) {
  .mic-button { width: 76px; height: 76px; }
  .mic-button svg { width: 30px; height: 30px; }
  .bottom-actions { flex-direction: column; align-items: center; }
  .btn { width: min(260px, 100%); }
}
