:root {
  --text: #f2f5fa;
  --muted: #b6c0d0;
  --accent: #5b8cff;
  --accent-2: #3ad0a0;
  --danger: #ff5c6c;
  --warn: #f4b740;
  --glass: rgba(16, 20, 28, 0.62);
  --glass-2: rgba(30, 37, 49, 0.75);
  --border: rgba(255, 255, 255, 0.12);
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #05070c;
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---------- fullscreen video ---------- */
.video-wrap {
  position: fixed; inset: 0; z-index: 0;
  background: #05070c;
  display: flex; align-items: center; justify-content: center;
  transition: box-shadow .25s;
}
.video-wrap.speaking { box-shadow: inset 0 0 0 3px rgba(58, 208, 160, .7), inset 0 0 60px rgba(58, 208, 160, .25); }
#avatar { width: 100%; height: 100%; object-fit: cover; background: #05070c; display: none; }
#avatar.live { display: block; }
.video-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; color: var(--muted); text-align: center; padding: 24px;
}
.video-placeholder[hidden] { display: none; }
.spinner-ring {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- overlay base (glass) ---------- */
.hud {
  position: fixed; z-index: 10;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

/* status pill (top-left) */
.status-pill {
  top: calc(12px + var(--sa-top)); left: calc(12px + var(--sa-left));
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px;
  max-width: calc(100vw - 24px - var(--sa-left) - var(--sa-right));
  overflow: hidden;
}
.status-pill strong { flex: none; }
.status-pill .status {
  color: var(--muted); font-size: 13px; text-transform: capitalize;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: background .3s, box-shadow .3s; }
.dot.on { background: var(--accent-2); box-shadow: 0 0 0 4px rgba(58,208,160,.22); }
.dot.connecting { background: var(--warn); box-shadow: 0 0 0 4px rgba(244,183,64,.22); }
.dot.err { background: var(--danger); }

/* speaking badge (top-center) */
.speaking-badge {
  top: calc(12px + var(--sa-top)); left: 50%; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 999px;
  color: var(--accent-2); font-size: 12px; font-weight: 700;
  border-color: rgba(58,208,160,.4);
}
.speaking-badge[hidden] { display: none; }

/* ---------- transcript panel (right on desktop) ---------- */
.transcript-panel {
  top: 60px; right: 12px; bottom: 84px;
  width: min(380px, calc(100vw - 24px));
  display: none;                     /* shown once connected */
  flex-direction: column; overflow: hidden;
}
body.connected .transcript-panel { display: flex; }
.transcript-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
}
.transcript-head h2 { margin: 0; font-size: 15px; }
.transcript { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.transcript .hint { color: var(--muted); font-size: 13px; text-align: center; margin: auto 0; }

.line { display: flex; flex-direction: column; gap: 2px; }
.line .who { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.line.you .who { color: var(--accent); }
.line.agent .who { color: var(--accent-2); }
.line .text {
  background: var(--glass-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 11px; white-space: pre-wrap; word-break: break-word;
}
.line.you .text { border-color: rgba(91,140,255,.4); }
.line.agent .text { border-color: rgba(58,208,160,.4); }
.line.interim .text { opacity: .6; font-style: italic; }
.line.typed .text { border-style: dashed; }

.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.composer input {
  flex: 1; min-width: 0; background: var(--glass-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 16px;   /* 16px avoids iOS zoom-on-focus */
}
.composer input:focus { outline: none; border-color: var(--accent); }
.composer input:disabled { opacity: .5; }

/* ---------- buttons ---------- */
.btn {
  background: var(--glass-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 15px; font-size: 14px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary.danger { background: var(--danger); border-color: var(--danger); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #1a1200; font-weight: 600; }
.btn.muted-on { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }

.live-only { display: none; }
body.connected .live-only { display: inline-flex; }

/* ---------- controls: plain centered button pre-connect, glass bar when live ---------- */
.controls {
  position: fixed; z-index: 10;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
#connectBtn { padding: 13px 30px; font-size: 16px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
body.connected .controls {
  top: auto; bottom: calc(16px + var(--sa-bottom)); transform: translateX(-50%);
  flex-wrap: wrap; max-width: calc(100vw - 20px);
  padding: 8px 10px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--border);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
body.connected #connectBtn { padding: 10px 16px; font-size: 14px; box-shadow: none; }

.mic-meter { width: 72px; height: 8px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; align-self: center; }
.mic-meter span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .08s; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(84px + var(--sa-bottom)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.5); z-index: 50;
}
.toast[hidden] { display: none; }

/* ---------- phones ---------- */
@media (max-width: 720px) {
  .btn { min-height: 46px; padding: 12px 18px; font-size: 15px; }
  .btn.tiny { min-height: 0; padding: 5px 10px; }
  #connectBtn { padding: 15px 40px; }

  .status-pill { padding: 7px 12px; font-size: 13px; }
  .status-pill strong { display: none; }        /* drop brand word to save width */

  /* control bar sits at the very bottom, transcript sheet above it */
  body.connected .controls { bottom: calc(10px + var(--sa-bottom)); gap: 8px; }
  body.connected .mic-meter { display: none; }   /* mute button already shows state */

  .transcript-panel {
    left: 8px; right: 8px; width: auto; top: auto;
    height: 42dvh; bottom: calc(80px + var(--sa-bottom));
    border-radius: 18px;
  }

  .toast { left: 8px; right: 8px; transform: none; bottom: calc(94px + var(--sa-bottom)); }
}

/* ---------- short / landscape phones ---------- */
@media (max-height: 480px) and (max-width: 900px) {
  .transcript-panel { height: 56dvh; bottom: calc(64px + var(--sa-bottom)); }
  .btn { min-height: 40px; }
}
