:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-hover: #1e1e1e;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-dim: #737373;
  --text-muted: #525252;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --font: 'Sora', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Screens ---- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
}

/* ---- Screen 1: Code Entry ---- */

#screen-code {
  background: var(--bg);
  justify-content: center;
  align-items: center;
}

.code-screen-inner {
  width: 100%;
  max-width: 360px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Brand */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

/* Code Input */
.code-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#room-code {
  width: 100%;
  padding: 18px 16px;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 12px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
  caret-color: var(--accent);
}

#room-code::placeholder {
  color: var(--text-muted);
  letter-spacing: 12px;
}

#room-code:focus {
  border-color: var(--accent);
}

/* Connect Button */
#connect-btn {
  width: 100%;
  padding: 18px;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

#connect-btn:active:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(0.98);
}

#connect-btn:disabled {
  background: var(--surface);
  color: var(--text-muted);
  cursor: not-allowed;
}

#connect-btn.loading {
  background: var(--surface);
  color: var(--text-dim);
  pointer-events: none;
}

/* Status Bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-text {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* Status dot colors */
.status-dot.connecting {
  background: var(--amber);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot.connected { background: var(--green); }
.status-dot.error { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---- Screen 2: Camera ---- */

#screen-camera {
  background: #000;
}

#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

/* Top overlay */
.camera-overlay-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(env(safe-area-inset-top, 16px), 16px) 20px 24px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, transparent 100%);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 10;
}

.cam-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 100px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.cam-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
  animation: pulse 1.4s ease-in-out infinite;
}

.cam-status-dot.connected {
  background: var(--green);
  animation: none;
}

.cam-status-dot.error {
  background: var(--red);
  animation: none;
}

.cam-status-text {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.cam-room-code {
  padding: 10px 14px;
  border-radius: 100px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 2px;
}

/* Bottom overlay */
.camera-overlay-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 20px max(env(safe-area-inset-bottom, 20px), 20px);
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, transparent 100%);
  display: flex;
  justify-content: center;
  z-index: 10;
}

#disconnect-btn {
  padding: 14px 40px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  border-radius: 100px;
  border: none;
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.1s ease;
}

#disconnect-btn:active {
  background: rgba(220, 38, 38, 1);
  transform: scale(0.96);
}
