/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #07080f;
  --text:      #e8ecf8;
  --text-dim:  rgba(220,228,255,0.38);
  --blue:      #4f7fff;
  --blue-lt:   #7ba3ff;
  --purple:    #9d78ff;
  --green:     #2fd98f;
  --amber:     #ffb938;
  --red:       #ff6b6b;
  --font:      -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Deep space background ── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 75% 60% at 50% 38%,
      rgba(50,80,200,0.40) 0%,
      rgba(60,40,160,0.18) 45%,
      transparent 72%),
    radial-gradient(ellipse 100% 45% at 50% 0%,
      rgba(40,60,180,0.22) 0%,
      transparent 60%),
    radial-gradient(ellipse 55% 40% at 18% 105%,
      rgba(100,55,210,0.14) 0%,
      transparent 55%),
    radial-gradient(ellipse 60% 35% at 88% 98%,
      rgba(30,70,170,0.12) 0%,
      transparent 50%),
    linear-gradient(170deg, #0d1020 0%, #09101e 45%, #070810 100%);
  pointer-events: none;
}

/* ── Host login ── */
.login-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4,6,12,0.76);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.login-card {
  width: min(100%, 420px);
  padding: 28px;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(160deg, rgba(20,26,58,0.92), rgba(8,10,20,0.94));
  box-shadow: 0 30px 90px rgba(0,0,0,0.70), 0 0 60px rgba(80,120,255,0.18);
}

.login-eyebrow {
  color: var(--blue-lt);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.login-card h1 {
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: -0.04em;
  margin-bottom: 12px;
}

.login-card p {
  color: rgba(220,228,255,0.58);
  font-size: 14px;
  line-height: 1.55;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}

.login-form input,
.login-form button {
  width: 100%;
  min-height: 50px;
  border-radius: 16px;
  font: inherit;
}

.login-form input {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 0 16px;
  outline: none;
}

.login-form input:focus {
  border-color: rgba(123,163,255,0.7);
  box-shadow: 0 0 0 3px rgba(79,127,255,0.18);
}

.login-form button {
  border: none;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.login-error {
  margin-top: 12px;
  color: var(--red) !important;
}

/* ── App shell ── */
.app {
  position: relative; z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top:    max(var(--safe-t), 20px);
  padding-bottom: max(var(--safe-b), 20px);
  padding-left:  20px;
  padding-right: 20px;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.logo {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(130deg, #fff 0%, var(--blue-lt) 60%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Status pill ── */
.status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all 0.5s cubic-bezier(0.4,0,0.2,1);
}

.status-pill.idle {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.09);
  color: var(--text-dim);
}
.status-pill.connecting {
  background: rgba(255,185,56,0.12);
  border-color: rgba(255,185,56,0.28);
  color: var(--amber);
}
.status-pill.live {
  background: rgba(47,217,143,0.12);
  border-color: rgba(47,217,143,0.28);
  color: var(--green);
}
.status-pill.error {
  background: rgba(255,107,107,0.12);
  border-color: rgba(255,107,107,0.28);
  color: var(--red);
}

.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.status-pill.idle .status-dot       { opacity: 0.45; }
.status-pill.connecting .status-dot { animation: blink 1s ease infinite; }
.status-pill.live .status-dot       { animation: pdot 2s ease infinite; }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.1} }
@keyframes pdot  {
  0%,100% { box-shadow: 0 0 0 0 rgba(47,217,143,0.7); }
  50%     { box-shadow: 0 0 0 5px rgba(47,217,143,0); }
}

/* ── Orb section ── */
.orb-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  min-height: 0;
}

/* ── Orb scene ── */
.orb-scene {
  position: relative;
  width: 220px; height: 220px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Ambient glow halos (HTML elements for layered control) */
.glow {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.glow-outer {
  width: 400px; height: 400px;
  background: radial-gradient(circle,
    rgba(50,90,255,0.14) 0%,
    rgba(70,50,200,0.07) 45%,
    transparent 68%);
  filter: blur(32px);
  animation: halo-idle 5s ease infinite;
}
.glow-mid {
  width: 300px; height: 300px;
  background: radial-gradient(circle,
    rgba(70,110,255,0.18) 0%,
    rgba(90,60,220,0.08) 50%,
    transparent 70%);
  filter: blur(18px);
  animation: halo-idle 5s ease infinite 0.8s;
}
.orb-scene.live .glow-outer {
  background: radial-gradient(circle,
    rgba(60,110,255,0.22) 0%,
    rgba(90,50,220,0.10) 45%,
    transparent 68%);
  animation: halo-live 3.5s ease infinite;
}
.orb-scene.live .glow-mid {
  background: radial-gradient(circle,
    rgba(80,130,255,0.26) 0%,
    rgba(100,60,240,0.10) 50%,
    transparent 70%);
  animation: halo-live 3.5s ease infinite 0.6s;
}
.orb-scene.connecting .glow-outer {
  background: radial-gradient(circle,
    rgba(255,185,56,0.14) 0%,
    rgba(200,120,30,0.06) 45%,
    transparent 68%);
  animation: halo-idle 1.2s ease infinite;
}
.orb-scene.connecting .glow-mid {
  background: radial-gradient(circle,
    rgba(255,185,56,0.16) 0%,
    rgba(200,120,30,0.07) 50%,
    transparent 70%);
  animation: halo-idle 1.2s ease infinite 0.3s;
}

@keyframes halo-idle {
  0%,100% { opacity: 0.70; transform: scale(1); }
  50%     { opacity: 1.00; transform: scale(1.04); }
}
@keyframes halo-live {
  0%,100% { opacity: 0.80; transform: scale(1); }
  50%     { opacity: 1.00; transform: scale(1.10); }
}

/* Always-on soft ambient pool */
.orb-scene::before {
  content: '';
  position: absolute;
  width: 360px; height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(60,90,255,0.22) 0%,
    rgba(80,60,200,0.10) 40%,
    transparent 68%);
  filter: blur(28px);
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.orb-scene.live::before {
  background: radial-gradient(circle,
    rgba(70,120,255,0.28) 0%,
    rgba(90,60,220,0.12) 40%,
    transparent 70%);
  animation: breathe 3s ease infinite;
}
.orb-scene.connecting::before {
  background: radial-gradient(circle,
    rgba(255,185,56,0.16) 0%,
    rgba(200,120,30,0.06) 40%,
    transparent 70%);
}
@keyframes breathe {
  0%,100% { transform: scale(1);    opacity: 1; }
  50%     { transform: scale(1.12); opacity: 0.75; }
}

/* Rotating ring */
#ring-canvas {
  position: absolute;
  width: 280px; height: 280px;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* ── The orb button ── */
.orb {
  position: relative; z-index: 2;
  width: 220px; height: 220px;
  border-radius: 50%; border: none; background: none;
  cursor: pointer; touch-action: manipulation;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  outline: none;
  user-select: none; -webkit-user-select: none;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
  -webkit-tap-highlight-color: transparent;
}
.orb:active { transform: scale(0.91); }

/* Outer CSS pulse ring — always visible, CSS-only */
.orb::before {
  content: '';
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  border: 1px solid rgba(90,140,255,0.24);
  box-shadow: 0 0 12px rgba(80,130,255,0.12) inset,
              0 0 16px rgba(80,130,255,0.10);
  animation: css-ring 4s ease infinite;
  pointer-events: none;
}
.orb::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid rgba(90,140,255,0.14);
  pointer-events: none;
}
.orb-scene.live .orb::before {
  border-color: rgba(80,140,255,0.42);
  box-shadow: 0 0 20px rgba(80,130,255,0.20) inset,
              0 0 28px rgba(80,130,255,0.18);
  animation: css-ring-live 2.4s ease infinite;
}
.orb-scene.live .orb::after {
  border-color: rgba(90,140,255,0.26);
  animation: css-ring-live 2.4s ease infinite 0.4s;
}

@keyframes css-ring {
  0%,100% { transform: scale(1);    opacity: 0.8; }
  50%     { transform: scale(1.04); opacity: 0.4; }
}
@keyframes css-ring-live {
  0%,100% { transform: scale(1);    opacity: 1; }
  50%     { transform: scale(1.07); opacity: 0.5; }
}

/* Glass sphere surface */
.orb-surface {
  position: absolute; inset: 0;
  border-radius: 50%;
  transition: all 0.5s cubic-bezier(0.4,0,0.2,1);

  background:
    radial-gradient(circle at 33% 26%,
      rgba(255,255,255,0.22) 0%,
      rgba(180,200,255,0.08) 36%,
      transparent 56%),
    radial-gradient(circle at 68% 74%,
      rgba(60,80,220,0.12) 0%,
      transparent 46%),
    linear-gradient(145deg,
      rgba(65,100,230,0.50) 0%,
      rgba(40,55,180,0.38) 45%,
      rgba(18,22,80,0.50) 100%);
  box-shadow:
    0 0 0 1px rgba(120,160,255,0.30),
    0 0 0 1px rgba(255,255,255,0.07) inset,
    0 2px 0 rgba(200,220,255,0.16) inset,
    0 36px 90px rgba(0,0,0,0.80),
    0 0 50px rgba(55,90,220,0.25),
    0 0 100px rgba(50,80,200,0.12);
}

.orb-scene.connecting .orb-surface {
  background:
    radial-gradient(circle at 33% 26%,
      rgba(255,210,100,0.22) 0%,
      rgba(255,180,50,0.06) 42%,
      transparent 62%),
    linear-gradient(145deg,
      rgba(180,110,20,0.18) 0%,
      rgba(100,60,10,0.10) 50%,
      rgba(10,8,4,0.20) 100%),
    rgba(40,28,10,0.40);
  box-shadow:
    0 0 0 1px rgba(255,185,56,0.28),
    0 2px 0 rgba(255,220,120,0.12) inset,
    0 36px 90px rgba(0,0,0,0.75),
    0 0 60px rgba(255,185,56,0.14);
}

.orb-scene.live .orb-surface {
  background:
    radial-gradient(circle at 33% 26%,
      rgba(140,175,255,0.30) 0%,
      rgba(80,120,255,0.09) 44%,
      transparent 62%),
    radial-gradient(circle at 70% 74%,
      rgba(140,80,255,0.12) 0%,
      transparent 48%),
    linear-gradient(145deg,
      rgba(60,110,255,0.22) 0%,
      rgba(40,60,200,0.14) 50%,
      rgba(10,15,60,0.22) 100%),
    rgba(16,22,70,0.40);
  box-shadow:
    0 0 0 1px rgba(90,150,255,0.36),
    0 2px 0 rgba(180,210,255,0.18) inset,
    0 36px 90px rgba(0,0,0,0.75),
    0 0 80px rgba(70,120,255,0.26),
    0 0 160px rgba(60,100,255,0.12);
}

/* Inner icon wrapper */
.orb-inner {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px;
}

.orb-svg {
  width: 36px; height: 36px;
  color: rgba(255,255,255,0.55);          /* default */
  transition: color 0.3s, opacity 0.3s;
}

.orb-scene.idle .orb-svg        { color: rgba(255,255,255,0.55); }
.orb-scene.connecting .orb-svg  { color: rgba(255,200,80,0.95); }
.orb-scene.live .orb-svg        { color: rgba(160,195,255,0.95); }

.hidden { display: none !important; }

/* Spinner */
.orb-spinner {
  width: 32px; height: 32px;
  border: 2.5px solid rgba(255,185,56,0.15);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Label */
.orb-label {
  position: relative; z-index: 1;
  font-size: 13px; font-weight: 500; letter-spacing: 0.02em;
  color: rgba(255,255,255,0.32);          /* default */
  transition: color 0.4s;
  pointer-events: none;
}
.orb-scene.idle .orb-label        { color: rgba(255,255,255,0.32); }
.orb-scene.connecting .orb-label  { color: rgba(255,200,80,0.70); }
.orb-scene.live .orb-label        { color: rgba(140,185,255,0.80); }

/* ── Waveform ── */
#waveform {
  width: 100%;
  height: 60px;
  display: block;
  flex-shrink: 0;
  /* soft left/right fade */
  -webkit-mask-image: linear-gradient(to right,
    transparent 0%, black 12%, black 88%, transparent 100%);
  mask-image: linear-gradient(to right,
    transparent 0%, black 12%, black 88%, transparent 100%);
}

/* ── Transcript ── */
.transcript-section {
  flex-shrink: 0;
  height: 34vh;
  min-height: 120px;
  max-height: 280px;
}

.transcript {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.transcript::-webkit-scrollbar { display: none; }

/* Empty state */
.transcript-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  height: 100%;
  color: rgba(160,180,255,0.30);
}
.transcript-empty svg { width: 24px; height: 24px; }
.transcript-empty p { font-size: 13px; text-align: center; line-height: 1.5; letter-spacing: 0.01em; }

/* Chat bubbles */
.bubble-row {
  display: flex;
  margin-bottom: 8px;
  animation: bubbleIn 0.2s cubic-bezier(0.34,1.3,0.64,1);
}
.bubble-row.you       { justify-content: flex-end; }
.bubble-row.companion { justify-content: flex-start; }

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  font-size: 14px; line-height: 1.55;
}

.bubble-row.you .bubble {
  background: linear-gradient(135deg,
    rgba(70,110,255,0.22) 0%,
    rgba(90,80,220,0.16) 100%);
  border: 1px solid rgba(100,140,255,0.22);
  border-radius: 18px 18px 4px 18px;
  color: var(--text);
}

.bubble-row.companion .bubble {
  background: rgba(255,255,255,0.065);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px 18px 18px 4px;
  color: var(--text);
}

.bubble.partial { color: rgba(220,228,255,0.45); }

/* ── Footer ── */
.footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 10px;
  min-height: 60px;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.controls.hidden { display: none; }

/* Mode toggle */
.mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 99px;
  padding: 3px; gap: 2px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.mode-btn {
  padding: 8px 22px;
  border: none; border-radius: 99px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
  transition: all 0.2s ease;
  min-height: 36px; min-width: 80px;
  -webkit-tap-highlight-color: transparent;
}
.mode-btn.active {
  background: rgba(255,255,255,0.09);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

/* PTT hold */
.btn-ptt-hold {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 15px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
  min-height: 54px;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.btn-ptt-hold.hidden { display: none; }
.btn-ptt-hold:active,
.btn-ptt-hold.active {
  background: linear-gradient(135deg,
    rgba(70,110,255,0.22) 0%,
    rgba(90,80,220,0.16) 100%);
  border-color: rgba(100,140,255,0.30);
  color: var(--blue-lt);
  box-shadow: 0 0 32px rgba(70,110,255,0.20);
}

.share-card {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 16px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.055);
  box-shadow: 0 18px 60px rgba(0,0,0,0.32), 0 0 35px rgba(70,110,255,0.10);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.share-card.hidden { display: none; }

.qr-code {
  display: grid;
  place-items: center;
  width: 168px;
  min-height: 168px;
  padding: 10px;
  border-radius: 18px;
  background: #fff;
  color: #111;
  font-size: 12px;
  font-weight: 700;
}

.qr-code svg {
  display: block;
  width: 148px;
  height: 148px;
}

.share-card p {
  color: rgba(232,236,248,0.78);
  font-size: 13px;
  font-weight: 700;
}

.share-card a {
  max-width: 100%;
  color: var(--blue-lt);
  font-size: 12px;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
}

/* ── Responsive ── */
@media (max-height: 680px) {
  .orb, .orb-scene { width: 180px; height: 180px; }
  #ring-canvas { width: 240px; height: 240px; }
  .transcript-section { min-height: 90px; max-height: 180px; }
  .orb-section { gap: 22px; }
}

@media (min-width: 480px) {
  .transcript-section { max-height: 240px; }
}
