/* NOISE workspace chrome: one station head shared by every workspace (proposed).

   Markup contract (zones are optional; order in the DOM is the reading order):
     header.wc-head[data-wc-head]
       a.wc-escape          leave for the hub; hidden inside a Lab room, whose rail owns it
       div.wc-ident         .wc-no + .wc-name(.wc-cap + h1)        which station this is
       label.wc-project     .wc-cap + select                       which project the work belongs to
       div.wc-meta          .wc-cap + .wc-val                      what that project resolves to right now
       div.wc-display       button[data-wc-menu-toggle] + .wc-menu[data-wc-menu]   personal display prefs
       a.wc-style           UI-style switch, fenced off at the far end; hidden when hosted
       nav.workspace-flow   task navigation; workspace-layout.js injects it, it always lands in row 2
   Both rows have fixed heights and row 2 is reserved before the flow arrives, so the head keeps
   one geometry per viewport and font size no matter which workspace, language or project loads.
   Colours fall back to the acoustic-lab tokens when a page defines them. */

.wc-head {
  --wc-row1: 3.25rem;
  --wc-row2: 2.5rem;
  --wc-zone: 2.75rem;
  --wc-gap: .75rem;
  --wc-ink: var(--ink, #121412);
  --wc-ink-3: var(--ink-3, #62655d);
  --wc-rule: var(--rule, rgb(18 20 18 / .14));
  --wc-rule-2: var(--rule-2, rgb(18 20 18 / .26));
  --wc-bg: var(--paper, #ecebe6);
  --wc-plate: var(--plate, #f7f6f2);
  --wc-field: var(--field, #fff);
  /* a tint, not a surface: pages may set --wc-bg to their plate colour, and the hover must still show */
  --wc-hover: color-mix(in srgb, var(--wc-ink) 7%, transparent);
  --wc-mark: var(--signal, #c4ee2c);
  --wc-ring: var(--ring, #121412);
  --wc-lift: var(--lift, 0 .75rem 2rem rgb(0 0 0 / .18));
  --wc-r: var(--r, .375rem);
  --wc-ui: var(--f-ui, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif);
  --wc-face: var(--f-display, Bahnschrift, "DIN Alternate", "Segoe UI", sans-serif);
  --wc-num: var(--f-num, "Cascadia Mono", Consolas, ui-monospace, monospace);
  --wc-ease: var(--ease, cubic-bezier(.2, .7, .2, 1));
  position: relative;
  z-index: 40;
  display: grid;
  grid-template-columns: auto minmax(0, max-content) minmax(0, max-content) minmax(0, 1fr) auto auto;
  grid-template-rows: var(--wc-row1) var(--wc-row2);
  grid-template-areas:
    "escape ident project meta display style"
    "flow   flow  flow    flow flow    flow";
  column-gap: var(--wc-gap);
  align-items: center;
  box-sizing: border-box;
  min-width: 0;
  margin: 0;
  padding: 0 max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--wc-rule);
  background: var(--wc-bg);
  color: var(--wc-ink);
  font-family: var(--wc-ui);
}
/* zones set their own display, so an engine-hidden child must still disappear */
.wc-head [hidden] { display: none !important; }
/* The row-2 hairline exists before the flow does, so nothing moves when it is injected. */
.wc-head::before {
  content: "";
  grid-area: flow;
  align-self: start;
  margin-inline: calc(-1 * max(1rem, env(safe-area-inset-left))) calc(-1 * max(1rem, env(safe-area-inset-right)));
  border-top: 1px solid var(--wc-rule);
  pointer-events: none;
}
.wc-head > .wc-escape { grid-area: escape; }
.wc-head > .wc-ident { grid-area: ident; }
.wc-head > .wc-project { grid-area: project; }
.wc-head > .wc-meta { grid-area: meta; }
.wc-head > .wc-display { grid-area: display; }
.wc-head > .wc-style { grid-area: style; }

.wc-sr, .wc-head .wc-hide {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Caption over value: every zone reads the same way, like labelled channels on a desk. */
.wc-cap {
  display: block;
  overflow: hidden;
  font: 600 .6875rem/1.2 var(--wc-ui);
  letter-spacing: .06em;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--wc-ink-3);
}
.wc-val {
  display: flex;
  align-items: center;
  gap: .375rem;
  min-width: 0;
  overflow: hidden;
  font: 600 .875rem/1.35 var(--wc-ui);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wc-val svg, .wc-escape svg, .wc-menu svg { flex: none; width: 1.125rem; height: 1.125rem; }

.wc-escape {
  display: inline-grid;
  place-items: center;
  inline-size: var(--wc-zone);
  block-size: var(--wc-zone);
  border-radius: var(--wc-r);
  color: inherit;
  text-decoration: none;
}
.wc-escape:hover { background: var(--wc-plate); }

.wc-ident { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.wc-no {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-inline-size: 2.125rem;
  block-size: 2.125rem;
  padding-inline: .25rem;
  box-sizing: border-box;
  border: 1px solid currentColor;
  border-radius: var(--wc-r);
  font: 600 .875rem/1 var(--wc-num);
  font-variant-numeric: tabular-nums;
}
.wc-name { display: grid; min-width: 0; }
.wc-name h1 {
  margin: 0;
  overflow: hidden;
  font: 600 1.125rem/1.2 var(--wc-face);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Project identity: the whole box opens the select, the caption never moves. */
.wc-project {
  position: relative;
  display: block;
  inline-size: clamp(11rem, 18vw, 19rem);
  block-size: var(--wc-zone);
  box-sizing: border-box;
  border: 1px solid var(--wc-rule-2);
  border-radius: var(--wc-r);
  background: var(--wc-field);
  cursor: pointer;
}
.wc-project > .wc-cap { position: absolute; inset: .3125rem 2rem auto .625rem; z-index: 1; pointer-events: none; }
.wc-project > select {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 1.125rem 2rem 0 .625rem;
  overflow: hidden;
  appearance: none;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: inherit;
  font: 600 .875rem/1.3 var(--wc-ui);
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.wc-project::after, .wc-menu-btn::after {
  content: "";
  position: absolute;
  inset-inline-end: .75rem;
  inset-block-start: 50%;
  width: .4375rem;
  height: .4375rem;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.wc-project > select:focus-visible { outline: none; }
.wc-project:focus-within:has(select:focus-visible) { outline: 2px solid var(--wc-ring); outline-offset: 2px; }
.wc-project:hover { border-color: var(--wc-ink-3); }

.wc-meta { display: grid; align-content: center; min-width: 0; }
.wc-meta > * { min-width: 0; }

.wc-display { position: relative; min-width: 0; }
.wc-menu-btn, .wc-style {
  position: relative;
  display: grid;
  align-content: center;
  block-size: var(--wc-zone);
  box-sizing: border-box;
  margin: 0;
  padding: 0 .75rem;
  border: 1px solid transparent;
  border-radius: var(--wc-r);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
.wc-menu-btn { min-inline-size: 7.5rem; padding-inline-end: 2rem; border-color: var(--wc-rule); }
.wc-menu-btn:hover, .wc-style:hover { background: var(--wc-hover); }
.wc-menu-btn[aria-expanded="true"] { border-color: var(--wc-ink); background: var(--wc-plate); }
.wc-menu-btn[aria-expanded="true"]::after { transform: translateY(-25%) rotate(-135deg); }

/* The UI-style switch is a different kind of decision, so it stands apart behind a fence. */
.wc-style { margin-inline-start: .125rem; }
.wc-style::before {
  content: "";
  position: absolute;
  inset-block: .5rem;
  inset-inline-start: calc(-.5 * var(--wc-gap) - .0625rem);
  border-inline-start: 1px solid var(--wc-rule-2);
}

.wc-menu {
  position: absolute;
  inset-block-start: calc(100% + .375rem);
  inset-inline-end: 0;
  z-index: 60;
  display: grid;
  gap: .125rem;
  inline-size: max-content;
  min-inline-size: min(16rem, calc(100vw - 1.5rem));
  max-inline-size: calc(100vw - 1.5rem);
  box-sizing: border-box;
  padding: .375rem;
  border: 1px solid var(--wc-rule-2);
  border-radius: var(--wc-r);
  background: var(--wc-plate);
  box-shadow: var(--wc-lift);
  transform-origin: top right;
  animation: wc-drop .16s var(--wc-ease);
}
.wc-menu:not([data-open]) { display: none; }
.wc-menu > .wc-cap { padding: .375rem .5rem .25rem; }
.wc-row, .wc-menu > .noise-settings-entry {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .625rem;
  inline-size: 100%;
  min-block-size: 2.5rem;
  block-size: auto;
  box-sizing: border-box;
  margin: 0;
  padding: 0 .5rem;
  border: 0;
  border-radius: calc(var(--wc-r) - .125rem);
  background: transparent;
  color: inherit;
  font: 500 .875rem/1.3 var(--wc-ui);
  text-align: start;
  cursor: pointer;
}
.wc-row:hover, .wc-menu > .noise-settings-entry:hover { background: var(--wc-hover); }
.wc-row > svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wc-row select {
  min-block-size: 2rem;
  padding: 0 .5rem;
  border: 1px solid var(--wc-rule-2);
  border-radius: calc(var(--wc-r) - .125rem);
  background: var(--wc-field);
  color: inherit;
  font: 600 .8125rem/1 var(--wc-ui);
}
.wc-row-val { font: 600 .8125rem/1 var(--wc-ui); color: var(--wc-ink-3); }
/* display-preferences.js appends its Settings entry here; give it a visible name, keep its node. */
.wc-menu > .noise-settings-entry { margin-top: .25rem; border-top: 1px solid var(--wc-rule); border-radius: 0; }
.wc-menu > .noise-settings-entry::after { content: attr(title); grid-column: 2; }
.wc-menu > .noise-settings-entry svg { grid-column: 1; }

.wc-head :is(a, button, select):focus-visible { outline: 2px solid var(--wc-ring); outline-offset: 2px; }

/* Task navigation keeps to row 2 and never wraps into a third line. */
.wc-head.wc-head > .workspace-flow {
  grid-area: flow;
  align-self: stretch;
  order: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: .5rem;
  inline-size: auto;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.wc-head.wc-head > .workspace-flow .workspace-rail { min-inline-size: 0; overflow-x: auto; scrollbar-width: none; }

@keyframes wc-drop { from { opacity: 0; transform: translateY(-.25rem) scale(.98); } }

@media (pointer: coarse) {
  .wc-head { --wc-row1: 3.5rem; --wc-row2: 2.75rem; }
  .wc-row, .wc-menu > .noise-settings-entry { min-block-size: 2.75rem; }
  .wc-row select { min-block-size: 2.5rem; }
}

/* Medium: the meta channel and captions on the right condense first. */
@media (max-width: 63.99rem) {
  .wc-head { grid-template-columns: auto minmax(0, max-content) minmax(0, 1fr) 0 auto auto; }
  .wc-head > .wc-meta, .wc-name > .wc-cap { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .wc-project { inline-size: auto; max-inline-size: 18rem; }
  .wc-menu-btn { min-inline-size: 0; }
}

/* Phone: the flow's current-workspace label already names the station, so the title steps
   back to the accessibility tree and the project gets the width. */
@media (max-width: 39.99rem) {
  .wc-head {
    --wc-gap: .375rem;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "escape project display style"
      "flow   flow    flow    flow";
    padding-inline: max(.5rem, env(safe-area-inset-left)) max(.5rem, env(safe-area-inset-right));
  }
  .wc-head::before { margin-inline: calc(-1 * max(.5rem, env(safe-area-inset-left))) calc(-1 * max(.5rem, env(safe-area-inset-right))); }
  .wc-head > .wc-ident { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .wc-project { max-inline-size: none; }
  .wc-menu-btn, .wc-style { padding-inline: .5rem; }
  .wc-menu-btn { padding-inline-end: 1.625rem; }
  .wc-menu-btn::after { inset-inline-end: .5rem; }
  .wc-menu-btn > .wc-cap, .wc-style > .wc-cap { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .wc-style .wc-val > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* Short landscape and short windows: one row, nothing scrolls the canvas away. */
@media (max-height: 31.99rem) and (min-width: 40rem) {
  .wc-head {
    --wc-row1: 3rem;
    grid-template-columns: auto minmax(0, max-content) minmax(0, 16rem) minmax(0, 1fr) auto auto;
    grid-template-rows: var(--wc-row1);
    grid-template-areas: "escape ident project flow display style";
  }
  .wc-head::before { display: none; }
  .wc-head > .wc-meta { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .wc-head.wc-head > .workspace-flow { justify-content: flex-end; }
}
@media (max-height: 31.99rem) and (min-width: 40rem) and (max-width: 63.99rem) {
  .wc-head > .wc-ident { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* The secondary style destination uses the same icon-only treatment as on a
   phone. Give short-window navigation readable labels before spending height. */
@media (max-height: 31.99rem) and (min-width: 40rem) {
  .wc-head:not([data-wc-reading]) {
    grid-template-columns: auto minmax(0, max-content) minmax(0, 14rem) minmax(0, 1fr) auto auto;
    grid-template-rows: minmax(var(--wc-row1), auto);
  }
  .wc-head:not([data-wc-reading]) > .wc-style > .wc-cap,
  .wc-head:not([data-wc-reading]) > .wc-style .wc-val > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .wc-head:not([data-wc-reading]).wc-head > .workspace-flow { flex-wrap: wrap; align-content: center; gap: .25rem; }
  .wc-head:not([data-wc-reading]) .workspace-flow > :is(.workspace-jump, .workspace-next) { flex-shrink: 0; }
  .wc-head:not([data-wc-reading]) .workspace-flow :is(.workspace-jump > summary, .workspace-next) > span { white-space: nowrap; }
}

/* Inside a Lab room the room rail already carries escape, station title and UI style,
   so the in-frame head keeps only project identity, display and task navigation. */
:root[data-lab-host] .wc-head > :is(.wc-escape, .wc-style) { display: none; }
:root[data-lab-host] .wc-head > .wc-ident { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:root[data-lab-host] .wc-head {
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto;
  grid-template-areas:
    "project meta display"
    "flow    flow flow";
}
@media (max-width: 39.99rem) {
  :root[data-lab-host] .wc-head { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "project display" "flow flow"; }
}
@media (max-height: 31.99rem) and (min-width: 40rem) {
  :root[data-lab-host] .wc-head { grid-template-columns: minmax(0, 16rem) minmax(0, 1fr) auto; grid-template-areas: "project flow display"; }
}

@media (prefers-reduced-motion: reduce) { .wc-menu { animation: none; } }
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) .wc-menu { animation: none; }

/* Engineering recovery: personal text enlargement must not share the fixed
   station rows used at ordinary text size. Keep the same controls and tokens;
   let their natural heights participate in document scrolling. */
.wc-head[data-wc-reading] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding-block: .5rem;
}
.wc-head[data-wc-reading]::before { display: none; }
.wc-head[data-wc-reading] > :is(.wc-ident, .wc-meta) { max-inline-size: 100%; }
.wc-head[data-wc-reading] .wc-name h1 { white-space: normal; overflow-wrap: anywhere; }
.wc-head[data-wc-reading] > .wc-project { flex: 1 1 14rem; inline-size: auto; max-inline-size: 100%; min-inline-size: 0; }
.wc-head[data-wc-reading] > .wc-display { flex: 1 1 8rem; max-inline-size: 100%; }
.wc-head[data-wc-reading] .wc-menu-btn { inline-size: 100%; }
.wc-head[data-wc-reading] > .wc-style { flex: 0 1 auto; max-inline-size: 100%; }
.wc-head[data-wc-reading] .wc-row {
  grid-template-columns: 1.25rem minmax(0, 1fr);
  row-gap: .25rem;
  padding-block: .25rem;
}
.wc-head[data-wc-reading] .wc-row > :nth-child(3) {
  grid-column: 2;
  justify-self: start;
  max-inline-size: 100%;
}
.wc-head[data-wc-reading].wc-head > .workspace-flow {
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: stretch;
  block-size: auto;
  min-block-size: 0;
  padding-block: .25rem;
  border-top: 1px solid var(--wc-rule);
}
.wc-menu[popover] { margin: 0; }
.wc-menu[popover]::backdrop { background: transparent; }

@media (forced-colors: active) {
  .wc-head, .wc-project, .wc-menu-btn, .wc-menu { border-color: CanvasText; }
  .wc-head::before, .wc-style::before { border-color: CanvasText; }
}
