/* ============================================================
   ReconMed call screen — fluid glass
   ------------------------------------------------------------
   Ambient radial-gradient blobs behind frosted glass surfaces.
   Only transform/opacity animate on the ambient layer; blur is
   applied to a few static panels at 14px (see notes below).
   Fallbacks: @supports, prefers-reduced-transparency,
   prefers-reduced-motion.
   ============================================================ */

:root {
  --radius: 22px;
  --radius-lg: 28px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* Motion: a soft ease-out and a lively spring. */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.4, 0.4, 1);

  --blur: 14px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f5;
  --text: #1d2025;
  --muted: #5d646d;
  --card-solid: #ffffff;

  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.75);
  --glass-shadow: 0 18px 50px rgba(31, 41, 55, 0.14), 0 2px 8px rgba(31, 41, 55, 0.06);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9);

  --accent: #0e7c66;
  --accent-2: #159d80;
  --accent-soft: rgba(14, 124, 102, 0.12);
  --accent-ink: #ffffff;
  --danger: #c23b3b;
  --warn: #b8852a;

  --bubble-other: rgba(255, 255, 255, 0.72);
  --bubble-self: rgba(14, 124, 102, 0.14);
  --bubble-self-text: #0b3d33;

  --blob-1: rgba(98, 205, 178, 0.85);
  --blob-2: rgba(255, 199, 148, 0.8);
  --blob-3: rgba(150, 186, 255, 0.75);
  --blob-4: rgba(214, 168, 255, 0.55);
  --field: rgba(255, 255, 255, 0.7);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f12;
  --text: #eceef2;
  --muted: #98a0aa;
  --card-solid: #1b1e23;

  --glass-bg: rgba(30, 34, 40, 0.55);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(0, 0, 0, 0.35);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.07);

  --accent: #35b795;
  --accent-2: #4fd3b0;
  --accent-soft: rgba(53, 183, 149, 0.16);
  --accent-ink: #05241d;
  --danger: #e06a6a;
  --warn: #d9a441;

  --bubble-other: rgba(42, 46, 53, 0.72);
  --bubble-self: rgba(53, 183, 149, 0.18);
  --bubble-self-text: #d6f4ec;

  --blob-1: rgba(28, 158, 128, 0.5);
  --blob-2: rgba(196, 122, 60, 0.35);
  --blob-3: rgba(64, 104, 220, 0.42);
  --blob-4: rgba(150, 78, 210, 0.3);
  --field: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow-x: hidden;
  transition: background-color 0.4s var(--ease-out), color 0.4s var(--ease-out);
}

/* ---------------------------------------------------------- ambient */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  width: 72vmax;
  height: 72vmax;
  border-radius: 50%;
  opacity: 0.75;
  will-change: transform;
}
/* Soft by construction (radial falloff) — no filter:blur, so this stays cheap. */
.b1 { background: radial-gradient(circle at 50% 50%, var(--blob-1) 0%, transparent 60%); top: -26vmax; left: -18vmax; animation: drift1 30s ease-in-out infinite; }
.b2 { background: radial-gradient(circle at 50% 50%, var(--blob-2) 0%, transparent 60%); bottom: -30vmax; right: -20vmax; animation: drift2 36s ease-in-out infinite; }
.b3 { background: radial-gradient(circle at 50% 50%, var(--blob-3) 0%, transparent 58%); top: -14vmax; right: -24vmax; animation: drift3 42s ease-in-out infinite; }
.b4 { background: radial-gradient(circle at 50% 50%, var(--blob-4) 0%, transparent 55%); bottom: -24vmax; left: -14vmax; animation: drift4 48s ease-in-out infinite; }

@keyframes drift1 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(8vmax, 6vmax, 0) scale(1.15); }
}
@keyframes drift2 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1.08); }
  50% { transform: translate3d(-9vmax, -5vmax, 0) scale(1); }
}
@keyframes drift3 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(-7vmax, 7vmax, 0) scale(1.2); }
}
@keyframes drift4 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1.12); }
  50% { transform: translate3d(6vmax, -6vmax, 0) scale(1); }
}

/* ---------------------------------------------------------- glass */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  backdrop-filter: blur(var(--blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-inset);
  transform: translateZ(0); /* nudge onto the GPU */
}

/* No backdrop-filter → solid panel, still legible. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--card-solid); }
}
/* Users who ask for less transparency get a solid surface. */
@media (prefers-reduced-transparency: reduce) {
  .glass {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--card-solid);
  }
}

/* ---------------------------------------------------------- frame */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  animation: dropIn 0.6s var(--ease-out) both;
}

.brand { display: flex; align-items: center; gap: 0.65rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  color: #fff;
  box-shadow: 0 8px 22px rgba(14, 124, 102, 0.35);
}
.brand-name { font-weight: 650; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-site { color: var(--muted); font-size: 0.85rem; margin-left: 0.1rem; }

.top-actions { display: flex; gap: 0.5rem; }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease-out), transform 0.25s var(--spring),
    background-color 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
}
.icon-btn:hover { color: var(--text); transform: translateY(-2px); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

html[data-theme="light"] .icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }

/* ---------------------------------------------------------- stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem 1.25rem;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
}

.hidden { display: none !important; }
/* The [hidden] attribute must win even where an element sets its own display. */
[hidden] { display: none !important; }

/* ---------------------------------------------------------- welcome */
.welcome {
  margin: auto 0;
  width: 100%;
  max-width: 580px;
  text-align: center;
  padding-bottom: 5vh;
}
.welcome-title {
  font-size: clamp(2.6rem, 7vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 700;
  margin: 0 0 2.2rem;
  background: linear-gradient(160deg, var(--text) 30%, var(--accent) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: riseIn 0.8s var(--ease-out) 0.05s both;
}

.welcome-form {
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: left;
  animation: riseIn 0.8s var(--ease-out) 0.18s both;
}
.who-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.55rem;
}
.welcome-note {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------------------------------------------------------- idle */
/* The handset before it rings: the time, and nothing else. */
.idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
}
.idle-time {
  font-size: clamp(3.4rem, 16vw, 5.5rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}
.idle-date {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}
html[data-mode="phone"] .idle-time { color: #fff; }
html[data-mode="phone"] .idle-date { color: var(--phone-muted); }
.who-row { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.who-select {
  flex: 1 1 200px;
  min-height: 54px;
  padding: 0 1rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--glass-border);
  border-radius: 15px;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}
.who-select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------------------------------------------------------- cta */
.cta {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 54px;
  padding: 0 1.5rem;
  border: none;
  border-radius: 16px;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  font-size: 1.08rem;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(14, 124, 102, 0.32);
  transition: transform 0.3s var(--spring), box-shadow 0.3s var(--ease-out), filter 0.2s ease;
}
.cta:hover { transform: translateY(-2px); box-shadow: 0 18px 40px rgba(14, 124, 102, 0.38); }
.cta:active { transform: scale(0.97); }
.cta:disabled { opacity: 0.55; cursor: default; transform: none; }
.cta.small { min-height: 46px; font-size: 1rem; padding: 0 1.15rem; }
/* Light sweep across the button on hover. */
.cta-shine {
  position: absolute;
  top: 0; bottom: 0;
  left: -60%;
  width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-18deg);
  pointer-events: none;
}
.cta:hover .cta-shine { animation: shine 0.9s var(--ease-out); }
@keyframes shine {
  from { left: -60%; }
  to { left: 120%; }
}

/* ---------------------------------------------------------- call */
.call {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.call.entering > * { animation: riseIn 0.6s var(--ease-out) both; }
.call.entering > *:nth-child(1) { animation-delay: 0.02s; }
.call.entering > *:nth-child(2) { animation-delay: 0.08s; }
.call.entering > *:nth-child(3) { animation-delay: 0.14s; }
.call.entering > *:nth-child(4) { animation-delay: 0.20s; }

.welcome.leaving { animation: fadeScaleOut 0.35s var(--ease-out) both; }
.call.leaving { animation: fadeScaleOut 0.3s var(--ease-out) both; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeScaleOut {
  to { opacity: 0; transform: scale(0.97); }
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: none; }
}

.status-line {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 1rem;
  min-height: 2.4rem;
}
.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  transition: background-color 0.3s ease;
}
.call[data-state="listening"] .status-dot { background: var(--accent); animation: dotPulse 1.8s ease-in-out infinite; }
.call[data-state="thinking"] .status-dot { background: var(--warn); animation: dotPulse 1s ease-in-out infinite; }
.call[data-state="speaking"] .status-dot { background: #4c86e0; animation: dotPulse 0.9s ease-in-out infinite; }
.call[data-state="muted"] .status-dot { background: var(--danger); }
@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.65; }
}

/* conversation */
.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.5rem 0.5rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 220px;
  /* Instant, not smooth: text grows word by word and a smooth scroll lags behind it. */
  scroll-behavior: auto;
}

.msg {
  max-width: 78%;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius);
  font-size: 1.2rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.08);
  animation: bubbleIn 0.5s var(--spring) both;
}
.msg .who {
  display: block;
  font-size: 0.76rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.msg.agent {
  align-self: flex-start;
  background: var(--bubble-other);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 7px;
}
.msg.patient {
  align-self: flex-end;
  background: var(--bubble-self);
  color: var(--bubble-self-text);
  border: 1px solid transparent;
  border-bottom-right-radius: 7px;
}
.msg.patient .who { color: var(--accent); opacity: 0.9; }
.msg.interim {
  opacity: 0.6;
  border: 1.5px dashed var(--accent);
  background: transparent;
  box-shadow: none;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0.2rem 0.5rem;
  box-shadow: none;
  animation: fadeIn 0.4s var(--ease-out) both;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* thinking dots */
.typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  border-bottom-left-radius: 7px;
  background: var(--bubble-other);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  animation: bubbleIn 0.4s var(--spring) both;
}
.typing i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.3s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------------------------------------------------------- orb */
.orb {
  position: relative;
  align-self: center;
  width: 116px; height: 116px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: default;
  margin: 0.3rem 0 0.5rem;
}
.orb-core {
  position: absolute;
  inset: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--accent-2), var(--accent) 70%);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18) inset,
    0 14px 40px rgba(14, 124, 102, 0.4),
    0 0 60px var(--accent-soft);
  transition: transform 0.12s var(--ease-out), background 0.3s ease, box-shadow 0.3s ease;
  transform: scale(calc(1 + var(--level, 0) * 0.16));
}
.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
.call[data-state="listening"] .orb-ring.r1 { animation: breathe 2.6s var(--ease-out) infinite; }
.call[data-state="listening"] .orb-ring.r2 { animation: breathe 2.6s var(--ease-out) 1.3s infinite; }
.call[data-state="thinking"] .orb-ring.r1 { animation: breathe 1.2s var(--ease-out) infinite; border-color: var(--warn); }
.call[data-state="speaking"] .orb-core { animation: speak 0.85s ease-in-out infinite alternate; }
.call[data-state="muted"] .orb-core {
  background: radial-gradient(circle at 34% 28%, #8b929c, #6b7280);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
}
.call[data-state="idle"] .orb-core { background: radial-gradient(circle at 34% 28%, #9aa1ab, #7c838d); }

@keyframes breathe {
  0% { transform: scale(0.85); opacity: 0.85; }
  100% { transform: scale(1.75); opacity: 0; }
}
@keyframes speak {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

/* ---------------------------------------------------------- dock */
.dock {
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.dock-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 48px;
  padding: 0 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--field);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.28s var(--spring), border-color 0.2s ease, background-color 0.2s ease;
}
.pill-btn:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--accent); }
.pill-btn:active:not(:disabled) { transform: scale(0.96); }
.pill-btn:disabled { opacity: 0.45; cursor: default; }
.pill-btn.danger { color: var(--danger); }
.pill-btn.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.link-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0.5rem;
  transition: color 0.2s ease;
}
.link-btn:hover { color: var(--text); }

.type-row { display: flex; gap: 0.6rem; margin-top: 0.85rem; animation: riseIn 0.35s var(--ease-out) both; }
.type-input {
  flex: 1;
  min-height: 48px;
  padding: 0 1rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
}
.type-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.error {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  max-width: min(560px, 92vw);
  background: var(--danger);
  color: #fff;
  padding: 0.75rem 1.15rem;
  border-radius: 14px;
  font-size: 0.95rem;
  box-shadow: var(--glass-shadow);
  z-index: 40;
  animation: riseIn 0.35s var(--spring) both;
}

/* ---------------------------------------------------------- dev drawer */
.dev-scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.35);
  z-index: 29;
  animation: fadeIn 0.25s ease both;
}
@media (min-width: 901px) {
  /* On a wide screen the main view stays usable while the drawer is open. */
  .dev-scrim { display: none; }
}

.dev {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  border-radius: 0;
  border-right: none;
  border-top: none;
  border-bottom: none;
  display: flex;
  flex-direction: column;
  z-index: 30;
  animation: slideIn 0.45s var(--ease-out) both;
}
@media (min-width: 901px) {
  .dev {
    top: 1rem;
    bottom: 1rem;
    right: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
  }
}
@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.dev-head {
  padding: 1rem 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.dev-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.dev-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.dev-close {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  border: 1px solid var(--glass-border);
  background: var(--field);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.25s var(--spring), border-color 0.2s ease;
}
.dev-close:hover { color: var(--text); border-color: var(--accent); transform: rotate(90deg); }

.pill {
  font-size: 0.75rem;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: var(--accent); border-color: var(--accent); }
.pill.bad { color: var(--danger); border-color: var(--danger); }
.pill.warn { color: var(--warn); border-color: var(--warn); }

.dev-tabs { display: flex; gap: 0.25rem; }
.dev-tab {
  position: relative;
  flex: 1;
  border: none;
  background: none;
  padding: 0.65rem 0.4rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease;
}
.dev-tab::after {
  content: '';
  position: absolute;
  left: 50%; bottom: 0;
  width: 0; height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateX(-50%);
  transition: width 0.3s var(--spring);
}
.dev-tab.active { color: var(--accent); }
.dev-tab.active::after { width: 100%; }

.dev-body { flex: 1; overflow-y: auto; padding: 1rem; }
.dev-page { font-size: 0.85rem; animation: fadeIn 0.3s ease both; }
.dev-page .muted { color: var(--muted); }
.dev-page .small { font-size: 0.8rem; }

.dev-page details.acc {
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--field);
}
.dev-page details.acc summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}
.dev-page pre.raw {
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0.4rem 0 0.2rem;
}
.dev-page ul.tight { margin: 0.3rem 0; padding-left: 1.1rem; }
.dev-page ul.tight li { margin: 0.15rem 0; }
.kv { margin: 0.5rem 0; }
.kv > span { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.pillrow { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; }

.log-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.7rem; }
.mini-btn {
  border: 1px solid var(--glass-border);
  background: var(--field);
  color: var(--text);
  border-radius: 10px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.25s var(--spring), border-color 0.2s ease;
}
.mini-btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.mini-btn.ghost { color: var(--muted); }
.loglist { display: flex; flex-direction: column; gap: 0.4rem; }
.log-item {
  font-family: var(--mono);
  font-size: 0.72rem;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 0.45rem 0.65rem;
  background: var(--field);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: bubbleIn 0.3s var(--ease-out) both;
}
.log-item b { color: var(--accent); }

/* ---------------------------------------------------------- focus & motion */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .blob { animation: none !important; }
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  .msg { max-width: 88%; }
  .brand-site { display: none; }
}

/* ============================================================
   PHONE MODE — iOS-style Phone call UI
   ------------------------------------------------------------
   Everything is scoped to html[data-mode="phone"], so the
   desktop layout is byte-for-byte unaffected when the toggle
   is off. Reuses the existing elements/ids; only restyles and
   reorders them. No fake Dynamic Island: on a real iPhone the
   notch is hardware, so we use env(safe-area-inset-*).
   ============================================================ */

.phone-only { display: none !important; }
html[data-mode="phone"] .phone-only { display: flex !important; }

html[data-mode="phone"] {
  --phone-bg: #08090d;
  --phone-muted: #b8b8c0;
  --phone-button: rgba(118, 118, 128, 0.34);
  -webkit-text-size-adjust: 100%;
}

html[data-mode="phone"],
html[data-mode="phone"] body {
  height: 100%;
  overscroll-behavior: none;
}

html[data-mode="phone"] body {
  background: var(--phone-bg);
  color: #fff;
}

html[data-mode="phone"] .bg { display: none; }
html[data-mode="phone"] .app {
  min-height: 100dvh;
  background: var(--phone-bg);
}

/* Floating top controls only — keeps a way back to desktop mode. */
html[data-mode="phone"] .topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  padding: calc(env(safe-area-inset-top) + 4px) 10px 4px;
  justify-content: flex-end;
  pointer-events: none;
}
html[data-mode="phone"] .topbar .brand { display: none; }
html[data-mode="phone"] .top-actions { pointer-events: auto; gap: 0.4rem; opacity: 0.92; }
html[data-mode="phone"] .icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
/* iOS call screens have no chrome. Keep only a faint toggle back to desktop. */
html[data-mode="phone"] #devToggle,
html[data-mode="phone"] #themeToggle { display: none !important; }
html[data-mode="phone"] #phoneToggle { width: 34px; height: 34px; opacity: 0.28; }
html[data-mode="phone"] #phoneToggle:hover,
html[data-mode="phone"] #phoneToggle:focus-visible { opacity: 1; }

html[data-mode="phone"] .stage {
  max-width: none;
  width: 100%;
  padding: 0;
  align-items: stretch;
}

/* ---------------------------------------------------------- lobby */
html[data-mode="phone"] .welcome {
  max-width: none;
  width: 100%;
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(env(safe-area-inset-top) + 64px) 24px calc(env(safe-area-inset-bottom) + 28px);
  background:
    radial-gradient(circle at 50% 20%, rgba(48, 52, 68, 0.5), rgba(8, 9, 13, 0.92) 72%),
    var(--phone-bg);
}
/* The contact card carries the title; the greeting would just repeat it. */
html[data-mode="phone"] .welcome-title { display: none; }
html[data-mode="phone"] .welcome-form {
  background: none;
  border: none;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  padding: 0;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
html[data-mode="phone"] .phone-contact {
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.1rem;
}
html[data-mode="phone"] .phone-contact-avatar {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.1rem;
  font-weight: 500;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  margin-bottom: 0.7rem;
}
html[data-mode="phone"] .phone-contact-name { font-size: 1.5rem; font-weight: 600; }
html[data-mode="phone"] .phone-contact-sub { color: var(--phone-muted); font-size: 0.9rem; margin-top: 2px; }
html[data-mode="phone"] .who-label {
  color: var(--phone-muted);
  font-weight: 400;
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 0.55rem;
}
html[data-mode="phone"] .welcome-note {
  color: var(--phone-muted);
  text-align: center;
  font-size: 0.9rem;
  max-width: 300px;
  margin: 0 auto;
}
html[data-mode="phone"] .who-row {
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  width: 100%;
}
html[data-mode="phone"] .who-select {
  /* Desktop sets flex: 1 1 200px; in a column that becomes a 200px-tall box. */
  flex: 0 0 auto;
  width: 100%;
  height: 54px;
  min-height: 54px;
  text-align: center;
  text-align-last: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
  border-radius: 14px;
}
html[data-mode="phone"] .who-select option { color: #111; }

/* Green call button — icon only, like the Phone app. */
html[data-mode="phone"] #start {
  width: 74px;
  height: 74px;
  min-height: 74px;
  padding: 0;
  border-radius: 50%;
  background: #34c759;
  color: #fff;
  box-shadow: 0 12px 34px rgba(52, 199, 89, 0.45);
}
html[data-mode="phone"] #start:hover { transform: translateY(-2px); }
html[data-mode="phone"] #start > span:not(.cta-shine) { display: none; }
html[data-mode="phone"] #start .cta-shine { display: none; }
html[data-mode="phone"] #start svg { width: 31px; height: 31px; }

/* ---------------------------------------------------------- call */
html[data-mode="phone"] #callView {
  min-height: 100dvh;
  width: 100%;
  gap: 0;
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 52px) 20px calc(env(safe-area-inset-bottom) + 16px);
  /* Near-flat, like the iOS call background; only a whisper of depth. */
  background: radial-gradient(circle at 50% 16%, rgba(38, 41, 54, 0.32), var(--phone-bg) 58%);
  background-color: var(--phone-bg);
}
/* The entering stagger fights the fixed header; keep it quiet. */
html[data-mode="phone"] #callView.entering > * { animation: none; }
html[data-mode="phone"] #status { display: none; }

html[data-mode="phone"] .phone-call-header {
  order: 1;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
html[data-mode="phone"] .phone-party {
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
html[data-mode="phone"] .phone-call-meta {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--phone-muted);
  font-size: 1rem;
}
html[data-mode="phone"] .phone-timer { font-variant-numeric: tabular-nums; }

/* The orb becomes the caller avatar. */
html[data-mode="phone"] .orb {
  order: 2;
  flex: 0 0 auto;
  width: 128px;
  height: 128px;
  margin: 1.5rem auto 0;
}
html[data-mode="phone"] .orb-core {
  inset: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}
html[data-mode="phone"] .orb-core svg { display: none; }
html[data-mode="phone"] .orb-initials {
  font-size: 2.3rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}
html[data-mode="phone"] .orb-ring { display: none; }
/* No mic-level scaling on an avatar; convey state with a quiet ring instead. */
html[data-mode="phone"] .orb-core { transform: none; }
html[data-mode="phone"] #callView[data-state="listening"] .orb-core { box-shadow: 0 0 0 3px rgba(120, 180, 255, 0.3); }
html[data-mode="phone"] #callView[data-state="thinking"] .orb-core { box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.42); }
html[data-mode="phone"] #callView[data-state="speaking"] .orb-core {
  animation: none;
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.42);
}
html[data-mode="phone"] #callView[data-state="muted"] .orb-core,
html[data-mode="phone"] #callView[data-state="idle"] .orb-core {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}

/* Conversation becomes iOS live captions. */
html[data-mode="phone"] #conversation {
  order: 3;
  flex: 1 1 auto;
  min-height: 0;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.75rem 0;
  overflow-y: auto;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 16%);
  mask-image: linear-gradient(to bottom, transparent, #000 16%);
}
html[data-mode="phone"] #conversation .msg,
html[data-mode="phone"] #conversation .msg.agent,
html[data-mode="phone"] #conversation .msg.patient {
  align-self: center;
  max-width: 100%;
  text-align: center;
  border: none;
  border-radius: 12px;
  padding: 5px 11px;
  font-size: 1rem;
  line-height: 1.3;
  color: #fff;
  background: rgba(0, 0, 0, 0.38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: none;
}
html[data-mode="phone"] #conversation .msg.patient { background: rgba(255, 255, 255, 0.16); }
html[data-mode="phone"] #conversation .msg .who {
  display: inline;
  margin-right: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--phone-muted);
}
html[data-mode="phone"] #conversation .msg.patient .who { color: rgba(255, 255, 255, 0.72); }
html[data-mode="phone"] #conversation .msg.system {
  background: none;
  padding: 0;
  color: var(--phone-muted);
  font-size: 0.95rem;
}
html[data-mode="phone"] #conversation .msg.interim {
  opacity: 0.75;
  border: none;
  background: rgba(0, 0, 0, 0.3);
}
html[data-mode="phone"] #conversation .typing {
  align-self: center;
  border: none;
  background: rgba(0, 0, 0, 0.42);
}
html[data-mode="phone"] #conversation .typing i { background: var(--phone-muted); }

/* ---------------------------------------------------------- controls */
html[data-mode="phone"] .dock {
  order: 4;
  flex: 0 0 auto;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  padding: 0;
}
html[data-mode="phone"] .dock-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-items: center;
  align-items: start;
  gap: 18px 16px;
  flex-wrap: nowrap;
}
html[data-mode="phone"] .dock-row .pill-btn {
  flex-direction: column;
  gap: 7px;
  width: 74px;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: #fff;
  font-weight: 400;
  font-size: 0.82rem;
}
html[data-mode="phone"] .dock-row .pill-btn:hover:not(:disabled) { transform: none; border-color: transparent; }
html[data-mode="phone"] .dock-row .pill-btn:active:not(:disabled) { transform: scale(0.94); }
html[data-mode="phone"] .dock-row .pill-btn svg {
  box-sizing: content-box;
  width: 25px;
  height: 25px;
  padding: 23px;
  border-radius: 50%;
  background: var(--phone-button);
  color: #fff;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out);
}
html[data-mode="phone"] .dock-row .pill-btn:disabled { opacity: 0.45; }

html[data-mode="phone"] #mute { order: 1; }
html[data-mode="phone"] [data-ios="keypad"] { order: 2; }
html[data-mode="phone"] [data-ios="speaker"] { order: 3; }
html[data-mode="phone"] [data-ios="add"] { order: 4; }
html[data-mode="phone"] [data-ios="facetime"] { order: 5; }
html[data-mode="phone"] [data-ios="contacts"] { order: 6; }
html[data-mode="phone"] #end {
  order: 7;
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 10px;
}
html[data-mode="phone"] #end svg { background: #ff3b30; }
html[data-mode="phone"] #mute.on svg { background: #fff; color: #111; }

html[data-mode="phone"] #typeToggle,
html[data-mode="phone"] #backToStart {
  order: 8;
  grid-column: 1 / -1;
  justify-self: center;
  color: var(--phone-muted);
  font-size: 0.82rem;
}
html[data-mode="phone"] #backToStart { order: 9; }
html[data-mode="phone"] .type-row { margin-top: 0.7rem; }
html[data-mode="phone"] #typeToggle { opacity: 0.55; }
html[data-mode="phone"] .type-input {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}
html[data-mode="phone"] .type-input::placeholder { color: var(--phone-muted); }

html[data-mode="phone"] .error { bottom: calc(env(safe-area-inset-bottom) + 1rem); }

/* Short phones (SE, 568pt) — tighten so the controls stay on screen. */
@media (max-height: 700px) {
  html[data-mode="phone"] #callView {
    padding-top: calc(env(safe-area-inset-top) + 30px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 6px);
  }
  html[data-mode="phone"] .phone-party { font-size: 1.45rem; }
  html[data-mode="phone"] .orb { width: 84px; height: 84px; margin-top: 0.6rem; }
  html[data-mode="phone"] .orb-initials { font-size: 1.5rem; }
  html[data-mode="phone"] #conversation { max-height: 18vh; }
  html[data-mode="phone"] .dock-row { gap: 6px 12px; }
  html[data-mode="phone"] .dock-row .pill-btn { font-size: 0.72rem; gap: 4px; }
  html[data-mode="phone"] .dock-row .pill-btn svg { padding: 13px; }
  html[data-mode="phone"] #end { margin-top: 4px; }
  /* On short screens the typed fallback would push End Call off screen. */
  html[data-mode="phone"] #typeToggle,
  html[data-mode="phone"] #backToStart { display: none !important; }
}

/* Wide screens: phone mode previews as a centred 430pt frame. */
@media (min-width: 720px) {
  html[data-mode="phone"] .stage { max-width: 430px; margin-inline: auto; }
  html[data-mode="phone"] .topbar {
    left: 50%;
    right: auto;
    width: 430px;
    transform: translateX(-50%);
  }
}

/* --------------------------------------------------------------------------
   Incoming call.

   Full-bleed and dark regardless of theme, because every phone in the world
   does this and a ringing call that looks like the rest of the page does not
   read as a ringing call.
-------------------------------------------------------------------------- */
.incoming {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #1d2430 0%, #0d1117 100%);
  color: #f5f7fa;
  animation: incoming-in 260ms ease-out;
}

.incoming.hidden {
  display: none;
}

@keyframes incoming-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.incoming-inner {
  width: min(420px, 88vw);
  text-align: center;
}

.incoming-label {
  margin: 0 0 8px;
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(245, 247, 250, 0.62);
}

.incoming-party {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  /* The ring pulses, nothing else moves. */
  animation: incoming-pulse 2s ease-in-out infinite;
}

@keyframes incoming-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.66; }
}

.incoming-sub {
  margin: 6px 0 0;
  color: rgba(245, 247, 250, 0.72);
}

.incoming-acts {
  display: flex;
  justify-content: center;
  gap: 64px;
  margin-top: 56px;
}

.round-btn {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(245, 247, 250, 0.82);
  font: inherit;
  cursor: pointer;
}

.round-glyph {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  color: #fff;
  transition: transform 120ms ease;
}

.round-btn:hover .round-glyph { transform: scale(1.06); }
.round-btn:active .round-glyph { transform: scale(0.96); }
.round-btn:focus-visible .round-glyph { outline: 3px solid #fff; outline-offset: 3px; }

.answer .round-glyph { background: #2fae5b; }
.decline .round-glyph { background: #e0453c; }

.round-label {
  font-size: 0.8125rem;
  color: rgba(245, 247, 250, 0.7);
}

@media (prefers-reduced-motion: reduce) {
  .incoming { animation: none; }
  .incoming-party { animation: none; }
  .round-btn:hover .round-glyph { transform: none; }
}
