:root {
  color-scheme: dark;
  --bg: #07111c;
  --panel: rgba(7, 17, 28, 0.88);
  --panel-strong: rgba(4, 10, 18, 0.95);
  --line: rgba(148, 163, 184, 0.24);
  --text: #e8f0f8;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --warn: #fbbf24;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.viewer-shell,
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scene {
  display: block;
  outline: 0;
  touch-action: none;
}

.topbar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: #7dd3fc;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1 {
  max-width: 720px;
  margin: 0;
  color: #f8fafc;
  font-size: clamp(18px, 2.2vw, 30px);
  line-height: 1.08;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.72);
}

.status-wrap {
  display: grid;
  justify-items: end;
  gap: 5px;
  text-align: right;
}

.status,
.revision {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(12px);
  font-size: 11px;
}

.status {
  color: #bae6fd;
}

.revision {
  color: var(--muted);
}

.toolbar {
  position: fixed;
  top: 92px;
  left: 18px;
  z-index: 6;
  display: grid;
  gap: 8px;
  width: min(650px, calc(100vw - 36px));
  pointer-events: auto;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 5px;
  width: max-content;
  max-width: 100%;
  padding: 6px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  scrollbar-width: none;
}

.control-group::-webkit-scrollbar {
  display: none;
}

.control-label {
  padding: 0 7px 0 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.toolbar button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.08);
  color: #cbd5e1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.toolbar button:hover,
.toolbar button:focus-visible {
  border-color: rgba(56, 189, 248, 0.6);
  outline: none;
}

.toolbar button.active,
.toolbar button[aria-pressed="true"] {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(14, 165, 233, 0.2);
  color: #e0f2fe;
}

.scan-warning {
  position: fixed;
  top: 222px;
  left: 18px;
  z-index: 6;
  width: min(520px, calc(100vw - 36px));
  padding: 9px 11px;
  border: 1px solid rgba(251, 191, 36, 0.48);
  border-radius: 10px;
  background: rgba(52, 32, 4, 0.92);
  color: #fde68a;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  font-size: 11px;
  line-height: 1.4;
  pointer-events: none;
}

.scan-warning[hidden] {
  display: none;
}

body[data-scan-mode="true"] .axis-chip,
body[data-scan-mode="true"] .legend-panel {
  display: none;
}

.info-panel {
  position: fixed;
  top: 180px;
  right: 18px;
  z-index: 6;
  width: min(310px, calc(100vw - 36px));
  max-height: calc(100vh - 300px);
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-strong);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.info-panel[hidden] {
  display: none;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#close-info {
  width: 27px;
  height: 27px;
  border: 0;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.1);
  color: #cbd5e1;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.info-panel h2 {
  margin: 10px 0 5px;
  font-size: 18px;
  line-height: 1.16;
}

.info-panel > p {
  margin: 0 0 12px;
  color: #b6c4d4;
  font-size: 12px;
  line-height: 1.45;
}

.info-panel dl {
  display: grid;
  gap: 6px;
  margin: 0;
}

.info-panel dl div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  font-size: 11px;
  line-height: 1.35;
}

.info-panel dt {
  color: var(--muted);
}

.info-panel dd {
  margin: 0;
  color: #e2e8f0;
  overflow-wrap: anywhere;
}

.info-panel dd a {
  color: #7dd3fc;
  text-underline-offset: 3px;
}

.info-panel dd a:hover,
.info-panel dd a:focus-visible {
  color: #bae6fd;
}

.legend-panel {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 6;
  width: min(360px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.legend-toggle {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: #dbeafe;
  text-align: left;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.legend-content {
  max-height: calc(100vh - 180px);
  padding: 0 12px 11px;
  overflow: auto;
}

.legend-content[hidden] {
  display: none;
}

.legend-content p {
  margin: 7px 0 0;
  color: #aab8c8;
  font-size: 10.5px;
  line-height: 1.4;
}

.legend-content b {
  color: #e2e8f0;
}

.systems {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.systems span {
  color: #cbd5e1;
  font-size: 10.5px;
}

.systems i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 999px;
  background: var(--swatch);
  box-shadow: 0 0 10px color-mix(in srgb, var(--swatch), transparent 20%);
}

.model-downloads {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 0 1px;
}

.model-downloads a {
  padding: 6px 7px;
  border: 1px solid rgba(125, 211, 252, 0.24);
  border-radius: 7px;
  background: rgba(14, 165, 233, 0.08);
  color: #bae6fd;
  font-size: 10px;
  text-align: center;
  text-decoration: none;
}

.model-downloads a:hover,
.model-downloads a:focus-visible {
  border-color: rgba(125, 211, 252, 0.56);
  background: rgba(14, 165, 233, 0.16);
}

.actual-pump-register {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 9px;
  background: rgba(6, 78, 59, 0.12);
}

.actual-phe-register {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 9px;
  background: rgba(3, 105, 161, 0.12);
}

.actual-phe-register-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  color: #dbeafe;
  font-size: 10px;
}

.actual-phe-register-title span {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.2);
  color: #7dd3fc;
  font-weight: 800;
}

.actual-pump-register-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  color: #d1fae5;
  font-size: 10px;
}

.actual-pump-register-title span {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  font-weight: 800;
}

.pump-register {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.phe-register {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pump-register-item {
  display: grid;
  min-height: 58px;
  gap: 2px;
  padding: 7px;
  border: 1px solid rgba(110, 231, 183, 0.22);
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.68);
  color: #dbeafe;
  text-align: left;
  cursor: pointer;
}

.phe-register-item {
  display: grid;
  min-height: 58px;
  gap: 2px;
  padding: 7px;
  border: 1px solid rgba(125, 211, 252, 0.26);
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.68);
  color: #dbeafe;
  text-align: left;
  cursor: pointer;
}

.pump-register-item:hover,
.pump-register-item:focus-visible {
  border-color: rgba(110, 231, 183, 0.72);
  outline: none;
  background: rgba(6, 95, 70, 0.3);
}

.phe-register-item:hover,
.phe-register-item:focus-visible {
  border-color: rgba(125, 211, 252, 0.8);
  outline: none;
  background: rgba(3, 105, 161, 0.28);
}

.pump-register-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  color: #a7f3d0;
  font-size: 9px;
}

.phe-register-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  color: #bae6fd;
  font-size: 9px;
}

.pump-register-heading b {
  padding: 1px 4px;
  border-radius: 999px;
  background: #059669;
  color: #ecfdf5;
  font-size: 8px;
  letter-spacing: 0.05em;
}

.phe-register-heading b {
  padding: 1px 4px;
  border-radius: 999px;
  background: #0284c7;
  color: #f0f9ff;
  font-size: 8px;
  letter-spacing: 0.05em;
}

.pump-register-item strong {
  font-size: 10px;
  line-height: 1.2;
}

.phe-register-item strong {
  font-size: 10px;
  line-height: 1.2;
}

.pump-register-item > span:last-child {
  color: #9fb2c7;
  font-size: 8.5px;
  line-height: 1.25;
}

.phe-register-item > span:last-child {
  color: #9fbacf;
  font-size: 8.5px;
  line-height: 1.25;
}

.actual-pump-register > p {
  margin-bottom: 0;
  color: #a7c8bd;
  font-size: 9px;
}

.actual-phe-register > p {
  margin-bottom: 0;
  color: #a9c9dc;
  font-size: 9px;
}

.spec-reconciliation {
  margin-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  padding: 7px 0;
}

.spec-reconciliation summary {
  min-height: 34px;
  padding: 7px 8px;
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.72);
  color: #e2e8f0;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.spec-table-scroll {
  margin-top: 7px;
  overflow-x: auto;
}

.spec-reconciliation table {
  width: 760px;
  border-collapse: collapse;
  color: #cbd5e1;
  font-size: 8.5px;
}

.spec-reconciliation th,
.spec-reconciliation td {
  padding: 5px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  vertical-align: top;
  text-align: left;
  line-height: 1.3;
}

.spec-reconciliation th {
  position: sticky;
  top: 0;
  background: #111d2a;
  color: #bae6fd;
}

.spec-reconciliation h3 {
  margin: 8px 0 4px;
  color: #e2e8f0;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.reconciliation-list,
.material-reconciliation {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: #aebdcd;
  font-size: 8.5px;
  line-height: 1.35;
}

.material-reconciliation li {
  display: grid;
  gap: 1px;
}

.material-reconciliation strong {
  color: #dbeafe;
}

.axis-chip {
  position: fixed;
  left: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  gap: 11px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(4, 10, 18, 0.82);
  color: var(--muted);
  font-size: 10px;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.axis-chip i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 50%;
}

.axis-x { background: #ef4444; }
.axis-y { background: #22c55e; }
.axis-z { background: #3b82f6; }

.labels-layer {
  position: fixed;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.scene-label {
  position: absolute;
  max-width: 165px;
  padding: 4px 7px;
  transform: translate(-50%, -100%);
  border: 1px solid rgba(226, 232, 240, 0.26);
  border-radius: 6px;
  background: rgba(3, 9, 16, 0.82);
  color: #f1f5f9;
  box-shadow: 0 5px 13px rgba(0, 0, 0, 0.22);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  backdrop-filter: blur(5px);
}

.scene-label.derived {
  border-style: dashed;
  color: #fde68a;
}

.scene-label.actual-pump {
  max-width: 220px;
  border-color: rgba(52, 211, 153, 0.72);
  background: rgba(2, 44, 34, 0.9);
  color: #d1fae5;
  white-space: pre-line;
}

.scene-label.actual-phe {
  max-width: 230px;
  border-color: rgba(56, 189, 248, 0.78);
  background: rgba(3, 37, 65, 0.92);
  color: #dbeafe;
  white-space: pre-line;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(19px, env(safe-area-inset-bottom));
  z-index: 4;
  padding: 7px 10px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(4, 10, 18, 0.76);
  color: #93a4b8;
  font-size: 10px;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (max-width: 860px) {
  .topbar {
    left: 12px;
    right: 12px;
  }

  .status-wrap {
    display: none;
  }

  .toolbar {
    top: 82px;
    left: 12px;
    width: calc(100vw - 24px);
  }

  .info-panel {
    top: auto;
    right: 12px;
    bottom: calc(126px + env(safe-area-inset-bottom));
    width: min(290px, calc(100vw - 24px));
    max-height: 32vh;
    padding: 11px;
  }

  .scan-warning {
    top: 208px;
    left: 12px;
    width: calc(100vw - 24px);
  }

  .info-panel h2 {
    margin-top: 7px;
    font-size: 15px;
  }

  .legend-panel {
    right: 12px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: min(330px, calc(100vw - 24px));
  }

  .axis-chip {
    display: none;
  }

  .hint {
    display: none;
  }
}

@media (max-width: 560px) {
  h1 {
    max-width: 94vw;
    font-size: 18px;
  }

  .eyebrow {
    font-size: 9px;
  }

  .toolbar {
    top: 76px;
    gap: 5px;
  }

  .control-group {
    width: 100%;
    border-radius: 10px;
  }

  .toolbar button {
    min-height: 28px;
    font-size: 11px;
  }

  .scan-warning {
    top: 196px;
  }

  .info-panel {
    left: 12px;
    right: 12px;
    bottom: calc(104px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 28vh;
  }

  .legend-panel {
    left: 12px;
    right: 12px;
    width: auto;
  }

  .legend-content {
    max-height: 32vh;
    overflow: auto;
  }

  .pump-register,
  .phe-register {
    grid-template-columns: 1fr;
  }

  .pump-register-item,
  .phe-register-item {
    min-height: 44px;
  }

  .scene-label {
    max-width: 120px;
    padding: 3px 5px;
    font-size: 8.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
