:root {
  --bg0: #0b0f1a;
  --bg1: #131a2e;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-brd: rgba(255, 255, 255, 0.10);
  --text: #eaf0ff;
  --muted: #8b96b3;
  --accent: #7c5cff;
  --accent2: #25d0d6;
  --user: #2a3556;
  --nancy: rgba(124, 92, 255, 0.16);
  --level: 0;            /* live mic / voice intensity 0..1 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(124,92,255,0.20), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(37,208,214,0.12), transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
  overflow: hidden;
}

.app {
  display: flex; flex-direction: column;
  height: 100dvh;
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bot) + 12px);
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand-name { font-size: 20px; }
.logo-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #9d86ff, var(--accent));
  box-shadow: 0 0 14px var(--accent);
}
.actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--glass-brd);
  color: var(--muted); cursor: pointer; transition: .2s;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.09); }
.icon-btn.active { color: #ff6b7d; border-color: rgba(255,107,125,.4); }
#muteBtn.active #wave1, #muteBtn.active #wave2 { display: none; }

/* Stage / orb */
.stage { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 14px 0 4px; }
.orb-wrap { position: relative; width: 180px; height: 180px; display: grid; place-items: center; }
.orb {
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b9a6ff 0%, var(--accent) 45%, #4a2fb0 100%);
  box-shadow: 0 0 40px rgba(124,92,255,.55), inset 0 0 30px rgba(255,255,255,.25);
  transform: scale(calc(1 + var(--level) * 0.18));
  transition: transform .08s ease-out;
  position: relative; z-index: 2;
}
.orb-ring {
  position: absolute; border-radius: 50%; border: 1.5px solid rgba(124,92,255,.35);
  inset: 0; opacity: 0;
}
.ring1 { width: 130px; height: 130px; }
.ring2 { width: 156px; height: 156px; }
.ring3 { width: 180px; height: 180px; }

@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes ripple { 0% { opacity: .5; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.25); } }
@keyframes spin { to { transform: rotate(360deg); } }

body[data-state="idle"] .orb { animation: breathe 5s ease-in-out infinite; }
body[data-state="listening"] .orb { background: radial-gradient(circle at 35% 30%, #8df0f2 0%, var(--accent2) 50%, #146e72 100%); box-shadow: 0 0 50px rgba(37,208,214,.6), inset 0 0 30px rgba(255,255,255,.3); }
body[data-state="listening"] .orb-ring { animation: ripple 1.4s ease-out infinite; opacity: 1; border-color: rgba(37,208,214,.4); }
body[data-state="listening"] .ring2 { animation-delay: .45s; }
body[data-state="listening"] .ring3 { animation-delay: .9s; }
body[data-state="transcribing"] .orb,
body[data-state="thinking"] .orb { animation: breathe 1.6s ease-in-out infinite; }
body[data-state="thinking"] .orb-wrap::after {
  content: ""; position: absolute; width: 150px; height: 150px; border-radius: 50%;
  border: 2px solid transparent; border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
body[data-state="speaking"] .orb-ring { animation: ripple 1s ease-out infinite; opacity: 1; }
body[data-state="speaking"] .ring2 { animation-delay: .33s; }
body[data-state="speaking"] .ring3 { animation-delay: .66s; }

.status { margin: 14px 0 0; color: var(--muted); font-size: 14px; min-height: 18px; letter-spacing: .2px; }

/* Transcript */
.transcript {
  flex: 1 1 auto; overflow-y: auto; padding: 14px 4px; display: flex; flex-direction: column; gap: 10px;
  mask-image: linear-gradient(180deg, transparent 0, #000 18px, #000 calc(100% - 8px), transparent 100%);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent;
}
.transcript::-webkit-scrollbar { width: 6px; }
.transcript::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 16px; font-size: 15.5px; line-height: 1.45;
  animation: rise .25s ease-out; word-wrap: break-word;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.bubble.nancy { align-self: flex-start; background: var(--nancy); border: 1px solid var(--glass-brd); border-bottom-left-radius: 6px; }
.bubble.nancy.streaming::after { content: "▍"; opacity: .6; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Dock */
.dock { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
.text-row { display: flex; gap: 8px; width: 100%; }
.text-input {
  flex: 1; background: var(--glass); border: 1px solid var(--glass-brd); color: var(--text);
  border-radius: 14px; padding: 12px 14px; font-size: 15px; outline: none;
}
.text-input::placeholder { color: var(--muted); }
.text-input:focus { border-color: rgba(124,92,255,.5); }
.send-btn {
  display: grid; place-items: center; width: 46px; border-radius: 14px; border: none;
  background: var(--glass); color: var(--muted); cursor: pointer;
}
.send-btn:hover { color: var(--text); }

.mic-btn {
  position: relative; width: 78px; height: 78px; border-radius: 50%; border: none; cursor: pointer;
  color: #fff; background: linear-gradient(145deg, var(--accent), #5a3ee0);
  box-shadow: 0 10px 30px rgba(124,92,255,.45); display: grid; place-items: center;
  transition: transform .12s ease;
}
.mic-btn:active { transform: scale(.94); }
body[data-state="listening"] .mic-btn { background: linear-gradient(145deg, var(--accent2), #1aa6ab); box-shadow: 0 10px 34px rgba(37,208,214,.5); }
.mic-pulse {
  position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(37,208,214,.6);
  opacity: 0; pointer-events: none;
}
body[data-state="listening"] .mic-pulse { animation: ripple 1.2s ease-out infinite; opacity: 1; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

.disconnected .logo-dot { background: #ff6b7d; box-shadow: 0 0 12px #ff6b7d; }

/* Settings sheet */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 16, 0.6); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 560px) { .overlay { align-items: center; } }

.sheet {
  width: 100%; max-width: 520px;
  background: linear-gradient(180deg, #161d33, #111728);
  border: 1px solid var(--glass-brd); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(var(--safe-bot) + 18px);
  box-shadow: 0 -20px 60px rgba(0,0,0,.5);
  animation: slideup .25s ease;
}
@media (min-width: 560px) { .sheet { border-radius: 22px; } }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field-label { font-size: 13px; color: var(--muted); letter-spacing: .3px; }
.field-note { margin: -8px 0 14px; font-size: 12.5px; color: var(--muted); min-height: 16px; }
.select {
  appearance: none; -webkit-appearance: none;
  background: var(--glass) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%238b96b3' stroke-width='2'/></svg>") no-repeat right 14px center;
  border: 1px solid var(--glass-brd); color: var(--text);
  border-radius: 14px; padding: 13px 40px 13px 14px; font-size: 15px; outline: none; cursor: pointer;
}
.select:focus { border-color: rgba(124,92,255,.5); }
.select:disabled { opacity: .5; cursor: not-allowed; }
.select option { background: #161d33; color: var(--text); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-secondary, .btn-primary {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px; border-radius: 14px; font-size: 15px; font-weight: 600; cursor: pointer; border: none;
}
.btn-secondary { background: var(--glass); border: 1px solid var(--glass-brd); color: var(--text); }
.btn-secondary:hover { background: rgba(255,255,255,.09); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(145deg, var(--accent), #5a3ee0); color: #fff; }
.btn-primary:active { transform: scale(.98); }
