:root {
  --bg: #0b0d10;
  --panel: #15181d;
  --panel-2: #1c2026;
  --border: #2a2e35;
  --text: #e6e8eb;
  --muted: #9aa0a8;
  --accent: #3b82f6;
  --accent-dim: #1e3a6e;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

svg { width: 1.4em; height: 1.4em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 16px;
  flex: 0 0 auto;
}
.topbar h1 { font-size: 1.35rem; font-weight: 600; margin: 0; flex: 1; }
.status { display: flex; align-items: center; gap: 10px; font-size: 0.95rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.off { background: var(--red); box-shadow: none; }

.icon-btn {
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px;
  border-radius: 10px;
  display: inline-flex;
  cursor: pointer;
}
.icon-btn svg { width: 1.6em; height: 1.6em; }
.icon-btn:active { background: var(--panel-2); }

/* ---- layout ---- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 150px 1fr 150px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 0 12px 12px;
}
.wheel { grid-row: 1; }
#panel-left { grid-column: 1; }
.video { grid-column: 2; grid-row: 1; }
#panel-right { grid-column: 3; }
.ptz, .zoom, .gyro { grid-row: 2; }
.ptz { grid-column: 1; }
.zoom { grid-column: 2; }
.gyro { grid-column: 3; }

/* Portrait / narrow: stack */
@media (max-width: 899px) {
  html, body { height: auto; min-height: 100%; }
  .layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }
  .layout .video { grid-column: 1 / 3; grid-row: 1; min-height: 260px; }
  #panel-left { grid-column: 1; grid-row: 2; }
  #panel-right { grid-column: 2; grid-row: 2; }
  .ptz { grid-column: 1; grid-row: 3; }
  .zoom { grid-column: 2; grid-row: 3; }
  .gyro { grid-column: 1 / 3; grid-row: 4; }
  .wheel .vslider-wrap { flex: 0 0 auto; height: 280px; }
}

/* ---- panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.panel h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 10px; }

.value-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
}
.value-box .value { font-size: 1.9rem; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.value-box.small { min-width: 72px; padding: 10px 8px; }
.value-box.small .value { font-size: 1.5rem; color: var(--text); }
.range-hint { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 6px 0 4px; }

/* ---- wheel panels ---- */
.wheel { align-items: stretch; text-align: center; }
.vslider-wrap {
  flex: 1;
  min-height: 160px;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 10px;
  padding: 14px 0;
}
.vlabels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2px 0;
}

.stop-btn {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font: inherit;
}
.stop-btn:active { background: var(--panel-2); border-color: var(--red); }
.stop-value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stop-label { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.08em; }

/* ---- custom sliders ---- */
.slider {
  position: relative;
  touch-action: none;
  cursor: pointer;
  flex: 0 0 auto;
}
.slider .track {
  position: absolute;
  background: var(--accent-dim);
  border-radius: 999px;
  overflow: hidden;
}
.slider .fill { position: absolute; background: var(--accent); }
.slider .thumb {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}
.slider.active .thumb { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0.25), 0 2px 10px rgba(0, 0, 0, 0.5); }

.slider.vertical { width: 44px; height: 100%; }
.slider.vertical .track { left: 50%; top: 0; bottom: 0; width: 22px; transform: translateX(-50%); }
.slider.vertical .fill { left: 0; right: 0; }
.slider.vertical .thumb { left: 50%; }

.slider.horizontal { width: 100%; height: 44px; }
.slider.horizontal .track { top: 50%; left: 0; right: 0; height: 12px; transform: translateY(-50%); }
.slider.horizontal .fill { top: 0; bottom: 0; }
.slider.horizontal .thumb { top: 50%; width: 32px; height: 32px; }

/* ---- video ---- */
.video { padding: 0; overflow: hidden; }
.video-surface {
  position: relative;
  flex: 1;
  background: #000 radial-gradient(ellipse at center, #1a2230 0%, #000 75%);
  display: grid;
  place-items: center;
}
.video.fullscreen { position: fixed; inset: 0; z-index: 50; border-radius: 0; border: 0; }
.no-video { color: var(--muted); font-size: 1rem; }
.live-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 24, 30, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
}
.live-badge .rec { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1.2s infinite; }
.live-badge.connecting .rec { background: #f59e0b; }
.live-badge.off .rec { background: var(--muted); animation: none; }
.live-badge .sep { width: 1px; height: 16px; background: var(--border); }
@keyframes blink { 50% { opacity: 0.3; } }
.video-tools { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; }
.tool-btn {
  background: rgba(20, 24, 30, 0.85);
  border: 1px solid var(--border);
}
.tool-btn.on { border-color: var(--accent); color: var(--accent); }

/* Live feeds: one cell per publisher, the grid columns are set by live.js */
.video-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 2px;
  background: #000;
}
.video-grid:empty { display: none; }
.video-grid .feed { position: relative; min-width: 0; min-height: 0; background: #000; }
.video-grid video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.video-grid audio { display: none; }
.feed-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(20, 24, 30, 0.7);
  font-size: 0.8rem;
  color: var(--muted);
}
.video-grid .feed:only-child .feed-label { display: none; }

/* ---- bottom panels ---- */
.ptz-values { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.mini-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mini-label { font-size: 0.8rem; color: var(--muted); }
.mini-box .value { font-size: 1.5rem; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }

.wide-btn {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 12px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
}
.wide-btn:active { background: var(--panel-2); }
.wide-btn.on { border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: 10px; margin-top: auto; }

.zoom-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.hslider-wrap { flex: 1; min-width: 0; }
.hlabels { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; padding: 0 4px; }

.gyro-body { display: flex; align-items: center; gap: 14px; flex: 1; }
.gyro-icon { width: 96px; height: 96px; flex: 0 0 auto; color: var(--accent); stroke-width: 3; }
.gyro-help { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 0.95rem; }
.gyro-help .arrow { color: var(--muted); margin: 0 4px; }
.gyro .wide-btn { margin-top: 10px; flex: 0 0 auto; }

/* Placed last on purpose: these override the component rules above at equal specificity. */
/* Landscape iPad: wheels on the sides, video in the middle, one compact band below */
@media (min-width: 900px) {
  .layout { grid-template-columns: 132px 0.9fr 1.6fr 0.5fr 132px; gap: 10px; padding: 0 10px 10px; }
  .opt { display: none; }
  #panel-left { grid-column: 1; grid-row: 1; }
  .video { grid-column: 2 / 5; grid-row: 1; }
  #panel-right { grid-column: 5; grid-row: 1; }
  .ptz { grid-column: 1 / 3; grid-row: 2; }
  .zoom { grid-column: 3; grid-row: 2; }
  .gyro { grid-column: 4 / 6; grid-row: 2; }

  .wheel { padding: 10px; }
  .wheel h2 { font-size: 0.95rem; }
  .wheel .value-box .value { font-size: 1.6rem; }
  .vslider-wrap { padding: 10px 0; gap: 6px; }

  /* Bottom panels: title on the left, everything else on one line */
  .ptz, .zoom, .gyro {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
  }
  .ptz h2, .zoom h2, .gyro h2 { margin: 0; font-size: 0.9rem; white-space: nowrap; flex: 0 0 auto; }

  .ptz-values { flex: 1; min-width: 0; margin: 0; gap: 8px; }
  .mini-box { min-width: 0; padding: 4px 6px; flex-direction: row; justify-content: space-between; gap: 6px; }
  .mini-label { font-size: 0.7rem; white-space: nowrap; }
  .mini-box .value { font-size: 1.15rem; }

  .wide-btn { padding: 8px 10px; font-size: 0.95rem; flex: 0 0 auto; gap: 0; }
  .wide-btn svg { width: 1.3em; height: 1.3em; }

  .zoom-row { flex: 1; min-width: 0; margin: 0; gap: 10px; }
  .hslider-wrap { min-width: 90px; }
  .hlabels { display: none; }
  .slider.horizontal { height: 36px; }
  .value-box.small { min-width: 54px; padding: 6px 4px; }
  .value-box.small .value { font-size: 1.15rem; }
  .btn-row { margin: 0; gap: 8px; }

  .gyro-body { flex: 1; gap: 10px; justify-content: center; }
  .gyro-icon { width: 40px; height: 40px; stroke-width: 4; }
  .gyro-help { display: none; }
  .gyro .wide-btn { margin: 0; }
}
