/* RC50 responsive and short-height contracts. */
@media (max-width: 90rem) {
  :root { --sim-rail-input: 15rem; --sim-rail-proof: 18rem; }
  .sim-wb-timeline-toolbar { grid-template-columns: auto minmax(12rem, 1fr) auto; }
  .sim-wb-speed-control { grid-column: 3; }
  .sim-wb-timeline-state { grid-column: 1 / 3; grid-row: 2; }
  .sim-wb-analysis-context { min-width: 24rem; }
}

@media (min-width: 821px) and (max-height: 720px) {
  .simulation-workbench-page .sim-workbench-titlebar { display: none; }
  .sim-workbench-topbar { top: var(--site-header-height, 4rem); }
  .sim-workbench-topbar-inner { min-height: 3.35rem; padding-block: .25rem; }
  .sim-wb-selector select,
  .sim-wb-selector button,
  .sim-wb-action,
  .sim-wb-tools > summary { min-height: 2.45rem; padding: .42rem .55rem; }
  .sim-wb-app-shell {
    height: calc(100dvh - 7.35rem);
    min-height: 29rem;
    max-height: none;
  }
  .sim-workbench-shell[data-mode="explore"] { --sim-rail-input: 0rem; }
  .sim-wb-scene-header { min-height: 3rem; padding: .4rem .58rem; }
  .sim-wb-state-strip div { padding: .38rem .5rem; }
  .sim-wb-state-strip span { font-size: .65rem; }
  .sim-wb-state-strip strong { font-size: .73rem; }
  .sim-wb-layer-toolbar { min-height: 2.3rem; }
  .sim-wb-layer-toolbar button { min-height: 2rem; padding-block: .35rem; }
  .sim-wb-canvas-shell,
  .sim-wb-canvas-shell canvas { min-height: 10rem; }
  .sim-wb-timeline { padding: .4rem .58rem .46rem; }
  .sim-wb-timeline button,
  .sim-wb-speed-control select { min-height: 2.4rem; padding: .4rem .5rem; }
  .sim-wb-event-legend { display: none; }
  .sim-wb-timeline-event { padding-top: .2rem; }
  .sim-wb-analysis-header { min-height: 3rem; }
  .sim-wb-analysis-toggle { min-height: 3rem; }
  .sim-wb-analysis-content { height: min(42dvh, 21rem); min-height: 14rem; }
}

@media (max-width: 1180px) and (min-width: 821px) {
  :root { --sim-rail-input: 14rem; --sim-rail-proof: 16rem; }
  .sim-wb-primary-workspace { grid-template-columns: var(--sim-rail-input) minmax(24rem, 1fr) var(--sim-rail-proof); }
  .sim-wb-state-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sim-wb-state-strip > div:nth-child(4),
  .sim-wb-state-strip > div:nth-child(5) { display: none; }
  .sim-wb-timeline-toolbar { grid-template-columns: 1fr auto; }
  .sim-wb-timeline-transport { grid-column: 1; }
  .sim-wb-timeline-evidence { grid-column: 1; grid-row: 2; }
  .sim-wb-timeline-state { grid-column: 1; grid-row: 3; }
  .sim-wb-speed-control { grid-column: 2; grid-row: 1 / 4; align-self: end; }
}

@media (max-width: 820px) {
  .simulation-workbench-page .sim-workbench-titlebar { display: none; }
  .sim-workbench-topbar { position: sticky; top: var(--site-header-height, 3.6rem); }
  .sim-workbench-topbar-inner { padding: .4rem .55rem; }
  .sim-wb-selector:first-child { width: 100%; }
  .sim-wb-selector:first-child select { min-width: 0; flex: 1; }
  .sim-wb-run-status { display: none; }
  .sim-wb-command-primary {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: .15rem;
  }
  .sim-wb-command-primary > * { flex: 0 0 auto; }
  .sim-wb-region-switcher {
    position: sticky;
    top: calc(var(--site-header-height, 3.6rem) + 7.2rem);
    z-index: 35;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    color: var(--sim-text);
    background: #07161e;
    border-bottom: 1px solid var(--sim-line-strong);
  }
  .sim-wb-region-switcher button {
    min-width: 0;
    min-height: 2.75rem;
    padding: .5rem .25rem;
    color: var(--sim-text);
    background: var(--sim-control-bg);
    border: 0;
    border-right: 1px solid var(--sim-line);
    font: 800 .7rem/1.2 var(--font-mono, var(--mono, ui-monospace, monospace));
  }
  .sim-wb-region-switcher button[aria-pressed="true"] { color: #041018; background: var(--sim-cyan); }
  .sim-wb-app-shell {
    height: calc(100dvh - 17.25rem);
    min-height: 32rem;
    grid-template-rows: minmax(0, 1fr);
  }
  .sim-wb-primary-workspace {
    min-height: 0;
    display: block;
    overflow: hidden;
  }
  .sim-wb-input-rail,
  .sim-wb-proof-rail,
  .sim-wb-center-workspace,
  .sim-wb-analysis-drawer {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
  }
  .sim-wb-input-rail,
  .sim-wb-proof-rail { overflow-y: auto; }
  .sim-wb-center-workspace { grid-template-rows: minmax(0, 1fr) auto; }
  .sim-wb-analysis-drawer {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .sim-wb-analysis-header { grid-template-columns: 1fr; }
  .sim-wb-analysis-context { min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sim-wb-analysis-content { height: auto; min-height: 0; }
  .sim-wb-scene-panel { grid-template-rows: auto auto auto auto minmax(12rem, 1fr) auto; }
  .sim-wb-scene-header { align-items: flex-start; }
  .sim-wb-scene-toolbar { justify-content: flex-start; }
  .sim-wb-state-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sim-wb-state-strip > div:nth-child(n+4) { display: none; }
  .sim-wb-layer-toolbar { display: none; }
  .sim-wb-canvas-shell,
  .sim-wb-canvas-shell canvas { min-height: 13rem; }
  .sim-wb-timeline-toolbar { display: grid; grid-template-columns: 1fr auto; }
  .sim-wb-timeline-evidence { display: none; }
  .sim-wb-timeline-state { grid-column: 1; grid-row: 2; }
  .sim-wb-speed-control { grid-column: 2; grid-row: 1 / 3; }
  .sim-wb-timeline-transport .sim-wb-control-label { display: none; }
  .sim-wb-event-legend { display: none; }
  .sim-wb-timeline-event span { display: none; }
  .sim-wb-tabs button { min-height: 2.75rem; }
}

@media (max-width: 420px) {
  .sim-wb-app-shell { height: calc(100dvh - 17.25rem); min-height: 31rem; }
  .sim-wb-region-switcher { top: calc(var(--site-header-height, 3.6rem) + 7.8rem); }
  .sim-wb-mode-group button { padding-inline: .42rem; }
  .sim-wb-scene-header h2 { font-size: .88rem; }
  .sim-wb-scene-toolbar button { min-height: 2.55rem; padding-inline: .48rem; }
  .sim-wb-timeline { padding-inline: .4rem; }
  .sim-wb-timeline button { min-width: 2.55rem; min-height: 2.55rem; padding-inline: .4rem; }
}

/* RC50 P0 short-height density: retain the scene, timeline, and a compact
   synchronized analysis view in the same viewport. Advanced evidence jumps
   remain available through the proof inspector and Tools surface. */
@media (min-width: 821px) and (max-height: 720px) {
  .sim-wb-app-shell {
    grid-template-rows: minmax(15rem, 1fr) auto;
  }
  .sim-wb-timeline-toolbar {
    grid-template-columns: auto minmax(9rem, 1fr) auto;
    gap: .35rem;
  }
  .sim-wb-timeline-evidence {
    display: none !important;
  }
  .sim-wb-timeline-state {
    grid-column: 2;
    grid-row: 1;
    align-self: end;
  }
  .sim-wb-speed-control {
    grid-column: 3;
    grid-row: 1;
    align-self: end;
  }
  .sim-wb-group-label,
  .sim-wb-speed-control > span {
    font-size: .64rem;
  }
  .sim-wb-timeline-track {
    margin-top: .28rem;
  }
  .sim-wb-timeline-event {
    padding-top: .12rem;
  }
  .sim-wb-analysis-header {
    min-height: 2.75rem;
  }
  .sim-wb-analysis-toggle {
    min-height: 2.75rem;
    padding-block: .35rem;
  }
  .sim-wb-analysis-toggle .eyebrow,
  .sim-wb-analysis-context dt {
    font-size: .64rem;
  }
  .sim-wb-analysis-toggle strong {
    font-size: .84rem;
  }
  .sim-wb-analysis-context div {
    padding: .3rem .42rem;
  }
  .sim-wb-analysis-context dd {
    margin-top: .1rem;
    font-size: .7rem;
  }
  .sim-wb-analysis-content {
    height: min(24dvh, 9rem);
    min-height: 8rem;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-summary,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-summary {
    display: none;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-rail .sim-wb-panel-header,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-rail .sim-wb-panel-header {
    min-height: 2.85rem;
    padding: .35rem .45rem;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-rail .sim-wb-panel-body,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-rail .sim-wb-panel-body {
    padding: .4rem;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-compact,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-compact {
    gap: .25rem;
    padding: .42rem;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-compact p:not(.eyebrow),
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-compact p:not(.eyebrow) {
    display: none;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-compact strong,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-compact strong {
    font-size: .78rem;
    line-height: 1.15;
  }
  .sim-workbench-shell[data-mode="explore"] .sim-wb-proof-compact button,
  .sim-workbench-shell[data-mode="guided"] .sim-wb-proof-compact button {
    min-height: 2.35rem;
    padding: .32rem .4rem;
    font-size: .68rem;
  }
}

/* Mobile uses a single deliberate region. Global workbench controls stay in
   document flow so focus and pointer scrolling cannot land underneath an
   independent sticky toolbar. The site header remains the only sticky layer. */
@media (max-width: 820px) {
  .sim-workbench-topbar,
  .sim-wb-region-switcher {
    position: relative;
    top: auto;
  }
  .sim-wb-tabs button,
  .sim-wb-tabpanel {
    scroll-margin-top: 4.5rem;
  }
  .sim-wb-app-shell {
    height: calc(100dvh - 13rem);
    min-height: 33rem;
  }
}

@media (max-width: 420px) {
  .sim-wb-app-shell {
    height: calc(100dvh - 13rem);
    min-height: 32rem;
  }
}

@media (min-width: 821px) and (max-height: 720px) {
  .sim-wb-analysis-content {
    height: 7.25rem;
    min-height: 7.25rem;
  }
}

@media (max-width: 820px) {
  .sim-wb-command-primary > .sim-wb-action,
  .sim-wb-command-primary > .sim-wb-tools {
    min-width: 4rem;
  }
  .sim-wb-command-primary > [data-analysis-toggle] {
    min-width: 4.75rem;
  }
}
