:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3347;
  --accent: #5c6ef8;
  --accent-hover: #7080ff;
  --danger: #e05c5c;
  --text: #e8eaf0;
  --text-muted: #7b82a0;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Layout ── */
.page { width: 100%; max-width: 520px; padding: 32px 20px; }
.page-wide { width: 100%; max-width: 1100px; padding: 16px; }

/* ── Header ── */
.header {
  text-align: center;
  margin-bottom: 36px;
}
.header h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; }
.header h1 span { color: var(--accent); }
.header p { margin-top: 8px; color: var(--text-muted); font-size: 0.95rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Form ── */
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }

input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 10px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-muted); }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 18px;
  transition: background 0.15s, transform 0.05s;
}
button:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-full { width: 100%; }

.divider { text-align: center; color: var(--text-muted); margin: 12px 0; font-size: 0.85rem; }

.active-rot { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }

/* ── Lobby code badge ── */
.code-badge {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  color: var(--accent);
  background: var(--bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 12px 20px;
  font-family: 'Courier New', monospace;
  cursor: pointer;
  transition: background 0.15s;
}
.code-badge:hover { background: #1a1f3a; }

/* ── QR ── */
#qr-container { display: flex; justify-content: center; margin: 16px 0; }
#qr-container canvas { border-radius: 8px; border: 4px solid #fff; }

/* ── Share row ── */
.share-row { display: flex; gap: 8px; align-items: center; }
.share-row input { flex: 1; font-size: 0.8rem; color: var(--text-muted); }

/* ── Status pill ── */
.status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 0.82rem; color: var(--text-muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.dot.green { background: #4caf7d; }
.dot.red { background: var(--danger); }
.dot.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
@keyframes focusPulse { 0%{opacity:1;transform:scale(1)} 100%{opacity:0;transform:scale(1.6)} }

/* ── Host layout ── */
.host-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  align-items: start;
}
@media(max-width:768px){ .host-grid { grid-template-columns: 1fr; } }

/* ── Video ── */
.video-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
}
video {
  width: 100%; height: 100%; object-fit: contain;
  display: block;
}
#capture-flash {
  position: absolute; inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
}
#capture-flash.flash { opacity: 0.6; transition: none; }

/* ── Camera controls ── */
.cam-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
}

/* ── Capture interval ── */
.interval-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.interval-row label { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
input[type="range"] { cursor: pointer; accent-color: var(--accent); }

/* ── Viewer ── */
.viewer-wrap {
  position: relative;
  overflow: hidden;
  background: #000;
  border-radius: var(--radius);
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 400px;
  touch-action: none;
  cursor: grab;
}
.viewer-wrap:active { cursor: grabbing; }

#snapshot-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
  background: rgba(15,17,23,0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 8px 16px;
}
.zoom-label { color: var(--text-muted); font-size: 0.8rem; min-width: 44px; text-align: center; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 18px;
  font-size: 0.88rem; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
  white-space: nowrap;
  z-index: 1000;
}
#toast.show { opacity: 1; }

/* ── Spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.placeholder-msg {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.placeholder-msg .icon { font-size: 3rem; margin-bottom: 12px; }

/* ── Recent rooms ── */
.recent-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.recent-entry:last-child { border-bottom: none; padding-bottom: 0; }
.recent-entry:first-child { padding-top: 0; }
.recent-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.recent-icon { font-size: 1.3rem; flex-shrink: 0; }
.recent-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.recent-actions { display: flex; gap: 6px; flex-shrink: 0; }
