/* The shell and its navigation (components/sidebar.rs). On a desktop: a rail
   on the left that grows on hover or keyboard focus and lies over the page,
   or takes its full width in the layout when pinned. Under 640 px: a glass
   strip at the top and a bar at the bottom, in thumb reach. */

.app-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 100vh;
}

/* Holds the rail's place in the layout. The rail itself is fixed, so
   growing on hover does not move the page; only pinning widens the slot. */
.app-sidebar-slot {
  width: var(--sidebar-width-collapsed);
  transition: width var(--duration-fast) var(--ease-out);
}

.app-sidebar-slot--pinned {
  width: var(--sidebar-width-expanded);
}

.app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: var(--sidebar-width-collapsed);
  padding: var(--space-3);
  padding-right: calc(var(--space-3) - var(--border-width));
  border-right: var(--border-width) solid var(--color-border);
  background: var(--color-surface);
  transition:
    width var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast);
}

.app-sidebar--expanded {
  width: var(--sidebar-width-expanded);
}

/* Open over the page rather than pinned: lift it like a menu. */
.app-sidebar--overlay {
  box-shadow: var(--shadow-menu);
}

/* A label beside an icon: faded out, and squeezed to nothing by its row,
   while the rail is collapsed. It stays readable by assistive technology. */
.app-sidebar__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.app-sidebar--expanded .app-sidebar__label {
  opacity: 1;
}

/* Head: the brand and the pin */

.app-sidebar__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.app-sidebar__brand {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  border-radius: var(--radius);
  color: var(--color-fg);
  text-decoration: none;
}

/* The original site's logo: the character in the collapsed rail, and the
   wordmark beside it once the rail opens. */
.app-sidebar__mark {
  flex: none;
  width: var(--size-control);
  height: var(--size-control);
  border-radius: var(--radius);
  object-fit: cover;
}

.app-sidebar__wordmark {
  width: auto;
  height: var(--size-control);
  min-width: 0;
  object-fit: contain;
  object-position: left center;
}

/* Shown once the rail has room; keyboard focus opens the rail before the
   next Tab reaches it. */
.app-sidebar__pin {
  display: none;
  color: var(--color-muted);
}

.app-sidebar--expanded .app-sidebar__pin {
  display: inline-flex;
}

.app-sidebar__pin[aria-pressed="true"] {
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}

/* Navigation */

.app-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.app-nav__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--size-control);
  /* Centres the icon in a collapsed rail, and keeps it there as it grows. */
  padding: 0 calc((var(--size-control) - var(--size-icon)) / 2);
  border-radius: var(--radius-pill);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition:
    background-color var(--duration-fast),
    color var(--duration-fast);
}

.app-nav__link:hover {
  background: var(--color-hover);
  color: var(--color-fg);
}

.app-nav__link[aria-current="page"] {
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}

/* The marker: a short pink bar on the rail's edge, beside the current item. */
.app-nav__link[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: calc(var(--space-3) * -1);
  width: var(--space-1);
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--color-primary);
}

/* Foot: language, then "Sign in" or the account menu */

.app-sidebar__foot {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: var(--border-width) solid var(--color-border);
}

.app-sidebar__foot .select select {
  flex: 1;
  min-width: 0;
}

.app-sidebar__foot .button {
  justify-content: flex-start;
  padding: 0 calc((var(--size-control) - var(--size-icon)) / 2);
}

.app-sidebar__foot .menu {
  /* The panel is placed against the foot, beside the rail. */
  position: static;
}

.app-sidebar__foot .menu__trigger {
  width: 100%;
}

.app-sidebar--expanded .menu__trigger-name {
  display: block;
}

.app-sidebar__foot .menu__panel {
  top: auto;
  right: auto;
  bottom: 0;
  left: calc(100% + var(--space-3) + var(--space-2));
  transform-origin: bottom left;
}

/* Collapsed (desktop only): each foot control is one square, its words
   hidden visually and shown as its `title`. */

@media (width > 640px) {
  .app-sidebar:not(.app-sidebar--expanded) .app-sidebar__foot .select,
  .app-sidebar:not(.app-sidebar--expanded) .app-sidebar__foot .button,
  .app-sidebar:not(.app-sidebar--expanded) .app-sidebar__foot .menu__trigger {
    justify-content: center;
    width: var(--size-control);
    padding: 0;
  }

  .app-sidebar:not(.app-sidebar--expanded) .menu__trigger .icon {
    display: none;
  }

  /* Hidden like `.visually-hidden`, so it stays the button's name. */
  .app-sidebar:not(.app-sidebar--expanded) .button__label {
    position: absolute;
    width: var(--border-width);
    height: var(--border-width);
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .app-sidebar:not(.app-sidebar--expanded) .menu__trigger {
    min-height: var(--size-control);
  }

  /* Only the globe shows; the control itself covers it, invisibly. */
  .app-sidebar:not(.app-sidebar--expanded) .select select {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
  }
}

/* Phone: a strip at the top, the navigation at the bottom */

@media (max-width: 640px) {
  .app-shell {
    display: block;
  }

  .app-sidebar-slot,
  .app-sidebar-slot--pinned {
    position: sticky;
    top: 0;
    z-index: 10;
    width: auto;
  }

  .app-sidebar,
  .app-sidebar--expanded {
    position: relative;
    top: auto;
    bottom: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    width: auto;
    min-height: var(--size-header);
    padding: 0 var(--space-3);
    border-right: 0;
    border-bottom: var(--border-width) solid var(--color-border);
    background: transparent;
    box-shadow: none;
  }

  /* The glass is on a pseudo-element: a backdrop filter on the strip itself
     would make it the containing block of the fixed bottom navigation. */
  .app-sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--color-glass);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
  }

  .app-sidebar .app-sidebar__label {
    opacity: 1;
  }

  .app-sidebar__head {
    min-width: 0;
  }

  .app-sidebar__mark,
  .app-sidebar__wordmark {
    height: var(--space-5);
  }

  .app-sidebar__mark {
    width: var(--space-5);
  }

  .app-sidebar--expanded .app-sidebar__pin {
    display: none;
  }

  .app-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
    border-top: var(--border-width) solid var(--color-border);
    background: var(--color-glass);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
  }

  .app-nav__link {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius);
    font-size: var(--text-xs);
  }

  .app-nav__link[aria-current="page"]::before {
    content: none;
  }

  .app-sidebar__foot {
    flex-direction: row;
    align-items: center;
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    border-top: 0;
  }

  .app-sidebar__foot .menu {
    position: relative;
  }

  .app-sidebar__foot .menu__panel {
    top: calc(100% + var(--space-2));
    right: 0;
    bottom: auto;
    left: auto;
    transform-origin: top right;
  }

  .app-sidebar--expanded .menu__trigger-name,
  .app-sidebar--expanded .app-sidebar__foot .menu__trigger .icon {
    display: none;
  }

  .app-sidebar__foot .menu__trigger {
    width: auto;
    padding: var(--space-1);
  }

  .app-sidebar__foot .button {
    padding: 0 var(--space-3);
  }

  .app-sidebar__foot .button .icon {
    display: none;
  }

  /* Only the globe shows, in either state. */
  .app-sidebar__foot .select {
    justify-content: center;
    width: var(--size-control);
    padding: 0;
  }

  .app-sidebar__foot .select select {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
  }
}
