:root {
  --bg: #0f172a;
  --bg-elev: #111c33;
  --fg: #e2e8f0;
  --fg-dim: #94a3b8;
  --brand: #1e40af;
  --brand-2: #06b6d4;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --border: #1e293b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* iOS safe-area */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-dim);
  transition: background 200ms ease;
}
.brand .dot.connected { background: var(--success); }
.brand .dot.error     { background: var(--danger); }
.title { font-weight: 600; }
.status { color: var(--fg-dim); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

.audio-test {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-left: 10px;
  -webkit-user-select: none;
  user-select: none;
}
.audio-test:active { background: var(--brand); color: #fff; }

/* Debug log pane (collapsible overlay, top-right) */
.debug-pane {
  position: fixed;
  top: 8px;
  right: 8px;
  width: 280px;
  max-width: 70vw;
  z-index: 100;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: var(--fg-dim);
  display: flex;
  flex-direction: column;
  max-height: 50dvh;
  pointer-events: auto;
}
.debug-pane.debug-collapsed .debug-log,
.debug-pane.debug-collapsed .debug-clear { display: none; }
.debug-pane.debug-collapsed { width: auto; }
.debug-toggle, .debug-clear {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  font-family: inherit;
  font-size: 0.7rem;
  padding: 4px 8px;
  cursor: pointer;
}
.debug-toggle { font-weight: 600; align-self: flex-start; }
.debug-clear  { position: absolute; top: 0; right: 4px; }
.debug-log {
  overflow-y: auto;
  padding: 4px 8px 8px;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}
.debug-log .lvl-warn  { color: var(--warn-500, #f59e0b); }
.debug-log .lvl-error { color: var(--danger-500, #ef4444); }

.terminal {
  background: #000;
  padding: 8px;
  overflow: hidden;
  min-height: 0;
}
.terminal .xterm { height: 100%; }
.terminal .xterm-viewport::-webkit-scrollbar { width: 6px; }
.terminal .xterm-viewport::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.transcript {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 0.875rem;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 25dvh;
  overflow-y: auto;
}
.transcript-row { line-height: 1.4; }
.t-label {
  color: var(--brand-2);
  font-weight: 600;
  margin-right: 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.t-text { color: var(--fg); }
#response-row .t-label.forwarded { color: var(--success); }
.timings {
  color: var(--fg-dim);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

.composer {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
}
.ptt {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 9999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: 0 6px 16px rgba(30, 64, 175, 0.4);
  transition: transform 80ms ease, background 120ms ease, box-shadow 120ms ease;
}
.ptt:active, .ptt.recording {
  background: var(--danger);
  transform: scale(0.97);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.5);
}
.ptt.recording .ptt-label::after {
  content: " ●";
  animation: pulse 1s ease-in-out infinite;
}
.ptt:disabled { opacity: 0.5; cursor: not-allowed; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#player { display: none; }

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; }
  .transcript { padding: 8px 12px; max-height: 30dvh; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .ptt { padding: 16px 32px; font-size: 1.05rem; }
}
