/* Linked Spatial workspace: diagram + teaching CT + existing Three.js stage */

#btnSpatial.active,
#btnSpatial[aria-pressed="true"] {
  background: var(--amber-dim, rgba(226, 177, 90, 0.18));
  color: #f2c9a4;
  border-color: var(--amber, #e2b15a);
}

.spatial-toolbar {
  display: none;
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 24px);
  padding: 6px;
  border-radius: 12px;
  background: rgba(18, 14, 11, 0.78);
  border: 1px solid rgba(196, 168, 130, 0.28);
  backdrop-filter: blur(8px);
}

body.spatial-on .spatial-toolbar { display: flex; }

.spatial-toolbar .btn {
  font-size: 13px;
  min-height: 36px;
  padding: 6px 10px;
}

.spatial-toolbar .spatial-status {
  flex: 1 1 100%;
  margin: 2px 4px 0;
  font-size: 12px;
  color: var(--muted, #b9a894);
  text-align: center;
  line-height: 1.35;
}

.spatial-shell {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

body.spatial-on .spatial-shell {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(280px, 1.35fr);
  grid-template-rows: 1fr;
  gap: 8px;
  padding: 96px 10px 88px;
  pointer-events: none;
}

body.spatial-on .spatial-shell > * { pointer-events: auto; }

body.spatial-on .stage-caption { display: none; }
body.spatial-on .world-labels { display: none; }
body.spatial-on .toolbar { z-index: 7; }

.spatial-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 14px;
  border: 1px solid rgba(196, 168, 130, 0.28);
  background: rgba(16, 12, 10, 0.92);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.spatial-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(196, 168, 130, 0.18);
  font-size: 12px;
  color: #e8dcc8;
  flex: 0 0 auto;
}

.spatial-pane-head strong { font-weight: 600; letter-spacing: 0.02em; }
.spatial-pane-head .muted { color: var(--muted, #b9a894); font-weight: 400; }

.spatial-pane-body {
  position: relative;
  flex: 1;
  min-height: 0;
}

.spatial-zoom-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.spatial-zoom-viewport:active { cursor: grabbing; }

.spatial-zoom-content {
  transform-origin: 0 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spatial-svg {
  width: min(100%, 360px);
  height: auto;
  max-height: 100%;
}

.spatial-svg-title {
  fill: #e8dcc8;
  font-size: 13px;
  font-family: Archivo, system-ui, sans-serif;
  font-weight: 600;
}

.spatial-region {
  cursor: pointer;
  transition: stroke 0.15s ease, fill 0.15s ease, filter 0.15s ease;
}

.spatial-region:hover,
.spatial-region.is-selected {
  filter: drop-shadow(0 0 6px rgba(226, 177, 90, 0.65));
  stroke: #e2b15a !important;
}

.spatial-region.is-selected {
  fill: rgba(226, 177, 90, 0.28) !important;
}

#spatialCtCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.spatial-disclaimer {
  margin: 0;
  padding: 6px 10px 8px;
  font-size: 11px;
  line-height: 1.35;
  color: #f0d9a8;
  background: rgba(80, 50, 20, 0.35);
  border-top: 1px solid rgba(226, 177, 90, 0.25);
  flex: 0 0 auto;
}

.spatial-fallback-msg,
.spatial-empty {
  padding: 16px;
  color: var(--muted, #b9a894);
  font-size: 13px;
  line-height: 1.5;
}

.spatial-mobile-tabs {
  display: none;
  gap: 6px;
  padding: 0 0 8px;
  pointer-events: auto;
}

body.spatial-on .spatial-3d-frame {
  position: relative;
  pointer-events: auto;
}

body.spatial-on .spatial-live-canvas,
body.spatial-on .spatial-3d-frame > #view {
  position: absolute !important;
  left: 0;
  right: 0;
  top: 36px;
  bottom: 0;
  width: 100% !important;
  height: auto !important;
  border: 0;
  border-radius: 0 0 14px 14px;
  z-index: 1;
}

/* Unmapped modules: hide CT, keep diagram fallback + 3D */
body.spatial-on.spatial-fallback .spatial-shell {
  grid-template-columns: minmax(200px, 0.9fr) minmax(280px, 1.4fr);
}
body.spatial-on.spatial-fallback .spatial-pane-ct { display: none; }

@media (max-width: 1040px) {
  body.spatial-on .spatial-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto minmax(150px, 36%);
    padding: 88px 8px 72px;
    gap: 6px;
  }

  body.spatial-on .spatial-mobile-tabs {
    display: flex;
    grid-row: 2;
    grid-column: 1;
    justify-content: center;
    z-index: 5;
    margin: 0;
    padding: 0;
  }

  body.spatial-on .spatial-3d-frame {
    grid-row: 1;
    grid-column: 1;
  }

  body.spatial-on .spatial-pane-diagram,
  body.spatial-on .spatial-pane-ct {
    grid-row: 3;
    grid-column: 1;
  }

  body.spatial-on:not([data-spatial-tab="ct"]) .spatial-pane-ct { display: none; }
  body.spatial-on[data-spatial-tab="ct"] .spatial-pane-diagram { display: none; }
  body.spatial-on[data-spatial-tab="ct"] .spatial-pane-ct { display: flex; }

  body.spatial-on .spatial-live-canvas,
  body.spatial-on .spatial-3d-frame > #view {
    top: 32px;
    border-radius: 0 0 12px 12px;
  }

  body.spatial-on.spatial-fallback .spatial-shell {
    grid-template-columns: 1fr;
  }

  body.spatial-on .spatial-toolbar {
    top: 48px;
    max-width: calc(100% - 16px);
  }
}

@media (max-width: 600px) {
  body.spatial-on .spatial-shell {
    padding-top: 78px;
    grid-template-rows: minmax(0, 1fr) auto minmax(130px, 34%);
  }
  .spatial-toolbar .btn { font-size: 12px; min-height: 34px; padding: 5px 8px; }
}
