/* eyesunstrung site stylesheet.
 *
 * Accessibility rules this file holds to (WCAG 2.2 AA):
 *   - No px root font size; the reader's browser setting wins.
 *   - Focus is always visible, as a thick outline.
 *   - Text meets 4.5:1 contrast in both light and dark schemes.
 *   - Layout reflows to 320px wide with no horizontal scrolling.
 *   - Links are underlined, so they are not told apart by colour alone.
 *   - Nothing is sticky or fixed, so nothing can cover the focused element.
 */

/* Atkinson Hyperlegible Next, by the Braille Institute, designed for low vision
 * readers. SIL Open Font License 1.1; the licence ships as assets/fonts/OFL.txt.
 * Copied from the @fontsource-variable package at build time. One variable file
 * covers weights 200 to 800. font-display: swap shows text in the fallback face
 * at once rather than waiting for the font. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/assets/fonts/atkinson-hyperlegible-next-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* Contrast against the page background, then against --surface:
 *   light: text 15.8 / 14.5, muted 9.0 / 8.2, link 8.4 / 7.7,
 *          visited 9.9 / 9.1, focus 6.1 / 5.6, border 4.6 / 4.2
 *   dark:  text 15.5 / 13.4, muted 10.1 / 8.7, link 10.3 / 8.9,
 *          visited 9.4 / 8.1, focus 10.4 / 9.0, border 6.0 / 5.2
 * Borders are decorative; focus needs 3:1 and has well over it. */
:root {
  --text: #1f2328;
  --text-muted: #424a53;
  --background: #ffffff;
  --surface: #f3f5f7;
  --link: #0b4f8a;
  --link-visited: #5b2a86;
  --border: #6e7781;
  --focus: #b3361b;
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e6edf3;
    --text-muted: #b8c1ca;
    --background: #121518;
    --surface: #1e2328;
    --link: #8cc8ff;
    --link-visited: #d2a8ff;
    --border: #8b949e;
    --focus: #ffb27a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  color: var(--text);
  background-color: var(--background);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-size: 1.0625rem;
  line-height: 1.6;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Off screen until focused. Not display: none, which would take it out of the
   tab order. */
.skip-link {
  position: absolute;
  left: -100vw;
  top: 0;
  padding: 0.75rem 1rem;
  background-color: var(--background);
  color: var(--link);
}

.skip-link:focus {
  left: 0;
}

a {
  color: var(--link);
  text-underline-offset: 0.15em;
}

a:visited {
  color: var(--link-visited);
}

/* Page widths. The banner, menu bar and footer span up to --page-width; a
   page's text column is held to --measure for comfortable line length. */
:root {
  --page-width: 80rem;
  --panel-width: 18rem;
}

.site-header,
.main-menu > ul,
.site-footer,
.panel-layout {
  max-width: var(--page-width);
  margin-inline: auto;
  padding-inline: 1rem;
}

main {
  max-width: var(--measure);
  margin-inline: auto;
  padding: 1.5rem 1rem 3rem;
}

/* The banner: one image, drawn by scripts/build-banner.mjs, linking home. It
   has its own dark background in both colour schemes. */
.site-header {
  padding-block: 0;
}

.banner {
  display: block;
}

.banner img {
  display: block;
  width: 100%;
  height: auto;
}

/* The Main navigation: a full-width slate bar between the banner and the page,
   the same in light and dark mode. Contrast, measured: the bar against the
   white page 7.6:1 and the dark page 2.4:1; the cream text on it 6.3:1; the
   orange focus outline on it 4.3:1. The cream line along its top, the banner
   title's colour, separates it from the banner's brown bottom edge, which is
   close to the slate in lightness. */
.main-menu {
  --bar: #475569;
  --bar-text: #f3e9d2;
  --bar-focus: #ffb27a;
  background-color: var(--bar);
  border-top: 2px solid var(--bar-text);
}

.main-menu > ul > li > a,
.main-menu > ul > li > a:visited,
.main-menu summary {
  color: var(--bar-text);
}

.main-menu > ul > li > a:focus-visible,
.main-menu summary:focus-visible {
  outline-color: var(--bar-focus);
}

.main-menu > ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.75rem;
  margin-block: 0;
  list-style: none;
}

.main-menu li {
  position: relative;
}

/* Links and dropdown buttons in the bar: at least a 24px target (WCAG 2.5.8). */
.main-menu > ul > li > a,
.main-menu summary {
  display: inline-block;
  min-height: 24px;
  padding-block: 0.6rem;
}

.main-menu summary {
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

/* A chevron after each dropdown button, pointing down when closed and up when
   open. Drawn with borders and no text, so a screen reader has nothing to
   read; the button's expanded state already says whether it is open. Needed
   because display: inline-block removes the browser's own triangle. */
.main-menu summary::after {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin-inline-start: 0.5em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.2em) rotate(45deg);
}

.main-menu details[open] > summary::after {
  transform: translateY(0.1em) rotate(-135deg);
}

/* The dropdown list opens below its button, over the page. The script in
   menu.js closes it when focus leaves, so it cannot hide a focused element. */
.submenu > ul {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1;
  width: max-content;
  max-width: min(24rem, 90vw);
  margin: 0;
  padding: 0.5rem 1rem;
  list-style: none;
  background-color: var(--background);
  border: 1px solid var(--border);
}

.submenu li a {
  display: inline-block;
  min-height: 24px;
  padding-block: 0.3rem;
}

nav a[aria-current="page"] {
  font-weight: 700;
  text-decoration-thickness: 3px;
}

/* Pages with side panels (articles, and pages with contentsPanel: true): the
   panels in a left column, the page beside it. On narrow screens the column stacks above the article, in the
   same order a screen reader reads them. */
.panel-layout {
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  gap: 0 2.5rem;
  align-items: start;
}

.panel-layout main {
  margin-inline: 0;
  padding-inline: 0;
}

@media (max-width: 50rem) {
  .panel-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.side-panels {
  padding-block: 1.5rem;
}

.panel {
  margin-block-end: 1.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
}

.panel-title {
  margin: 0 0 0.5rem;
  font-weight: 700;
}

.panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.panel ul ul {
  padding-left: 1rem;
}

.panel li a {
  display: inline-block;
  min-height: 24px;
  padding-block: 0.2rem;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

h1 {
  font-size: 2rem;
  margin-block: 0 1.5rem;
}

h2 {
  font-size: 1.5rem;
  margin-block: 2.5rem 0.75rem;
}

h3 {
  font-size: 1.25rem;
  margin-block: 2rem 0.5rem;
}

/* No bullets on bulleted lists, at Joel's request, carried over from the
   original Physics, Math, and Music page. List semantics are kept by
   role="list", added to every <ul> in eleventy.config.js. Numbered lists keep
   their numbers. */
main ul {
  list-style: none;
  padding-left: 1.25rem;
}

main ul li {
  margin-bottom: 0.5rem;
}

.article-date {
  margin-block: -1rem 1.5rem;
  color: var(--text-muted);
}

/* The quotation opening the home page: as wide as its text, centred, with the
   attribution aligned to its right edge. */
.epigraph {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 1.5rem;
  padding: 1rem 1.25rem;
  background-color: var(--surface);
  border-left: 4px solid var(--border);
}

.epigraph blockquote {
  margin: 0;
  font-size: 1.2rem;
  font-style: italic;
}

.epigraph blockquote p {
  margin: 0;
}

.epigraph figcaption {
  margin-top: 0.5rem;
  text-align: end;
  color: var(--text-muted);
}

.site-footer {
  padding-block: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}

.site-footer p {
  margin-block: 0.25rem;
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  margin: 0.25rem 0;
  padding: 0;
  list-style: none;
}

.site-footer a {
  display: inline-block;
  min-height: 24px;
}

/* On touchscreens, standalone links and the dropdown buttons get 44px tall
   targets, the size Apple and Google recommend, instead of the 24px WCAG AA
   minimum used with a mouse. Links inside sentences are left alone. */
@media (pointer: coarse) {
  .main-menu > ul > li > a,
  .main-menu summary,
  .submenu li a,
  .panel li a,
  .site-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}
