/* The theme of ba3a.dev: crisp and professional.

   It loads after coffer's own stylesheet and changes the engine's custom
   properties (see github.com/ba3a/coffer/blob/v0.1.0/docs/themes.md), plus the few rules the compact header
   needs. The palette is cool slate with one teal accent. Light values are on
   :root; dark values are repeated under the system preference and under
   [data-theme="dark"], and light is forced under [data-theme="light"], exactly as
   the engine does it. Every foreground and background pair below is checked for
   WCAG AA contrast by scripts/site-test/ba3a-theme.test.mjs. */

/* Manrope Bold (SIL OFL 1.1), latin and latin-ext subsets, self-hosted. The
   files are in fonts/ next to this stylesheet; see themes/ba3a/README.md. */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/manrope-latin-ext-700.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/manrope-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --coffer-bg: #ffffff;
  --coffer-text: #0f1b2d;
  --coffer-muted: #4a5a70;
  --coffer-accent: #0a6b80;
  --coffer-border: #d3dce8;
  --coffer-code-bg: #eef3f8;
  --coffer-code-fg: #0f1b2d;
  /* Borders that identify a control (buttons, the search field) need 3:1. */
  --ba3a-control-border: #6f8099;

  --coffer-font-heading: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --coffer-bg: #0c1320;
    --coffer-text: #e6edf6;
    --coffer-muted: #9fb0c6;
    --coffer-accent: #4fc8df;
    --coffer-border: #27354b;
    --coffer-code-bg: #16202f;
    --coffer-code-fg: #e6edf6;
    --ba3a-control-border: #71839d;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --coffer-bg: #0c1320;
  --coffer-text: #e6edf6;
  --coffer-muted: #9fb0c6;
  --coffer-accent: #4fc8df;
  --coffer-border: #27354b;
  --coffer-code-bg: #16202f;
  --coffer-code-fg: #e6edf6;
  --ba3a-control-border: #71839d;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --coffer-bg: #ffffff;
  --coffer-text: #0f1b2d;
  --coffer-muted: #4a5a70;
  --coffer-accent: #0a6b80;
  --coffer-border: #d3dce8;
  --coffer-code-bg: #eef3f8;
  --coffer-code-fg: #0f1b2d;
  --ba3a-control-border: #6f8099;

  color-scheme: light;
}

/* Typography ------------------------------------------------------------- */

h1,
h2,
h3 {
  letter-spacing: -0.015em;
}

/* A game's page may set its own display font (--project-font, see
   github.com/ba3a/coffer/blob/v0.1.0/docs/projects.md). The engine declares that font as one face of normal
   weight, and the headings and buttons ask for bold; without this rule the
   browser would draw a second, synthetic bold on top of the real one. */

.game-page h1,
.game-page h2,
.game-page h3,
.game-page .project-pitch,
.game-page .game-button {
  font-synthesis-weight: none;
}

/* Controls --------------------------------------------------------------- */

.theme-switch,
.search-input,
.carousel-button {
  border-color: var(--ba3a-control-border);
}

/* Page frame: the header, the main element and the footer are one frame with
   the same width, --frame, centred with margin-inline: auto, and with no side
   padding of their own, so the bottom rule of the header, the top rule of the
   footer and the rules inside main start and end where the text starts and ends.
   The width is min(100% - 2rem, --frame): a margin of 1rem each side on a narrow
   screen, where the engine used padding.

   --frame is the engine's measure, a length the engine resolves once at the root
   (see @property --coffer-measure in coffer.css), so it is the same in the
   header, in main and in the footer whatever their font sizes, and the children
   of main, which the engine caps at the same measure, fill the column. The
   footer text is left-aligned with the body text.

   Every text page uses the narrow reading column. A page with a second column
   (the documentation sidebar) or a card grid (the projects index, where the cards
   are direct children of main) gets the measure plus 20rem, again for all three
   elements. The :where() keeps the specificity of --frame low. The print rule
   at the end resets the frame. ------------------------------------------- */

/* A bit wider than the engine's 68ch. html:root outranks the engine's :root. */
html:root {
  --coffer-measure: 76ch;
}

:where(body) {
  --frame: var(--coffer-measure);
}

body:where(:has(.docs-layout)),
body:where(:has(main > .project-cards)) {
  --frame: calc(var(--coffer-measure) + 20rem);
}

.site-header,
.site-footer,
main {
  box-sizing: border-box;
  width: min(100% - 2rem, var(--frame));
  max-width: none;
  margin-inline: auto;
  padding-inline: 0;
}

.site-footer {
  text-align: left;
}

/* Header: a wordmark on the left, the navigation and the theme switch to its
   right, in one row where they fit. -------------------------------------- */

.site-header {
  gap: 0.25rem 1.25rem;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
}

.site-header .site-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1875rem;
  letter-spacing: -0.02em;
}

/* The mark in front of the name: the letter B with a ">" prompt cut out of it.
   On a light page it is on its slate tile (brand/logo.svg), on a dark page it
   is the bare letter (brand/logo-dark.svg). It is decoration only. The dark
   rules are repeated for the system preference and for the theme switch, and
   light is forced again after them, as the colours above are. */
.site-header .site-title::before {
  content: "";
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  background: url("brand/logo.svg") center / contain no-repeat;
}

@media (prefers-color-scheme: dark) {
  .site-header .site-title::before {
    background-image: url("brand/logo-dark.svg");
  }
}

:root[data-theme="dark"] .site-header .site-title::before {
  background-image: url("brand/logo-dark.svg");
}

:root[data-theme="light"] .site-header .site-title::before {
  background-image: url("brand/logo.svg");
}

.site-header nav ul {
  gap: 0 1rem;
}

.site-header nav a {
  padding: 0.375rem 0;
  border-bottom: 2px solid transparent;
  color: var(--coffer-muted);
  font-size: 0.9375rem;
  text-decoration: none;
}

.site-header nav a:hover {
  color: var(--coffer-text);
  border-bottom-color: var(--coffer-border);
}

.site-header nav a[aria-current="page"] {
  color: var(--coffer-text);
  border-bottom-color: var(--coffer-accent);
}

.site-header .theme-switch {
  padding: 0.1875rem 0.625rem;
  font-size: 0.8125rem;
}

@media (max-width: 30rem) {
  .site-header .theme-switch {
    margin-left: auto;
  }
}

/* The links under the home page sections: "All projects" and "All posts" have
   one size and one gap above (the engine gives them 0.9375rem and the inherited
   size), and the secondary links are a deliberate muted, smaller line with a
   stated size (the engine's 0.875em depends on the parent). --------------- */

.all-projects,
.all-posts {
  margin-top: 1rem;
  font-size: 1rem;
}

.secondary-links {
  margin-top: 2rem;
  color: var(--coffer-muted);
  font-size: 0.875rem;
}

/* The rule between the items of a post list (home, blog index, tags, series): the same
   1px line on both sites, as wide as the text because the list sits in the frame. The
   last item has none, so the list does not end in a rule above what follows it. The
   padding is the engine's: 1rem below the last item plus the 1rem gap of the link
   after the list is within 1px of the gap between two items. ---------------------- */

.post-item {
  border-bottom: 1px solid var(--coffer-border);
}

.post-item:last-child {
  border-bottom: 0;
}

/* A whole post on the blog index, the tag pages and the series pages (index: full). The
   engine writes the item as the title (h2), the meta line and then the same
   <div class="post-body"> the post page has, so the body takes the post page's
   typography with no font setting here, and the title and meta line keep the engine's
   style. It adds no class to the list, so these rules find a full post by its body; the
   home page's compact "Latest posts" items have none and are not touched. The rule
   between posts is the .post-item one above, at the width of the list; a full post has
   2rem above and below it, equal on both sides. The engine keeps wide content (code,
   carousels, images) inside the column. ---------- */

.post-item:has(> .post-body) {
  padding: 2rem 0;
}

/* Tables are the one wide content that may leave the column: a table takes the
   width its content needs, at least the column and at most two thirds of the
   screen, and is centred on the column. Beyond that it scrolls in its own box.
   The page itself never scrolls sideways. ---------------------------------- */

.post-body table {
  position: relative;
  left: 50%;
  translate: -50% 0;
  width: max-content;
  min-width: 100%;
  max-width: max(100%, min(67vw, 100vw - 2rem));
  overflow-x: auto;
}

.docs-layout .post-body table {
  position: static;
  translate: none;
  width: auto;
  min-width: 0;
  max-width: 100%;
}

/* The table of contents of a post, on a wide screen: the engine puts it in a
   second column, which narrows the text. Here it floats at the right edge of
   the column, so the text flows around it and runs the full width of the column
   once the table ends. The column of such a page is the narrow one, like every
   text page (see the page frame above). On a narrow screen, and in print, the
   engine's rules are kept. ------------------------------------------------ */

@media (min-width: 60rem) {
  .post-layout.has-toc {
    display: flow-root;
  }

  .post-layout.has-toc .post-body {
    max-width: none;
  }

  .post-layout.has-toc .toc {
    float: right;
    box-sizing: border-box;
    width: 13rem;
    max-height: none;
    margin: 0 0 1rem 1.5rem;
    overflow: visible;
    position: static;
  }
}

/* Print: the engine prints black on white whatever the reader chose, but this
   stylesheet comes later and would win with its own colours, so the print
   values are set again here. ---------------------------------------------- */

@media print {
  :root,
  :root[data-theme] {
    --coffer-bg: #ffffff;
    --coffer-text: #000000;
    --coffer-muted: #333333;
    --coffer-accent: #000000;
    --coffer-border: #999999;
    --coffer-code-bg: #ffffff;
    --coffer-code-fg: #000000;

    color-scheme: light;
  }

  .site-header .site-title::before {
    display: none;
  }

  /* The frame above would otherwise win over the engine's print rule, which is
     full width with no side padding. */
  body .site-header,
  body .site-footer,
  body main {
    width: auto;
    max-width: none;
    margin: 0;
  }
}
