:root {
  --bg: #0f1720;
  --panel: rgba(15, 23, 32, 0.82);
  --panel-solid: #141e29;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8eef3;
  --muted: #94a3b2;
  --accent: #57c7a5;
  --ok: #4cc38a;
  --warn: #f0b429;
  --alarm: #f05252;
  --live: #4cc38a;
  --sim: #7aa7ff;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; -webkit-font-smoothing: antialiased; }
#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 600; }

/* Header */
#top { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; padding: max(14px, env(safe-area-inset-top)) 16px 28px; pointer-events: none;
  background: linear-gradient(to bottom, rgba(15,23,32,.85), rgba(15,23,32,0)); }
#top > * { pointer-events: auto; }
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.logo { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M4 26V12l12-7 12 7v14h-6v-8H10v8z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M4 26V12l12-7 12 7v14h-6v-8H10v8z'/%3E%3C/svg%3E") center/contain no-repeat; }
h1 { font-size: 17px; letter-spacing: .1px; }
.sub { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); white-space: nowrap; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.live .dot { background: var(--live); box-shadow: 0 0 0 3px rgba(76,195,138,.2); animation: pulse 2s infinite; }
.pill.sim .dot { background: var(--sim); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(76,195,138,0); } }

/* Panel */
#panel { position: fixed; top: 84px; right: 16px; width: 300px; max-height: calc(100% - 160px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
#panel-body { overflow-y: auto; padding: 4px 14px 14px; }
.sheet-handle { display: none; }
section { margin-top: 12px; }
h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.stamp { text-transform: none; letter-spacing: 0; font-weight: 400; font-variant-numeric: tabular-nums; }
.cards { display: grid; gap: 8px; }
.card { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.04); border: 1px solid var(--line); cursor: pointer;
  border-left: 3px solid var(--ok); transition: background .15s; text-align: left; width: 100%; }
.card:hover, .card.sel { background: rgba(255,255,255,.08); }
.card.warn { border-left-color: var(--warn); } .card.alarm { border-left-color: var(--alarm); }
.card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .name { font-weight: 600; }
.card .big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(76,195,138,.15); color: var(--ok); }
.tag.warn { background: rgba(240,180,41,.15); color: var(--warn); } .tag.alarm { background: rgba(240,82,82,.18); color: var(--alarm); }
.bar { height: 4px; border-radius: 2px; background: rgba(255,255,255,.08); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
#alerts { margin: 0; padding-left: 18px; color: var(--alarm); }
.about p { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.links { display: flex; flex-wrap: wrap; gap: 12px; }
.links a { color: var(--accent); text-decoration: none; }
.links a:hover { text-decoration: underline; }

/* Camera buttons */
#views { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; gap: 4px;
  padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  max-width: calc(100% - 32px); overflow-x: auto; scrollbar-width: none; }
#views::-webkit-scrollbar { display: none; }
#views button { border: 0; background: none; padding: 7px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap; color: var(--muted); }
#views button:hover { color: var(--text); }
#views button.on, #views button[aria-pressed="true"] { background: rgba(87,199,165,.18); color: var(--text); }

/* 3D badges */
#badges { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.badge { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); padding: 5px 9px 5px 8px; border-radius: 8px;
  background: rgba(15,23,32,.88); border: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; display: flex; gap: 7px; align-items: center;
  pointer-events: auto; cursor: pointer; will-change: transform; }
.badge::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 2px; height: 6px; margin-left: -1px; background: rgba(255,255,255,.35); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.badge.warn .dot { background: var(--warn); } .badge.alarm .dot { background: var(--alarm); animation: blink 1s infinite; }
.badge.alarm { border-color: rgba(240,82,82,.6); }
.badge b { font-variant-numeric: tabular-nums; }
.badge .door { color: var(--warn); font-size: 11px; }
.badge.fork .dot { background: #f5c518; }
.badge.hidden { display: none; }
@keyframes blink { 50% { opacity: .3; } }

/* Loading and failure */
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--muted);
  background: var(--bg); transition: opacity .5s; z-index: 5; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.1); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#fail { position: fixed; left: 16px; top: 96px; max-width: 360px; padding: 16px; background: var(--panel-solid); border-radius: var(--radius); border: 1px solid var(--line); }
#fail p { color: var(--muted); }

/* Phone: panel becomes a bottom sheet above the camera buttons */
@media (max-width: 720px) {
  #top { padding-bottom: 20px; }
  h1 { font-size: 15px; }
  .sub { display: none; }
  .pill { font-size: 11px; padding: 4px 8px; }
  #panel { top: auto; right: 0; left: 0; bottom: 0; width: auto; max-height: 50vh; border-radius: 16px 16px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom); transition: transform .25s; z-index: 3; }
  #panel.collapsed { transform: translateY(calc(100% - 50px - env(safe-area-inset-bottom))); }
  #views { bottom: calc(60px + env(safe-area-inset-bottom)); }
  #panel:not(.collapsed) ~ #views { display: none; }
  .sheet-handle { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: none; padding: 8px 0 2px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
  .grip { width: 36px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .card .big { font-size: 19px; }
  .badge { font-size: 11.5px; padding: 4px 7px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
