/* Three-dimensional ocean structure workbench.
 * Loaded last so the diagnostic canvas remains legible across every viewport tier.
 */

.ocean-structure-stage {
  isolation: isolate;
}

.ocean-structure-stage > .scene-stage-title {
  position: relative;
  z-index: 6;
  flex: 0 0 auto;
  grid-template-columns: minmax(0, 1fr) auto !important;
  gap: 10px;
}

.scene-header-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.scene-header-meta span {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid rgba(102, 205, 222, 0.24);
  border-radius: 999px;
  color: #bcd7df;
  background: rgba(5, 20, 30, 0.76);
  font: 700 8px/1 "Cascadia Mono", "Consolas", monospace;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.scene-header-meta span:last-child {
  border-color: rgba(103, 224, 178, 0.26);
  color: #bcefdc;
}

.ocean-scene-shell {
  position: relative;
  z-index: 3;
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  min-height: 240px;
  overflow: hidden;
  border-radius: 0 0 6px 6px;
  background:
    radial-gradient(circle at 54% 18%, rgba(47, 151, 176, 0.11), transparent 42%),
    #03101a;
}

.ocean-scene-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 20, 31, 0.24), transparent 22%, transparent 72%, rgba(2, 10, 17, 0.34)),
    linear-gradient(90deg, rgba(84, 202, 220, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(84, 202, 220, 0.022) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
}

.ocean-scene-shell > #terrainCanvas {
  position: absolute !important;
  inset: 0;
  z-index: 2;
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #03101a !important;
  touch-action: none;
  cursor: grab;
}

.ocean-scene-shell > #terrainCanvas:active {
  cursor: grabbing;
}

.scene-commandbar {
  position: absolute;
  z-index: 8;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  pointer-events: none;
}

.scene-mode-group,
.scene-camera-group {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid rgba(116, 188, 208, 0.18);
  border-radius: 8px;
  background: rgba(3, 15, 24, 0.84);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.scene-mode-group {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.scene-mode-group::-webkit-scrollbar {
  display: none;
}

.scene-mode-group button,
.scene-camera-group button {
  min-width: 0;
  min-height: 27px;
  padding: 5px 8px;
  border: 0;
  border-radius: 5px;
  color: #8faeba;
  background: transparent;
  box-shadow: none;
  font-size: 8px;
  font-weight: 720;
  line-height: 1;
  white-space: nowrap;
}

.scene-mode-group button:hover,
.scene-camera-group button:hover {
  color: #e9f8fb;
  background: rgba(86, 194, 215, 0.1);
}

.scene-mode-group button.active {
  color: #f3fbfd;
  background: rgba(60, 186, 211, 0.18);
  box-shadow: inset 0 -2px 0 #58d4e6;
}

.scene-layer-toggles {
  position: absolute;
  z-index: 8;
  top: 49px;
  left: 8px;
  display: flex;
  max-width: calc(100% - 16px);
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid rgba(116, 188, 208, 0.14);
  border-radius: 7px;
  background: rgba(3, 15, 24, 0.76);
  backdrop-filter: blur(8px);
}

.scene-layer-toggles label {
  position: relative;
  display: block;
  cursor: pointer;
}

.scene-layer-toggles input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scene-layer-toggles span {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  padding: 4px 7px;
  border-radius: 4px;
  color: #7895a2;
  font-size: 7px;
  font-weight: 700;
  white-space: nowrap;
}

.scene-layer-toggles input:checked + span {
  color: #cdeef3;
  background: rgba(83, 213, 224, 0.11);
}

.scene-layer-toggles input:focus-visible + span,
.scene-mode-group button:focus-visible,
.scene-camera-group button:focus-visible {
  outline: 2px solid #8ce8f4;
  outline-offset: 1px;
}

.scene-legend,
.scene-info,
.scene-provenance {
  position: absolute;
  z-index: 7;
  border: 1px solid rgba(112, 179, 198, 0.14);
  background: rgba(3, 15, 24, 0.78);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.scene-legend {
  left: 8px;
  bottom: 8px;
  width: clamp(118px, 25%, 190px);
  padding: 7px 8px;
  border-radius: 7px;
}

.scene-legend > span {
  display: block;
  margin-bottom: 5px;
  overflow: hidden;
  color: #c1d9e1;
  font: 700 7px/1 "Cascadia Mono", "Consolas", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-legend > i {
  display: block;
  width: 100%;
  height: 7px;
  border: 1px solid rgba(231, 247, 250, 0.16);
  border-radius: 999px;
  background: linear-gradient(90deg, #173b8f, #16a7cf 25%, #61d18b 52%, #f1c84b 76%, #e64c45);
}

.scene-legend > div {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: #8ca8b3;
  font: 650 6px/1 "Cascadia Mono", "Consolas", monospace;
}

.scene-info {
  right: 8px;
  bottom: 8px;
  display: grid;
  max-width: min(48%, 300px);
  padding: 7px 9px;
  border-radius: 7px;
}

.scene-info strong {
  overflow: hidden;
  color: #d9eef2;
  font-size: 8px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-info span {
  margin-top: 3px;
  overflow: hidden;
  color: #7897a4;
  font-size: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-provenance {
  right: 8px;
  top: 49px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 9px;
  max-width: min(58%, 360px);
  padding: 6px 8px;
  border-radius: 7px;
  color: #7896a2;
  font-size: 6px;
}

.scene-provenance span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.scene-provenance i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #f0bc55;
}

.scene-provenance i.live {
  background: #5dd9a8;
  box-shadow: 0 0 6px rgba(93, 217, 168, 0.7);
}

/* Desktop: the 3D canvas becomes a primary diagnostic surface and spans both rows. */
@media (min-width: 981px) and (orientation: landscape) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace.workspace {
    grid-template-columns: minmax(500px, 1.55fr) minmax(380px, 1fr) !important;
    grid-template-rows: var(--pc-ribbon, 58px) minmax(230px, 1fr) minmax(155px, 0.62fr) var(--pc-metrics, 82px) !important;
    grid-template-areas:
      "ribbon ribbon"
      "map scene"
      "profile scene"
      "metrics metrics" !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .ocean-structure-stage {
    min-width: 380px;
    min-height: 0;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .ocean-scene-shell {
    min-height: 280px;
  }
}

@media (min-width: 1600px) and (min-height: 820px) and (orientation: landscape) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace.workspace {
    grid-template-columns: minmax(660px, 1.62fr) minmax(480px, 1fr) !important;
  }

  .scene-mode-group button,
  .scene-camera-group button {
    min-height: 30px;
    padding-inline: 10px;
    font-size: 9px;
  }

  .scene-layer-toggles {
    top: 54px;
  }

  .scene-provenance {
    top: 54px;
  }
}

@media (min-width: 3000px) and (orientation: landscape) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace.workspace {
    grid-template-columns: minmax(1100px, 1.7fr) minmax(760px, 1fr) !important;
  }

  .scene-commandbar {
    top: 14px;
    left: 14px;
    right: 14px;
  }

  .scene-mode-group button,
  .scene-camera-group button {
    min-height: 38px;
    padding-inline: 15px;
    font-size: 12px;
  }

  .scene-layer-toggles,
  .scene-provenance {
    top: 66px;
  }

  .scene-layer-toggles {
    left: 14px;
  }

  .scene-layer-toggles span {
    min-height: 31px;
    padding-inline: 11px;
    font-size: 10px;
  }

  .scene-legend,
  .scene-info {
    bottom: 14px;
    padding: 11px 13px;
  }
}

/* Portrait/mobile: give the 3D scene a full row and enough physical height for touch. */
@media (max-width: 980px) and (orientation: portrait) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .ocean-structure-stage {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    height: clamp(420px, 58vh, 520px) !important;
    min-height: 420px !important;
  }

  .scene-header-meta span:last-child {
    display: none;
  }

  .scene-header-meta span {
    min-height: 25px;
    padding-inline: 7px;
    font-size: 7px;
  }

  .scene-commandbar {
    top: 8px;
  }

  .scene-mode-group {
    flex: 1 1 auto;
  }

  .scene-mode-group button,
  .scene-camera-group button {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 9px;
  }

  .scene-camera-group button:not(:first-child) {
    display: none;
  }

  .scene-layer-toggles {
    top: 53px;
  }

  .scene-layer-toggles span {
    min-height: 30px;
    padding-inline: 9px;
    font-size: 8px;
  }

  .scene-provenance {
    top: 54px;
    max-width: 48%;
    font-size: 7px;
  }

  .scene-provenance span:last-child {
    display: none;
  }

  .scene-legend {
    width: 142px;
    padding: 8px 9px;
  }

  .scene-info {
    max-width: calc(100% - 174px);
    padding: 8px 10px;
  }

  .scene-info strong {
    font-size: 9px;
  }

  .scene-info span {
    font-size: 7px;
  }
}

@media (max-width: 380px) and (orientation: portrait) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .ocean-structure-stage {
    height: 420px !important;
  }

  .scene-camera-group {
    display: none;
  }

  .scene-provenance {
    display: none;
  }

  .scene-info span {
    display: none;
  }
}

@media (max-width: 1180px) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .ocean-structure-stage {
    min-height: 390px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ocean-scene-shell *,
  .ocean-scene-shell *::before,
  .ocean-scene-shell *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
