@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@400;500;600&display=swap');

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

:root {
  --bg:           #080c10;
  --surface:      #0f1318;
  --surface2:     #151c26;
  --green:        #00ff88;
  --green-dim:    rgba(0, 255, 136, 0.08);
  --green-border: rgba(0, 255, 136, 0.22);
  --green-glow:   rgba(0, 255, 136, 0.45);
  --red:          #ff3355;
  --amber:        #ffaa00;
  --text:         #c2d8c2;
  --text-dim:     rgba(194, 216, 194, 0.42);
  --mono:         'Space Mono', 'Courier New', monospace;
  --ui:           'Inter', -apple-system, sans-serif;
  --r:            12px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Page container ─────────────────────────────────────────── */
#page {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

/* ── Header ─────────────────────────────────────────────────── */
#header {
  margin-bottom: 20px;
}

#header h1 {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text);
}

.accent {
  color: var(--green);
  text-shadow: 0 0 18px var(--green-glow);
}

/* ── Camera container 16:9 ──────────────────────────────────── */
#cam-wrap {
  width: 100%;
}

#cam-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--r);
  overflow: hidden;
  border: 1px solid var(--green-border);
  box-shadow:
    0 0 0 1px rgba(0, 255, 136, 0.04),
    0 0 40px rgba(0, 255, 136, 0.07),
    0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Fullscreen state */
#cam-container:fullscreen,
#cam-container:-webkit-full-screen {
  border-radius: 0;
  border: none;
  aspect-ratio: unset;
  width: 100vw;
  height: 100vh;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* ── Error bar ──────────────────────────────────────────────── */
#error-bar {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(255, 51, 85, 0.08);
  border: 1px solid rgba(255, 51, 85, 0.3);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--red);
  line-height: 1.5;
}

/* ── Stats bar ──────────────────────────────────────────────── */
#stats-bar {
  display: flex;
  align-items: center;
  margin-top: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r);
  font-family: var(--mono);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}

.stat-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  line-height: 1;
  text-shadow: 0 0 10px var(--green-glow);
  min-width: 32px;
  text-align: center;
}

.stat-lbl {
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-top: 3px;
}

.stat-sep {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.stat-ws {
  flex-direction: row;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  padding-right: 0;
}

/* ── WS dot ─────────────────────────────────────────────────── */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green), 0 0 12px var(--green-glow);
  animation: pulse 2.5s ease-in-out infinite;
}

.dot.disconnected {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.dot.connecting {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
  animation: blink 0.7s ease-in-out infinite;
}

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

/* ── Action bar ─────────────────────────────────────────────── */
#action-bar {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.action-btn {
  flex: 1;
  height: 42px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-btn:hover {
  background: var(--surface2);
  border-color: var(--green-border);
  color: var(--green);
}

.action-btn:active { transform: scale(0.97); }

/* ── Modal backdrop ─────────────────────────────────────────── */
#modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.22s ease;
}

#modal-backdrop.hidden { opacity: 0; pointer-events: none; }

/* ── Settings modal ─────────────────────────────────────────── */
#modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 101;
  width: min(480px, calc(100vw - 32px));
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--green-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0, 255, 136, 0.05),
    0 24px 64px rgba(0, 0, 0, 0.65);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#modal.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.95);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 4px;
  color: var(--green);
  text-shadow: 0 0 10px var(--green-glow);
}

.close-btn {
  width: 30px;
  height: 30px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.close-btn:hover { color: var(--green); border-color: var(--green-border); }

.modal-body {
  overflow-y: auto;
  padding: 16px 20px 24px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* ── Setting groups ─────────────────────────────────────────── */
.s-group {
  margin-bottom: 18px;
}

.s-group:last-child { margin-bottom: 0; }

.s-label {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 2.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.s-row {
  display: flex;
  gap: 8px;
}

.s-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Toggle buttons ─────────────────────────────────────────── */
.tog {
  flex: 1;
  min-height: 40px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Camera list: full-width left-aligned buttons */
.s-col .tog {
  flex: none;
  text-align: left;
  padding: 0 14px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tog.active {
  background: var(--green-dim);
  border-color: var(--green-border);
  color: var(--green);
  text-shadow: 0 0 8px var(--green-glow);
}

.tog:active { transform: scale(0.96); }
