/* FRANKLIN — the one shared stylesheet.
 *
 * Card FR-1 requires responsive semantic HTML with a clean typographic
 * hierarchy, a print stylesheet, and no JavaScript required to read. This file
 * is the whole presentation layer; it is committed, served at
 * /assets/franklin.css, and compiled into the service binary so the deployed
 * image has no runtime dependency on the filesystem.
 *
 * The measure of this design is legibility of a legal text at any width. The
 * indentation a reader sees is a consequence of real structural nesting, not
 * of margins guessed at, so a subsection always sits inside its section and a
 * clause always sits inside its paragraph.
 */

:root {
  --ink:           #12100c;
  --ink-soft:      #4a453c;
  --ink-faint:     #756e61;
  --ground:        #fbfaf7;
  --ground-raised: #ffffff;
  --rule:          #ddd8cd;
  --rule-soft:     #eae6dc;
  --accent:        #7a2718;
  --accent-soft:   #f3ece9;
  --quote-ground:  #f5f2ea;

  --serif: "Century Schoolbook", "New Century Schoolbook", Georgia,
           "Times New Roman", Times, serif;
  --sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial,
           sans-serif;
  --mono:  ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 38rem;
  --gutter: 1.25rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:           #eae5da;
    --ink-soft:      #b8b1a3;
    --ink-faint:     #8b8474;
    --ground:        #14130f;
    --ground-raised: #1c1a15;
    --rule:          #37342c;
    --rule-soft:     #2a2822;
    --accent:        #e08b76;
    --accent-soft:   #2a1d19;
    --quote-ground:  #1f1d17;
  }
}

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

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

body {
  margin: 0;
  padding: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem var(--gutter);
  border-bottom: 1px solid var(--rule);
  background: var(--ground-raised);
  font-family: var(--sans);
}

.masthead__home {
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.8125rem;
  color: var(--ink);
  text-decoration: none;
}
.masthead__home:hover { color: var(--accent); }

.masthead__rule { flex: 0 0 1.5rem; height: 1px; background: var(--rule); }

.masthead__sub {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ layout */

main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 2rem var(--gutter) 5rem;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

code { font-family: var(--mono); font-size: 0.875em; }

/* ---------------------------------------------------------- identification */

.identification {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
}

.identification__citation {
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.identification__title {
  font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.25rem);
  line-height: 1.2;
  margin: 0 0 0.75rem;
  font-weight: 700;
  text-wrap: balance;
}

.identification__official {
  font-size: 1rem;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 1rem;
  max-width: var(--measure);
}

.identification__facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1rem;
  margin: 1rem 0 0;
  font-family: var(--sans);
  font-size: 0.8125rem;
}
.identification__facts dt {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.6875rem;
  padding-top: 0.15rem;
}
.identification__facts dd { margin: 0; color: var(--ink-soft); }

.identification__links {
  margin: 1.25rem 0 0;
  font-family: var(--sans);
  font-size: 0.8125rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------- the measure */

.document { max-width: var(--measure); }

.level {
  margin: 1.5rem 0;
  /* Nested levels indent. The indent is structural: a subsection is inside a
     section in the markup, so it is inside it on the page. */
  padding-left: 0;
}
.level .level {
  padding-left: 1.5rem;
  border-left: 1px solid var(--rule-soft);
  margin: 0.9rem 0;
}

.level__head {
  font-family: var(--sans);
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 0.5rem;
  position: relative;
  text-wrap: pretty;
}

.level--title > .level__head,
.level--subtitle > .level__head,
.level--division > .level__head {
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin-top: 2.5rem;
}

.level--section > .level__head { font-size: 1.0625rem; }
.level--subsection > .level__head,
.level--paragraph > .level__head,
.level--subparagraph > .level__head,
.level--clause > .level__head,
.level--subclause > .level__head {
  font-size: 0.9375rem;
  font-weight: 600;
}

.level__anchor {
  position: absolute;
  left: -1.15rem;
  top: 0;
  color: var(--rule);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 120ms ease-in-out;
}
.level:hover > .level__head > .level__anchor,
.level__anchor:focus { opacity: 1; color: var(--accent); }

/* Always visible on touch, where there is no hover to reveal it. */
@media (hover: none) {
  .level__anchor { opacity: 1; color: var(--rule); }
}

.level:target {
  background: var(--accent-soft);
  border-radius: 3px;
  box-shadow: 0 0 0 0.5rem var(--accent-soft);
}

.enum { font-variant-numeric: tabular-nums; }
.heading { font-weight: inherit; }

.text { margin: 0.65rem 0; text-wrap: pretty; }

/* The lead paragraph of a level carries the enumerator that numbers it, run
   in as legislative typography sets it, with the self-link hung in the
   margin beside it. */
.text--lead { position: relative; margin-top: 0.35rem; }
.text--lead > .enum { font-weight: 600; }
.text--lead > .level__anchor { top: 0; }
.text.chapeau { margin-bottom: 0.4rem; }
.text.continuation { margin-top: 0.4rem; }

.official-title {
  font-style: italic;
  color: var(--ink-soft);
  margin: 1rem 0;
}

.enacting {
  font-variant: small-caps;
  letter-spacing: 0.01em;
  margin: 1.25rem 0;
}

.whereas { margin: 0.65rem 0; }

.quoted-block {
  margin: 1rem 0;
  padding: 0.85rem 1.1rem;
  background: var(--quote-ground);
  border-left: 3px solid var(--rule);
  border-radius: 2px;
  font-size: 0.9375rem;
}
.quoted-block .level { margin: 0.6rem 0; }

.quote { quotes: "\201C" "\201D" "\2018" "\2019"; }

.amendment { margin: 0.75rem 0; }

.ref { text-decoration-style: dotted; }

.note {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.preface {
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--ink-soft);
  margin-bottom: 2rem;
}
.preface .text { margin: 0.35rem 0; }

.closing {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

.actor { font-weight: 600; }
.smallcaps { font-variant: small-caps; }
.centered { text-align: center; }
.marker { color: var(--ink-faint); font-size: 0.75em; }

.toc {
  font-family: var(--sans);
  font-size: 0.875rem;
  margin: 1.5rem 0;
  padding-left: 0;
}
.toc .toc { padding-left: 1.25rem; }

/* Structure FRANKLIN did not recognise is shown, and shown as unrecognised. */
.unknown {
  border-left: 2px dashed var(--rule);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
}
.unknown::before {
  content: "<" attr(data-element) ">";
  display: block;
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; margin: 1.25rem 0; }

table { border-collapse: collapse; width: 100%; font-size: 0.875rem; }
th, td {
  text-align: left;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}
thead th {
  font-family: var(--sans);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------- index */

.index h1 {
  font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.5rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.015em;
}

.lede {
  font-size: 1.125rem;
  color: var(--ink-soft);
  max-width: 44rem;
  margin: 0 0 2.5rem;
  text-wrap: pretty;
}

.index h2 {
  font-family: var(--sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  margin: 2.5rem 0 1rem;
}

.figures__note, .listing__note, .figures__run {
  font-size: 0.875rem;
  color: var(--ink-faint);
  max-width: 44rem;
}

.figures__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1px;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
  margin: 1.25rem 0;
}

.figure {
  background: var(--ground-raised);
  padding: 1rem 1.1rem;
}
.figure dt {
  font-family: var(--sans);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}
.figure dd { margin: 0; }
.figure__value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.figure__detail {
  display: block;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.counts__table { max-width: 34rem; }
.listing__table td.cite { white-space: nowrap; font-weight: 600; }
.listing__table td.formats { white-space: nowrap; font-family: var(--sans); font-size: 0.75rem; }

/* -------------------------------------------------------------- provenance */

.provenance {
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-faint);
  line-height: 1.5;
}
.provenance p { margin: 0.35rem 0; max-width: 44rem; }

/* ------------------------------------------------------------------ narrow */

@media (max-width: 34rem) {
  body { font-size: 1rem; }
  main { padding: 1.5rem var(--gutter) 3rem; }
  .level .level { padding-left: 0.9rem; }
  .level__anchor { display: none; }
  .identification__facts { grid-template-columns: 1fr; gap: 0 0; }
  .identification__facts dt { margin-top: 0.5rem; }
  .figure__value { font-size: 1.5rem; }
}

/* ------------------------------------------------------------------- print */

@media print {
  :root {
    --ink: #000;
    --ink-soft: #222;
    --ink-faint: #555;
    --ground: #fff;
    --ground-raised: #fff;
    --rule: #999;
    --rule-soft: #ccc;
    --accent: #000;
    --accent-soft: #fff;
    --quote-ground: #f4f4f4;
  }

  @page { margin: 20mm 18mm; }

  body { font-size: 11pt; line-height: 1.45; background: #fff; }
  main { max-width: none; padding: 0; }

  .masthead,
  .identification__links,
  .level__anchor,
  .listing__table td.formats { display: none; }

  a { color: #000; text-decoration: none; }
  /* A printed page cannot be clicked, so external destinations are spelled
     out. Internal anchors are not: the reader is holding the document. */
  .ref[href^="http"]::after {
    content: " <" attr(href) ">";
    font-family: var(--mono);
    font-size: 0.75em;
    color: #555;
  }

  .identification { border-bottom-width: 1.5pt; }
  .level { break-inside: avoid-page; }
  .level--title > .level__head,
  .level--section > .level__head { break-after: avoid-page; }
  .level:target { background: none; box-shadow: none; }
  .quoted-block { break-inside: avoid-page; }
  table { break-inside: auto; }
  tr { break-inside: avoid; break-after: auto; }
  thead { display: table-header-group; }
  .provenance { break-before: avoid; }
}

/* ---------------------------------------------------------- accessibility */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

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