/* Stop 8 local candidate viewer. Layout rule: the viewport is the primary
   surface on every screen size. Panels are closed by default on phone, are
   `hidden` (display:none) when closed so they can never intercept an orbit
   gesture, and dock beside the stage — never on top of it — on desktop. */

[hidden] { display: none !important; }

:root {
  --bg: #0a0f16;
  --panel-bg: #101823;
  --sunken: #0d151f;
  --ink: #eaf1f8;
  --muted: #8b99ab;
  --line: #223045;
  --cyan: #55b9dc;
  --blue: #4c8dff;
  --amber: #e9a23b;
  --magenta: #ed3a77;
  --violet: #8b6bd9;
  --green: #4cc38a;
  --control-size: 44px;
  --panel-w: 340px;
  --modes-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
}

button, input, select { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------- banner ---------- */

.banner {
  flex: 0 0 auto;
  background: var(--magenta);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-align: center;
  padding: 6px 10px;
  min-height: var(--control-size);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- topbar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.topbar-title { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.topbar-sub { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  min-height: var(--control-size);
  min-width: var(--control-size);
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #17212f;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.chip.chip-small { min-height: 36px; padding: 0 10px; font-size: 12px; }
.chip.chip-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip[aria-expanded="true"] { background: var(--cyan); border-color: var(--cyan); color: #06222c; }
.chip[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: #201400; }

.chip-badge {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.9;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- stage layout ---------- */

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  position: relative;
}

.model-stage {
  grid-column: 2;
  position: relative;
  min-height: 260px;
  min-width: 0;
  background: #050a10;
  overflow: hidden;
}

model-viewer {
  width: 100%;
  height: 100%;
  display: block;
  --poster-color: transparent;
}

.progress { width: 0; }

/* ---------- huds ---------- */

.hud { position: absolute; z-index: 4; }

.compass {
  top: 8px;
  left: 8px;
  background: rgba(10, 15, 22, 0.86);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  max-width: 220px;
}

.compass-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 6px;
}

.compass-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.compass-hold-chip {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--amber);
}

.compass-peek {
  display: none;
  width: 100%;
  justify-content: space-between;
  gap: 4px;
}

.compass.collapsed .compass-peek { display: flex; }
.compass.collapsed .compass-body,
.view-controls.collapsed .vc-body { display: none; }

.compass-peek .pt {
  flex: 1 1 0;
  min-width: 36px;
  min-height: var(--control-size);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #17212f;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.compass-peek .pt.active { background: var(--cyan); border-color: var(--cyan); color: #06222c; }

.mini-toggle {
  min-width: 30px;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #17212f;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.compass-body { padding-top: 6px; }

.compass-dial {
  display: grid;
  grid-template-columns: repeat(3, var(--control-size));
  grid-template-rows: repeat(3, var(--control-size));
  gap: 4px;
  justify-content: center;
}

.compass-dial .pt {
  min-width: var(--control-size);
  min-height: var(--control-size);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #17212f;
  cursor: pointer;
  font-size: 13px;
}

.compass-dial .pt.active { background: var(--cyan); border-color: var(--cyan); color: #06222c; font-weight: 700; }

.pt-n { grid-column: 2; grid-row: 1; }
.pt-w { grid-column: 1; grid-row: 2; }
.pt-home { grid-column: 2; grid-row: 2; background: var(--blue); border-color: var(--blue); color: #fff; }
.pt-e { grid-column: 3; grid-row: 2; }
.pt-s { grid-column: 2; grid-row: 3; }
.pt-top { grid-column: 1 / span 3; grid-row: 4; width: 100%; margin-top: 4px; }

.facing-line {
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.street-line { margin: 4px 0 0; font-size: 10px; color: var(--muted); text-align: center; line-height: 1.35; }
.plan-north-note { margin: 4px 0 0; font-size: 9px; color: var(--amber); text-align: center; }

.view-controls { top: 8px; right: 8px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.vc-head { display: flex; justify-content: flex-end; }
.vc-body { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }

/* ---------- cardinal / street edge labels ---------- */

/* Street chips ride the screen-space direction of each plan-cardinal axis, so
   whichever way the model is orbited the reader can still see which side of
   the site faces them. Pointer-events off — these never eat an orbit drag. */
.cardinal-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.cardinal-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 22, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
  line-height: 1.3;
}

.cardinal-chip b { display: block; font-size: 11px; color: var(--cyan); letter-spacing: 0.08em; }
.cardinal-chip.cardinal-north { border-color: var(--cyan); }
.cardinal-chip.cardinal-north b { color: #fff; }

/* ---------- gesture hint / pick toast ---------- */

.gesture-hint {
  position: absolute;
  left: 50%;
  bottom: 52px;
  transform: translateX(-50%);
  background: rgba(10, 15, 22, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  text-align: center;
  z-index: 5;
  /* The hint is informational. Never steal orbit/pan from the model. */
  pointer-events: none;
}

.hint-phone { display: none; }

.gesture-hint button {
  min-width: 28px; min-height: 28px;
  background: transparent; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer;
  pointer-events: auto;
}

.pick-toast {
  position: absolute;
  left: 50%;
  bottom: 52px;
  transform: translateX(-50%);
  z-index: 6;
  max-width: calc(100% - 24px);
  background: rgba(16, 24, 35, 0.96);
  border: 1px solid var(--amber);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink);
}

.pick-toast strong { color: var(--amber); display: block; font-size: 11px; letter-spacing: 0.03em; text-transform: uppercase; margin-bottom: 2px; }

/* ---------- status strip ---------- */

.status-strip {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 4;
  background: rgba(10, 15, 22, 0.9);
  border-top: 1px solid var(--line);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  min-height: var(--control-size);
}

.status-mode-btn {
  min-height: 36px;
  border: 1px solid var(--cyan);
  border-radius: 999px;
  background: rgba(85, 185, 220, 0.14);
  color: var(--cyan);
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.status-sub { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status-asset-label { margin-left: auto; }

/* ---------- panels ---------- */

.panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}

.panel-left { grid-column: 1; grid-row: 1; width: var(--modes-w); border-left: none; border-right: 1px solid var(--line); }
.panel-right { grid-column: 3; grid-row: 1; width: var(--panel-w); }

.panel header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.panel-close {
  min-width: var(--control-size);
  min-height: var(--control-size);
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px 24px; -webkit-overflow-scrolling: touch; }
.panel-note { color: var(--muted); font-size: 12px; margin: 0 0 10px; line-height: 1.45; }
.panel-h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--cyan); margin: 16px 0 8px; }
.panel-h3:first-child { margin-top: 0; }

/* ---------- mode drawer ---------- */

.mode-groups { display: flex; flex-direction: column; gap: 14px; }
.focus-context-note { margin-top: 16px; }
.focus-context-note .kv-list { margin-bottom: 0; }
.mode-group-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 6px; }
.mode-group-list { display: flex; flex-direction: column; gap: 4px; }

.mode-btn {
  width: 100%;
  min-height: var(--control-size);
  text-align: left;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #17212f;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mode-btn .mode-count { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mode-btn.active { background: var(--cyan); border-color: var(--cyan); color: #06222c; font-weight: 700; }
.mode-btn.active .mode-count { color: #0a3341; }

/* ---------- find / facets ---------- */

.search-box { display: block; margin-bottom: 10px; }

.search-box input {
  width: 100%;
  min-height: var(--control-size);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--sunken);
  color: var(--ink);
  padding: 0 12px;
  font-size: 16px;
}

.facets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.facet { display: flex; flex-direction: column; gap: 3px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.facet select {
  min-height: var(--control-size);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--sunken);
  color: var(--ink);
  padding: 0 8px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  max-width: 100%;
}

.check-row { display: flex; align-items: center; gap: 8px; min-height: var(--control-size); font-size: 12px; color: var(--ink); }
.check-row input { width: 20px; height: 20px; }
.facet-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.facet-actions .panel-note { margin: 0; }

.search-results { display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto; }

.search-row {
  min-height: var(--control-size);
  text-align: left;
  border: 1px solid var(--line);
  background: var(--sunken);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
}

.search-row:hover { border-color: var(--cyan); }
.search-row-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.search-row-sys { color: var(--muted); font-size: 10px; text-transform: uppercase; white-space: nowrap; }

.status-dot { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.25); }

/* ---------- inspector ---------- */

.inspector-detail h3 { font-size: 13px; margin: 0 0 6px; color: var(--cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.chip-row { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }

.tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.tag-normal { color: var(--cyan); border-color: var(--cyan); }
.tag-hold, .tag-conflict, .tag-potential { color: var(--magenta); border-color: var(--magenta); }
.tag-proposed { color: var(--violet); border-color: var(--violet); }
.tag-inferred { color: var(--amber); border-color: var(--amber); }
.tag-blank { color: var(--muted); border-color: var(--muted); border-style: dashed; }

.inspector-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }

.kv-list { display: grid; grid-template-columns: minmax(118px, 42%) 1fr; gap: 4px 10px; margin: 0 0 12px; font-size: 12px; }
.kv-list dt { color: var(--muted); font-weight: 600; }
.kv-list dd { margin: 0; color: var(--ink); word-break: break-word; line-height: 1.45; }
.kv-list dd.blank { color: var(--muted); font-style: italic; }

/* ---------- legend ---------- */

.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: flex-start; gap: 10px; font-size: 12px; line-height: 1.45; }

.legend-swatch {
  flex: 0 0 auto; width: 16px; height: 16px; border-radius: 4px; margin-top: 2px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.legend-text strong { text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; color: var(--cyan); }
.legend-text .legend-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend-mat { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; word-break: break-all; }

.notice { border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.45; margin-bottom: 12px; }
.notice-stop { background: rgba(237, 58, 119, 0.12); border: 1px solid var(--magenta); }
.notice-stop strong { color: var(--magenta); display: block; margin-bottom: 4px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em; }
.notice-info { background: rgba(85, 185, 220, 0.10); border: 1px solid var(--line); }
.notice-info strong { color: var(--cyan); display: block; margin-bottom: 4px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em; }
.notice p { margin: 0; color: var(--ink); }

.about-caption { font-size: 12px; line-height: 1.5; margin: 0 0 12px; color: var(--ink); }

/* ---------- phone ---------- */

@media (max-width: 860px) {
  .stage-wrap { display: block; }

  .model-stage {
    position: absolute;
    inset: 0;
    min-height: 0;
  }

  /* Panels become bottom sheets. Closed panels are `hidden`, so they occupy no
     space and cannot capture an orbit gesture on the stage. */
  .panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 62vh;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .topbar { padding: 4px 8px; }
  .topbar-title { font-size: 13px; }
  .topbar-sub { display: none; }
  .topbar-actions { width: 100%; justify-content: space-between; gap: 4px; }
  .topbar-actions .chip { flex: 1 1 auto; padding: 0 6px; font-size: 12px; }
  .chip-badge { display: none; }

  .facets { grid-template-columns: 1fr; }
  .kv-list { grid-template-columns: 1fr; }
  .kv-list dt { margin-top: 6px; }

  .compass { max-width: 220px; padding: 5px; }
  .compass-dial { grid-template-columns: repeat(3, var(--control-size)); gap: 3px; }
  .street-line, .plan-north-note { display: none; }
  .compass.collapsed .compass-body,
  .view-controls.collapsed .vc-body { display: none; }

  .status-strip {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 2px 8px;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0));
  }
  .status-mode-btn {
    flex: 1 1 100%;
    max-width: none;
    width: 100%;
    display: flex;
    align-items: center;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.25;
    text-align: left;
    justify-content: flex-start;
    min-height: 36px;
    padding: 6px 12px;
  }
  .status-meta {
    flex: 1 1 100%;
    width: 100%;
    justify-content: flex-start;
  }
  .status-sub {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.3;
  }
  /* GLB filename stays in the DOM for tests; it is not useful on a phone strip. */
  #status-asset-label { display: none; }

  .search-results { max-height: 34vh; }
  .hint-desktop { display: none; }
  .hint-phone { display: inline; }
  .gesture-hint {
    font-size: 11px;
    bottom: 78px;
    padding: 6px 10px;
    max-width: calc(100% - 16px);
    white-space: nowrap;
  }
  .pick-toast { bottom: 78px; }
}

@media (max-width: 400px) {
  .banner { font-size: 10px; padding: 4px 6px; }
}
