/* Layout: the page column (`main`), the header and the footer. The header and footer span the window up to
   --container-wide-width; the content stays in the grid (--container-width, --grid-margin). */

main {
  flex: 1;
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: var(--space-6) var(--grid-margin);
}

/* Full width: add `full` to a block in `main` to take it out of the page column and the grid. It spans the whole
   window (its background reaches the edges), and its content lines up with the header and footer: --grid-margin at
   the sides, at most --container-wide-width, centred beyond. 100cqi is the body's width (base.css), so the scrollbar
   never makes the page scroll sideways. `!important` because the block's own rules come later (pages/*.css) and
   often set its margin or width, e.g. `.popular { margin: … 0 … }`, which would put it back in the column. */
.full {
  width: 100cqi !important;
  max-width: none !important;
  margin-inline: calc(50% - 50cqi) !important;
  padding-inline: max(
    var(--grid-margin),
    (100cqi - var(--container-wide-width)) / 2 + var(--grid-margin)
  ) !important;
}

/* Header, rail, footer */

/* The header is sticky (below): `#anchor` links and keyboard focus scroll their target to just under it, not behind
   it. A little more than its height (73px on phones, 93px from 64rem). */
html {
  scroll-padding-top: calc(var(--space-20) + var(--space-2));
}

@media (min-width: 64rem) {
  html {
    scroll-padding-top: calc(var(--space-20) + var(--space-8));
  }
}

/* Phones: the home link with the language and theme on the first row, the menu on its own row below (it wraps if it
   ever has to). From 48rem: one row. Its content spans the whole window with only --grid-margin at the sides, up to
   --container-wide-width, then centred (the padding, as `.full`); the page's content (the header search, `main`)
   stays in the grid. Sticky: it stays at the top while the page scrolls, over the content, so it has the page's own
   background (fixed, like the body's, so the two line up) and a line under it. Being positioned, the account and nav
   menus' panels still hang from it on phones. */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-dropdown);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'menu tools'
    'nav nav';
  align-items: center;
  gap: var(--space-3) var(--space-4);
  width: 100%;
  padding: var(--space-5)
    max(var(--grid-margin), (100cqi - var(--container-wide-width)) / 2 + var(--grid-margin));
  background: var(--gradient-page);
  background-attachment: fixed;
  border-bottom: var(--border-width) solid var(--color-border);
  font-size: var(--text-md);
}

/* The hamburger: phones only, and only with JS — without it the menu below is simply always open. */
.nav-toggle {
  grid-area: menu;
  justify-self: start;
}

.nav-toggle svg:last-child,
.nav-toggle[aria-expanded='true'] svg:first-child {
  display: none;
}

.nav-toggle[aria-expanded='true'] svg:last-child {
  display: block;
}

.site-header a {
  color: var(--color-text);
  text-decoration: none;
}

.site-header a:hover {
  color: var(--color-accent);
}

.site-nav {
  grid-area: nav;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-5);
}

/* With JS on a phone the menu is a panel hanging from the header, like the account menu's (account.css), and the
   header is one row: the hamburger and the tools. */
html.js .site-nav {
  display: none;
}

html.js .site-nav[data-open] {
  position: absolute;
  top: 100%;
  right: var(--grid-margin);
  left: var(--grid-margin);
  z-index: var(--z-dropdown);
  display: grid;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: menu-in var(--duration-base) var(--ease-out);
}

html.js .site-nav[data-open] > a {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}

html.js .site-nav[data-open] > a:hover {
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-surface));
}

/* Phones: while the menu is open the page behind it is dimmed, so the header (raised above the dim) stands out.
   Clicking the dim closes the menu (nav.js: a click outside). */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-dropdown) - 1);
  background: rgb(0 0 0 / 0.65); /* darker than --color-overlay (0.4), which is for dialogs */
  /* Always there but invisible, so it can fade both ways; `visibility` waits for the fade-out to finish. */
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-base) var(--ease-out),
    visibility 0s var(--duration-base);
}

html[data-nav-open] body::before {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

html[data-nav-open] .site-header {
  z-index: var(--z-dropdown);
  background: var(--color-bg); /* not dimmed with the page */
}

@media (min-width: 48rem) {
  html[data-nav-open] body::before {
    display: none;
  }
}

/* One row with the panel out of the flow: no empty menu track under the header. */
html.js .site-header {
  grid-template-areas: 'menu tools';
}

.header-tools {
  grid-area: tools;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

@media (min-width: 48rem) {
  .site-header,
  html.js .site-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'nav tools';
  }

  /* `.site-header` beats `.icon-button`'s own display. */
  .site-header .nav-toggle {
    display: none;
  }

  /* A row of links again, the home link at its left end. */
  .site-nav,
  html.js .site-nav {
    position: static;
    display: flex;
    gap: var(--space-2) var(--space-5);
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
    animation: none;
  }

  .site-home {
    margin-right: auto;
  }

  /* The language and theme are not pages of the site: a divider sets them apart from the menu. */
  .header-tools {
    padding-left: var(--space-5);
    border-left: var(--border-width) solid var(--color-border);
  }
}

/* The logo in the home link; one image, readable on both themes. */
.site-home {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

.site-logo {
  height: 2.75rem;
  width: auto;
}

.site-nav a[aria-current='page']:not(.button) {
  color: var(--color-accent);
}

/* The other language, with its flag. */
.language-switch a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.flag {
  flex: none;
  width: var(--space-5);
  height: var(--space-3);
  border-radius: var(--radius-xs);
  box-shadow: 0 0 0 var(--border-width) var(--color-border);
}

.theme-toggle .theme-icon-light,
:root[data-theme='dark'] .theme-toggle .theme-icon-dark {
  display: none;
}

:root[data-theme='dark'] .theme-toggle .theme-icon-light {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .theme-icon-dark {
    display: none;
  }

  :root:not([data-theme='light']) .theme-toggle .theme-icon-light {
    display: block;
  }
}

.header-search {
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 var(--grid-margin);
}

.discord-button {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-raised);
  display: grid;
  place-items: center;
  width: var(--size-fab);
  height: var(--size-fab);
  color: var(--color-on-accent);
  background: var(--color-accent);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

/* Footer: about the site, link columns, the Discord call, then the copyright line. Stacked on phones. Like the header,
   its content spans the whole window with only --grid-margin at the sides, up to --container-wide-width, then is
   centred; its background always reaches the edges. */
.site-footer {
  --footer-width: calc(var(--container-wide-width) - 2 * var(--grid-margin));
  margin-top: var(--space-20);
  padding: var(--space-12) var(--grid-margin) var(--space-20);
  color: var(--color-text);
  font-size: var(--text-md);
  background: var(--color-surface);
  border-top: var(--border-width) solid var(--color-border);
}

.footer-columns {
  display: grid;
  gap: var(--space-8);
  max-width: var(--footer-width);
  margin: 0 auto;
}

.site-footer h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.site-footer p {
  margin: 0 0 var(--space-2);
}

.site-footer .icon {
  color: var(--color-accent);
}

.footer-title {
  display: inline-block;
  margin-bottom: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.footer-muted {
  color: var(--color-text-muted);
}

.footer-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, max-content));
  gap: var(--space-8) var(--space-12);
}

.footer-links ul {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-links a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--color-accent);
}

.footer-discord {
  position: relative;
  align-self: start;
  overflow: hidden;
  padding: var(--space-6);
  color: var(--color-on-discord);
  background: linear-gradient(135deg, var(--color-discord-start), var(--color-discord-end));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition:
    translate var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out);
}

@media (hover: hover) {
  .footer-discord:hover {
    translate: 0 calc(-1 * var(--space-1));
    box-shadow: var(--shadow-lg);
  }
}

/* The mark: in a soft light circle, giving a little wave while the card is hovered. */
.footer-discord-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size-control-lg);
  height: var(--size-control-lg);
  margin-bottom: var(--space-4);
  background: var(--color-discord-mark);
  border-radius: var(--radius-full);
  transition: rotate var(--duration-base) var(--ease-out);
}

@media (hover: hover) {
  .footer-discord:hover .footer-discord-mark {
    rotate: -8deg;
  }
}

.site-footer .footer-discord h2 {
  position: relative;
  margin: 0 0 var(--space-2);
  color: var(--color-on-discord);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.footer-discord p {
  position: relative;
  margin: 0 0 var(--space-5);
  color: var(--color-on-discord);
}

/* The button turned inside out: white with ink text in both themes, so it stands out on the card. */
.site-footer .footer-discord-join {
  color: var(--color-discord-ink);
  font-weight: var(--weight-semibold);
  background: var(--color-discord-button);
  border-color: var(--color-discord-button);
}

.site-footer .footer-discord-join:hover {
  color: var(--color-discord-ink);
  background: var(--color-discord-button);
  border-color: var(--color-discord-button);
}

.footer-discord-join .icon {
  transition: translate var(--duration-base) var(--ease-out);
}

/* The movement only where hovering is real; on a touch screen a tap would leave the button shifted. */
@media (hover: hover) {
  .site-footer .footer-discord-join:hover {
    translate: 0 calc(-1 * var(--space-half));
  }

  .footer-discord-join:hover .icon {
    translate: var(--space-1) 0;
  }
}

/* The button's own hover stars: white ones would vanish on the white button, so they take its ink. */
.footer-discord .footer-discord-join .sparkles i:nth-child(2),
.footer-discord .footer-discord-join .sparkles i:nth-child(5) {
  --star-color: var(--color-discord-ink);
}

/* Stars across the card, twinkling slowly all the time (reduced motion stops them, base.css). Prefixed with the card
   so they win over sparkles.css, which loads later. */
.footer-discord .footer-discord-stars i {
  --star-color: var(--color-on-discord);
  animation: twinkle 3.6s ease-in-out var(--d) infinite;
}

.footer-discord .footer-discord-stars i:nth-child(1) {
  --x: 70%;
  --y: 18%;
}

.footer-discord .footer-discord-stars i:nth-child(2) {
  --x: 88%;
  --y: 40%;
  --d: 0.9s;
  --star-color: var(--color-sparkle);
}

.footer-discord .footer-discord-stars i:nth-child(3) {
  --x: 62%;
  --y: 62%;
  --d: 1.8s;
}

.footer-discord .footer-discord-stars i:nth-child(4) {
  --x: 92%;
  --y: 82%;
  --d: 2.7s;
  --star-color: var(--color-sparkle);
}

.footer-discord .footer-discord-stars i:nth-child(5) {
  --x: 80%;
  --y: 8%;
  --d: 1.3s;
}

.footer-discord .footer-discord-stars i:nth-child(6) {
  --x: 50%;
  --y: 30%;
  --d: 2.2s;
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-3);
  max-width: var(--footer-width);
  margin: var(--space-8) auto 0;
  padding-top: var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
  border-top: var(--border-width) solid var(--color-border);
}

/* The counter still runs and still reports the page view: `counter.js` sets the image's `src` the moment it builds
   the element, before it is ever put in the page, so the request goes out whatever CSS says about it. Only TOP.GE's
   badge is hidden -- the owner did not want it on the page -- and the box is collapsed so it leaves no gap. */
.footer-counter {
  visibility: hidden;
  height: 0;
  overflow: hidden;
}

@media (min-width: 40rem) {
  .footer-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 64rem) {
  /* About | the two link columns together | Discord: three balanced parts, the about column with room of its own. */
  .footer-columns {
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: var(--space-12);
  }
}

@media (min-width: 64rem) {
  .site-header {
    padding-block: var(--space-6);
  }

  .site-footer {
    padding-bottom: var(--space-8);
  }
}
