:root {
  --bg: #0f1113;
  --panel: #1a1e22;
  --text: #f2f4f5;
  --muted: #9aa4ad;
  --accent: #3b82f6;
  --ok: #22c55e;
  --bad: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

html.viewer-page, html.viewer-page body { background: #fff; }
html.viewer-page h1 { color: #111; }

body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.25rem; }

.viewer, .admin {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.pill {
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #2a3036;
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { background: rgba(34, 197, 94, 0.18); color: var(--ok); }
.pill.bad { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

.player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player video { width: 100%; height: 100%; display: block; background: #000; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.overlay[hidden] { display: none; }

.btn {
  font: inherit;
  min-height: 48px;
  min-width: 48px;
  padding: 0 16px;
  border: 1px solid #2f363d;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.btn:focus-visible, select:focus-visible, input:focus-visible, .link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { background: var(--accent); border-color: var(--accent); }
.btn[hidden] { display: none; }

.ptz {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.ptz[hidden] { display: none; }

.ptz-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  align-items: center;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 72px);
  gap: 8px;
}
.dpad .btn {
  width: 100%;
  height: 100%;
  font-size: 1.4rem;
  touch-action: none;
}
.dpad-center { border-radius: 50%; background: #23292f; }

.zoom { display: flex; flex-direction: column; gap: 8px; }
.zoom .btn { width: 72px; height: 72px; font-size: 1.8rem; touch-action: none; }

.speed { display: flex; align-items: center; gap: 8px; color: var(--muted); }
select, input, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS Safari zoom-on-focus */
  color: var(--text);
  background: #0c0f12;
  border: 1px solid #2f363d;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
.speed select { width: auto; }

.msg { min-height: 1.4em; margin: 0; color: #fca5a5; text-align: center; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 12px; }
.notice { margin: 0 0 8px; }
.notice.bad, .notice.error { color: #fca5a5; }

fieldset {
  border: 1px solid #2f363d;
  border-radius: var(--radius);
  padding: 12px 16px 16px;
  margin: 0 0 16px;
  background: var(--panel);
}
legend { padding: 0 6px; font-weight: 600; }
fieldset label { display: block; margin: 10px 0; color: var(--muted); }
fieldset label input, fieldset label select { margin-top: 4px; color: var(--text); }
fieldset label.check { display: flex; gap: 10px; align-items: center; color: var(--text); }
fieldset label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.embed { margin-top: 24px; }
.embed textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; margin-bottom: 8px; }

.link { color: var(--accent); }

@media (min-width: 720px) {
  .viewer, .admin { padding: 24px; }
  .dpad { grid-template-columns: repeat(3, 84px); grid-template-rows: repeat(3, 84px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
