:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-alt: #121820;
  --card: #171f29;
  --border: #263140;
  --text: #e7edf3;
  --muted: #93a3b5;
  --accent: #3aa0ff;
  --accent-dark: #1c7ed6;
  --ok: #35c46f;
  --off: #ff5a5f;
  --warn: #f5a623;
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden], .u-hidden { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

a { color: var(--accent); }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

header.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: var(--bg-alt); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05131f;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-danger { border-color: var(--off); color: var(--off); }
.btn-danger:hover { background: rgba(255, 90, 95, 0.12); }

.btn-block { width: 100%; }

.center-screen {
  min-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 24px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  width: 100%;
  max-width: 640px;
}

@media (max-width: 560px) {
  .choice-grid { grid-template-columns: 1fr; }
}

.choice-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s, transform 0.15s;
}

.choice-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.choice-card .icon { font-size: 2.5rem; }
.choice-card h2 { margin: 0; font-size: 1.1rem; }
.choice-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.form-group { margin-bottom: 16px; text-align: left; }
label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
}

.error-msg { color: var(--off); font-size: 0.85rem; min-height: 1.2em; margin-top: 6px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.status-pill.online .dot { background: var(--ok); }
.status-pill.online { color: var(--ok); }
.status-pill.offline { color: var(--off); }
.status-pill.connecting .dot { background: var(--warn); }
.status-pill.connecting { color: var(--warn); }

.cam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.cam-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cam-video-box {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}

.cam-video-box video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.cam-video-box .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  flex-direction: column;
  gap: 8px;
}

.cam-video-box .fs-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}

.cam-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 8px;
}

.cam-meta .name {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 16px;
  grid-column: 1 / -1;
}

.helper-text { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.publish-preview {
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 60vh;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
}
.publish-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }

.banner {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}
.banner.warn { background: rgba(245, 166, 35, 0.15); color: var(--warn); border: 1px solid rgba(245, 166, 35, 0.3); }
.banner.error { background: rgba(255, 90, 95, 0.15); color: var(--off); border: 1px solid rgba(255, 90, 95, 0.3); }
.banner.ok { background: rgba(53, 196, 111, 0.15); color: var(--ok); border: 1px solid rgba(53, 196, 111, 0.3); }

footer.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 24px;
}

.viewer-count-note { color: var(--muted); font-size: 0.8rem; margin-bottom: 12px; }

.hero-title { font-size: 1.6rem; margin-bottom: 6px; }
.hero-subtitle { color: var(--muted); margin-top: 0; }
.auth-card { max-width: 380px; width: 100%; text-align: left; }
.auth-back-link { text-align: center; margin-bottom: 0; }
.row-auto { flex: none; }
.key-panel { max-width: 420px; margin: 0 auto; }
.tight-heading { margin-top: 0; }
.status-row { margin-top: 14px; }
.viewer-count-pill { margin-left: 8px; }
.dot-accent { background: var(--accent); }
