/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* === Theme Tokens === */
:root {
  --bg-start: #18181b;
  --bg-mid: #1c1917;
  --bg-end: #18181b;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(250, 204, 21, 0.15);
  --glass-hover: rgba(255, 255, 255, 0.1);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.45);
  --text-muted: rgba(255, 255, 255, 0.25);
  --accent-start: #eab308;
  --accent-end: #facc15;
  --accent-text: #18181b;
  --accent-shadow: rgba(234, 179, 8, 0.35);
  --hint-bg: rgba(234, 179, 8, 0.1);
  --hint-border: rgba(234, 179, 8, 0.25);
  --hint-text: #facc15;
  --preview-bg: rgba(0, 0, 0, 0.3);
  --preview-border: rgba(255, 255, 255, 0.06);
  --link-bg: rgba(0, 0, 0, 0.25);
  --link-text: #facc15;
  --btn-secondary-bg: rgba(255, 255, 255, 0.08);
  --btn-secondary-text: var(--text-primary);
  --control-bg: rgba(255, 255, 255, 0.08);
  --control-border: rgba(255, 255, 255, 0.1);
  --control-text: #ffffff;
  --end-bg: rgba(239, 68, 68, 0.8);
  --end-shadow: rgba(239, 68, 68, 0.4);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-start: #fafafa;
    --bg-mid: #f5f5f4;
    --bg-end: #fafafa;
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(234, 179, 8, 0.2);
    --glass-hover: rgba(255, 255, 255, 0.7);
    --text-primary: #18181b;
    --text-secondary: rgba(24, 24, 27, 0.5);
    --text-muted: rgba(24, 24, 27, 0.25);
    --accent-shadow: rgba(234, 179, 8, 0.25);
    --hint-bg: rgba(234, 179, 8, 0.08);
    --hint-border: rgba(202, 138, 4, 0.25);
    --hint-text: #a16207;
    --preview-bg: rgba(0, 0, 0, 0.04);
    --preview-border: rgba(0, 0, 0, 0.06);
    --link-bg: rgba(0, 0, 0, 0.04);
    --link-text: #a16207;
    --btn-secondary-bg: rgba(0, 0, 0, 0.06);
    --btn-secondary-text: var(--text-primary);
    --control-bg: rgba(255, 255, 255, 0.55);
    --control-border: rgba(0, 0, 0, 0.08);
    --control-text: #18181b;
  }
}

/* === Layout === */
body {
  background: linear-gradient(135deg, var(--bg-start), var(--bg-mid), var(--bg-end));
  min-height: 100vh;
}

.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* === Glass Card === */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 36px 32px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.app-icon {
  font-size: 40px;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.app-title {
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

/* === Buttons === */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  color: var(--accent-text, #18181b);
  padding: 14px 32px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--accent-shadow);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-shadow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: var(--glass-hover);
}

/* === Camera Preview === */
.camera-preview {
  background: var(--preview-bg);
  border: 1px solid var(--preview-border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-preview .placeholder {
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === Hint Banner === */
.hint-banner {
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint-banner i {
  color: var(--hint-text);
  font-size: 18px;
  flex-shrink: 0;
}

.hint-banner span {
  color: var(--hint-text);
  font-size: 13px;
  font-weight: 500;
}

/* === Share Link === */
.share-section {
  margin-bottom: 16px;
}

.share-label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 8px;
}

.share-link {
  background: var(--link-bg);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-family: monospace;
  color: var(--link-text);
  margin-bottom: 10px;
  word-break: break-all;
  user-select: all;
}

.share-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.waiting-text {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.waiting-text i {
  animation: spin 1s linear infinite;
}

/* === In-Call View === */
.call-page.active {
  display: flex;
  padding: 0;
  justify-content: stretch;
  align-items: stretch;
}

.call-container {
  width: 100%;
  height: 100vh;
  position: relative;
  background: #0f0f0f;
  overflow: hidden;
}

.remote-videos {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 2px;
}

.remote-videos.count-1 {
  grid-template-columns: 1fr;
}

.remote-videos.count-2 {
  grid-template-columns: 1fr 1fr;
}

.remote-videos.count-3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #1a1a1a;
}

.remote-video-container {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f0f, #1a1a1a);
}

.remote-video-container .no-video-label {
  color: rgba(255, 255, 255, 0.2);
  font-size: 14px;
  position: absolute;
}

/* === PIP (self-view) === */
.pip-video {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 140px;
  height: 105px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.pip-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

/* === Controls Bar === */
.controls-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 12px 28px;
  z-index: 10;
}

.control-btn {
  width: 48px;
  height: 48px;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--control-text);
  cursor: pointer;
  transition: background 0.15s;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.control-btn.muted {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.4);
}

.control-btn.end {
  background: var(--end-bg);
  border: none;
  box-shadow: 0 4px 15px var(--end-shadow);
}

.control-btn.end:hover {
  background: rgba(239, 68, 68, 0.9);
}

/* === Flip Camera (mobile only) === */
.flip-btn {
  display: none;
}

@media (pointer: coarse) {
  .flip-btn {
    display: flex;
  }
}

/* === Status Messages === */
.status-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  text-align: center;
  z-index: 5;
}

/* === Responsive === */
@media (max-width: 480px) {
  .glass-card {
    padding: 28px 20px;
    width: 95%;
  }

  .pip-video {
    width: 100px;
    height: 75px;
    top: 10px;
    right: 10px;
  }

  .controls-bar {
    padding: 10px 20px;
    gap: 12px;
    bottom: 16px;
  }

  .control-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}
