:root {
  --ink-bg: #0c1118;
  --panel: #141b24;
  --ink: #e8eef6;
  --muted: #8b97a8;
  --line: rgba(232, 238, 246, 0.12);
  --green: #10b981;
  --green-soft: #34d399;
  --danger: #f07178;
  --user: rgba(16, 185, 129, 0.16);
  --orb-size: 120px;
  --bar: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Instrument Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--ink-bg);
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--bar);
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.topbar {
  display: flex;
  align-items: center;
  padding: 14px 16px 8px;
}

.logo {
  height: 26px;
  width: auto;
}

.console {
  min-height: 0;
  padding: 0 16px 8px;
}

.pane { min-height: 0; }

.talk-view,
.call-view {
  height: 100%;
}

.talk-view {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
}

.agent-name {
  font-family: Syne, "Instrument Sans", sans-serif;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}

.orb-shell {
  position: relative;
  width: var(--orb-size);
  height: var(--orb-size);
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
}

.orb-shell:disabled { cursor: not-allowed; opacity: 0.5; }

.orb-shell:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 8px;
}

.orb-ring,
.orb-ring-2 {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 1px solid rgba(16, 185, 129, 0.22);
  opacity: 0;
}

.orb-core {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 32%, rgba(255, 255, 255, 0.45), transparent 26%),
    radial-gradient(circle at 50% 58%, #34d399, #0f766e 62%, #0c1118 78%);
  box-shadow: inset 0 -16px 28px rgba(0, 0, 0, 0.35);
}

.orb-shell.is-live .orb-ring,
.orb-shell.is-live .orb-ring-2 {
  opacity: 1;
  animation: ringPulse 2.6s ease-in-out infinite;
}

.orb-shell.is-live .orb-ring-2 {
  inset: -4%;
  animation-delay: -1.1s;
}

.orb-shell.is-live .orb-core { animation: breathe 2.4s ease-in-out infinite; }

.orb-shell.is-speaking .orb-core { animation: speak 0.85s ease-in-out infinite; }

.orb-label { display: grid; gap: 4px; }

.orb-label strong {
  font-family: Syne, "Instrument Sans", sans-serif;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}

.orb-label span,
.page-status,
.outbound-status,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.page-status.error,
.outbound-status.error { color: var(--danger); }

.mic-meter-wrap {
  display: none;
  align-items: center;
  gap: 8px;
  width: min(220px, 70vw);
}

.stage.is-active .mic-meter-wrap { display: flex; }

.mic-meter {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.mic-meter > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--green);
}

.mic-meter-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.call-view {
  display: grid;
  align-content: center;
}

.outbound-panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.outbound-panel h2 {
  font-family: Syne, "Instrument Sans", sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.caller-id {
  color: var(--muted);
  font-size: 0.92rem;
}

.caller-id a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.outbound-copy {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.outbound-form {
  display: grid;
  gap: 10px;
}

.outbound-form input {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c1118;
  padding: 0 14px;
}

.outbound-form input:focus {
  outline: 2px solid rgba(16, 185, 129, 0.45);
  outline-offset: 1px;
}

.outbound-btn {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer;
  color: #062016;
  background: var(--green);
}

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

.transcript-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
}

.transcript-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.transcript-head strong {
  font-family: Syne, "Instrument Sans", sans-serif;
  font-size: 1rem;
}

#transcripts {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border-bottom-left-radius: 4px;
}

.msg.partial { opacity: 0.92; }

.msg-stream { white-space: pre-wrap; word-break: break-word; }

.msg-stream .w-live {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.msg.partial .msg-stream .w:last-child {
  animation: wordPulse 0.35s ease;
}

@keyframes wordPulse {
  from { opacity: 0.35; }
  to { opacity: 0.55; }
}

.empty-transcript {
  margin: auto;
  color: var(--muted);
  text-align: center;
  max-width: 16rem;
  line-height: 1.45;
}

.mode-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #10161e;
}

.mode-bar button {
  position: relative;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mode-bar button.is-active {
  background: rgba(16, 185, 129, 0.14);
  color: var(--ink);
}

@media (max-width: 767px) {
  .console {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    min-height: 0;
  }

  body[data-mode="talk"] .call-view {
    display: none;
  }

  body[data-mode="talk"] .talk-view {
    display: grid;
    flex-shrink: 0;
    align-content: start;
    gap: 8px;
    height: auto;
    padding-top: 2px;
  }

  body[data-mode="talk"] .pane-transcript {
    display: flex;
    flex: 1;
    min-height: 0;
  }

  body[data-mode="talk"] .transcript-panel {
    min-height: 0;
    flex: 1;
  }

  body[data-mode="talk"] #transcripts {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body[data-mode="call"] .talk-view,
  body[data-mode="call"] .pane-transcript {
    display: none;
  }

  body[data-mode="call"] .call-view {
    display: grid;
    flex: 1;
    min-height: 0;
    align-content: start;
  }

  body[data-mode="call"] .pane-control {
    display: block;
    flex: 1;
    min-height: 0;
  }

  .agent-name {
    font-size: 1rem;
  }

  .orb-label strong {
    font-size: 1.05rem;
  }
}

@media (min-width: 768px) {
  body[data-mode="call"] .talk-view {
    display: none;
  }

  body[data-mode="talk"] .call-view {
    display: none;
  }
}

@media (min-width: 768px) {
  :root { --orb-size: 200px; --bar: 0px; }

  body { overflow: hidden; }

  .app {
    max-width: 1100px;
    margin: 0 auto;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 8px 20px 20px;
  }

  .mode-bar { display: none; }

  .console {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    gap: 18px;
    height: 100%;
    padding: 0;
  }

  body[data-mode] .pane-control,
  body[data-mode] .pane-transcript {
    display: block;
  }

  .pane-control {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 22px;
    min-height: 0;
  }

  body[data-mode] .talk-view,
  body[data-mode] .call-view {
    display: grid;
    height: auto;
  }

  .talk-view { align-content: end; }

  .call-view { align-content: start; }

  .outbound-form {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

}

@media (min-width: 768px) and (max-height: 740px) {
  :root { --orb-size: 148px; }
  .pane-control { gap: 12px; }
  .outbound-copy { display: none; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

@keyframes speak {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

@keyframes ringPulse {
  0%, 100% { transform: scale(0.98); opacity: 0.35; }
  50% { transform: scale(1.03); opacity: 0.8; }
}

@media (prefers-reduced-motion: reduce) {
  .orb-shell.is-live .orb-core,
  .orb-shell.is-speaking .orb-core,
  .orb-shell.is-live .orb-ring,
  .orb-shell.is-live .orb-ring-2 {
    animation: none !important;
  }

  .msg.partial .msg-stream .w:last-child {
    animation: none !important;
  }
}
