/* Voice Companion — dark theme, near-black, soft glows. Mobile responsive. */

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

:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --border: #2a3340;
  --text: #e6edf3;
  --dim: #8b98a5;
  --accent-blue: #3b82f6;
  --accent-teal: #14b8a6;
  --accent-amber: #f59e0b;
  --accent-violet: #8b5cf6;
  --accent-red: #ef4444;
  --glow-blue: rgba(59, 130, 246, 0.45);
  --glow-teal: rgba(20, 184, 166, 0.45);
  --glow-amber: rgba(245, 158, 11, 0.4);
  --glow-violet: rgba(139, 92, 246, 0.45);
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(1200px 800px at 50% -10%, #16202c 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
}

button {
  cursor: pointer;
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
button:active {
  transform: scale(0.96);
}
button:hover {
  border-color: #3d4b61;
}

/* ---------- status dot ---------- */
#status-dot {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #5b6673;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.15);
  transition: background 0.3s, box-shadow 0.3s;
  z-index: 50;
}
#status-dot[data-status="connected"] {
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.7);
}
#status-dot[data-status="reconnecting"] {
  background: var(--accent-amber);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.7);
  animation: blink 1s infinite;
}
#status-dot[data-status="error"] {
  background: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
}
@keyframes blink {
  50% {
    opacity: 0.4;
  }
}

/* ---------- error banner ---------- */
#error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(127, 29, 29, 0.92);
  color: #fecaca;
  border-bottom: 1px solid rgba(239, 68, 68, 0.5);
  backdrop-filter: blur(6px);
  transform: translateY(-120%);
  transition: transform 0.25s;
}
#error-banner.visible {
  transform: translateY(0);
}
#error-banner #error-text {
  flex: 1;
}
#error-banner button {
  background: transparent;
  border: none;
  font-size: 20px;
  color: inherit;
}

/* ---------- overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(8px);
}
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 30px;
  width: min(400px, 90vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.overlay-card h1 {
  font-size: 22px;
  letter-spacing: 0.3px;
  margin-bottom: 22px;
}
.token-row {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}
.token-row label {
  text-align: left;
  font-size: 12px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.token-row input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
}
#begin-btn {
  width: 100%;
  background: var(--accent-blue);
  border-color: transparent;
  font-size: 16px;
  font-weight: 600;
  padding: 14px;
}
#begin-btn:hover {
  background: #4f8df7;
}
.hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--dim);
}

/* ---------- scene / orb ---------- */
#scene {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.orb-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.orb {
  width: 250px;
  height: 250px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #6ea4f5, var(--accent-blue) 55%);
  box-shadow:
    0 0 60px var(--glow-blue),
    0 0 20px rgba(59, 130, 246, 0.35);
  transition: background 0.6s, box-shadow 0.6s, transform 0.12s ease-out;
}
.orb.idle {
  animation: breathe 4s ease-in-out infinite;
}
.orb.listening {
  background: radial-gradient(circle at 32% 30%, #4cd8c6, var(--accent-teal) 55%);
  box-shadow: 0 0 70px var(--glow-teal), 0 0 24px rgba(20, 184, 166, 0.4);
}
.orb.thinking {
  background: radial-gradient(circle at 32% 30%, #fcd34d, var(--accent-amber) 55%);
  box-shadow: 0 0 60px var(--glow-amber), 0 0 18px rgba(245, 158, 11, 0.35);
  animation: pulse 1.4s ease-in-out infinite;
}
.orb.speaking {
  background: radial-gradient(circle at 32% 30%, #b59cff, var(--accent-violet) 55%);
  box-shadow: 0 0 70px var(--glow-violet), 0 0 26px rgba(139, 92, 246, 0.45);
  animation: wave 2s ease-in-out infinite;
}
.orb.interrupt {
  background: radial-gradient(circle at 32% 30%, #ffffff, #f1f5f9 55%);
  box-shadow: 0 0 90px rgba(255, 255, 255, 0.9);
}
@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}
@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}
@keyframes wave {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.07) translateY(-6px);
  }
}
#status-text {
  font-size: 15px;
  letter-spacing: 0.4px;
  color: var(--dim);
  text-transform: uppercase;
}

@media (max-width: 640px) {
  .orb {
    width: 200px;
    height: 200px;
  }
}

/* ---------- controls ---------- */
#controls {
  width: 100%;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}
#controls .left,
#controls .right {
  display: flex;
  gap: 10px;
}
#controls .left {
  justify-content: flex-start;
}
#mode-toggle {
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 600;
  min-width: 72px;
}
#mode-toggle.ptt {
  background: var(--accent-teal);
  border-color: transparent;
}
#ptt-btn {
  border-radius: 50%;
  width: 76px;
  height: 76px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-teal);
  border-color: transparent;
  box-shadow: 0 0 24px rgba(20, 184, 166, 0.5);
  touch-action: none;
}
#ptt-btn.active {
  background: var(--accent-red);
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.6);
}
#chat-btn,
#gear-btn {
  width: 46px;
  height: 46px;
  font-size: 18px;
  border-radius: 12px;
}
#chat-btn.active {
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

/* ---------- drawer ---------- */
#drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(55vh, 460px);
  z-index: 40;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  transform: translateY(102%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.45);
}
#drawer.open {
  transform: translateY(0);
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head button,
.settings-head button {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--dim);
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#interim {
  padding: 4px 18px 0;
  color: var(--dim);
  font-style: italic;
  font-size: 13px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
  min-height: 0;
}
#interim:empty {
  display: none;
  padding: 0;
}
.msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.interim-user {
  opacity: 0.55;
}

/* ---------- settings ---------- */
#settings {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(360px, 92vw);
  z-index: 45;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#settings.open {
  transform: translateX(0);
}
.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
#settings label {
  font-size: 13px;
  color: var(--dim);
}
#settings label .value {
  color: var(--text);
  font-weight: 600;
}
#settings textarea {
  width: 100%;
  resize: vertical;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font: inherit;
}
#settings input[type="range"] {
  width: 100%;
  accent-color: var(--accent-blue);
}
#settings h4 {
  margin-top: 8px;
  color: var(--text);
  font-size: 14px;
}
#stats-box {
  font-size: 13px;
  color: var(--dim);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
}
#stats-box .stat-row {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
#stats-box .stat-row.head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}