:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f5f7f8;
  color: #172026;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(340px, min(40vw, 560px)) minmax(0, 1fr);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0)),
    #eef3f4;
  overflow: hidden;
}

.stage {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background: #11181c;
}

#cameraPreview,
#frameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cameraPreview {
  object-fit: cover;
  transform: scaleX(-1);
}

#frameCanvas {
  display: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.46), rgba(0, 0, 0, 0.05) 40%, rgba(0, 0, 0, 0.58));
  pointer-events: none;
}

.stage-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(20px, 3vw, 36px);
  color: white;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  opacity: 0.78;
}

h1 {
  margin: 0;
  max-width: 9ch;
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.status-pill {
  align-self: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.36);
  background: rgba(18, 25, 30, 0.58);
  backdrop-filter: blur(16px);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.stage-status {
  display: grid;
  gap: 10px;
  justify-items: start;
}

.ai-state {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  background: rgba(18, 25, 30, 0.64);
  backdrop-filter: blur(16px);
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 650;
}

.ai-state-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #a8b3b8;
  box-shadow: 0 0 0 4px rgba(168, 179, 184, 0.18);
}

.ai-state.listening .ai-state-dot {
  background: #49d39b;
  box-shadow: 0 0 0 4px rgba(73, 211, 155, 0.22);
}

.ai-state.thinking .ai-state-dot {
  background: #f7c84f;
  box-shadow: 0 0 0 4px rgba(247, 200, 79, 0.24);
}

.ai-state.responding .ai-state-dot {
  background: #76b7ff;
  box-shadow: 0 0 0 4px rgba(118, 183, 255, 0.24);
}

.ai-state.error .ai-state-dot {
  background: #ff7373;
  box-shadow: 0 0 0 4px rgba(255, 115, 115, 0.22);
}

.status-pill.connected {
  background: rgba(18, 112, 84, 0.78);
}

.status-pill.error {
  background: rgba(178, 49, 49, 0.78);
}

.workspace {
  min-width: 0;
  max-width: 100%;
  height: 100vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel {
  min-width: 0;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d8e1e3;
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(31, 48, 56, 0.08);
}

.config-panel {
  min-width: 0;
  flex: 0 0 auto;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.advanced-config {
  border: 1px solid #d8e1e3;
  border-radius: 8px;
  background: #f7fafb;
}

.advanced-config-toggle {
  min-height: 42px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #26343b;
  cursor: pointer;
  font-weight: 650;
  text-align: left;
}

.advanced-config-toggle:hover {
  background: #edf3f5;
}

.summary-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #e6ecee;
  color: #52636c;
  transition: transform 160ms ease;
}

.advanced-config.expanded .summary-chevron {
  transform: rotate(180deg);
}

.advanced-config-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 12px;
}

.advanced-config-body[hidden] {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  color: #41515a;
  font-size: 0.88rem;
}

input,
select {
  min-width: 0;
  width: 100%;
  border: 1px solid #c7d2d6;
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: #172026;
  outline: none;
}

input:focus {
  border-color: #2d6f8f;
  box-shadow: 0 0 0 3px rgba(45, 111, 143, 0.16);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.toggles,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toggle {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 36px;
}

.toggle input {
  width: 18px;
  height: 18px;
}

button {
  border: 0;
  border-radius: 7px;
  min-height: 42px;
  padding: 0 15px;
  background: #185a73;
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button.secondary {
  background: #e6ecee;
  color: #26343b;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  flex: 0 0 clamp(280px, 38vh, 520px);
  min-height: 280px;
  min-width: 0;
}

.transcript {
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 88%;
  border-radius: 8px;
  padding: 11px 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: #dcebef;
}

.message.assistant {
  align-self: flex-start;
  background: #f0f3f4;
}

.message.system {
  align-self: center;
  max-width: 100%;
  padding: 8px 10px;
  color: #5c6870;
  background: transparent;
  font-size: 0.88rem;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #d8e1e3;
  min-width: 0;
}

.telemetry-panel {
  min-width: 0;
  max-width: 100%;
  flex: 0 0 auto;
  padding: 14px;
  overflow: hidden;
}

dl {
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

dl div {
  padding: 10px;
  border-radius: 7px;
  background: #f4f7f8;
}

dt {
  color: #65727a;
  font-size: 0.78rem;
}

dd {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

pre {
  margin: 0;
  width: 100%;
  min-width: 0;
  min-height: 96px;
  max-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  color: #47565e;
  font-size: 0.78rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .stage {
    height: min(42vh, 360px);
    min-height: 260px;
  }

  .workspace {
    height: auto;
    min-height: 58vh;
  }

  .chat-panel {
    flex-basis: 360px;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 10px;
  }

  .control-grid,
  .query-form,
  dl {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2.45rem;
  }
}
