/* --- GLOBAL VARIABLES --- */
:root {
  --primary: #8b5cf6; /* Violet */
  --secondary: #ec4899; /* Pink */
  --success: #10b981; /* Green */
  --danger: #ef4444; /* Red */
  --bg: #0f0f13;
  --card-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 50% 0%, #2a2a35 0%, var(--bg) 70%);
  color: white;
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  /* Push footer to bottom */
  flex: 1; 
}

/* --- HEADER --- */
header { text-align: center; margin-bottom: 10px; }
h1 {
  margin: 0;
  font-size: 2.5rem;
  background: linear-gradient(to right, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
  letter-spacing: -1px;
}
.status { color: #888; font-size: 0.9rem; margin-top: 8px; font-weight: 600; }

/* --- VIEW AREA --- */
.view-area {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.frame-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.frame-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #aaa;
  font-weight: 600;
}

.frame-container {
  width: 100%;
  aspect-ratio: 1/1;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 40px -10px rgba(0,0,0,0.5);
  border: 1px solid var(--glass-border);
}

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

/* --- OUTPUT & LOADER --- */
.output-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0; left: 0;
  transition: opacity 0.2s ease-in-out;
  opacity: 0;
  z-index: 1;
}
.output-image.active { opacity: 1; z-index: 2; }

/* The Loader Overlay */
.loader {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.loader.show { opacity: 1; pointer-events: auto; }

/* CSS Spinner */
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255,255,255,0.1);
  border-left-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- CONTROLS --- */
.controls-card {
  background: var(--card-bg);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 24px;
  backdrop-filter: blur(10px);
}

.control-group { margin-bottom: 20px; }
.control-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 12px; color: #ddd; }

.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}

.option-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid transparent;
  padding: 12px 8px;
  border-radius: 12px;
  color: #ccc;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}
.option-btn:hover { background: rgba(255,255,255,0.1); }
.option-btn.selected {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
  border-color: rgba(255,255,255,0.2);
  font-weight: 600;
}

.action-row { display: flex; gap: 15px; justify-content: center; margin-top: 10px; }
.action-btn {
  flex: 1; max-width: 200px; padding: 16px;
  border-radius: 16px; border: none; font-size: 1.1rem;
  font-weight: 700; cursor: pointer; transition: transform 0.1s;
  text-transform: uppercase;
}
.action-btn:active { transform: scale(0.96); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-start { background: var(--success); color: #003300; box-shadow: 0 0 20px rgba(16, 185, 129, 0.3); }
.btn-stop { background: var(--card-bg); color: #aaa; border: 1px solid var(--glass-border); }
.btn-stop.active { background: var(--danger); color: white; box-shadow: 0 0 20px rgba(239, 68, 68, 0.3); }

/* --- FOOTER & MODAL --- */
.footer {
  margin-top: 40px;
  display: flex;
  gap: 20px;
  justify-content: center;
  font-size: 0.9rem;
  /* Ensure footer doesn't shrink awkwardly */
  flex-shrink: 0; 
  padding-bottom: 20px;
}
.footer a {
  color: #888;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s;
}
.footer a:hover { color: white; }

/* Modal Backdrop */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

/* Modal Content Box */
.modal-content {
  background: #1a1a20;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  width: 90%;
  max-width: 600px; /* Slightly wider for reading */

  /* ⚡ SCROLLING LOGIC */
  max-height: 85vh; /* Never taller than 85% of screen */
  display: flex;    /* Use flex to stack header and body */
  flex-direction: column;

  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.3s;
}
.modal-overlay.open .modal-content { transform: translateY(0); }

/* Fixed Header */
.modal-header {
  font-size: 1.5rem;
  font-weight: bold;
  padding: 25px 30px 15px 30px; /* Padding inside header */
  flex-shrink: 0; /* Don't let header shrink */
}

/* Scrollable Body */
.modal-body {
  color: #ccc;
  line-height: 1.6;
  font-size: 0.95rem;
  padding: 0 30px 30px 30px; /* Padding inside body */
  overflow-y: auto; /* ⚡ Enables vertical scrolling */
}

.close-modal {
  position: absolute; top: 20px; right: 20px;
  background: none; border: none; color: #aaa;
  font-size: 1.8rem; cursor: pointer;
  z-index: 5;
}
.close-modal:hover { color: white; }

/* ⚡ Custom Scrollbar Styling (Webkit/Chrome/Safari) */
.modal-body::-webkit-scrollbar {
  width: 8px;
}
.modal-body::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.02);
  margin-bottom: 20px; /* Space at bottom */
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.3);
}