:root {
  color-scheme: light;
  --trelis-blue: #0d579b;
  --trelis-green: #329239;
  --trelis-orange: #f7931a;
  --trelis-orange-bright: #ff9f2e;
  --trelis-gray: #4d4d4d;
  --trelis-spectrum: linear-gradient(90deg,#0d579b 0%,#329239 50%,#f7931a 100%);
  --bg-white: #ffffff;
  --bg-light: #fafbfc;
  --bg-subtle: #f0f4f8;
  --text-primary: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 9999px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10);
  --shadow-blue: 0 4px 20px rgba(13,87,155,.15);
  --transition: 0.3s cubic-bezier(0.4,0,0.2,1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -14rem, rgba(13,87,155,.10), transparent 32rem),
    linear-gradient(180deg, var(--bg-white) 0%, var(--bg-light) 46%, var(--bg-subtle) 100%);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

.spectrum-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 3px;
  background: var(--trelis-spectrum);
}

.app-shell {
  width: min(100%, 980px);
  padding: clamp(1rem, 2vw, 2rem);
}

.app-header {
  min-height: 72px;
  margin-bottom: 1rem;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
}

.wordmark-row {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.app-title {
  color: var(--text-primary);
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
}

.eyebrow,
.diag-label,
.form-label {
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dev-switch {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.dev-switch .form-check-input {
  border-color: #cbd5e1;
  box-shadow: none;
}

.dev-switch .form-check-input:checked {
  background-color: var(--trelis-blue);
  border-color: var(--trelis-blue);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-width: 6.6rem;
  justify-content: center;
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-pill);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0.5rem 0.85rem;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}

[data-state="LISTENING"] .status-pill {
  border-color: rgba(50,146,57,.28);
  background: rgba(50,146,57,.10);
  color: var(--trelis-green);
}

[data-state="WARMING"] .status-pill {
  border-color: rgba(247,147,26,.32);
  background: rgba(247,147,26,.12);
  color: #b45f08;
}

[data-state="THINKING"] .status-pill {
  border-color: rgba(247,147,26,.32);
  background: rgba(247,147,26,.12);
  color: #b45f08;
}

[data-state="SPEAKING"] .status-pill {
  border-color: rgba(13,87,155,.30);
  background: rgba(13,87,155,.10);
  color: var(--trelis-blue);
}

.voice-stage {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  margin: 0 auto 1.5rem;
  padding: clamp(1.75rem, 5vw, 3rem) 1rem 1.25rem;
}

.voice-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.voice-pick-label {
  font-size: 0.85rem;
  opacity: 0.8;
  margin: 0;
}

.voice-pick .form-select {
  width: auto;
  min-width: 12rem;
}

.mic-wrap {
  position: relative;
  display: grid;
  place-items: center;
}

.status-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 132px;
  height: 132px;
  border-radius: var(--radius-pill);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

[data-state="LISTENING"] .status-orbit {
  border: 1px solid rgba(50,146,57,.26);
  animation: listenPulse 1.9s ease-out infinite;
}

[data-state="WARMING"] .status-orbit {
  border: 1px solid rgba(247,147,26,.32);
  animation: speakPulse 0.95s ease-in-out infinite alternate;
}

[data-state="SPEAKING"] .status-orbit {
  border: 1px solid rgba(247,147,26,.32);
  animation: speakPulse 0.95s ease-in-out infinite alternate;
}

.mic-button {
  position: relative;
  z-index: 1;
  display: grid;
  width: 104px;
  height: 104px;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--trelis-blue);
  color: #ffffff;
  box-shadow: var(--shadow-blue);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.mic-button::before {
  content: "";
  position: absolute;
  inset: -35% auto -35% -70%;
  width: 52%;
  background: linear-gradient(100deg, transparent 0%, rgba(255,255,255,.42) 50%, transparent 100%);
  transform: skewX(-18deg);
  transition: left 0.7s cubic-bezier(0.4,0,0.2,1);
}

.mic-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), var(--shadow-blue);
}

.mic-button:hover:not(:disabled)::before {
  left: 118%;
}

.mic-button:disabled {
  cursor: default;
  opacity: 0.95;
}

[data-state="LISTENING"] .mic-button {
  background: var(--trelis-green);
}

[data-state="WARMING"] .mic-button {
  background: var(--trelis-orange);
}

[data-state="SPEAKING"] .mic-button {
  background: var(--trelis-orange);
}

.mic-button:focus-visible,
.stop-button:focus-visible {
  outline: 3px solid rgba(13,87,155,.30);
  outline-offset: 4px;
}

.mic-glyph {
  position: relative;
  width: 26px;
  height: 38px;
  /* lift the capsule so the stand (::after) and the label below have clear room */
  transform: translateY(-10px);
  border: 3px solid currentColor;
  border-radius: 18px;
}

.mic-glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 3px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: currentColor;
  transform: translateX(-50%);
}

.mic-glyph::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -17px;
  width: 24px;
  height: 12px;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  border-left: 3px solid currentColor;
  border-radius: 0 0 16px 16px;
  transform: translateX(-50%);
}

.mic-label {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
}

.stop-button {
  min-width: 9.25rem;
  border: 1px solid rgba(247,147,26,.32);
  border-radius: var(--radius-pill);
  background: #fff8ef;
  color: #b45f08;
  font-weight: 700;
  padding: 0.7rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stop-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stop-button:disabled {
  display: none;
}

.status-detail {
  color: var(--text-secondary);
  font-size: 0.98rem;
  text-align: center;
}

.warmup-notice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(247,147,26,.22);
  border-radius: var(--radius-pill);
  background: rgba(247,147,26,.10);
  color: #9a5208;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.55rem 0.85rem;
}

.warmup-notice[hidden] {
  display: none;
}

.conversation-wrap {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem 0.6rem clamp(1rem, 3vw, 1.5rem);
  border-bottom: 1px solid #e6edf4;
}

.conversation-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.reset-btn {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.reset-btn:hover {
  color: var(--trelis-blue);
  border-color: var(--trelis-blue);
  background: rgba(13,87,155,.05);
}

.transcript-panel {
  height: min(48vh, 520px);
  min-height: 320px;
  overflow: auto;
  padding: clamp(1rem, 3vw, 1.5rem);
  scroll-behavior: smooth;
}

.transcript-panel:empty::before {
  content: "Your conversation will appear here.";
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
}

.turn {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.turn-user {
  align-items: flex-end;
}

.turn-assistant {
  align-items: flex-start;
}

.role {
  margin: 0 0 0.28rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.text {
  max-width: min(78%, 42rem);
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-md);
  background: var(--bg-white);
  color: var(--text-primary);
  line-height: 1.48;
  padding: 0.82rem 1rem;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}

.turn-user .text {
  border-color: rgba(13,87,155,.20);
  background: var(--trelis-blue);
  color: #ffffff;
}

.diagnostics-panel {
  margin-top: 1.5rem;
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
  padding: clamp(1rem, 3vw, 1.4rem);
}

[data-dev-mode="off"] .dev-only {
  display: none !important;
}

.panel-title {
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 800;
}

.diagnostic-badge {
  border-radius: var(--radius-pill);
  background: rgba(50,146,57,.10);
  color: var(--trelis-green);
  font-size: 0.76rem;
  font-weight: 800;
  padding: 0.35rem 0.65rem;
  text-transform: uppercase;
}

.diag-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.diag-card,
.settings-panel,
.event-log-wrap {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-md);
  background: var(--bg-white);
  padding: 1rem;
}

.diag-value {
  min-height: 1.45rem;
  margin-top: 0.5rem;
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.form-control {
  border-color: #cbd5e1;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  min-height: 2.45rem;
}

.form-control:focus {
  border-color: rgba(13,87,155,.68);
  box-shadow: 0 0 0 0.2rem rgba(13,87,155,.12);
}

.event-log {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow: auto;
}

.event-row {
  border-radius: var(--radius-sm);
  background: var(--bg-light);
  color: var(--trelis-gray);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 0.5rem 0.6rem;
  overflow-wrap: anywhere;
}

@keyframes listenPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(50,146,57,.24);
    transform: translate(-50%, -50%) scale(0.96);
  }
  100% {
    box-shadow: 0 0 0 24px rgba(50,146,57,0);
    transform: translate(-50%, -50%) scale(1.06);
  }
}

@keyframes speakPulse {
  from {
    box-shadow: 0 0 0 6px rgba(247,147,26,.16);
    transform: translate(-50%, -50%) scale(0.98);
  }
  to {
    box-shadow: 0 0 0 18px rgba(247,147,26,.04);
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start !important;
    flex-direction: column;
    gap: 0.9rem;
  }

  .app-header > .d-flex {
    width: 100%;
    justify-content: space-between;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .status-pill {
    min-width: 5.85rem;
  }

  .mic-button {
    width: 84px;
    height: 84px;
  }

  .status-orbit {
    width: 108px;
    height: 108px;
  }

  .text {
    max-width: 92%;
  }

  .diag-grid {
    grid-template-columns: 1fr;
  }
}
