* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f0f;
  color: #fff;
  min-height: 100dvh;
  overflow: hidden;
}

body.home-page {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.container {
  max-width: 600px;
  width: 90%;
  text-align: center;
}

h1 { font-size: 2rem; margin-bottom: 0.25rem; }

.subtitle { color: #aaa; margin-bottom: 2rem; }

.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #555; cursor: not-allowed; }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; background: #333; color: #fff; }
.btn-sm:hover { background: #444; }

.btn-open { background: #059669; }
.btn-open:hover { background: #047857; }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled { background: #555; cursor: not-allowed; }

.result { margin-top: 2rem; text-align: left; }
.result h2 { text-align: center; margin-bottom: 1rem; color: #22c55e; }

.link-group { margin-bottom: 1rem; }
.link-group label { display: block; font-size: 0.85rem; color: #aaa; margin-bottom: 0.3rem; }

.link-row { display: flex; gap: 0.5rem; }
.link-row input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.85rem;
}

.room-info { text-align: center; color: #888; font-size: 0.85rem; margin-top: 1rem; }

.error {
  margin-top: 1rem;
  padding: 1rem;
  background: #7f1d1d;
  border-radius: 8px;
  color: #fca5a5;
  text-align: center;
}

.key-input { margin-bottom: 1rem; text-align: left; }
.key-input label { display: block; font-size: 0.85rem; color: #aaa; margin-bottom: 0.3rem; }
.key-input input {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.9rem;
  font-family: monospace;
}

.divider { border: none; border-top: 1px solid #333; margin: 1.5rem 0; }

.close-section { text-align: left; }
.close-section h2 { font-size: 1.1rem; text-align: center; margin-bottom: 0.25rem; }
.section-desc { text-align: center; color: #888; font-size: 0.85rem; margin-bottom: 0.75rem; }

.close-result {
  margin-top: 0.75rem;
  padding: 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
}

.close-success { background: #14532d; color: #86efac; }
.close-fail { background: #7f1d1d; color: #fca5a5; }

.hidden { display: none !important; }

/* ── Call page ───────────────────────────────────── */

.call-container {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.prejoin {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
}

.prejoin h2 { font-size: 1.3rem; }

.video-preview-wrapper {
  width: min(320px, 80vw);
  aspect-ratio: 16/9;
  border-radius: 12px;
  overflow: hidden;
  background: #1a1a1a;
  flex-shrink: 1;
  min-height: 0;
}

.video-preview-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.prejoin-info { display: flex; gap: 0.75rem; align-items: center; font-size: 0.9rem; }

.role-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.role-badge.host { background: #2563eb; }
.role-badge.guest { background: #7c3aed; }

.prejoin-controls { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }

.incall { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.video-grid {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  min-height: 0;
}

.video-wrapper { position: absolute; }

.remote-wrapper { inset: 0; }

.remote-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  color: #888;
  font-size: 1.1rem;
  text-align: center;
  padding: 1rem;
}

.local-wrapper {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: min(200px, 25vw);
  aspect-ratio: 16/9;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #444;
  z-index: 10;
}

.local-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  border-top: 1px solid #222;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ctrl-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #333;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.ctrl-btn:hover { background: #555; }
.ctrl-btn.muted { background: #7f1d1d; }
.ctrl-btn.recording { background: #dc2626; animation: pulse-rec 1.2s ease-in-out infinite; }

@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.ctrl-end { background: #dc2626; }
.ctrl-end:hover { background: #b91c1c; }

.status-bar {
  text-align: center;
  padding: 0.3rem;
  background: #111;
  font-size: 0.75rem;
  color: #888;
  flex-shrink: 0;
}

.error-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.error-message { text-align: center; padding: 2rem; }
.error-message p { font-size: 1.2rem; color: #fca5a5; margin-bottom: 1.5rem; }

.ended {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.ended h2 { font-size: 1.8rem; }
.ended p { color: #aaa; margin-bottom: 1rem; }

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 600px) {
  .local-wrapper { width: min(130px, 30vw); bottom: 8px; right: 8px; }
  .controls { gap: 0.6rem; padding: 0.6rem; }
  .ctrl-btn { width: 42px; height: 42px; font-size: 1rem; }
}

@media (min-width: 1200px) {
  .local-wrapper { width: 240px; bottom: 16px; right: 16px; }
  .ctrl-btn { width: 52px; height: 52px; font-size: 1.3rem; }
}
