/* Scientific Workspace layout manager: the model owns the stage, tools live in
   fixed corner zones and open on request. Active only once the script marks
   body.zx-ws, so without JavaScript the original layout (and every panel) stays.

   Zones: TL environment selector · TR actions, parameters, formulas, settings ·
   BL experiment control + compact timeline · BR legend and assistant.
   Panels open one at a time (body[data-zx-ws-open]); main.focus-mode is the
   existing Immersive view. Safari 15 safe: no :has(), no container queries. */
@media (min-width: 480px) {
  body.zx-ws {
    --ws-pad: 12px;
    --ws-top: calc(10px + env(safe-area-inset-top, 0px));
    --ws-left: calc(var(--ws-pad) + env(safe-area-inset-left, 0px));
    --ws-right: calc(var(--ws-pad) + env(safe-area-inset-right, 0px));
    --ws-bottom: calc(var(--ws-pad) + env(safe-area-inset-bottom, 0px));
    --ws-row2: calc(var(--ws-top) + 50px);
    --ws-panel-top: calc(var(--ws-top) + 98px);
    --ws-panel-width: min(560px, calc(100% - 2 * var(--ws-pad) - 72px));
    --ws-br-reserve: 200px;
  }
  /* The stage is the whole workspace; the BR zone no longer needs a strip. */
  body.zx-ws.zx-native.zx-journey-page:not(.zx-embedded-page) main.journey.model-flow { max-height: none; }
  @media (min-width: 901px) {
    body.zx-ws.zx-native.zx-journey-page:not(.zx-embedded-page) main.journey { bottom: 0 !important; }
  }

  /* TL — compact environment selector: symbols only until opened. */
  body.zx-ws main.journey .models {
    top: var(--ws-top); left: var(--ws-left); right: auto; bottom: auto; transform: none;
    max-height: calc(100% - var(--ws-top) - 96px); max-width: none; overflow: auto;
  }
  body.zx-ws main.journey .models .model-label { display: none; }
  body.zx-ws main.journey .models .runtime-nav-link { gap: 0; padding: 4px; }
  body.zx-ws[data-zx-ws-open="models"] main.journey .models .model-label { display: block; }
  body.zx-ws[data-zx-ws-open="models"] main.journey .models .runtime-nav-link { gap: 12px; padding: 8px; }
  body.zx-ws[data-zx-ws-open="models"] main.journey .models {
    z-index: 7; padding: 6px; border-radius: 14px; background: #0c1823e6; border: 1px solid #bbd9ea26;
  }

  /* TR — model actions (scales, help, immersive, model parameters). */
  body.zx-ws main.journey .topbar { top: var(--ws-top); left: auto; right: var(--ws-right); gap: 6px; }
  body.zx-ws main.journey .topbar .brand { display: none; }
  body.zx-ws main.journey .telemetry { top: var(--ws-panel-top); right: var(--ws-right); font-size: 11px; line-height: 1.7; }

  /* TR — panels, opened on request, one at a time. */
  body.zx-ws main.journey :is(.formula, .live-equation, .scene-tools, .camera-actions, .joystick) { display: none; }
  /* The scene description keeps its heading in the accessibility tree while collapsed. */
  body.zx-ws:not([data-zx-ws-open="info"]) main.journey .scene-info {
    width: 1px; height: 1px; max-width: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; margin: -1px; padding: 0;
  }
  body.zx-ws main.journey .camera-hint { display: none; }
  body.zx-ws[data-zx-ws-open="params"] main.journey .formula {
    display: flex; top: var(--ws-panel-top); left: auto; right: var(--ws-right); transform: none; width: var(--ws-panel-width); z-index: 7;
  }
  body.zx-ws[data-zx-ws-open="params"] main.journey .live-equation {
    display: block; top: calc(var(--ws-panel-top) + 62px); left: auto; right: var(--ws-right); transform: none; width: var(--ws-panel-width);
    max-height: calc(100% - var(--ws-panel-top) - 150px); overflow: auto; z-index: 7;
  }
  body.zx-ws[data-zx-ws-open="info"] main.journey .scene-info {
    display: block; pointer-events: auto; top: var(--ws-panel-top); bottom: auto; left: auto; right: var(--ws-right); max-width: min(460px, calc(100% - 2 * var(--ws-pad) - 72px));
    max-height: calc(100% - var(--ws-panel-top) - 96px); overflow: auto; padding: 14px 16px; border-radius: 12px; background: #0c1823d9; z-index: 7;
  }
  body.zx-ws[data-zx-ws-open="info"] main.journey .scene-info h1 { font-size: clamp(22px, 3vw, 34px); }
  body.zx-ws[data-zx-ws-open="tools"] main.journey .camera-actions {
    display: flex; flex-wrap: wrap; justify-content: flex-end; top: var(--ws-panel-top); bottom: auto; left: auto; right: var(--ws-right);
    max-width: var(--ws-panel-width); z-index: 7;
  }
  body.zx-ws[data-zx-ws-open="tools"] main.journey .scene-tools {
    display: flex; top: calc(var(--ws-panel-top) + 54px); left: auto; right: var(--ws-right); transform: none;
    max-width: var(--ws-panel-width); flex-wrap: wrap; justify-content: flex-end; z-index: 7;
  }
  body.zx-ws[data-zx-ws-open="tools"] main.journey .joystick { display: grid; bottom: calc(var(--ws-bottom) + 76px); right: var(--ws-right); }
  body.zx-ws[data-zx-ws-open]:not([data-zx-ws-open=""]):not([data-zx-ws-open="models"]) main.journey .telemetry { visibility: hidden; }

  /* BL + bottom edge — experiment control with a compact timeline; the BR
     corner stays free for the legend and the assistant. */
  body.zx-ws main.journey .transport {
    left: var(--ws-left); right: calc(var(--ws-right) + var(--ws-br-reserve)); bottom: var(--ws-bottom);
    min-height: 0; gap: 10px; padding: 6px 10px; border-radius: 12px;
  }
  body.zx-ws main.journey .transport :is(.playbtn, .stepbtn, .resetbtn) { width: 36px; height: 36px; }
  body.zx-ws main.journey .transport .time-value { min-width: 58px; font-size: 13px; }

  /* BR — colour scale of the field stays visible: it is part of the data. */
  body.zx-ws main.journey .axis-legend { top: auto; left: auto; bottom: calc(var(--ws-bottom) + 64px); right: var(--ws-right); font-size: 11px; }

  body.zx-ws main.journey :is(.toast, .selection) { z-index: 8; }

  /* Workspace toolbar (outside React's tree, fixed under the TR actions). */
  #zx-ws-bar {
    position: fixed; z-index: 40; display: flex; gap: 6px;
    top: calc(var(--zx-shell-height, var(--zx-topbar, 56px)) + var(--ws-row2));
    right: var(--ws-right);
  }
  #zx-ws-bar button {
    min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid #bbd9ea26;
    background: #0c1823cc; color: #d3d9df; font: 600 16px/1 Georgia, serif; cursor: pointer;
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); touch-action: manipulation;
  }
  #zx-ws-bar button[aria-pressed="true"] { border-color: var(--zx-accent, #dfff00); color: var(--zx-accent, #dfff00); }
  #zx-ws-bar button:focus-visible { outline: 2px solid var(--zx-accent, #dfff00); outline-offset: 2px; }
  #zx-ws-bar .zx-ws-exit { display: none; }

  /* Immersive Scientific View: only the model, the legend and the way back. */
  body.zx-ws.zx-ws-immersive #zx-ws-bar { top: var(--ws-top); }
  body.zx-ws.zx-ws-immersive #zx-ws-bar button { display: none; }
  body.zx-ws.zx-ws-immersive #zx-ws-bar .zx-ws-exit { display: block; }
  body.zx-ws.zx-ws-immersive main.journey :is(.models, .formula, .live-equation, .scene-tools, .camera-actions, .joystick, .scene-info) { display: none; }
  body.zx-ws.zx-ws-immersive main.journey .axis-legend { opacity: 1; }
  body.zx-ws.zx-ws-immersive .zx-assistant-root { display: none; }
}
@media (max-width: 479.98px) { #zx-ws-bar { display: none; } }
@media (prefers-reduced-motion: reduce) { #zx-ws-bar button { transition: none; } }
/* In portrait and tablet Split View the Models button is the collapsed
   selector. Reusing the full horizontal model list here would cover actions. */
@media (min-width: 480px) and (max-width: 900px) {
  body.zx-ws #zx-ws-bar .zx-ws-models { position: fixed; top: calc(var(--zx-shell-height, var(--zx-topbar, 56px)) + var(--ws-top)); left: var(--ws-left); }
  body.zx-ws main.journey .models { display: none; }
  body.zx-ws[data-zx-ws-open="models"] main.journey .models {
    display: block; top: var(--ws-panel-top); max-width: calc(100% - 2 * var(--ws-pad)); overflow: auto;
  }
  body.zx-ws[data-zx-ws-open="models"] main.journey .telemetry { visibility: hidden; }
  body.zx-ws[data-zx-ws-open="tools"] main.journey .camera-actions {
    flex-direction: row; flex-wrap: nowrap; max-width: calc(100% - 2 * var(--ws-pad)); overflow-x: auto;
  }
  body.zx-ws main.journey .transport { gap: 6px; }
}
@media (min-width: 480px) and (max-width: 650px) {
  /* The shell uses an icon-only assistant up to the same breakpoint. */
  body.zx-ws { --ws-br-reserve: 64px; }
}
@media (min-width: 480px) and (max-width: 900px) {
  body.zx-ws main.journey.model-flow .axis-legend { display: block; }
  body.zx-ws.zx-native.zx-journey-page:not(.zx-embedded-page) main.journey.model-flow { bottom: var(--zx-bottom) !important; }
  body.zx-ws.zx-native.zx-journey-page:not(.zx-embedded-page) main.journey.model-flow.focus-mode { bottom: 0 !important; }
}
