/*
 * The top bar of every talgrim.dev site: the current site on the left, the sites to switch to,
 * the site's own links, then the language switcher and the account button on the right.
 * Synced from talgrim/site-kit, so change it there, not in the site. Needs tokens.css.
 * The markup it styles is described in docs/site-bar.md.
 * The bar sits in the page flow (it is not fixed), so no page needs an offset below it.
 */
.site-bar,
.site-bar *,
.site-bar *::before,
.site-bar *::after {
  box-sizing: border-box;
}

.site-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font: 16px/1.5 var(--font-sans);
}

/* The path of the page, from the specific to the general: the current site, then talgrim.dev (`Notes · talgrim.dev`). */
.site-bar__title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.site-bar__site,
.site-bar__brand {
  color: var(--text);
  text-decoration: none;
}

.site-bar__site {
  font-weight: 600;
}

.site-bar__brand {
  color: var(--muted);
}

/* On the home site the brand is the only part of the title, so it is the site's name and reads like one. */
.site-bar__brand:only-child {
  color: var(--text);
  font-weight: 600;
}

.site-bar__brand:hover {
  color: var(--text);
}

/* The dot only joins the two when the site comes first; on home the brand stands alone. */
.site-bar__site + .site-bar__brand::before {
  content: '·';
  margin-right: 0.5rem;
  color: var(--muted);
}

.site-bar__sites,
.site-bar__nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* The switcher is for signed-in visitors only: a site renders it with the hidden attribute until it knows who is there. */
.site-bar__sites[hidden] {
  display: none;
}

.site-bar__sites a,
.site-bar__nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-bar__sites a:hover,
.site-bar__nav a:hover,
.site-bar__nav button:hover {
  color: var(--text);
}

/*
 * Three different things sit in a row: where the visitor is (the title), where else they can go (the switcher) and what
 * this site offers (its own links). A line sets each apart from the one before it, so `talgrim.dev` is not read as one
 * phrase with the first link. A line only appears when both neighbours are there (a visitor who is signed out has no
 * switcher, and a site may have no links of its own).
 */
.site-bar__title + :is(.site-bar__sites:not([hidden]), .site-bar__nav),
.site-bar__sites:not([hidden]) + .site-bar__nav {
  padding-left: 1rem;
  border-left: 1px solid var(--muted);
}

/*
 * Within the switcher and within the nav, a short faint line sits in the gap between neighbouring links, so each one
 * reads as its own option. It is smaller than the full-height line between the groups above and takes no room of its
 * own: it is placed over the middle of the gap, so the layout does not change.
 */
.site-bar__sites > * + *,
.site-bar__nav > * + * {
  position: relative;
}

.site-bar__sites > * + *::before,
.site-bar__nav > * + *::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -0.5rem;
  width: 1px;
  height: 0.9em;
  margin-top: -0.45em;
  background: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

/* An action of the site (such as locking it) sits among its links and reads like one. */
.site-bar__nav button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.site-bar__sites [aria-current='page'],
.site-bar__nav [aria-current='page'] {
  color: var(--text);
  text-decoration: underline;
}

/* Everything after the site's own links goes to the right edge. */
.site-bar__end {
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-left: auto;
}

.site-bar__languages {
  display: flex;
  gap: 0.25rem;
}

/* Buttons where the site switches in place, links where it navigates (home). */
.site-bar__languages :is(button, a) {
  padding: 0.25rem 0.5rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.site-bar__languages :is(button, a):hover {
  color: var(--text);
}

.site-bar__languages :is([aria-pressed='true'], [aria-current]) {
  color: var(--text);
  font-weight: 600;
}

/* The one button or link for logging in, or for the signed-in menu. */
.site-bar__account-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.site-bar__account-button:hover {
  background: var(--bg);
}

.site-bar :is(a, button):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* On a narrow screen the site switcher takes a row of its own under the brand and the right-hand side. */
@media (max-width: 40rem) {
  .site-bar__sites {
    order: 1;
    width: 100%;
  }

  .site-bar__nav {
    order: 2;
    width: 100%;
  }

  /* The title has the row to itself and the switcher and the nav have rows of their own, so there is no line to their left. */
  .site-bar__title + :is(.site-bar__sites:not([hidden]), .site-bar__nav) {
    padding-left: 0;
    border-left: 0;
  }

  /* The line between the switcher and the nav goes above the nav instead. */
  .site-bar__sites:not([hidden]) + .site-bar__nav {
    padding-top: 0.5rem;
    padding-left: 0;
    border-top: 1px solid var(--muted);
    border-left: 0;
  }
}
