/*
 * Page frame: header, shell, sidebar, main column, footer.
 *
 * Three breakpoints rather than the single 1024px jump the first design had,
 * which gave a phone's layout to everything up to a small laptop:
 *
 *   < 46rem   phone — single column, sticky section bar, menu in the header
 *   >= 46rem  tablet — wider gutters, two-up card grids, still no sidebar
 *   >= 64rem  laptop — persistent sidebar, section bar retires
 *   >= 88rem  wide — the content column stops growing and centres
 *
 * Between them nothing steps: type and space are fluid in tokens.css.
 */

/* --------------------------------------------------------------- header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  display: flex;
  align-items: center;
  /*
   * The same gap the logo uses internally, so identity always starts at the
   * same place. With a wider one here the game's name sat 4px further right
   * than the wordmark did, because on a game page below the sidebar
   * breakpoint the wordmark is hidden and the name takes its position — but
   * across this gap rather than the logo's own.
   */
  gap: var(--space-2);
  max-width: var(--width-page);
  min-height: var(--header-height);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
  white-space: nowrap;
}

/*
 * The mark: a rulebook seen face-on, its tabbed spine to the right.
 *
 * The favicon's drawing exactly, minus the plate behind it. The favicon keeps
 * that plate because it lands on browser chrome nobody controls; here the
 * surface is known, and a filled tile in the corner of a light header reads as
 * a sticker stuck on rather than a mark drawn in.
 *
 * Take the plate away and two of its fills have nothing to sit against: the
 * page was cream and the rules a grey that only worked on cream. They become
 * the surface's own two tones instead, which inverts the drawing in light mode
 * — a dark page with its rules cut out of it — and leaves dark mode looking as
 * it always did. The spine is the one colour that stays a colour, lightened in
 * dark so it does not close up.
 *
 * The drawing is cropped to itself. The favicon's artwork sits in a 32-unit
 * square with the book only 20 units tall — margin a favicon needs, because it
 * lands on browser chrome, and a mark beside a wordmark does not. The template
 * crops it away with a viewBox of 3.5 3.5 25 25, which makes the book bigger
 * inside an unchanged 24px box rather than by growing the box around it. Not a
 * coordinate of the drawing moves.
 */
.site-logo__mark {
  display: grid;
  place-items: center;

  --logo-spine: #9a5b12;
  --logo-spine: light-dark(#9a5b12, #c98430);
}

.site-logo__svg {
  display: block;
  height: 1.5rem;
  width: 1.5rem;
}

.site-logo__page {
  fill: var(--ink);
}

.site-logo__spine {
  fill: var(--logo-spine);
}

.site-logo__rules {
  fill: none;
  stroke: var(--surface);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.site-header__divider {
  width: 1px;
  height: 1.1rem;
  background: var(--line-strong);
}

/*
 * The game's name takes whatever room is left and truncates last. A long one
 * — "Xia: Legends of a Drift System" — matters more in context than the site's
 * own name, which is why the wordmark yields first below.
 */
.site-header__game {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--ui-weight);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-header__game:hover {
  color: var(--ink);
}

.site-header__actions {
  display: flex;
  align-items: center;
  flex: none;
  gap: var(--space-2);
  margin-left: auto;
}

/*
 * The site nav, shown only where the menu holding the same links is hidden.
 * Below that breakpoint it would be a second copy of the menu's first section
 * in a header that is deliberately thin.
 *
 * Set as quietly as the game's name beside it: these are the two least-used
 * things up here, and the search field is what the header is for.
 */
.site-nav {
  display: none;
}

@media (min-width: 64rem) {
  .site-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-right: var(--space-2);
  }
}

.site-nav__link {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--ui-weight);
  text-decoration: none;
  white-space: nowrap;
}

.site-nav__link:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

/*
 * Colour rather than the filled pill the sidebar uses: in a list a fill says
 * "this one of these", but there are only two here and one of them is the
 * page you are on nearly half the time.
 */
.site-nav__link.is-current {
  color: var(--accent-strong);
  font-weight: 650;
}

/*
 * The wordmark collapses to its mark wherever a game is open, up to the
 * sidebar breakpoint: in that range the header is carrying two names and the
 * game's is the one worth reading. The mark still links home.
 *
 * The divider goes with it. It is there to separate two names, and once the
 * wordmark is gone there is only one — a rule floating between the mark and
 * the game reads as a piece of the wordmark that failed to load.
 */
@media (max-width: 64rem) {
  body[data-game] .site-logo__text,
  body[data-game] .site-header__divider {
    display: none;
  }
}

@media (max-width: 26rem) {
  .site-logo__text,
  .site-header__divider {
    display: none;
  }
}

/* ---------------------------------------------------------- menu (narrow) */

/*
 * Out of the flow, hanging off the sticky header rather than sitting inside
 * its height.
 *
 * In the flow it added its own 497px to the top of the document every time it
 * opened, so the page reflowed under the reader twice per use. Scroll
 * anchoring then tried to compensate and got it wrong in both directions:
 * measured from 1500, opening moved the page 67px and closing moved it 861px
 * the other way, leaving the reader nine hundred pixels from the rule they had
 * been reading with no way back to it.
 *
 * Absolute against the header — `position: sticky` makes it a containing block
 * — so opening and closing change nothing about the document at all.
 */
.site-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: calc(100dvh - var(--header-height));
  overflow-y: auto;
  background: var(--surface-raised);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.site-menu__inner {
  display: grid;
  gap: var(--space-5);
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

/*
 * The menu sets bigger than the sidebar it stands in for. The sidebar is a
 * column the reader glances at beside the rules; this is the whole screen,
 * reached by a thumb, and usually in the middle of a game. Scoped to the menu
 * so the sidebar keeps its own scale.
 */
.site-menu .nav-link {
  padding-block: var(--space-3);
  font-size: var(--text-lg);
}

.site-menu .site-menu__heading,
.site-menu .nav-subheading {
  font-size: var(--text-sm);
}

/*
 * Set in title case rather than small caps. The label above a list of links is
 * read as a word — a game's name, a document's name — and uppercasing it makes
 * it a texture to be decoded instead. It also mangles the names themselves:
 * "&Cetera" and "Xia: Legends of a Drift System" are not written that way.
 * Without the caps the tracking goes too, which only ever existed to keep
 * uppercase from setting too tight.
 */
.site-menu__heading,
.sidebar__heading {
  margin-bottom: var(--space-2);
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 650;
}

/* --------------------------------------------------------- section bar */

/*
 * Sticky under the header, below the sidebar breakpoint. Answers "where am I"
 * continuously in a long rulebook, which was the main thing missing on a
 * phone.
 */
.section-bar {
  position: sticky;
  top: var(--header-height);
  z-index: 30;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--line);
}

.section-bar__button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: var(--width-page);
  min-height: var(--section-bar-height);
  margin-inline: auto;
  padding: var(--space-2) var(--space-4);
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}

.section-bar__meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
  flex: 1;
}

.section-bar__label {
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--ui-weight);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-bar__position {
  flex: none;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}

/*
 * The chevron points at what tapping it will do, not at where the list is: down
 * to open the list, up to put it away again. A control that keeps pointing down
 * while its list is open is describing the list rather than offering an action,
 * and the bar stays visible under the open sheet where that reads as wrong.
 */
.section-bar__chevron {
  flex: none;
  color: var(--ink-faint);
  transition: rotate 160ms ease;
}

[aria-expanded="true"] > .section-bar__chevron {
  rotate: 180deg;
}

/* ------------------------------------------------------------- shell */

.shell {
  max-width: var(--width-page);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.sidebar {
  display: none;
}

.main {
  min-width: 0;
  /*
   * The top step is smaller than the bottom one. What sits at the top of a
   * page is a line of breadcrumbs set in the smallest type on it, and small
   * text needs less room above it than the gap under the sticky chrome was
   * giving it — the page read as starting late.
   */
  padding-block: var(--space-5) var(--space-8);
}

.main:focus {
  outline: none;
}

.main--plain {
  max-width: var(--width-page);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.article,
.landing,
.home {
  min-width: 0;
}

.article {
  max-width: var(--width-prose);
}

/* ------------------------------------------------------- page header */

.page-header {
  margin-bottom: var(--space-6);
}

.eyebrow {
  margin-bottom: var(--space-2);
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
}

.eyebrow a {
  color: inherit;
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: var(--display-weight);
  letter-spacing: var(--display-tracking);
  line-height: var(--leading-flat);
  text-wrap: balance;
}

.page-subhead {
  max-width: var(--measure);
  margin-top: var(--space-3);
  color: var(--ink-muted);
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  text-wrap: pretty;
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--display-weight);
  letter-spacing: var(--display-tracking);
}

/* ----------------------------------------------------------- footer */

.site-footer {
  margin-top: var(--space-8);
  border-top: 1px solid var(--line);
  background: var(--surface-sunken);
}

.site-footer__inner {
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-6) var(--space-4);
}

.site-footer__title {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 700;
}

.site-footer__note {
  max-width: var(--measure);
  margin-top: var(--space-2);
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-4);
  padding: 0;
  list-style: none;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

/* ==================================================== >= 46rem (tablet) */

@media (min-width: 46rem) {
  .shell,
  .main--plain,
  .site-header__inner,
  .site-footer__inner,
  .site-menu__inner,
  .section-bar__button {
    padding-inline: var(--space-6);
  }
}

/* ==================================================== >= 64rem (sidebar) */

@media (min-width: 64rem) {
  /* The section bar's job is taken over by the sidebar. */
  .section-bar {
    display: none !important;
  }

  .menu-toggle,
  .site-menu {
    display: none !important;
  }

  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    gap: var(--space-7);
    align-items: start;
  }

  .sidebar {
    display: block;
    position: sticky;
    top: calc(var(--header-height) + var(--space-5));
    max-height: calc(100dvh - var(--header-height) - var(--space-7));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-block: var(--space-6);
    padding-right: var(--space-3);
  }

  .sidebar__block + .sidebar__block {
    margin-top: var(--space-5);
    padding-top: var(--space-5);
    border-top: 1px solid var(--line);
  }

  /* A landing page is art-led and wants the full width. */
  .shell--landing {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
}

/* ====================================================== >= 88rem (wide) */

@media (min-width: 88rem) {
  .shell {
    gap: var(--space-8);
  }
}

/* ------------------------------------------------------- page top row */

/*
 * Breadcrumbs and the page-level actions share a line. The breadcrumbs already
 * carried their own bottom margin, so the row takes it over and they keep none
 * of their own.
 */
.page-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-top .breadcrumbs {
  margin-bottom: 0;
  min-width: 0;
}

.print-button {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  cursor: pointer;
}

.print-button:hover {
  background: var(--surface-sunken);
  border-color: var(--line-strong);
  color: var(--ink);
}

/* The icon carries it on a phone; the word is what makes it obvious on a desk. */
@media (max-width: 34rem) {
  .print-button__label {
    display: none;
  }
}
