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

:root {
  --bg: #0c0c10;
  --surface: #16161c;
  --surface2: #1e1e26;
  --surface3: #26262f;
  --border: rgba(255,255,255,0.06);
  --text: #f0f0f5;
  --text-2: #a0a0b4;
  --text-3: #5a5a70;
  --blue: #5b8af5;
  --blue-soft: rgba(91,138,245,0.12);
  --green: #3dd68c;
  --green-soft: rgba(61,214,140,0.12);
  --red: #f06060;
  --red-soft: rgba(240,96,96,0.15);
  --orange: #f0a040;
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Status Bar ---- */
.status-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--orange);
  color: #1a1000;
  text-align: center;
  padding: calc(var(--safe-top) + 6px) 16px 6px;
  font-size: 13px;
  font-weight: 600;
  transform: translateY(-100%);
  transition: transform 0.35s var(--ease);
}
.status-bar.visible { transform: translateY(0); }

/* ---- Screens ---- */
.screen {
  display: none;
  width: 100vw;
  height: 100dvh;
}
.screen.active { display: flex; }

/* ---- Mode Select ---- */
#mode-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 48px;
}

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

.brand-icon {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 8px 24px rgba(91,138,245,0.25));
}

.brand h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand p {
  color: var(--text-3);
  font-size: 14px;
  font-weight: 500;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  transition: all 0.2s var(--ease);
}

.mode-card:active {
  transform: scale(0.98);
  background: var(--surface2);
}

.mode-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mode-card-icon.green {
  background: var(--green-soft);
  color: var(--green);
}

.mode-card-icon.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.mode-card-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-card-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mode-card-desc {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 400;
}

.mode-card-arrow {
  color: var(--text-3);
  flex-shrink: 0;
}

/* ---- Login ---- */
#login-screen {
  flex-direction: column;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 24px);
}

.login-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--blue);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 32px;
}

.login-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding-bottom: 80px;
}

.login-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-icon.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.login-form h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.input-group {
  width: 100%;
}

input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: all 0.2s var(--ease);
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

input::placeholder {
  color: var(--text-3);
}

.error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
  font-weight: 500;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--blue);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  letter-spacing: -0.01em;
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* ---- Camera Mode ---- */
#camera-screen {
  flex-direction: column;
  background: #000;
  position: relative;
}

.camera-overlay-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
}

.camera-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--red);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#camera-name-display {
  font-weight: 600;
  font-size: 15px;
  color: rgba(255,255,255,0.9);
}

.viewer-badge {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
}

.viewer-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.camera-setup.hidden { display: none; }

#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* ---- Viewer Mode ---- */
#viewer-screen {
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 16px) 20px 14px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.viewer-header h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.count-badge {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.no-cameras {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 32px;
  padding-bottom: 80px;
}

.no-cameras.hidden { display: none; }

.empty-icon {
  color: var(--text-3);
  opacity: 0.4;
  margin-bottom: 4px;
}

.empty-title {
  color: var(--text-2);
  font-size: 16px;
  font-weight: 600;
}

.empty-sub {
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

.camera-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  padding: 2px;
}

@media (min-width: 640px) {
  .camera-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
    padding: 3px;
  }
}

.camera-card {
  position: relative;
  background: var(--surface);
  aspect-ratio: 16/9;
  overflow: hidden;
  cursor: pointer;
}

.camera-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.camera-card .label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 28px 14px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  display: flex;
  align-items: center;
  gap: 8px;
}

.camera-card .label .cam-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.camera-card .label .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 6px var(--red-soft);
  animation: blink 1.5s infinite;
  flex-shrink: 0;
}

.unmute-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.unmute-btn:active {
  background: rgba(255,255,255,0.2);
}

.unmute-btn svg {
  width: 16px;
  height: 16px;
  color: #fff;
}

.camera-card .connecting {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  gap: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--surface3);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.camera-card.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  aspect-ratio: auto;
}

.camera-card.fullscreen video {
  object-fit: contain;
}

/* ---- Hidden utility ---- */
.status-dot { display: none; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
