:root {
  --bg: #0b1224;
  --bg-2: #0f1f3a;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --card: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.12), transparent 32%),
    radial-gradient(circle at 80% 0%, rgba(34, 211, 238, 0.08), transparent 28%),
    linear-gradient(145deg, var(--bg), var(--bg-2));
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.9rem;
}

.pill.warning {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.6);
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.video-frame {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a1020;
  aspect-ratio: 16 / 9;
  min-height: 420px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #0a1020;
}

.overlay.status {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text);
  z-index: 10;
}

.overlay.camera-info {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.7rem;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.85);
  font-family: 'Consolas', 'Monaco', monospace;
  text-align: right;
  z-index: 10;
  display: none;
}

.overlay-button {
  all: unset;
  position: absolute;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: transform 200ms ease, background 200ms ease;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.overlay-button:active {
  transform: scale(0.92);
  background: rgba(0, 0, 0, 0.75);
}

.sidebar-toggle {
  bottom: 24px;
  right: 24px;
}

.sidebar {
  position: fixed;
  top: 0;
  right: -320px;
  width: 320px;
  height: 100vh;
  background: linear-gradient(145deg, #0f1f3a, #0b1224);
  border-left: 2px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.7);
  z-index: 101;
  transition: right 300ms ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar.open {
  right: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.sidebar-close {
  all: unset;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  transition: background 200ms ease;
}

.sidebar-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-content {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.camera-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.no-camera {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.camera-option {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 200ms ease;
  position: relative;
}

.camera-option:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
}

.camera-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.camera-option input[type="radio"]:checked ~ .camera-label {
  color: var(--accent);
  font-weight: 600;
}

.camera-option input[type="radio"]:checked ~ .camera-checkmark {
  opacity: 1;
  transform: scale(1);
}

.camera-option:has(input[type="radio"]:checked) {
  background: rgba(56, 189, 248, 0.1);
  border-color: var(--accent);
}

.camera-label {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text);
  transition: all 200ms ease;
}

.camera-checkmark {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.5);
  transition: all 200ms ease;
}

.camera-checkmark::after {
  content: '✓';
  color: #0b1224;
  font-size: 14px;
  font-weight: bold;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: all;
}
  font-family: inherit;
  min-width: 200px;
  max-width: 280px;
  cursor: pointer;
  z-index: 11;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: background 200ms ease, border-color 200ms ease;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overlay-select:hover {
  background: rgba(0, 0, 0, 0.75);
  border-color: rgba(255, 255, 255, 0.3);
}

.overlay-select:focus {
  outline: none;
  border-color: var(--accent);
}

.overlay-select option {
  background: #1a1a1a;
  color: var(--text);
  padding: 8px;
  font-size: 0.9rem;
}

.overlay-flip {
  all: unset;
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 64px;
  height: 64px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
  transition: transform 200ms ease, background 200ms ease;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.overlay-flip:active {
  transform: scale(0.92);
  background: rgba(0, 0, 0, 0.75);
}

.controls {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

button {
  all: unset;
  cursor: pointer;
  padding: 12px 14px;
  text-align: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 600;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

button#startButton {
  display: none;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1224;
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.25);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

button:not(:disabled):active {
  transform: translateY(0);
}

.secondary-row {
  right: 66px;
  font-size: 0.65rem;
}

body.mobile-view .sidebar {
  width: 100%;
  right: -100%;
}

body.mobile-view .sidebar.open {
  right: 0;
}

.foot {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 700px) {
  .video-frame {
    min-height: 320px;
  }
}

/* Mobile optimizations */
body.mobile-view {
  padding: 0;
  margin: 0;
  overflow: hidden;
}

body.mobile-view .page {
  padding: 0;
  max-width: 100%;
  height: 100vh;
  gap: 0;
}

body.mobile-view .top-bar,
body.mobile-view .controls,
body.mobile-view .foot {
  display: none;
}

body.mobile-view .stage {
  height: 100vh;
  gap: 0;
}

body.mobile-view .video-frame {
  height: 100vh;
  min-height: 100vh;
  border-radius: 0;
  border: none;
}

body.mobile-view .overlay-flip {
  display: flex;
}

body.mobile-view .overlay.status {
  top: 12px;
  left: 12px;
}

body.mobile-view .overlay.camera-info {
  top: 12px;
  right: 12px;
  font-size: 0.65rem;
}

body.mobile-view .sidebar-toggle {
  bottom: 28px;
  right: 28px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 24px;
}

body.mobile-view .overlay-select {
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 28to;
  width: calc(100% - 48px);
  max-width: 320px;
  font-size: 0.85rem;
}

body.mobile-view .overlay-flip {
  bottom: 28px;
  left: 28px;
}
