/* The 3D universe's base layer (universe.mjs): the root and its three stacked layers (the WebGL canvas, the
   CSS2D label layer, the HUD layer), the TVs' name labels, the no-WebGL fallback and the lab's stats readout.
   The HUD's own look lives in hud.css; the tokens below are shared with it. Everything is scoped to .u-root
   (or prefixed u-) so it can't touch the rest of the app. */

.u-root {
  --u-blue: #006dff;
  --u-blue-2: #5c9dff;
  --u-blue-3: #8ab8ff;
  --u-navy: #00163d;
  --u-graphite: #0e1014;
  --u-text: #fff;
  --u-text-2: rgba(226, 236, 255, .74);
  --u-text-3: rgba(226, 236, 255, .52);
  --u-glass: rgba(5, 11, 26, .72);
  --u-glass-strong: rgba(5, 11, 26, .86);
  --u-edge: rgba(92, 157, 255, .26);
  --u-edge-strong: rgba(92, 157, 255, .62);
  --u-glow: 0 0 0 1px rgba(92, 157, 255, .22), 0 10px 36px rgba(0, 109, 255, .22);
  --u-ok: #3ddc84;
  --u-warn: #a86400;
  --u-danger: #d23a3a;
  --u-danger-text: #ff8f8f; /* the danger red, lifted enough to read as small text on the dark glass */
  --u-font: "SC Inter", Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --u-radius: 14px;
  --u-safe-top: env(safe-area-inset-top, 0px);
  --u-safe-right: env(safe-area-inset-right, 0px);
  --u-safe-bottom: env(safe-area-inset-bottom, 0px);
  --u-safe-left: env(safe-area-inset-left, 0px);
  overflow: hidden;
  isolation: isolate;
  background: #000;
  color: var(--u-text);
  font-family: var(--u-font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
}
/* The canvas fills the root, so the root needs to be positioned; :where() keeps this from beating the
   host's own rule (the lab's root is position: fixed, the app's may be absolute). */
:where(.u-root) { position: relative; }

.u-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* the controls own every touch on the 3D view */
  outline: none;
}
.u-canvas:focus-visible { outline: 2px solid var(--u-blue-2); outline-offset: -2px; }

/* Labels and HUD sit over the canvas and let the pointer through; anything clickable opts in with .u-hit. */
.u-labels { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.u-hud { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.u-root .u-hit { pointer-events: auto; }
.u-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A TV's name label (CSS2DObject). CSS2DRenderer writes `transform` on the element every frame to place it,
   so the label animates colour, opacity and shadow only, never transform. No backdrop-filter: blurring a
   canvas that redraws every frame costs a phone more than a whole TV does. */
.u-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  max-width: 240px;
  padding: 5px 11px 6px;
  border: 1px solid var(--u-edge);
  border-radius: 10px;
  background: var(--u-glass);
  color: var(--u-text);
  font: 600 12.5px/1.25 var(--u-font);
  letter-spacing: .005em;
  white-space: nowrap;
  opacity: .84;
  transition: opacity .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.u-label > * { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.u-label b { font-weight: 650; color: #fff; }
.u-label .u-sub { font-size: 11px; font-weight: 500; color: var(--u-text-2); }
.u-label .u-age { font-size: 10.5px; font-weight: 500; color: var(--u-text-3); font-variant-numeric: tabular-nums; }
.u-label .u-age.is-old { color: #e0b066; }
/* tvs.mjs's age line (it carries .u-sub too): the quieter look, amber once the picture is old. */
.u-label .u-tv-label-age { font-size: 10.5px; color: var(--u-text-3); font-variant-numeric: tabular-nums; }
.u-label .u-tv-label-age.is-old { color: #e0b066; }
.u-label.is-hover { opacity: 1; border-color: var(--u-edge-strong); }
.u-label.is-selected {
  opacity: 1;
  border-color: var(--u-blue-2);
  box-shadow: 0 0 0 1px rgba(92, 157, 255, .32), 0 0 20px rgba(0, 109, 255, .42);
}
.u-label.is-off .u-sub { color: var(--u-text-3); }
.u-label.is-offline .u-sub { color: var(--u-danger-text); }
.u-root.is-editing .u-label { opacity: .6; }
/* Size steps a TV sets from how big it is on screen: name only, then hidden unless hovered or selected. */
.u-label.is-compact .u-sub, .u-label.is-compact .u-age, .u-label.is-tiny .u-sub, .u-label.is-tiny .u-age { display: none; }
.u-label.is-compact, .u-label.is-tiny { padding: 3px 8px 4px; font-size: 11.5px; }
.u-label.is-tiny:not(.is-selected):not(.is-hover) { visibility: hidden; opacity: 0; }
/* The pictures come first: at rest a TV's label is just its name; where it hangs, what's on and the picture's
   age join it when you point at the TV or select it (the HUD's card says all of it too). */
.u-tv-label:not(.is-hover):not(.is-selected) .u-sub { display: none; }
.u-tv-label:not(.is-hover):not(.is-selected) { padding: 3px 9px 4px; font-size: 11.5px; opacity: .78; }
@media (max-width: 600px) {
  .u-label { max-width: 180px; padding: 4px 9px 5px; font-size: 11.5px; }
  .u-label .u-sub { font-size: 10.5px; }
}

/* No WebGL: a plain message and a way to the TVs (hud.css may dress it further). */
.u-fallback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--u-safe-top)) calc(20px + var(--u-safe-right)) calc(24px + var(--u-safe-bottom)) calc(20px + var(--u-safe-left));
  background: radial-gradient(120% 80% at 50% 20%, #0a2259 0%, var(--u-navy) 38%, #000 78%);
  user-select: text;
  -webkit-user-select: text;
}
.u-fallback-card {
  max-width: 420px;
  padding: 28px 24px 24px;
  border: 1px solid var(--u-edge);
  border-radius: 20px;
  background: var(--u-glass);
  box-shadow: var(--u-glow);
  text-align: center;
}
.u-fallback h2 { margin: 0 0 8px; color: #fff; font-size: 22px; font-weight: 700; letter-spacing: -.015em; }
.u-fallback .stop { color: var(--u-blue); }
.u-fallback p { margin: 0 0 20px; color: var(--u-text-2); font-size: 15px; line-height: 1.5; }
.u-fallback-go { min-height: 44px; min-width: 140px; }
.u-fallback-go:focus-visible { outline: 2px solid var(--u-blue-3); outline-offset: 2px; }

/* The lab's ?stats=1 readout (development only). */
.u-stats {
  position: fixed;
  left: calc(8px + env(safe-area-inset-left, 0px));
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  padding: 6px 9px;
  border: 1px solid rgba(92, 157, 255, .3);
  border-radius: 8px;
  background: rgba(0, 0, 0, .66);
  color: #cfe0ff;
  font: 500 11px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .u-root *, .u-root *::before, .u-root *::after {
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
  }
}
