/* lawcourse — design system
   Spec: lawcourse-build-spec.md §6–7. Palette is six values; oxblood
   appears only in .error-block. Grey never carries normal-size text on
   stone-deep grounds (4.39:1 — fails AA; see docs/plans build plan). */

/* ---------- Fonts ---------- */

@font-face {
  font-family: 'Literata';
  src: url('fonts/literata-var.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Literata';
  src: url('fonts/literata-italic-var.woff2') format('woff2');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-semibold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */

:root {
  --stone: #F4F0E8;
  --stone-deep: #E7E1D5;
  --ink: #1C1A17;
  --navy: #152A47;
  --oxblood: #6E2231;
  --grey: #6A665E;

  --font-body: 'Literata', Georgia, 'Times New Roman', serif;
  --font-ui: 'IBM Plex Sans', -apple-system, 'Segoe UI', sans-serif;

  --measure: 70ch;
  --rail-w: 220px;
  --gap: 1.25rem;
}

/* ---------- Reset & base ---------- */

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

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.7;
  text-align: left;
}

@media (min-width: 768px) {
  body { font-size: 19px; }
}

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

p, ul, ol, dl { margin: 0 0 1.1em; }

ul, ol { padding-left: 1.4em; }

li { margin-bottom: 0.35em; }

em, cite, i { font-style: italic; }

cite { font-style: italic; }

strong { font-weight: 600; }

a {
  color: var(--navy);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

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

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

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

/* ---------- Headings ---------- */

h1 {
  font-size: 1.75rem;
  line-height: 1.25;
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 0.5em;
}

/* The seven repeating section headings. Small caps live here and
   nowhere else — the treatment encodes structure. */
h2 {
  font-variant-caps: small-caps;
  font-synthesis: none;
  letter-spacing: 0.02em;
  color: var(--navy);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.9em;
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--navy);
  margin: 1.6em 0 0.5em;
}

/* ---------- Page scaffold ---------- */

.page-head {
  padding: 1.1rem var(--gap) 0.4rem;
  max-width: calc(var(--measure) + var(--rail-w) + 6rem);
  margin: 0 auto;
}

.page-head .home-link {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--grey);
  text-decoration: none;
}

.page-head .home-link:hover { color: var(--navy); text-decoration: underline; }

.page-head .doc-part {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--grey);
  margin: 0.9rem 0 0.15rem;
}

.page-head h1 { margin-bottom: 0.2em; }

.page-head .doc-standfirst {
  font-size: 1.05rem;
  color: var(--grey);
  font-style: italic;
  margin: 0 0 0.8em;
  max-width: var(--measure);
}

/* ---------- Sticky module nav ---------- */

.module-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--stone);
  border-top: 1px solid var(--stone-deep);
  border-bottom: 1px solid var(--navy);
  font-family: var(--font-ui);
}

.module-nav ol {
  list-style: none;
  margin: 0 auto;
  padding: 0 var(--gap);
  max-width: calc(var(--measure) + var(--rail-w) + 6rem);
  display: flex;
  gap: 1.1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.module-nav ol::-webkit-scrollbar { display: none; }

.module-nav li { margin: 0; flex: none; }

.module-nav a {
  display: block;
  padding: 0.55rem 0 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--grey);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.module-nav a:hover { color: var(--navy); }

.module-nav a[aria-current] {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

/* ---------- Content column + rail ---------- */

main.doc {
  padding: 1.6rem var(--gap) 3rem;
  max-width: calc(var(--measure) + var(--rail-w) + 6rem);
  margin: 0 auto;
}

.doc-section {
  padding: 0.4rem 0 1.2rem;
}

.doc-section > .body { max-width: var(--measure); }

/* Horizontal rules separate the seven sections and appear nowhere else. */
hr {
  border: 0;
  border-top: 1px solid var(--navy);
  opacity: 0.35;
  margin: 1.4rem 0;
  max-width: var(--measure);
}

.rail { display: none; }

@media (min-width: 900px) {
  .doc-section {
    display: grid;
    grid-template-columns: minmax(0, var(--measure)) var(--rail-w);
    column-gap: 3rem;
  }
  .doc-section > h2 { grid-column: 1 / -1; }
  .doc-section > .body { grid-column: 1; }
  .rail {
    display: block;
    grid-column: 2;
    grid-row: 2;
    position: relative;
    background: var(--stone-deep);
    border-radius: 2px;
    padding: 0.9rem 0.85rem;
    align-self: stretch;
    font-family: var(--font-ui);
  }
  /* Rail text sits on stone-deep: navy + ink only (grey fails AA here). */
  .rail-note {
    font-size: 0.8125rem;
    line-height: 1.45;
    margin: 0 0 0.85em;
    color: var(--ink);
  }
  .rail-note cite {
    display: block;
    font-style: italic;
    font-weight: 500;
    color: var(--navy);
  }
  .rail.is-aligned { padding-top: 0; padding-bottom: 0; background: none; }
  .rail.is-aligned .rail-note {
    position: absolute;
    left: 0;
    width: 100%;
    background: var(--stone-deep);
    border-radius: 2px;
    padding: 0.5rem 0.85rem 0.45rem;
  }
}

/* ---------- Case chip ---------- */

.case {
  font-style: italic;
  text-decoration: underline;
  text-decoration-color: var(--grey);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* JS adds .is-chip once the reveal behaviour exists. */
.case.is-chip { cursor: pointer; }

.case.is-chip[aria-expanded="true"] { text-decoration-thickness: 2px; }

.case-note {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--stone-deep);
  border-radius: 2px;
  padding: 0.5rem 0.7rem;
  margin: 0.4em 0 0.8em;
  max-width: 34em;
}

.case-note cite { font-weight: 500; color: var(--navy); }

/* On desktop the rail mirrors the chips; the inline note still works
   for keyboard/AT users, so it is not display-locked. */

/* ---------- Glossary term ---------- */

.gloss {
  text-decoration: underline dotted;
  text-decoration-color: var(--grey);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.gloss.is-chip { cursor: pointer; }

.gloss-def {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--stone-deep);
  border-radius: 2px;
  padding: 0.5rem 0.7rem;
  margin: 0.4em 0 0.8em;
  max-width: 34em;
}

/* ---------- Self-test (section 7) ---------- */

.selftest {
  border: 1px solid var(--stone-deep);
  border-radius: 2px;
  margin: 0 0 1rem;
  max-width: var(--measure);
}

.selftest summary {
  cursor: pointer;
  padding: 0.85rem 1rem;
  font-weight: 500;
  list-style-position: outside;
}

.selftest summary::marker { color: var(--navy); }

.selftest[open] summary { border-bottom: 1px solid var(--stone-deep); }

.selftest .selftest-answer {
  padding: 0.85rem 1rem 0.3rem;
  font-size: 0.95em;
}

.selftest .selftest-answer > p:first-child::before {
  content: "What a good answer contains — ";
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--navy);
}

/* ---------- Error block (section 6 — the only home of oxblood) ---------- */

.error-block {
  border-left: 4px solid var(--oxblood);
  background: var(--stone-deep);
  padding: 0.9rem 1.1rem 0.4rem;
  margin: 0 0 1.1rem;
  max-width: var(--measure);
}

.error-block > p:first-child strong:first-child,
.error-block > .error-title {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--oxblood);
  margin-bottom: 0.25em;
}

/* ---------- Worked example (A2) ---------- */

.worked-q {
  background: var(--stone-deep);
  border-radius: 2px;
  padding: 0.9rem 1.1rem 0.4rem;
  margin: 0 0 1.1rem;
  max-width: var(--measure);
}

.worked {
  border-left: 3px solid var(--stone-deep);
  padding-left: 1rem;
  margin: 0 0 1.1rem;
  max-width: var(--measure);
}

/* ---------- Case working set + decoder lists ---------- */

.case-list { list-style: none; padding-left: 0; }

.case-list li {
  padding-left: 1.1em;
  text-indent: -1.1em;
  margin-bottom: 0.55em;
}

.case-list cite { color: var(--navy); }

.decoder dt {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--navy);
}

.decoder dd {
  margin: 0.1em 0 0.8em;
}

/* ---------- Footer ---------- */

.site-foot {
  border-top: 1px solid var(--stone-deep);
  margin-top: 2rem;
  padding: 1.2rem var(--gap) 2.5rem;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--grey);
}

.site-foot .inner {
  max-width: calc(var(--measure) + var(--rail-w) + 6rem);
  margin: 0 auto;
}

.site-foot a { color: var(--grey); }

.site-foot a:hover { color: var(--navy); }

/* ---------- Index page ---------- */

.hero-citation {
  max-width: var(--measure);
  margin: 1.5rem 0 0.5rem;
}

.citation-line {
  font-size: 1.35rem;
  line-height: 1.4;
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.55em;
  row-gap: 1.1em;
  align-items: stretch;
}

.citation-line .part {
  display: flex;
  flex-direction: column;
}

.citation-line .part > .label {
  margin-top: 0.4em;
  font-family: var(--font-ui);
  font-style: normal;
  font-weight: 400;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--grey);
  max-width: 10em;
  border-top: 1px solid var(--grey);
  padding-top: 0.35em;
}

@media (max-width: 600px) {
  .citation-line { font-size: 1.1rem; }
  .citation-line .part > .label { max-width: 9em; }
}

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  max-width: var(--measure);
}

.doc-list li {
  margin: 0 0 0.9rem;
}

.doc-list .doc-code {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--navy);
  display: inline-block;
  min-width: 2.2em;
}

.doc-list a { font-weight: 500; }

.doc-list .doc-line {
  display: block;
  color: var(--grey);
  font-size: 0.95em;
  margin-left: 2.7em;
}

.index-note {
  max-width: var(--measure);
  font-size: 0.95em;
  color: var(--grey);
}
