/* Shared site header: brand, navigation, session chip and user menu.
   Used by home, player and admin. Colours and fonts come from vanguard.css. */

:root {
  --shell-header-h: 76px;
}

@media (max-width: 980px) {
  :root {
    --shell-header-h: 64px;
  }
}

/* Anything hidden by the markup stays hidden, whatever the page CSS says. */
.site-header [hidden] {
  display: none !important;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: clamp(18px, 2.6vw, 48px);
  min-height: 76px;
  padding: 0 clamp(24px, 2.6vw, 50px);
  background: #171716;
  border-bottom: 1px solid #ffffff14;
  transition: box-shadow .3s var(--ease), background-color .3s;
}

.site-header.is-scrolled {
  box-shadow: 0 12px 30px #0007;
  background: #161615f5;
}

.site-header .brand {
  padding-inline-end: clamp(18px, 2.3vw, 38px);
  border-inline-end: 1px solid #ffffff25;
}

.site-header .brand span {
  font-size: clamp(22px, 1.55vw, 29px);
}

.site-header nav {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  gap: clamp(12px, 1.65vw, 32px);
  margin-inline-end: auto;
}

.site-header nav > a,
.site-header nav > button {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 5px;
  background: transparent;
  color: #e0ddd7;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
  white-space: nowrap;
}

.site-header nav .nav-active,
.site-header nav > :hover {
  color: #fff;
}

.site-header nav .nav-active::after {
  position: absolute;
  inset: auto 5px 0;
  height: 2px;
  background: var(--amber);
  content: "";
}

.site-header nav [data-admin-link] {
  color: var(--amber);
}

.site-header .button-small {
  min-height: 38px;
  padding-inline: 14px;
  white-space: nowrap;
}

/* ---------- Session actions ---------- */

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
  /* Reserved width while the session answer is pending, so the header does not jump. */
  min-width: 150px;
}

.shell-session-pending {
  display: block;
  width: 132px;
  height: 38px;
}

.account-button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0;
  background: transparent;
  color: #e0ddd7;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.account-button:hover {
  color: #fff;
}

.user-menu {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(230px, 100%);
  min-height: 42px;
  padding: 3px 12px 3px 3px;
  border: 1px solid #ffffff26;
  background: #ffffff0d;
  color: #f2f4f6;
  transition: background-color .2s, border-color .2s;
}

.user-chip:hover,
.user-chip[aria-expanded="true"] {
  border-color: #ffffff4d;
  background: #ffffff1a;
}

.user-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--amber);
  color: #1d130d;
  font-family: Barlow, "Arial Narrow", sans-serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-caret {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-inline-start: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .2s var(--ease);
}

.user-chip[aria-expanded="true"] .user-caret {
  transform: translateY(2px) rotate(225deg);
}

.user-menu-list {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 30;
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  border: 1px solid #ffffff1f;
  background: #1b1d1e;
  box-shadow: 0 18px 40px #0009;
  transform-origin: top right;
  animation: shell-menu-in .18s var(--ease);
}

.user-menu-list :is(a, button) {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  background: transparent;
  color: #e0ddd7;
  font-size: 13px;
  font-weight: 600;
  text-align: start;
  white-space: nowrap;
}

.user-menu-list :is(a, button):hover,
.user-menu-list :is(a, button):focus-visible {
  background: #ffffff12;
  color: #fff;
}

.user-menu-list [data-admin-item] {
  color: var(--amber);
}

.user-menu-logout {
  margin-top: 4px;
  border-top: 1px solid #ffffff1f;
  border-radius: 0;
}

.user-menu-status {
  padding: 6px 12px 2px;
  color: #e7a39e;
  font-size: 12px;
  line-height: 1.4;
}

@keyframes shell-menu-in {
  from {
    opacity: 0;
    transform: translate3d(0, -6px, 0);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.mobile-toggle {
  display: none;
}

/* ---------- Narrow layouts ---------- */

/* Signed in, the chip needs the room the download button would take. */
@media (max-width: 1180px) {
  .header-actions:has(.user-menu:not([hidden])) .button {
    display: none;
  }

  .user-chip {
    max-width: 180px;
  }
}

@media (max-width: 1030px) {
  .header-actions .account-button {
    justify-content: center;
    width: 42px;
    border: 1px solid #fff3;
  }

  .header-actions .account-button span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

@media (max-width: 980px) {
  .site-header {
    min-height: 64px;
    gap: 8px;
    padding-inline: 20px;
  }

  .site-header .brand {
    padding-inline-end: 0;
    border: 0;
  }

  .site-header .brand img {
    width: 34px;
    height: 34px;
  }

  .header-actions {
    min-width: 0;
    margin-inline-start: auto;
  }

  .shell-session-pending {
    width: 42px;
  }

  .header-actions .button {
    display: none;
  }

  .mobile-toggle {
    display: flex;
    flex: 0 0 44px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    order: 4;
    gap: 4px;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
  }

  .mobile-toggle span {
    width: 19px;
    height: 1px;
    background: currentColor;
  }

  .mobile-toggle[aria-expanded="true"] span:first-child { transform: translateY(5px) rotate(45deg); }
  .mobile-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .mobile-toggle[aria-expanded="true"] span:last-child { transform: translateY(-5px) rotate(-45deg); }

  .site-header nav {
    position: absolute;
    inset: 100% 0 auto;
    display: none;
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding-inline: 20px;
    border-bottom: 1px solid #fff3;
    background: #171716;
  }

  .site-header nav.open {
    display: flex;
  }

  .site-header nav > :is(a, button) {
    min-height: 47px;
    border-top: 1px solid #fff2;
  }

  .site-header nav .nav-active::after {
    inset: auto auto auto -5px;
    width: 2px;
    height: 13px;
  }
}

@media (max-width: 420px) {
  .site-header .brand span {
    font-size: 19px;
  }

  .user-chip {
    max-width: 100%;
    padding-inline-end: 8px;
  }

  .user-caret {
    display: none;
  }
}

/* Very narrow phones: the icon carries the brand so the user name keeps its room. */
@media (max-width: 360px) {
  .site-header .brand span {
    display: none;
  }
}


/* ---------- Icons and Discord (header) ---------- */

.site-header .nav-icon {
  margin-inline-end: 8px;
  font-size: 14px;
  opacity: .85;
}

.site-header .header-discord {
  display: inline-flex;
  flex: none;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

.site-header .header-discord .icon {
  font-size: 18px;
}

.site-header nav .nav-discord {
  display: none;
}

.site-header nav .nav-discord .icon-brand {
  margin-inline-end: 8px;
  color: #8c94ff;
  font-size: 16px;
}

.header-actions .account-button .icon {
  font-size: 16px;
}

.user-menu-list .menu-icon {
  margin-inline-end: 10px;
  font-size: 15px;
  opacity: .85;
}

/* Between 981px and 1180px the header is full: keep the glyph only (the link keeps its aria-label). */
@media (min-width: 981px) and (max-width: 1180px) {
  .site-header .header-discord span {
    display: none;
  }
}

@media (max-width: 980px) {
  .site-header .header-discord {
    display: none;
  }

  .site-header nav .nav-discord {
    display: flex;
  }

  .site-header nav .nav-icon {
    font-size: 15px;
  }
}

/* Between the mobile menu and a wide screen the signed-in header is at its tightest (five links, Discord
   and the user chip): the links drop their icons and everything closes up so nothing leaves the screen. */
@media (min-width: 981px) and (max-width: 1180px) {
  .site-header {
    gap: 14px;
    padding-inline: 18px;
  }

  .site-header .brand {
    padding-inline-end: 14px;
  }

  .site-header nav {
    gap: 8px;
  }

  .site-header nav > a .icon,
  .site-header nav > button .icon {
    display: none;
  }

  .header-actions {
    min-width: 0;
  }

  .user-chip {
    max-width: 150px;
  }
}

/* ---------- Language switcher (ES | EN) ---------- */

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid #ffffff26;
  background: #ffffff0d;
}

.lang-switch a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 30px;
  padding: 0 8px;
  color: #cfcac2;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-decoration: none;
  transition: background-color .2s, color .2s;
}

.lang-switch a:hover {
  color: #fff;
  background: #ffffff14;
}

.lang-switch a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.lang-switch a[aria-current="true"] {
  background: var(--amber);
  color: #1d130d;
}

/* One switcher in the header bar on desktop, one inside the mobile menu. */
.site-header .lang-switch--menu {
  display: none;
}

@media (max-width: 980px) {
  .header-actions .lang-switch--bar {
    display: none;
  }

  .site-header nav .lang-switch--menu {
    display: inline-flex;
    align-self: flex-start;
    margin-top: 8px;
  }
}

/* Text for screen readers only: every page loads this sheet, so the rule lives here. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- The header keeps its own sizes on every page ---------- */

/* Page stylesheets restyle .button and reset min-width for their own content (the panel does both); these
   rules carry the header's selector so the bar and the account menu look the same everywhere. */
.site-header .header-actions .button,
.site-header .header-actions .discord-button {
  min-height: 38px;
  padding-block: 8px;
}

.site-header .header-actions .button {
  gap: 19px;
  padding-inline: 14px;
  font-size: 11px;
}

.site-header .header-actions .user-chip {
  min-height: 42px;
}

.site-header .user-menu .user-menu-list {
  right: 0;
  left: auto;
  width: max-content;
  min-width: 220px;
}

.site-header .user-menu-list :is(a, button) {
  width: 100%;
  min-height: 42px;
}
