/* Layout concept: a night-shift control room. The 3D floor fills the screen, an info
   panel docks right and a control strip runs along the bottom. Dark by design (single look). */
:root {
  --night: #0b1117;
  --panel: #111a23;
  --panel-2: #172330;
  --ink: #e6ecf1;
  --muted: #95a4b2;
  --rule: #273440;
  --signal: #f2b705;
  --signal-ink: #14202b;
  --flow: #74a6f2;
  --g: #34c26f;
  --y: #f5d547;
  --o: #f08c2e;
  --r: #e5483d;
  --paper: #efe9da;
  --raw: #8c9aa8;
  --pale: #c9d5e1;

  --f-display: "Big Shoulders Display", "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--flow); text-underline-offset: 3px; }
button, input, a { font: inherit; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
code { font-family: var(--f-mono); font-size: 0.85em; background: var(--panel-2); padding: 0.05em 0.35em; border-radius: 3px; overflow-wrap: anywhere; }

.app { display: flex; flex-direction: column; height: 100%; }

/* ---------- Top bar ---------- */
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 3.1rem;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  background: #070c11;
}
.brand {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--signal); }
.bar-title { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.back {
  margin-left: auto;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--rule);
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  white-space: nowrap;
}
.back:hover { border-color: var(--flow); }
.hazard { flex: 0 0 auto; height: 6px; background: repeating-linear-gradient(-45deg, var(--signal) 0 10px, #070c11 10px 20px); }

/* ---------- Stage ---------- */
.stage-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
.viewport { position: absolute; inset: 0; overflow: hidden; background: var(--night); isolation: isolate; z-index: 0; }
.viewport canvas { display: block; touch-action: none; }
.label-layer { position: absolute; top: 0; left: 0; pointer-events: none; }

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  max-width: 46ch;
  margin: auto;
}

/* Floating labels in the 3D scene */
.tag {
  pointer-events: auto;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  background: rgba(9, 14, 19, 0.86);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 6px 9px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.tag b { color: var(--signal); font-weight: 600; }
.tag:hover, .tag.hover { border-color: var(--flow); }
.tag.on { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.tag.on b { color: var(--signal-ink); }
.label-layer.compact .tag .nm { display: none; }
.label-layer.compact .tag { padding: 5px 7px; }
.mini {
  pointer-events: none;
  font-family: var(--f-mono);
  font-size: 10.5px;
  line-height: 1.25;
  text-align: center;
  color: var(--ink);
  background: rgba(9, 14, 19, 0.74);
  border-radius: 3px;
  padding: 2px 6px;
  white-space: nowrap;
}
.mini small { display: block; color: var(--muted); font-size: 9.5px; }

/* ---------- Dock ---------- */
.dock {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(17, 26, 35, 0.94);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 12px 12px;
  z-index: 3;
}
.progress { height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.progress span { display: block; height: 100%; width: 0; background: var(--signal); }
.dock-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.btns, .chips, .knobs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips { flex: 1 1 auto; min-width: 0; }
.dock button {
  cursor: pointer;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 6px 11px;
  font-size: 0.85rem;
  line-height: 1.2;
}
.dock button:hover { border-color: var(--flow); }
.dock button.primary { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); font-weight: 700; min-width: 7.5rem; }
.dock .chip { font-family: var(--f-mono); font-size: 0.78rem; padding: 6px 9px; }
.dock .chip[aria-pressed="true"] { background: var(--ink); color: var(--night); border-color: var(--ink); }
.knobs label { font-size: 0.8rem; color: var(--muted); }
.knobs input[type="range"] { width: 7rem; accent-color: var(--signal); }
.knobs output { font-family: var(--f-mono); font-size: 0.78rem; min-width: 2.6rem; font-variant-numeric: tabular-nums; }
.knobs .check { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--ink); cursor: pointer; }
.knobs .check input { accent-color: var(--signal); }

/* ---------- Panel ---------- */
.panel {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: calc(var(--dock-h, 96px) + 32px + env(safe-area-inset-bottom, 0px));
  width: 360px;
  overflow-y: auto;
  background: rgba(17, 26, 35, 0.94);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 18px 20px 20px;
  z-index: 2;
}
.panel .eyebrow { margin: 0 0 0.4rem; font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.panel h1 { margin: 0 0 0.35rem; font-family: var(--f-display); font-weight: 800; font-size: 2rem; line-height: 1.02; text-transform: uppercase; text-wrap: balance; }
.panel h1 .n { color: var(--signal); margin-right: 0.3rem; }
.panel .q { margin: 0 0 0.9rem; color: var(--flow); font-size: 0.95rem; }
.panel p { margin: 0 0 0.85rem; }
.panel .seeing { background: var(--panel-2); border-left: 3px solid var(--signal); border-radius: 0 4px 4px 0; padding: 0.7rem 0.85rem; margin: 0 0 1rem; font-size: 0.92rem; }
.panel .seeing h2 { margin: 0 0 0.25rem; font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--signal); font-weight: 600; }
.panel .seeing p { margin: 0; }
.panel ul.facts { margin: 0 0 1rem; padding-left: 1.1rem; font-size: 0.92rem; }
.panel ul.facts li { margin-bottom: 0.35rem; }
.panel h3 { margin: 1rem 0 0.5rem; font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.nbs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.nbs a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 7px 9px;
}
.nbs a:hover { border-color: var(--flow); }
.nbs .f { font-family: var(--f-mono); font-size: 0.76rem; overflow-wrap: anywhere; }
.nbs .l { font-family: var(--f-mono); font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.nbs .t { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); }

/* ---------- Legend ---------- */
.legend {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 230px;
  background: rgba(17, 26, 35, 0.9);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 2;
  font-size: 0.82rem;
}
.legend h2 { margin: 0 0 0.5rem; font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.legend ul { list-style: none; margin: 0 0 0.6rem; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.legend li { display: flex; align-items: center; gap: 4px; }
.legend li i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; flex: 0 0 auto; }
.legend li i:last-of-type { margin-right: 6px; }
.legend li i.flat { height: 5px; width: 14px; }
.legend p { margin: 0; color: var(--muted); font-size: 0.76rem; line-height: 1.45; }

/* ---------- Narrow screens: scene on top, everything else flows below ---------- */
@media (max-width: 899px) {
  .stage-wrap { overflow-y: auto; }
  .viewport { position: relative; inset: auto; height: 60%; min-height: 300px; }
  .dock, .panel, .legend { position: static; width: auto; margin: 12px 16px 0; }
  .panel { bottom: auto; overflow: visible; }
  .legend { margin-bottom: 16px; }
  .knobs input[type="range"] { width: 6rem; }
}
@media (max-width: 1180px) and (min-width: 900px) {
  .legend { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tag { transition: none; }
}
