:root {
  --bg: #0f1115;
  --panel: #181c24;
  --border: #2a3140;
  --text: #eef2f7;
  --muted: #98a4b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden {
  display: none !important;
}

.panel {
  width: min(420px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px var(--ok);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
}

.field input {
  background: #101319;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: opacity 0.15s, background 0.15s;
}

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

.btn.primary {
  background: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.secondary {
  background: #252c3a;
}

.btn.small {
  padding: 10px 14px;
  font-size: 14px;
}

.error {
  margin: 0;
  color: #fca5a5;
  font-size: 13px;
  line-height: 1.4;
}

/* Active call layout */
.call-screen {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
}

.video-stage {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0b0d11;
}

#local-video {
  position: absolute;
  right: 14px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  width: 112px;
  height: 156px;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: #141820;
  z-index: 5;
  transform: scaleX(-1);
}

.waiting-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 17, 0.72);
  z-index: 3;
}

.waiting-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 24px;
  border-radius: 16px;
  background: rgba(24, 28, 36, 0.9);
  border: 1px solid var(--border);
  text-align: center;
}

.waiting-card p {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.call-topbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
}

.status-pill, .icon-pill {
  pointer-events: auto;
  background: rgba(15, 17, 21, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  border-radius: 999px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  font-size: 13px;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.conn-dot.ok { background: var(--ok); }
.conn-dot.err { background: var(--danger); }

.icon-pill {
  width: 34px;
  height: 34px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.diag-panel {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  right: 14px;
  z-index: 10;
  background: rgba(15, 17, 21, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  min-width: 210px;
}

.diag-panel strong {
  color: var(--text);
}

.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 10px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
  z-index: 10;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 64px;
  height: 60px;
  border: 0;
  border-radius: 16px;
  background: rgba(32, 38, 50, 0.86);
  color: var(--text);
  cursor: pointer;
}

.ctrl-btn.off {
  background: rgba(255, 255, 255, 0.16);
  color: #fca5a5;
}

.ctrl-btn.danger {
  background: var(--danger);
  color: #fff;
}

.ctrl-icon {
  font-size: 20px;
  line-height: 1;
}

.ctrl-text {
  font-size: 10px;
  opacity: 0.9;
}

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 28, 36, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
}
