/*
  The sidebar, from the `--ds-*` tokens in design.css: down the left on a desktop, the top bar and
  the bottom tab bar on a phone. The same element in `hub-layout`, `site-layout` and `space-layout`.

  Every rule is keyed on the layout around it rather than on the element, because the layout is
  where the states live (`[rail]`, `[signed-in]`, `[hub-ready]`, set by `logic.ts`): the page beside
  the sidebar moves with them, and `HubLayout/style.css` reads the same ones for that.
*/

hub-sidebar {
  display: contents;
}

hub-sidebar[hidden] {
  display: none;
}

/* The system face, in a space too, where the page around it keeps its own. */
hub-sidebar,
hub-sidebar *:not(svg path) {
  font-family: var(--ds-font);
}

:is(hub-layout, site-layout, space-layout) [hub-bar] {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;
  height: calc(var(--ds-header, 52px) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--ds-line);
  background: var(--ds-glass);
  color: var(--ds-ink);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

:is(hub-layout, site-layout, space-layout) [hub-brand] {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
}

:is(hub-layout, site-layout, space-layout) [hub-mark],
:is(hub-layout, site-layout, space-layout) [hub-mark] svg {
  display: block;
  width: 26px;
  height: 26px;
}

:is(hub-layout, site-layout, space-layout) [hub-word] {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

:is(hub-layout, site-layout, space-layout) [hub-tabs] {
  display: flex;
  gap: 2px;
  margin-left: 12px;
  font-size: 13.5px;
  font-weight: 500;
}

:is(hub-layout, site-layout, space-layout) [hub-tab] {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--ds-r-tab, 8px);
  color: var(--ds-mute);
  text-decoration: none;
  transition:
    color var(--ds-fast, 120ms) ease,
    background-color var(--ds-fast, 120ms) ease;
}

:is(hub-layout, site-layout, space-layout) [hub-tab]:hover {
  color: var(--ds-ink);
}

/* Icons are for the phone's bottom bar only. */

:is(hub-layout, site-layout, space-layout) [hub-tab] > .ds-i {
  display: none;
}

/*
  The current tab. The attribute is set by the logic; the `:has()` rules draw it from the first
  paint, before any script has run, and after a navigation that kept this layout.
*/

:is(hub-layout, site-layout, space-layout) [hub-tab][aria-current='page'],
html > body > :is(hub-layout, site-layout):has(> :is(atomics-space-collection-view, atomics-space-creation-view)) [hub-tab='spaces'],
html > body > :is(hub-layout, site-layout):has(> atomics-starters-view) [hub-tab='starters'],
html > body > :is(hub-layout, site-layout):has(> :is(atomics-studio-view, atomics-studio-app-view)) [hub-tab='studio'],
html > body > :is(hub-layout, site-layout):has(
    > :is(
      atomics-marketplace-view,
      atomics-marketplace-apps-view,
      atomics-marketplace-kits-view,
      atomics-marketplace-clipart-view,
      atomics-marketplace-catalog-view
    )
  )
  [hub-tab='marketplace'] {
  background: var(--ds-fill);
  color: var(--ds-ink);
}

:is(hub-layout, site-layout, space-layout) [hub-gap] {
  flex: 1 1 auto;
}

:is(hub-layout, site-layout, space-layout) [hub-search] {
  display: flex;
  align-items: center;
  min-width: 0;
}

:is(hub-layout, site-layout, space-layout) [hub-search]:empty {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-theme] .ds-i {
  width: 17px;
  height: 17px;
}

:is(hub-layout, site-layout, space-layout) [hub-signin] > .ds-i {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-signin][hidden],
:is(hub-layout, site-layout, space-layout) [hub-bar] [hidden] {
  display: none;
}

/* The avatar is the menu's button: a bare circle, the photo or the initials in it. */

:is(hub-layout, site-layout, space-layout) [hub-avatar] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ds-ink);
  cursor: pointer;
}

:is(hub-layout, site-layout, space-layout) [hub-avatar]:hover > [hub-more] {
  opacity: 0.7;
}

:is(hub-layout, site-layout, space-layout) [hub-avatar] > [hub-more] {
  width: 18px;
  height: 18px;
}

/*
 * The unread bubble, on the avatar's top right. Its own ring in the page's colour keeps it legible
 * over a photo, and the count is the bubble's text so a glance gives the number, not only "some".
 */

:is(hub-layout, site-layout, space-layout) [hub-avatar] {
  position: relative;
}

:is(hub-layout, site-layout, space-layout) [hub-bubble] {
  position: absolute;
  top: -4px;
  right: -6px;
  box-sizing: border-box;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  /* The light scheme's red in both: dark's own (#ff7a70) under white figures is about 2.5:1. */
  background: #d1342a;
  color: #fff;
  box-shadow: 0 0 0 2px var(--ds-bg);
  font: 600 11px/18px var(--ds-font);
  font-variant-numeric: tabular-nums;
  text-align: center;
  pointer-events: none;
}

:is(hub-layout, site-layout, space-layout) [hub-bubble][hidden] {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-avatar][aria-expanded='true'] > .ds-avatar {
  box-shadow: 0 0 0 2px var(--ds-accent);
}

:is(hub-layout, site-layout, space-layout) [hub-face] > [hub-initials][hidden],
:is(hub-layout, site-layout, space-layout) [hub-face] > [hub-photo][hidden] {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-face] > [hub-photo] {
  position: absolute;
  inset: 0;
}

/* The menu. Its rows are `atomics-menu`'s; what is here is only this menu's own. */

:is(hub-layout, site-layout, space-layout) [hub-menu] {
  width: 260px;
}

:is(hub-layout, site-layout, space-layout) [hub-menu] [hidden] {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-who] {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 6px;
  min-width: 0;
}

:is(hub-layout, site-layout, space-layout) [hub-who-line] {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

:is(hub-layout, site-layout, space-layout) [hub-who-line] > b {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
  The plan pill. Free is an outline, sitting back; Pro takes the accent's soft tint, the way a
  selected chip does; Premium takes the note set's purple. Every pair is a token defined for both
  schemes, so the pill follows light and dark with no rule of its own for either.
*/

:is(hub-layout, site-layout, space-layout) [hub-plan] {
  flex: none;
  display: inline-flex;
}

:is(hub-layout, site-layout, space-layout) [hub-plan][hidden] {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-plan-pill] {
  height: 20px;
  padding: 0 8px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: var(--ds-mute);
  background: transparent;
  /* An outline rather than a fill: dark's grey is the popover's own, so a filled Free pill vanished. */
  box-shadow: inset 0 0 0 1px var(--ds-line-strong);
}

:is(hub-layout, site-layout, space-layout) [hub-plan][plan='pro'] [hub-plan-pill] {
  color: var(--ds-accent-ink);
  background: var(--ds-accent-soft);
  box-shadow: none;
}

:is(hub-layout, site-layout, space-layout) [hub-plan][plan='premium'] [hub-plan-pill] {
  color: var(--ds-note-purple-ink);
  background: var(--ds-note-purple);
  box-shadow: none;
}

/* Read by a screen reader, drawn for nobody: the pill above says the same thing to the eye. */

:is(hub-layout, site-layout, space-layout) [hub-plan-said] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:is(hub-layout, site-layout, space-layout) [hub-who] > small {
  color: var(--ds-mute);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:is(hub-layout, site-layout, space-layout) [hub-menu] [role^='menuitem'] > .ds-i {
  width: 15px;
  height: 15px;
}

:is(hub-layout, site-layout, space-layout) [hub-language] {
  display: block;
  padding-bottom: 6px;
}

:is(hub-layout, site-layout, space-layout) [hub-language] [menu-label] {
  display: block;
}

:is(hub-layout, site-layout, space-layout) [hub-locales] {
  display: block;
  box-sizing: border-box;
  width: calc(100% - 12px);
  margin: 0 6px;
  padding: 7px 30px 7px 10px;
  border: 1px solid var(--ds-line, rgba(0, 0, 0, 0.09));
  border-radius: 8px;
  background: var(--ds-panel, transparent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 14px;
  color: inherit;
  font: inherit;
  font-size: 14px;
  appearance: none;
  cursor: pointer;
}

:is(hub-layout, site-layout, space-layout) [hub-locales]:focus-visible {
  outline: 2px solid var(--ds-accent, #0a84ff);
  outline-offset: 1px;
}

:is(hub-layout, site-layout, space-layout) [hub-menu-foot] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 2px;
  color: var(--ds-mute);
  font-size: 11.5px;
}

/* Wider than a phone the top bar badge carries the streak, so the account menu does not. */

@media (min-width: 721px) {
  :is(hub-layout, site-layout, space-layout) [hub-menu] atomics-streak-row {
    display: none;
  }
}

/*
  Phone: the tabs leave the header for a bar along the bottom, with icons, the way an app's tab bar
  sits. The wordmark goes; the page keeps clear of the bar, and so do toasts.
*/

@media (max-width: 720px) {
  /*
    A backdrop filter makes its element the containing block of every fixed descendant, so the
    tab bar would be pinned to the bottom of the header instead of the screen. The glass moves to
    a layer behind the header's contents.
  */

  :is(hub-layout, site-layout, space-layout) [hub-bar] {
    gap: 10px;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-bar]::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--ds-glass);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
  }

  :is(hub-layout, site-layout, space-layout) [hub-word] {
    display: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tabs] {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 45;
    gap: 0;
    box-sizing: border-box;
    height: calc(56px + env(safe-area-inset-bottom));
    margin: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    border-top: 1px solid var(--ds-line);
    background: var(--ds-glass);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    font-size: 11px;
    font-weight: 600;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab] {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 0;
    border-radius: 0;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab] > .ds-i {
    display: block;
    width: 22px;
    height: 22px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab][aria-current='page'],
  html > body > :is(hub-layout, site-layout):has(> :is(atomics-space-collection-view, atomics-space-creation-view)) [hub-tab='spaces'],
  html > body > :is(hub-layout, site-layout):has(> atomics-starters-view) [hub-tab='starters'],
  html > body > :is(hub-layout, site-layout):has(> :is(atomics-studio-view, atomics-studio-app-view)) [hub-tab='studio'],
  html > body > :is(hub-layout, site-layout):has(
    > :is(
      atomics-marketplace-view,
      atomics-marketplace-apps-view,
      atomics-marketplace-kits-view,
      atomics-marketplace-clipart-view,
      atomics-marketplace-catalog-view
    )
  )
  [hub-tab='marketplace'] {
    background: transparent;
    color: var(--ds-accent-ink);
  }

  :is(hub-layout, site-layout, space-layout) [hub-search]:not(:empty) {
    flex: 1 1 auto;
  }

  /* No room in the top bar for the streak: the account menu carries it (`atomics-streak-row`). */

  :is(hub-layout, site-layout, space-layout) atomics-streak-badge [badge] {
    display: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-theme],
  :is(hub-layout, site-layout, space-layout) [hub-avatar] {
    width: 40px;
    height: 40px;
  }
}

/* ---------------------------------------------------------------- sidebar */

/*
  What only the sidebar has. On a phone the header is the top bar above, so these are not drawn
  there at all; the wrapper around the brand is no box of its own.
*/

:is(hub-layout, site-layout, space-layout) [hub-top] {
  display: contents;
}

:is(hub-layout, site-layout, space-layout) [hub-bar] :is([hub-collapse], [hub-recent], [hub-guide], [hub-tab='inbox'], [hub-face-text], [hub-subs]) {
  display: none;
}

:is(hub-layout, site-layout, space-layout) [hub-foot] {
  display: contents;
}

/*
  Wider than a phone the header stands down the left edge and the page moves over by its width.
  It is fixed rather than a grid column so that every page under it keeps flowing as the block it
  always was: nothing a page measures, pins or scrolls changes, except that the sticky header it
  used to keep clear of is gone (`--site-header-offset` is 0).

  `[rail]` folds it to icons. The logic sets it from what this device last chose, and starts a
  window narrower than 1100px folded.
*/

@media (min-width: 721px) {
  :is(hub-layout, site-layout, space-layout) [hub-bar] {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: var(--hub-side);
    height: auto;
    padding: max(14px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    border-bottom: 0;
    border-right: 1px solid var(--ds-line);
    background: var(--ds-panel2);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  :is(hub-layout, site-layout, space-layout) [hub-top] {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 12px 6px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-brand] {
    flex: 1 1 auto;
    min-width: 0;
  }

  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-collapse] {
    display: inline-flex;
    flex: none;
    color: var(--ds-mute);
  }

  :is(hub-layout, site-layout, space-layout) [hub-collapse] .ds-i {
    width: 18px;
    height: 18px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-search]:not(:empty) {
    display: block;
    margin: 0 0 12px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-search] > * {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    box-sizing: border-box;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tabs] {
    flex-direction: column;
    gap: 2px;
    margin: 0;
    font-size: 14px;
    font-weight: 550;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab],
  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-tab='inbox']:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 0 10px;
    border-radius: 9px;
    color: var(--ds-ink2);
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab]:hover {
    background: var(--ds-fill);
    color: var(--ds-ink);
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab] > .ds-i {
    display: block;
    width: 18px;
    height: 18px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab] > [hub-label] {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tab][aria-current='page'],
  html > body > :is(hub-layout, site-layout):has(> :is(atomics-space-collection-view, atomics-space-creation-view)) [hub-tab='spaces'],
  html > body > :is(hub-layout, site-layout):has(> atomics-starters-view) [hub-tab='starters'],
  html > body > :is(hub-layout, site-layout):has(> :is(atomics-studio-view, atomics-studio-app-view)) [hub-tab='studio'],
  html > body > :is(hub-layout, site-layout):has(
    > :is(
      atomics-marketplace-view,
      atomics-marketplace-apps-view,
      atomics-marketplace-kits-view,
      atomics-marketplace-clipart-view,
      atomics-marketplace-catalog-view
    )
  )
  [hub-tab='marketplace'] {
    font-weight: 650;
  }

  /* The unread count beside Inbox. The avatar's bubble says it on a phone; here this does. */

  :is(hub-layout, site-layout, space-layout) [hub-count]:not([hidden]) {
    box-sizing: border-box;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #d1342a;
    color: #fff;
    font: 650 11.5px/20px var(--ds-font);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  :is(hub-layout, site-layout, space-layout) [hub-bubble] {
    display: none;
  }

  /* Recent spaces. */

  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-recent]:not([hidden]) {
    display: block;
    margin-top: 20px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-head] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px 6px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-title] {
    margin: 0;
    color: var(--ds-mute);
    font: 600 12px/1.3 var(--ds-font);
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-all] {
    color: var(--ds-mute);
    font-size: 12px;
    text-decoration: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-all]:hover {
    color: var(--ds-ink);
    text-decoration: underline;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-list] {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-list] a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--ds-ink);
    font-size: 13.5px;
    text-decoration: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-list] a:hover {
    background: var(--ds-fill);
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-list] a[aria-current='page'] {
    background: var(--ds-fill);
    font-weight: 600;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tile] {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: var(--space-tile, #6e6e73);
    color: #fff;
    font: 700 11px/1 var(--ds-font);
  }

  :is(hub-layout, site-layout, space-layout) [hub-tile] svg {
    width: 13px;
    height: 13px;
  }

  /* Somebody's own image, cut to its shape (utils/spaceTile). */
  :is(hub-layout, site-layout, space-layout) [hub-tile][tile-kind='image'] {
    overflow: hidden;
    background: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tile][tile-kind='image'] img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tile][tile-shape='circle'] {
    border-radius: 50%;
  }

  :is(hub-layout, site-layout, space-layout) [hub-tile][tile-shape='square'] {
    border-radius: 2px;
  }

  /* An emoji is the icon whole, with no square behind it (utils/spaceTile). */
  :is(hub-layout, site-layout, space-layout) [hub-tile][tile-kind='emoji'] {
    background: none;
    font: 16px/1 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  }

  :is(hub-layout, site-layout, space-layout) [hub-recent-name] {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout) [hub-gap] {
    flex: 1 0 16px;
  }

  /* The space's folded guide, above the foot: its ring, its name and how far along it is. */

  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-guide]:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 10px;
    padding: 6px 10px 6px 6px;
    border: 1px solid var(--ds-line);
    border-radius: 12px;
    background: var(--ds-surface, transparent);
    color: var(--ds-ink);
    font: inherit;
    text-align: start;
    cursor: pointer;
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide]:hover {
    background: var(--ds-fill);
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-ring] {
    display: flex;
    flex: none;
    width: 30px;
    height: 30px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-ring] svg {
    width: 100%;
    height: 100%;
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-track] {
    stroke: var(--ds-line);
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-fill] {
    stroke: var(--ds-accent, #2456d6);
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-ring] text {
    fill: var(--ds-ink);
    font: 700 8.5px/1 var(--ds-font);
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-text] {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-name] {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout) [hub-guide-progress] {
    color: var(--ds-mute);
    font-size: 12px;
    white-space: nowrap;
  }

  /* The foot: the streak and the theme on one line, the account under them. */

  :is(hub-layout, site-layout, space-layout) [hub-foot] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 0 0;
    border-top: 1px solid var(--ds-line);
  }

  :is(hub-layout, site-layout, space-layout) [hub-foot] > atomics-streak-badge {
    margin-left: 4px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-foot] > [hub-theme] {
    margin-left: auto;
  }

  :is(hub-layout, site-layout, space-layout) [hub-foot] > [hub-signin]:not([hidden]) {
    flex: 1 1 100%;
    height: 36px;
    border-radius: 11px;
    font-size: 13px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-foot] > [hub-signin] > .ds-i {
    display: inline-block;
    width: 15px;
    height: 15px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-foot] > [hub-account] {
    flex: 1 1 100%;
    min-width: 0;
  }

  :is(hub-layout, site-layout, space-layout) [hub-avatar] {
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    height: auto;
    min-height: 48px;
    padding: 6px;
    border-radius: 11px;
    text-align: left;
  }

  :is(hub-layout, site-layout, space-layout) [hub-avatar]:hover {
    background: var(--ds-fill);
  }

  /*
    Signed out the account button is only "more", a quiet icon the size of the theme's, and the two
    sit together at the end of the streak's line with Sign in under them.
  */

  :is(hub-layout, site-layout, space-layout):not([signed-in]) [hub-foot] > [hub-account] {
    flex: none;
    order: 1;
    margin-left: auto;
  }

  :is(hub-layout, site-layout, space-layout):not([signed-in]) [hub-foot] > [hub-theme] {
    order: 2;
    margin-left: 0;
  }

  :is(hub-layout, site-layout, space-layout):not([signed-in]) [hub-foot] > [hub-signin] {
    order: 3;
  }

  :is(hub-layout, site-layout, space-layout):not([signed-in]) [hub-avatar] {
    justify-content: center;
    width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 50%;
    color: var(--ds-ink2);
  }

  :is(hub-layout, site-layout, space-layout) [hub-avatar] > .ds-avatar {
    position: relative;
    flex: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-face-text]:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  :is(hub-layout, site-layout, space-layout) [hub-face-name] {
    font-size: 13.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout) [hub-face-plan] {
    color: var(--ds-mute);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout) [hub-face-plan]:empty {
    display: none;
  }

  /* ---------------- the rail ---------------- */

  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] {
    padding-right: 12px;
    padding-left: 12px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-top] {
    flex-direction: column;
    gap: 6px;
    padding: 0 0 12px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-brand] {
    flex: none;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] :is([hub-word], [hub-label], [hub-recent-head], [hub-recent-name], [hub-face-text], [hub-search], [hub-guide-text], atomics-streak-badge) {
    display: none;
  }

  :is(hub-layout, site-layout, space-layout)[rail] :is([hub-tab], [hub-recent-list] a),
  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] [hub-tab='inbox']:not([hidden]) {
    position: relative;
    justify-content: center;
    width: 40px;
    min-height: 40px;
    margin: 0 auto;
    padding: 0;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] [hub-guide]:not([hidden]) {
    justify-content: center;
    align-self: center;
    padding: 4px;
    border-radius: 50%;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-tile] {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 12px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-tile] svg {
    width: 16px;
    height: 16px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-tile][tile-kind='emoji'] {
    font-size: 20px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] [hub-recent]:not([hidden]) {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--ds-line);
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-count]:not([hidden]) {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] > [hub-theme] {
    margin: 0;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] > :is([hub-account], [hub-signin]:not([hidden])) {
    flex: none;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-avatar] {
    justify-content: center;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 50%;
  }

  /* Folded, signed out: the more and theme icons in a column, and Sign in as an icon in a circle. */

  :is(hub-layout, site-layout, space-layout)[rail]:not([signed-in]) [hub-foot] > [hub-account] {
    margin-left: 0;
  }

  :is(hub-layout, site-layout, space-layout)[rail]:not([signed-in]) [hub-avatar] {
    width: 32px;
    min-height: 32px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] > [hub-signin]:not([hidden]) {
    width: 40px;
    height: 40px;
    margin-top: 2px;
    padding: 0;
    border-radius: 50%;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] > [hub-signin] > [hub-signin-label] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-foot] > [hub-signin] > .ds-i {
    width: 17px;
    height: 17px;
  }

  /* The open section's own pages, indented under its tab. */

  :is(hub-layout, site-layout, space-layout) [hub-bar] [hub-subs]:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 2px 0 8px;
    padding-left: 28px;
  }

  :is(hub-layout, site-layout, space-layout) [hub-sub] {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--ds-ink2);
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
  }

  :is(hub-layout, site-layout, space-layout) [hub-sub]:hover {
    background: var(--ds-fill);
    color: var(--ds-ink);
  }

  :is(hub-layout, site-layout, space-layout) [hub-sub][aria-current='page'] {
    background: var(--ds-fill);
    color: var(--ds-ink);
    font-weight: 650;
  }

  :is(hub-layout, site-layout, space-layout) [hub-sub-count]:not([hidden]) {
    box-sizing: border-box;
    min-width: 18px;
    height: 18px;
    margin-left: auto;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--ds-accent);
    color: #fff;
    font: 650 11px/18px var(--ds-font);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  :is(hub-layout, site-layout, space-layout) [hub-sub-note]:not([hidden]) {
    display: block;
    padding: 4px 10px 0;
    color: var(--ds-mute);
    font-size: 12px;
  }

  :is(hub-layout, site-layout, space-layout)[rail] [hub-bar] [hub-subs]:not([hidden]) {
    display: none;
  }
}

@media (min-width: 721px) and (prefers-reduced-motion: no-preference) {
  :is(hub-layout, site-layout, space-layout)[hub-ready] {
    transition: padding-left var(--ds-fast, 120ms) ease;
  }

  :is(hub-layout, site-layout, space-layout)[hub-ready] [hub-bar] {
    transition: width var(--ds-fast, 120ms) ease;
  }
}

/* ---------------------------------------------------------------- in a space */

/*
  A space carries the same sidebar, fixed down the left edge over the board. The board is not moved:
  the canvas keeps the whole window, so nothing that measures it or maps a pointer onto it changes,
  and the sidebar sits over its first `--hub-side` the way the dock sits over its corner. The space's
  own chrome does move over: `atomics-space-ui` (the header, the presence pills, the zoomer) and the
  dock and its tray, which are fixed in their own right.

  `[sidebar]` is set while it is drawn at all (`logic.ts`: the "Sidebar in a space" preference, and
  never on a phone, where a space has no top bar or tab bar to hold it).

  Under every panel and sheet that opens over a space (those start at a z-index of 3), except while
  its own account menu is open, which has to stand over the board's chrome.
*/
space-layout {
  --hub-side: 0px;
}

@media (min-width: 721px) {
  space-layout[sidebar] {
    --hub-side: 248px;
  }

  space-layout[sidebar][rail] {
    --hub-side: 64px;
  }

  space-layout [hub-bar] {
    z-index: 2;
  }

  space-layout [hub-bar]:has([aria-expanded='true']) {
    z-index: 60;
  }

  space-layout[sidebar] atomics-space-ui {
    left: var(--hub-side);
    width: calc(100% - var(--hub-side));
  }

  space-layout[sidebar] atomics-space-ui :is([toolbar], [tray]) {
    left: calc(var(--dock-inset) + var(--hub-side));
  }

  space-layout[sidebar] atomics-space-ui [toolbar] {
    max-width: calc(100vw - var(--hub-side) - var(--dock-inset) * 2);
  }

  space-layout[sidebar] atomics-space-ui [tray] {
    width: min(30rem, calc(100vw - var(--hub-side) - var(--dock-inset) * 2));
  }

  /*
    The guide's checklist opens beside the sidebar rather than over it, and its folded pill is the
    sidebar's own row (`[hub-guide]`), so `GuideCard` does not draw one while it is `[folded]`. The
    pill it draws while a tool's settings cover the card is moved over with the card.
  */
  space-layout[sidebar] atomics-guide-card:not([placed]) :is([card], [pill]) {
    inset-inline-start: calc(var(--hub-side) + 16px + env(safe-area-inset-left, 0px));
  }

  space-layout[sidebar] atomics-guide-card[folded] [pill] {
    display: none;
  }

  /*
    The space's pill leads with the space's own tile rather than a second Atomics mark beside the
    sidebar's, and its menu leaves out the places (All spaces, Starters, Exchange) the sidebar has.
  */
  space-layout[sidebar] atomics-space-ui [mainmenu] > [brand][tiled] svg[logo] {
    display: none;
  }

  space-layout[sidebar] atomics-space-ui [mainmenu] > [brand][tiled] [tile] {
    display: flex;
  }

  space-layout[sidebar] atomics-space-ui [mainmenu] [drawer] > [options][places] {
    display: none;
  }

  space-layout[sidebar] atomics-space-ui [mainmenu] [drawer] > [identity] + [options][places] + [options]::before {
    content: none;
  }
}

@media (max-width: 720px) {
  space-layout hub-sidebar {
    display: none;
  }
}
