:root {
  color-scheme: dark;
  --bg: #081017;
  --surface: #0f1b25;
  --surface-2: #132230;
  --border: #213243;
  --text: #eff6fb;
  --muted: #90a5b7;
  --accent: #65c4ff;
  --accent-strong: #9fe0ff;
  --success: #6ee7b7;
  --danger: #f97316;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(101, 196, 255, 0.15), transparent 34%),
    linear-gradient(180deg, #081017 0%, #060b10 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(320px, 0.95fr);
  gap: 20px;
  padding: 20px;
}

.stage, .control-panel {
  background: linear-gradient(180deg, rgba(19, 34, 48, 0.94), rgba(12, 20, 28, 0.98));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(9, 15, 22, 0.7);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.15);
}

.status-pill[data-state="connecting"] .status-dot { background: #fbbf24; box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.16); }
.status-pill[data-state="connected"] .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(110, 231, 183, 0.16); }

.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #03070b;
  border: 1px solid #203041;
  border-radius: 14px;
  overflow: hidden;
  min-height: 320px;
}

#avatarVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #02060a;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(6, 10, 14, 0.25), rgba(6, 10, 14, 0.68)),
    radial-gradient(circle at center, rgba(101, 196, 255, 0.14), transparent 55%);
}

.empty-state strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
}

.empty-state span {
  display: block;
  max-width: 360px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.avatar-mark {
  width: 88px;
  height: 88px;
  color: var(--accent-strong);
}

.avatar-mark svg { width: 100%; height: 100%; }

.control-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-section {
  display: grid;
  gap: 8px;
}

.panel-section label,
.metric-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.panel-section input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #09121b;
  color: var(--text);
  padding: 14px 15px;
  font-size: 14px;
  outline: none;
}

.panel-section input:focus {
  border-color: rgba(101, 196, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(101, 196, 255, 0.12);
}

.grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-two > div {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(9, 18, 27, 0.9);
  display: grid;
  gap: 6px;
}

.grid-two strong,
#micStatus,
#sessionId,
#iceState {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.button-row {
  display: flex;
  gap: 10px;
}

button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease, border-color 120ms ease;
}

button:active { transform: translateY(1px); }

button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.primary-button {
  flex: 1;
  background: linear-gradient(180deg, rgba(101, 196, 255, 1), rgba(64, 158, 216, 1));
  color: #04111a;
}

.ghost-button {
  flex: 0 0 auto;
  min-width: 114px;
  background: rgba(9, 18, 27, 0.92);
  color: var(--text);
  border: 1px solid var(--border);
}

button svg {
  width: 16px;
  height: 16px;
}

.audio-monitor {
  display: grid;
  gap: 10px;
}

.level-bar {
  height: 10px;
  background: #09121b;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.level-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(101, 196, 255, 0.7), rgba(110, 231, 183, 0.95));
  transition: width 120ms linear;
}

.event-log {
  margin: 0;
  padding-left: 18px;
  max-height: 240px;
  overflow: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.event-log li + li { margin-top: 6px; }

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .stage, .control-panel {
    padding: 14px;
    border-radius: 14px;
  }

  .topbar {
    flex-direction: column;
  }

  .button-row {
    flex-direction: column;
  }

  .ghost-button {
    width: 100%;
  }

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