:root {
  --bg: #0a0a0b;
  --bg-elev: #111114;
  --surface: #15151a;
  --surface-2: #1c1c22;
  --border: #23232b;
  --border-strong: #2e2e38;
  --fg: #ececf1;
  --fg-dim: #a5a5b0;
  --fg-mute: #6e6e7a;
  --accent: #e6e6ea;
  --accent-soft: rgba(230, 230, 234, 0.08);
  --signal: #6ee7b7;
  --signal-dim: rgba(110, 231, 183, 0.18);
  --warn: #fbbf24;
  --err: #f87171;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-1: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 40px rgba(0, 0, 0, 0.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font:
    "Inter var", "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text",
    system-ui, "Segoe UI", sans-serif;
  --font-mono:
    ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-feature-settings: "cv11", "ss01", "ss03";
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(
      1200px 600px at 50% -200px,
      rgba(255, 255, 255, 0.03),
      transparent 60%
    ),
    var(--bg);
}

button {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.011em;
}

/* ----- Shell ----- */
.shell {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 14px);
  gap: 14px;
}

/* ----- Topbar ----- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mark {
  width: 26px;
  height: 26px;
  color: var(--fg);
  opacity: 0.92;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--fg-mute);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: -0.005em;
  transition: border-color 0.2s, color 0.2s;
}

.status-pill.live {
  border-color: rgba(110, 231, 183, 0.4);
  color: var(--fg);
}
.status-pill.connecting {
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--fg);
}
.status-pill.error {
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--fg);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-mute);
  transition: background 0.2s, box-shadow 0.2s;
}
.status-pill.live .dot {
  background: var(--signal);
  box-shadow: 0 0 0 4px var(--signal-dim);
}
.status-pill.connecting .dot {
  background: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-pill.error .dot {
  background: var(--err);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ----- Main ----- */
.main {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-height: 0;
}

/* ----- Visual / orb ----- */
.visual {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 28px 0 12px;
}

.orb {
  position: relative;
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
}

.orb-core {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fafafa 0%, #c9c9d2 55%, #6b6b76 100%);
  box-shadow:
    inset 0 -6px 14px rgba(0, 0, 0, 0.45),
    inset 0 2px 4px rgba(255, 255, 255, 0.55),
    0 8px 32px rgba(0, 0, 0, 0.55);
  transform: scale(var(--scale, 1));
  transition: transform 0.12s ease-out, filter 0.3s ease;
  filter: saturate(0);
}

.orb-glow {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.16) 0%,
    transparent 65%
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0;
}

.orb.live .orb-glow {
  opacity: 1;
}
.orb.live .orb-ring {
  opacity: 1;
  animation: ring 3s ease-out infinite;
}
.orb.speaking .orb-core {
  filter: saturate(1);
  background:
    radial-gradient(
      circle at 35% 30%,
      #d8ffe9 0%,
      var(--signal) 55%,
      #1f7a5a 100%
    );
  box-shadow:
    inset 0 -6px 14px rgba(0, 0, 0, 0.4),
    inset 0 2px 4px rgba(255, 255, 255, 0.45),
    0 10px 40px rgba(110, 231, 183, 0.3);
}
.orb.listening .orb-glow {
  background: radial-gradient(
    circle,
    rgba(110, 231, 183, 0.18) 0%,
    transparent 65%
  );
}

@keyframes ring {
  0% { transform: scale(0.7); opacity: 0.5; }
  100% { transform: scale(1.4); opacity: 0; }
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--fg-mute);
  letter-spacing: -0.005em;
  text-align: center;
  min-height: 1.5em;
}

/* ----- Panel ----- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: var(--shadow-1);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-mute);
  font-weight: 600;
}

.text-btn {
  background: none;
  border: 0;
  color: var(--fg-mute);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.text-btn:hover {
  color: var(--fg);
  background: var(--accent-soft);
}

.transcript-panel {
  min-height: 180px;
  max-height: 42dvh;
}

.transcript {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.transcript:empty::before {
  content: "No transcript yet. Connect and speak to begin.";
  color: var(--fg-mute);
  font-size: 13px;
  font-style: normal;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: var(--radius);
  max-width: 88%;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.msg.user {
  align-self: flex-end;
  background: #ffffff;
  color: #18181b;
  border-color: transparent;
}

.msg.assistant {
  align-self: flex-start;
}

.msg .who {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  opacity: 0.55;
}
.msg.user .who {
  color: #52525b;
  opacity: 0.7;
}

/* ----- Action bar ----- */
.actionbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 2px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s, border-color 0.15s,
    box-shadow 0.2s, opacity 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:not(:disabled):hover {
  border-color: #3a3a46;
  background: var(--surface-2);
}

.btn:not(:disabled):active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #0a0a0b;
  border-color: transparent;
  box-shadow: 0 6px 24px rgba(255, 255, 255, 0.08);
}

.btn-primary:not(:disabled):hover {
  background: #ffffff;
  border-color: transparent;
}

.btn-primary.live {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--border-strong);
  box-shadow: none;
}

.btn-ghost.on {
  background: var(--surface-2);
  border-color: var(--err);
  color: var(--err);
}

/* ----- Debug ----- */
.debug {
  font-size: 11px;
  color: var(--fg-mute);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.debug summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-mute);
  padding: 4px 0;
}
.debug summary::-webkit-details-marker { display: none; }
.debug summary::before {
  content: "▸";
  font-size: 9px;
  transition: transform 0.15s;
  display: inline-block;
}
.debug[open] summary::before { transform: rotate(90deg); }
.debug pre {
  margin: 8px 0 0;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ----- Desktop ----- */
@media (min-width: 720px) {
  .shell {
    padding: 28px;
    gap: 20px;
  }
  .visual {
    padding: 40px 0 20px;
  }
  .orb {
    width: 160px;
    height: 160px;
  }
  .orb-core {
    width: 80px;
    height: 80px;
  }
  .actionbar {
    grid-template-columns: auto 1fr auto;
  }
  .actionbar .btn-primary {
    grid-column: 2 / 3;
    max-width: 280px;
    justify-self: center;
    width: 100%;
  }
}
