/* The column bar of direct archive fragments: the 44px link is its whole slot. */
:root .writing-room-nav.phasic-suite-header {
  --phasic-suite-height: 44px;
  min-height: 44px;
  padding: 0;
  margin-block-end: 8px;
}

html.rd-sphere-live .writing-room-nav {
  position: fixed;
  z-index: 4;
  top: max(68px, calc(env(safe-area-inset-top, 0px) + 60px));
  left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left, 0px));
  width: min(26rem, calc(100vw - 96px));
  background: #2c2c2c;
}

html[data-phasic-writing] body,
html[data-phasic-writing] #writing-sphere-mount[data-mount="sphere"]:not([hidden]) {
  background: transparent;
}

html[data-phasic-writing] .site-nav { display: none; }
/* The head script sets the guided state before the module unhides the name, so the name shows from the
   first paint too. */
html[data-phasic-writing] .writing-room-nav [data-writing-room-title][hidden] { display: inline; }
html[data-phasic-writing] .writing-page { padding: max(12px, env(safe-area-inset-top)) 32px 96px; }
/* On the guided entry the bar leaves the reading column and spans the page, so the mark sits in the suite
   slot as in every room. Direct archive fragments keep the column bar above. The bar spans the page only when
   the list is the page: neither the head gate's rd-sphere-boot (the sphere is expected) nor rd-sphere-live. */
html[data-phasic-writing]:not(.rd-sphere-boot):not(.rd-sphere-live) .writing-room-nav.phasic-suite-header {
  --phasic-suite-height: inherit;
  box-sizing: border-box;
  inline-size: auto;
  max-inline-size: none;
  min-height: var(--phasic-suite-height);
  margin-inline: calc(50% - 50vw);
  margin-block: calc(-1 * max(12px, env(safe-area-inset-top))) 8px;
  padding: max(5px, env(safe-area-inset-top)) max(var(--suite-gutter), env(safe-area-inset-right))
           5px max(var(--suite-gutter), env(safe-area-inset-left));
}
/* With the sphere live the bar stays a compact graphite band, anchored at the page's top left so the mark
   keeps the same place. The band takes that box as soon as the head gate expects the sphere (rd-sphere-boot,
   set before the first paint), so nothing in it moves when the sphere's first frame arrives. */
html[data-phasic-writing].rd-sphere-boot .writing-room-nav.phasic-suite-header,
html[data-phasic-writing].rd-sphere-live .writing-room-nav.phasic-suite-header {
  --phasic-suite-height: inherit;
  position: fixed;
  top: 0;
  left: 0;
  inline-size: min(calc(30rem + var(--suite-gutter)), 100vw);
  min-height: var(--phasic-suite-height);
  margin: 0;
  padding: max(5px, env(safe-area-inset-top)) 16px 5px max(var(--suite-gutter), env(safe-area-inset-left));
  background: rgb(44 44 44 / .9);
}
/* Until that frame the boot field covers the page, and the band waits unseen beneath it. If the gate gives up
   (the 8 s watchdog, a script error, a loader bail) the bar is first shown full width with the list, so it is
   never seen, or counted, moving from one box to the other. */
html[data-phasic-writing].rd-sphere-boot:not(.rd-sphere-live) .writing-room-nav.phasic-suite-header {
  visibility: hidden;
}

@media (horizontal-viewport-segments: 2) {
  html[data-phasic-writing].rd-sphere-live .writing-room-nav.phasic-suite-header {
    width: min(30rem, calc(env(viewport-segment-width 0 0, 50vw) - 48px));
  }
}

@media (max-width: 700px) {
  html.rd-sphere-live .writing-room-nav { top: max(60px, calc(env(safe-area-inset-top, 0px) + 52px)); }
}

@media (horizontal-viewport-segments: 2) {
  :root .writing-room-nav.phasic-suite-header {
    width: min(26rem, calc(env(viewport-segment-width 0 0, 50vw) - 48px));
    margin-inline-start: calc(24px - max(32px, (100vw - 760px) / 2 + 32px));
  }
  html.rd-sphere-live .writing-room-nav.phasic-suite-header {
    left: 24px;
    margin-inline-start: 0;
  }
}

/* Keep the guided controls in the first pane, including on the list fallback. The fold keeps its own
   compact band, with or without the sphere, and shows it over the boot field as it always has: the last
   selector of each list below outranks the two boot rules above. */
@media (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  html[data-phasic-writing] .writing-page { padding-block-start: calc(max(12px, env(safe-area-inset-top)) + 104px); }
  html[data-phasic-writing] .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing]:not(.rd-sphere-boot):not(.rd-sphere-live) .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing].rd-sphere-live .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing].rd-sphere-boot:not(.rd-sphere-live) .writing-room-nav.phasic-suite-header {
    --phasic-suite-height: 44px;
    position: fixed;
    z-index: 4;
    top: max(12px, env(safe-area-inset-top));
    left: max(24px, env(safe-area-inset-left));
    max-width: min(480px, calc(env(viewport-segment-width 0 0, 50vw) - 48px));
    min-height: 44px;
    margin: 0 0 8px;
    padding: 0;
    background: rgb(44 44 44 / .9);
    visibility: visible;
  }
  /* A fold's band before the sphere keeps the list state's width, as before. */
  html[data-phasic-writing].rd-sphere-boot:not(.rd-sphere-live) .writing-room-nav.phasic-suite-header { inline-size: auto; }
}

/* On a two-pane fold the guided band takes every room's place in the first pane: a full-height suite bar
   across that pane, with the mark at the fold's 16px gutter. Archive fragments keep their column bar. */
@media (horizontal-viewport-segments: 2) {
  html[data-phasic-writing] .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing]:not(.rd-sphere-boot):not(.rd-sphere-live) .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing].rd-sphere-live .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing].rd-sphere-boot:not(.rd-sphere-live) .writing-room-nav.phasic-suite-header {
    --phasic-suite-height: inherit;
    --suite-gutter: 16px;
    top: 0;
    left: env(viewport-segment-left 0 0, 0px);
    inline-size: env(viewport-segment-width 0 0, 50vw);
    width: env(viewport-segment-width 0 0, 50vw);
    max-width: none;
    min-height: var(--phasic-suite-height);
    margin: 0;
    padding: max(5px, env(safe-area-inset-top)) max(var(--suite-gutter), env(safe-area-inset-right))
             5px max(var(--suite-gutter), env(safe-area-inset-left));
  }
}

html[data-iframed] .writing-room-nav,
html:not([data-iframed])[data-phasic-guidance="hidden"] [data-writing-guide] { display: none; }

@media (forced-colors: active) {
  html.rd-sphere-live .writing-room-nav,
  html[data-phasic-writing] .writing-room-nav.phasic-suite-header,
  html[data-phasic-writing].rd-sphere-live .writing-room-nav { background: Canvas; }
}

@media print {
  :root .writing-room-nav.phasic-suite-header,
  [data-phasic-writing] [data-phasic-ink-canvas] { display: none; }
}
