:root {
  --workspace-gap: 16px;
  --pour-overlay-inset: clamp(8px, 1.5vw, 16px);
  --pour-overlay-width: clamp(170px, 24vw, 224px);
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 12px 16px;
  background: var(--theme-surface);
  border: 1px solid var(--theme-line);
  color: var(--theme-text);
}

.workspace-header h1 {
  margin: 0;
  color: var(--theme-text);
  font: 400 clamp(18px, 3vw, 30px)/1.12 var(--font-studio-pixel);
  letter-spacing: -0.08em;
}

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 4px;
}

.workspace-header::after {
  display: none;
}

.workspace-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding-inline: 12px;
  border: 1px solid var(--theme-control);
  color: var(--theme-accent);
  font: 500 12px/1 var(--font-studio-mono);
  text-decoration: none;
}

.workspace-link:hover,
.workspace-link:focus-visible {
  background: var(--studio-blue);
  color: #fff;
}

.workspace-link:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 3px;
}

body.public #pub {
  display: contents;
}

#studioHeader,
body:not(.public) #pHint {
  display: none;
}

body.public.clean #app,
body:not(.public):not(.clean) #app {
  gap: var(--workspace-gap);
  height: 100dvh;
  padding: max(var(--workspace-gap), env(safe-area-inset-top, 0px))
    max(var(--workspace-gap), env(safe-area-inset-right, 0px))
    max(var(--workspace-gap), env(safe-area-inset-bottom, 0px))
    max(var(--workspace-gap), env(safe-area-inset-left, 0px));
}

body.public.clean #app {
  grid-template:
    "header" auto
    "canvas" minmax(0, 1fr)
    "dock" auto / minmax(0, 1fr);
}

body:not(.public):not(.clean) #app {
  grid-template:
    "header header" auto
    "rail canvas" minmax(0, 1fr)
    "dock dock" auto / 320px minmax(0, 1fr);
}

#pTop.workspace-header {
  grid-area: header;
  position: static;
  min-height: 0;
  padding: 10px 16px;
  pointer-events: auto;
  background: var(--theme-surface);
  color: var(--theme-text);
}

#pTop .pTopBtns {
  align-items: center;
  gap: 6px;
}

.pWord {
  flex-shrink: 1;
  min-width: 0;
}

#pub #pTop button {
  border-color: var(--theme-line);
  background: var(--theme-surface);
  color: var(--theme-text);
}

#pub #pTop button:hover {
  background: var(--theme-inset);
  color: var(--theme-accent);
}

#pub #pTop button:focus-visible {
  outline-color: var(--theme-accent);
}

#pub #pTop #pGear {
  border-color: var(--studio-blue);
  background: var(--studio-blue);
  color: #fff;
}

#pWorkspace,
body:not(.public):not(.clean) #panel {
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--theme-surface);
  border: 1px solid var(--theme-line);
}

body:not(.public):not(.clean) #panel {
  grid-area: rail;
}

#pWorkspace {
  grid-area: canvas;
  z-index: 10;
  place-self: start;
  width: var(--pour-overlay-width);
  max-height: calc(100% - var(--pour-overlay-inset) * 2);
  margin: var(--pour-overlay-inset);
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
  box-shadow: 0 8px 24px #0b0d1433;
}

body.public.jugLeft #pWorkspace {
  justify-self: end;
}

#pWorkspace h2 {
  margin: 0;
  color: var(--theme-text);
  font: 600 15px/1.35 var(--font-studio-sans);
  text-transform: none;
  letter-spacing: 0;
}

#pMeters {
  display: grid;
  gap: 16px;
  min-width: 0;
}

#pMeters[hidden] {
  display: none;
}

#pWorkspace :is(#pGauge, #pFlowG) {
  position: static;
  width: 100%;
  height: auto;
  min-height: 44px;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  font: 500 12px/1.2 var(--font-studio-mono);
  color: var(--theme-text);
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#pWorkspace :is(#pGauge, #pFlowG):focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 3px;
  border-radius: 0;
}

#pWorkspace .gV {
  color: var(--theme-copy);
  font-variant-numeric: tabular-nums;
}

#pWorkspace :is(.meterTitle, .meterLimits) {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#pWorkspace .meterLimits {
  color: var(--theme-copy);
  font-size: 10px;
}

#pWorkspace :is(#pGauge, #pFlowG) .track {
  width: 100%;
  height: 10px;
  flex: none;
  background: var(--theme-inset);
}

#pWorkspace :is(#pGauge, #pFlowG) .track > * {
  right: auto;
  height: 100%;
}

#pWorkspace #pGauge .zHi {
  inset: 0 0 0 auto;
}

#pWorkspace #pGauge .zLo,
#pWorkspace #pFlowG .live {
  inset: 0 auto 0 0;
}

#pWorkspace #pFlowG .live {
  width: 0;
}

#pWorkspace :is(#pGauge .knob, #pFlowG .handle) {
  top: 50%;
  bottom: auto;
  height: 18px;
  width: 18px;
  margin: 0;
  transform: translate(-50%, -50%);
}

#pWorkspace #pGauge .knob {
  left: 0;
  width: 22px;
  height: 22px;
}

#pWorkspace #pGauge .heightLive {
  position: absolute;
  top: -3px;
  width: 2px;
  height: calc(100% + 6px);
  background: var(--p-high-text);
  transform: translateX(-50%);
  pointer-events: none;
}

#pWorkspace #pCtl {
  position: static;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--theme-line);
}

.pourControl {
  min-width: 0;
  display: grid;
  gap: 4px;
  color: var(--theme-copy);
  font: 500 10px/1.15 var(--font-studio-mono);
}

#pub #pWorkspace :is(#pAimDial, #pSpread, #pHigh) {
  width: 100%;
  height: 62px;
  min-width: 0;
}

#pub #pWorkspace #pHigh {
  grid-column: 1 / -1;
  min-height: 44px;
  height: auto;
  padding-block: 8px;
  background: light-dark(#fff1e9, #38221f);
  border-color: var(--p-high-text);
}

#pub #pWorkspace #pHigh.on {
  background: var(--studio-orange);
  color: var(--studio-ink);
}

body.public.clean #stage,
body.public.jugLeft.clean #stage,
body:not(.public):not(.clean) #stage {
  grid-area: canvas;
  isolation: isolate;
  padding: clamp(16px, 3vh, 32px);
  border: 1px solid var(--theme-line);
  background-color: var(--theme-inset);
  background-image: radial-gradient(
    var(--theme-control) 0.7px,
    transparent 0.7px
  );
  background-size: 24px 24px;
}

body.public.clean #stage,
body.public.jugLeft.clean #stage {
  padding-top: clamp(48px, 7.5vh, 66px);
  padding-inline: calc(
    var(--pour-overlay-width) + var(--pour-overlay-inset) + 12px
  );
}

body.public #pHint {
  position: absolute;
  top: 10px;
  max-width: calc(100% - 24px);
  width: max-content;
}

#pub #pBar {
  position: static;
  grid-area: dock;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  width: min(650px, 100%);
  margin-inline: auto;
  border-color: var(--theme-line);
  background: var(--theme-line);
}

#pub #pBar .pAct {
  width: 100%;
  min-width: 0;
  height: 48px;
  justify-content: center;
  gap: 7px;
  padding: 0 4px;
  background: var(--theme-surface);
  color: var(--theme-text);
  font: 500 12px/1.15 var(--font-studio-mono);
}

#pub #pBar .pAct.primary {
  background: var(--studio-blue);
  color: #fff;
}

#pub #pBar .pAct:not(:disabled):hover {
  background: var(--theme-inset);
  color: var(--theme-accent);
}

body.pouring #pBar,
body.jugLeft.pouring #pBar {
  transform: none;
}

body:not(.public):not(.clean) #studioHeader {
  grid-area: header;
  display: flex;
}

#studioHeader .studioHeaderActions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#studioHeader #cleanBtn {
  min-height: 44px;
  white-space: nowrap;
  border-radius: 0;
  border-color: var(--theme-control);
  background: var(--theme-surface);
  color: var(--theme-text);
  font: 500 12px/1.15 var(--font-studio-mono);
}

body:not(.public):not(.clean) #stage {
  padding-inline-end: 84px;
}

body:not(.public):not(.clean) #hud {
  bottom: 62px;
}

#highBtn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 64px;
  min-height: 44px;
  padding: 4px;
  border-radius: 0;
  border-color: var(--p-high-text);
  background: light-dark(#fff1e9, #38221f);
  color: var(--p-high-text);
  font: 600 13px/1.15 var(--font-studio-mono);
  touch-action: none;
}

#highBtn small {
  display: block;
}

#highBtn.on {
  background: var(--studio-orange);
  color: var(--studio-ink);
}

#highBtn:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 2px;
}

body:is(.public, .clean) #highBtn {
  display: none;
}

body:not(.public):not(.clean) #transport {
  grid-area: dock;
  min-width: 0;
  border: 1px solid var(--theme-line);
}

#pub #pSheet:not([hidden]) {
  inset: 12px;
  width: auto;
  height: fit-content;
  max-height: calc(100% - 24px);
  margin: auto;
  padding: 20px;
}

#pub .aSheet:not([hidden]) {
  width: min(620px, calc(100% - 24px));
  inset: 12px;
  height: fit-content;
  max-height: calc(100% - 24px);
  margin: auto;
}

#pub #aLib {
  width: min(820px, calc(100% - 24px));
}

#pub #aLib .aGrid {
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
}

#pub #aLib .aOpen {
  width: 100%;
  border: 1px solid var(--theme-line);
  background: var(--theme-inset);
  border-radius: 0;
  padding: 8px;
}

#pub #aLib .aOpen img {
  max-width: 100%;
}

@media (min-width: 820px) {
  #pub #pSheet:not([hidden]) {
    display: grid;
    width: min(880px, calc(100% - 24px));
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    align-items: start;
    gap: 14px;
  }

  #pSheet .pHead {
    grid-column: 1 / -1;
  }

  #pSheet .pGroup {
    padding: 12px;
    border: 1px solid var(--theme-line);
    background: var(--theme-surface);
  }

  #pub #aVid:not([hidden]) {
    inset: 12px 12px 12px auto;
    width: 386px;
    height: auto;
    margin: 0;
  }

  #pub #pCal:not([hidden]) {
    top: 12px;
    right: 12px;
    bottom: 12px;
    left: auto;
    width: min(400px, calc(100% - 24px));
    max-height: none;
    transform: none;
    align-content: start;
  }

  body.public #help .card {
    width: min(760px, calc(100% - 48px));
    max-width: 760px;
    display: grid;
    grid-template-columns: 136px minmax(0, 1fr);
    align-items: start;
    gap: 14px;
  }

  #help .pHead {
    grid-column: 1 / -1;
  }

  #help .hTabs {
    grid-row: 2 / span 5;
    flex-direction: column;
  }

  #help .hTabs button {
    text-align: left;
  }

  #help :is(.hPane, h3, .hSteps, .hFoot) {
    grid-column: 2;
    margin: 0;
  }
}

@media (max-width: 899px) {
  #pub #pTop :is(#pGetApp, #pSupport) {
    display: none;
  }
}

@media (orientation: portrait) {
  body.public.clean #stage,
  body.public.jugLeft.clean #stage {
    padding-top: 44px;
    padding-inline: 12px;
    padding-bottom: calc(
      var(--pour-overlay-height, 150px) + var(--pour-overlay-inset) + 8px
    );
  }

  body.public #pHint {
    top: 8px;
    padding: 6px 10px;
    font-size: 12px;
  }

  #pWorkspace,
  body.public.jugLeft #pWorkspace {
    place-self: end center;
    width: min(480px, calc(100% - var(--pour-overlay-inset) * 2));
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px 12px;
    padding: 8px 10px;
  }

  #pWorkspace h2 {
    grid-column: 1 / -1;
    font-size: 13px;
  }

  #pMeters {
    gap: 5px;
  }

  #pWorkspace :is(#pGauge, #pFlowG) {
    gap: 5px;
    font-size: 11px;
  }

  #pWorkspace #pCtl {
    padding: 0 0 0 8px;
    border: 0;
    border-inline-start: 1px solid var(--theme-line);
  }

  #pWorkspace #pMeters[hidden] + #pCtl {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0;
    border: 0;
  }

  #pub #pWorkspace :is(#pAimDial, #pSpread) {
    height: 44px;
  }

  #pub #pWorkspace #pHigh {
    min-height: 44px;
    padding-block: 4px;
  }

  #pub #pWorkspace #pMeters[hidden] + #pCtl #pHigh {
    grid-column: auto;
  }

  body.public.jugLeft #pMeters {
    grid-column: 2;
    grid-row: 2;
  }

  body.public.jugLeft #pWorkspace #pCtl {
    grid-column: 1;
    grid-row: 2;
    padding: 0 8px 0 0;
    border: 0;
    border-inline-end: 1px solid var(--theme-line);
  }

  body.public.jugLeft #pWorkspace #pMeters[hidden] + #pCtl {
    grid-column: 1 / -1;
    padding: 0;
    border: 0;
  }
}

@media (orientation: portrait), (max-width: 639px) {
  :root {
    --workspace-gap: 8px;
  }

  #pub #pBar .pAct {
    height: 52px;
    flex-direction: column;
    gap: 2px;
    font-size: 10px;
  }

  #pub #pBar .pAct svg {
    width: 17px;
    height: 17px;
  }

  #pTop.workspace-header,
  #studioHeader.workspace-header {
    gap: 6px;
    padding: 6px 8px;
  }

  #pTop .pTopBtns {
    gap: 4px;
  }

  #pub #pTop .pRound {
    flex-shrink: 0;
  }

  #pub #pBar {
    gap: 3px;
    border: 0;
    background: none;
  }

  #pub #pBar .pAct {
    border: 1px solid var(--theme-line);
  }

  #pub #pBar .pAct.primary {
    border-color: var(--studio-blue);
  }

  #pTop .workspace-link,
  #studioHeader .workspace-link {
    padding-inline: 7px;
    font-size: 11px;
  }

  .workspace-header h1 {
    font-size: clamp(16px, 4.6vw, 24px);
  }
}

@media (orientation: portrait),
  (max-width: 639px),
  (max-height: 500px) and (pointer: coarse) {
  body:not(.public):not(.clean) #app {
    grid-template:
      "header" auto
      "canvas" clamp(220px, 48dvh, 560px)
      "dock" auto
      "rail" auto / minmax(0, 1fr);
    align-content: start;
    overflow-y: auto;
  }

  body:not(.public):not(.clean) #stage {
    padding: 12px 84px 12px 12px;
  }

  body:not(.public):not(.clean) #panel {
    max-height: none;
    overflow: visible;
  }

  #studioHeader.workspace-header {
    padding: 6px 8px;
  }

  #studioHeader h1 {
    font-size: clamp(14px, 3.8vw, 24px);
  }

  #studioHeader #status {
    font-size: 9px;
  }

  #studioHeader .studioHeaderActions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
  }

  #studioHeader #cleanBtn {
    padding-inline: 6px;
  }

  #transport {
    padding: 6px 8px 8px;
  }

  #transport .sep {
    display: none;
  }

  #transport #tl {
    height: 56px;
  }

  #stage #banner {
    top: 2px;
    padding: 3px 6px;
    font-size: 10px;
  }

  :is(#panel, #transport, #cleanBar)
    :is(
      button,
      select,
      .btn,
      input:not([type]),
      input[type="number"],
      input[type="color"]
    ) {
    min-height: 44px;
    max-width: 100%;
  }

  :is(#panel, #transport, #cleanBar) button {
    min-width: 44px;
  }

  #panel .row {
    flex-wrap: wrap;
  }

  #panel :is(.row > input[type="range"], .swatches label) {
    min-width: 64px;
  }

  #panel .row > select {
    min-width: 0;
  }
}

@media (max-width: 370px) {
  #pTop.workspace-header {
    gap: 4px;
  }

  #pTop .pTopBtns {
    gap: 3px;
  }

  .workspace-header .pWord {
    gap: 4px;
    font-size: 14px;
  }

  .pWord .pBrandMark {
    width: 22px;
  }

  #studioHeader #cleanBtn,
  #studioHeader .workspace-link,
  #pTop .workspace-link {
    font-size: 10px;
    padding-inline: 5px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --workspace-gap: 8px;
  }

  #pWorkspace {
    gap: 6px;
    padding: 8px;
  }

  #pWorkspace h2 {
    font-size: 13px;
  }

  #pMeters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #pMeters,
  #pWorkspace :is(#pGauge, #pFlowG) {
    gap: 5px;
  }

  #pWorkspace #pCtl {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
    padding-top: 6px;
  }

  #pWorkspace .pourControl {
    font-size: 9px;
  }

  #pub #pWorkspace :is(#pAimDial, #pSpread, #pHigh) {
    grid-column: auto;
    min-height: 44px;
    height: 44px;
  }

  body.public.clean #stage,
  body.public.jugLeft.clean #stage {
    padding-block: 8px;
  }

  body.public:not(.uiHidden) #pHint {
    left: auto;
    right: var(--pour-overlay-inset);
    max-width: var(--pour-overlay-width);
    transform: none;
  }

  body.public.jugLeft:not(.uiHidden) #pHint {
    left: var(--pour-overlay-inset);
    right: auto;
  }
}

@media (orientation: landscape) and (max-width: 519px) {
  body.public.clean #stage,
  body.public.jugLeft.clean #stage {
    padding: 52px 12px 8px
      calc(var(--pour-overlay-width) + var(--pour-overlay-inset) + 12px);
  }

  body.public.jugLeft.clean #stage {
    padding-inline: 12px
      calc(var(--pour-overlay-width) + var(--pour-overlay-inset) + 12px);
  }

  body.public #pHint {
    max-width: calc(100% - var(--pour-overlay-width) - 24px);
    padding: 6px 10px;
    font-size: 12px;
  }
}

@media (max-width: 639px), (max-height: 500px) and (pointer: coarse) {
  :root {
    --sheet-top: max(8px, env(safe-area-inset-top, 0px));
    --sheet-right: max(8px, env(safe-area-inset-right, 0px));
    --sheet-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    --sheet-left: max(8px, env(safe-area-inset-left, 0px));
  }

  #cleanBar {
    right: var(--sheet-right);
    left: var(--sheet-left);
    width: auto;
    max-width: none;
    transform: none;
  }

  #cleanBar.away {
    transform: translateY(12px);
  }

  #pub :is(#pSheet, #aLib, #aVid, #aPro, #pCal):not([hidden]) {
    inset: var(--sheet-top) var(--sheet-right) var(--sheet-bottom)
      var(--sheet-left);
    width: min(620px, calc(100% - var(--sheet-left) - var(--sheet-right)));
    height: fit-content;
    max-height: calc(100dvh - var(--sheet-top) - var(--sheet-bottom));
    margin: auto;
    padding: 12px;
    scroll-padding-top: 68px;
  }

  #pub #pSheet:not([hidden]) {
    display: flex;
  }

  #pub #pCal:not([hidden]) {
    max-width: 400px;
    transform: none;
  }

  body.public #help {
    padding: var(--sheet-top) var(--sheet-right) var(--sheet-bottom)
      var(--sheet-left);
  }

  body.public #help .card {
    max-height: 100%;
  }

  #pub :is(#pSheet, .aSheet, #help .card) > * {
    flex-shrink: 0;
  }

  #pub :is(#pSheet, .aSheet, #help .card) .pHead {
    position: sticky;
    top: 0;
    z-index: 2;
    padding-block: 4px 8px;
    background: var(--p-surface);
  }

  #pub .pRow:has(.pSeg, .pSw, .aCups, #aDrinks, .aText) {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  #pub :is(.pSw, .aCups, #aDrinks) {
    flex-wrap: wrap;
  }

  #pub
    :is(
      .pSeg button,
      .pSw button,
      .pPill,
      .aLink,
      .aDel,
      select,
      .aText,
      .pRange
    ) {
    min-height: 44px;
  }

  #pub :is(.pSeg button, .pSw button, .aDel) {
    min-width: 44px;
  }

  #pub .pSeg button {
    flex: 1;
  }

  #pub .aText {
    width: 100%;
    font-size: 16px;
  }

  body.public #toast {
    max-width: min(440px, calc(100% - var(--sheet-left) - var(--sheet-right)));
  }
}

body.public.clean.uiHidden #app {
  grid-template: "canvas" minmax(0, 1fr) / minmax(0, 1fr);
  padding: 0;
}

body.public.uiHidden :is(#pWorkspace, #pTop, #pBar),
body.public.uiHidden #pub #pBar {
  display: none;
}

body.public.clean.uiHidden #stage {
  padding: max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  border: 0;
  background: var(--theme-canvas);
}
