/* Teach Me Maths: the maths exercise book.
   Design tokens first; change a colour or size here and it changes everywhere. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-400.63730b9efc0d.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-700.fed09c9882e4.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Colour */
  --paper: #ffffff;        /* page background */
  --grid: #e4eaf2;         /* table rules and borders */
  --ink: #1c2b45;          /* text */
  --ink-soft: #4a5872;     /* secondary text (7:1 on white) */
  --biro: #2b55c9;         /* links and buttons */
  --highlighter: #ffe35a;  /* the one accent: marks the newest series */
  --teal-pale: #e1eded;    /* 13% brand teal on white: the row under the cursor */
  --teal: #137475;         /* brand colour, from the logo */

  /* Type */
  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-sm: 0.9375rem;
  --text-base: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.625rem;
  --text-2xl: clamp(1.75rem, 1.2rem + 2.2vw, 2.5rem);
  --text-hero: clamp(1.6875rem, 1.2rem + 2.2vw, 2.5rem); /* home page heading */

  /* Space and layout */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --doodle-size: 640px;    /* one tile of the doodle background (static/img/doodle.svg) */
  --radius: 6px;
  --page-width: 72rem;
  --measure: 68ch;         /* comfortable line length for reading */
  --focus: 3px solid var(--biro);
}

/* Base ------------------------------------------------------------------ */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.55;
}

main {
  flex: 1;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-4);
}

h1 {
  font-size: var(--text-2xl);
}

h2 {
  font-size: var(--text-xl);
  margin-top: var(--space-8);
}

p,
ul {
  margin: 0 0 var(--space-4);
}

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

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

/* The hidden attribute always wins, even over an element's own display rule. */
[hidden] {
  display: none !important;
}

.wrap {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.page {
  padding-top: var(--space-6);
  padding-bottom: var(--space-12);
}

.prose > * {
  max-width: var(--measure);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -3rem;
  padding: var(--space-2) var(--space-4);
  background: var(--paper);
  z-index: 10;
}

.skip-link:focus {
  top: var(--space-2);
}

/* Header and footer ------------------------------------------------------ */

.site-header {
  border-bottom: 1px solid var(--grid);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap; /* if the name and menu can't share a line, the menu drops below */
  align-items: center;
  justify-content: space-between;
  column-gap: var(--space-4);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}

@media (max-width: 30rem) {
  .site-header__inner {
    column-gap: var(--space-3); /* a little more room for the name on small phones */
  }
}

/* The narrowest phones (under ~370px): slightly smaller menu text so the
   name and "Past Papers" still share one line. */
@media (max-width: 23rem) {
  .site-nav a {
    font-size: var(--text-sm);
  }
}

/* The site name, in place of a logo image. */
.site-header__name {
  color: var(--teal);
  font-size: calc(var(--text-hero) * 1.08); /* very slightly bigger than the home heading */
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap; /* always one line */
  padding: var(--space-2) 0;
}

.site-header__name:hover {
  text-decoration: underline;
}

.site-nav {
  display: flex;
  gap: var(--space-6);
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  padding: var(--space-2) 0;
}

.site-nav a:hover {
  color: var(--biro);
  text-decoration: underline;
}

.site-footer {
  border-top: 1px solid var(--grid);
  color: var(--ink-soft);
  font-size: var(--text-sm);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-8);
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

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

.site-footer__links {
  display: flex;
  gap: var(--space-4);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-2);
}

/* Home ------------------------------------------------------------------ */

/* Faint maths doodles (signs, shapes, pi, y = mx + c ...) on white, like the
   WhatsApp chat wallpaper. The tile repeats seamlessly; its colour is set in
   tools/make_doodle.py, which draws it. */
.doodle {
  background-color: var(--paper);
  background-image: url("../img/doodle.8b69417548f4.svg");
  background-size: var(--doodle-size) var(--doodle-size);
}

/* Paper pages: doodles only in the side margins. The content column is a
   white sheet running from the header to the footer. */
.doodle--sides {
  display: flex;
  flex-direction: column;
}

.doodle--sides > .page {
  flex: 1;
  background: var(--paper);
}

.hero {
  padding: var(--space-12) 0;
}

/* The home heading breaks where the meaning breaks:
   wider screens:  Maths past papers and mark schemes / for GCSE, A Level and IGCSE
   phones:         Maths past papers / and mark schemes for / GCSE, A Level and IGCSE */
.hero__title {
  font-size: var(--text-hero); /* 27px minimum so line 3 fits a 360px phone */
  text-wrap: balance; /* if a line still has to wrap, split it evenly */
}

.hero__title .phone-break {
  display: none;
}

@media (max-width: 30rem) {
  .hero__title .phone-break {
    display: inline;
  }

  .hero__title .wide-break {
    display: none;
  }
}

.hero__lead {
  font-size: var(--text-lg);
  margin-bottom: var(--space-8);
}

.choose {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--space-4);
  scroll-margin-top: var(--space-4);
}

.choose__card {
  background: var(--paper);
  border: 1px solid var(--grid);
  border-top: 4px solid var(--teal);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-6) var(--space-6);
}

.choose__title {
  font-size: var(--text-xl);
  margin: 0 0 var(--space-3);
}

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

.choose__boards a {
  display: block;
  padding: var(--space-2) 0;
  font-size: var(--text-lg);
  font-weight: 700;
}

.choose__also {
  margin: var(--space-3) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--grid);
}

/* A note under the cards (worksheets chooser). */
.choose__note {
  margin: var(--space-6) 0 0;
  color: var(--ink-soft);
}

/* Home page: two cards, Past Papers and Worksheets. */
.choose--two {
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  max-width: 44rem;
}

.choose--two .choose__title a {
  display: block;
  font-size: var(--text-xl);
  text-decoration: none;
}

.choose--two .choose__title a:hover {
  text-decoration: underline;
}

.choose--two p {
  margin: 0;
}

/* The past papers page: a hero that sits closer to the header, with breadcrumbs. */
.hero--inner {
  padding-top: var(--space-6);
}

/* Board page ------------------------------------------------------------ */

.breadcrumbs {
  font-size: var(--text-sm);
  color: var(--ink-soft);
  margin-bottom: var(--space-4);
}

.spec-code {
  font-weight: 400;
  color: var(--ink-soft);
}

.board-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
}

.board-bar__formulae {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.board-bar__note {
  margin: 0;
  color: var(--ink-soft);
}

/* Phones: the second sentence ("Foundation topics are also listed.") starts a new line. */
@media (max-width: 44rem) {
  .board-bar__also {
    display: block;
  }
}

/* Two-way switch (Higher | Foundation, A Level | AS Level). Plain links, no JavaScript. */
.switch {
  display: inline-flex;
  border: 2px solid var(--biro);
  border-radius: var(--radius);
  overflow: hidden;
}

.switch a {
  padding: var(--space-2) var(--space-4);
  font-weight: 700;
  text-decoration: none;
  min-width: 6.5rem;
  text-align: center;
}

.switch a + a {
  border-left: 2px solid var(--biro);
}

.switch a[aria-current="page"] {
  background: var(--biro);
  color: var(--paper);
}

.switch a:not([aria-current]):hover {
  background: var(--grid);
}

.switch a:focus-visible {
  outline-offset: -5px;
  outline-color: var(--highlighter);
}

/* The paper grid: one row per series, one column per paper. */
.paper-grid {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.paper-grid th,
.paper-grid td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--grid);
}

.paper-grid thead th {
  font-size: var(--text-sm);
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
}

.paper-grid tbody th {
  white-space: nowrap;
}

.paper-grid tbody th a {
  color: var(--ink);
  font-weight: 700;
}

/* The row you're looking at… */
.paper-grid tbody tr:hover > *,
.paper-grid tbody tr:focus-within > * {
  background: var(--teal-pale);
}

/* …and the newest series, marked like a highlighter pen across the name. */
.is-newest th a {
  background: var(--highlighter);
  padding: 0 var(--space-1);
  margin: 0 calc(-1 * var(--space-1));
  box-decoration-break: clone;
}

.newest-tag {
  display: block;
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--ink-soft);
}

.doc-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.doc-link {
  display: inline-block;
  padding: var(--space-1) 0;
}

/* Phones: each series becomes its own block with its papers listed inside. */
@media (max-width: 44rem) {
  .paper-grid,
  .paper-grid tbody,
  .paper-grid tr,
  .paper-grid th,
  .paper-grid td {
    display: block;
  }

  .paper-grid thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .paper-grid tbody tr {
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    overflow: hidden;
  }

  .paper-grid tbody th {
    font-size: var(--text-lg);
    background: var(--paper);
    border-bottom: 2px solid var(--ink);
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
  }

  .newest-tag {
    display: inline;
  }

  .paper-grid td {
    display: grid;
    grid-template-columns: minmax(6rem, 40%) 1fr;
    gap: var(--space-4);
  }

  .paper-grid td::before {
    content: attr(data-label);
    font-weight: 700;
  }

  .paper-grid td:last-child {
    border-bottom: 0;
  }

  .paper-grid td.is-empty {
    display: none;
  }
}

/* Series page ------------------------------------------------------------ */

.series-group h2 {
  margin-top: var(--space-6);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--ink);
}

.series-papers {
  list-style: none;
  padding: 0;
}

.series-paper {
  display: grid;
  grid-template-columns: minmax(8rem, 16rem) 1fr;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}

.series-paper:hover {
  background: var(--teal-pale);
}

.series-paper__name {
  font-weight: 700;
}

.series-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin: var(--space-8) 0 var(--space-4);
}

.series-nav__newer {
  margin-left: auto;
}

/* Worksheets -------------------------------------------------------------- */

/* Jump links to each strand (Number, Algebra …). */
.strand-nav ul {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  font-size: var(--text-sm);
}

.strand h2 {
  margin-top: var(--space-8);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--ink);
  scroll-margin-top: var(--space-4);
}

/* One row per worksheet: name on the left, the two PDF links on the right. */
.sheet-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sheet {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: var(--space-2) var(--space-6);
  padding: var(--space-3) var(--space-2);
  margin: 0 calc(-1 * var(--space-2));
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}

.sheet:hover,
.sheet:focus-within {
  background: var(--teal-pale);
}

.sheet__name a {
  color: var(--ink);
  font-weight: 700;
}

.sheet__meta {
  display: inline-block;
  margin-left: var(--space-2);
  color: var(--ink-soft);
  font-size: var(--text-sm);
}

/* Grade filter, sort and search (shown by static/js/worksheets.js). */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-6);
  align-items: flex-end;
  margin-bottom: var(--space-6);
  padding: var(--space-4);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
}

.controls__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.controls__field--search {
  flex: 1 1 14rem;
}

.controls label {
  font-size: var(--text-sm);
  font-weight: 700;
}

.controls select,
.controls input {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink-soft);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  min-height: 2.75rem;
}

.controls input {
  width: 100%;
}

.controls select:focus-visible,
.controls input:focus-visible {
  border-color: var(--biro);
  outline: var(--focus);
  outline-offset: 2px;
}

/* "× Reset filters": grey text under the controls, only while something is applied. */
.controls__reset {
  flex-basis: 100%;
  align-self: flex-start;
  width: max-content;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink-soft);
  cursor: pointer;
}

.controls__reset:hover {
  color: var(--biro);
  text-decoration: underline;
}

.no-match {
  padding: var(--space-4);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
}

.button--small {
  padding: var(--space-1) var(--space-4);
  margin-left: var(--space-2);
}

/* Small labels beside a title: grade, strand (in the flat views), tier. */
.tag,
.tier-tag {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 0 var(--space-2);
  border: 1px solid var(--ink-soft);
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: var(--text-sm);
  line-height: 1.4;
  vertical-align: 0.1em;
}

.grade-tag {
  border-color: var(--teal);
  color: var(--teal);
}

/* The strand label only earns its place when the list isn't grouped by strand. */
.sheets--strand .strand-tag {
  display: none;
}

/* Phones: title, then the tags, then the question count, each on its own line, with the links below. */
@media (max-width: 44rem) {
  .sheet {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .sheet__name a {
    display: inline-block;
  }

  .sheet__tags,
  .sheet__meta {
    display: block;
    margin: var(--space-1) 0 0;
  }

  .sheet__tags .tag,
  .sheet__tags .tier-tag {
    margin: 0 var(--space-2) 0 0;
  }
}

/* One worksheet's page: the two PDF buttons and its details. */
.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-6) 0;
}

.button {
  display: inline-block;
  padding: var(--space-2) var(--space-6);
  border: 2px solid var(--biro);
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
}

.button:first-child {
  background: var(--biro);
  color: var(--paper);
}

.button:hover {
  text-decoration: underline;
}

/* The sheet's facts: course, strand and grade in bold, one per line; then
   "15 questions, 32 marks, 6 pages" in grey underneath. */
.facts {
  max-width: var(--measure);
  margin: 0 0 var(--space-8);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}

.facts__main {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0;
  font-weight: 700;
  line-height: 1.7;
}

.facts__meta {
  margin: 0;
  color: var(--ink-soft);
}

/* Other pages ------------------------------------------------------------ */

.company {
  font-style: normal;
  color: var(--ink-soft);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
