/*
  \documentclass{tufte} for Lexo.
  Layout and typography follow tufte-css (https://edwardtufte.github.io/tufte-css/, MIT),
  adapted to Lexo's markup: <aside class="sidenote|marginnote">, <div class="p">, CSS-counted notes.
  A site overrides it by shipping its own assets/css/tufte.css.
*/

:root {
  --paper: #fffff8;
  --ink: #111;
  --muted: #555;
  --rule: #ccc;
  --link: #111;
  --code-bg: #f4f2e8;
  --font: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  --mono: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151515;
    --ink: #ddd;
    --muted: #999;
    --rule: #444;
    --link: #ddd;
    --code-bg: #222;
  }
}

html { font-size: 15px; }

body {
  width: 87.5%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 12.5%;
  font-family: var(--font);
  background-color: var(--paper);
  color: var(--ink);
  counter-reset: sidenote-counter;
}

/* ── Site chrome ─────────────────────────────────────────────────────────── */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
  width: 55%;
  padding: 1.5rem 0 0;
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.site-header a { text-decoration: none; }
.site-title { font-size: 1.3rem; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 1.1rem; }

.site-footer {
  width: 55%;
  margin: 4rem 0 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 1rem;
}

/* ── Title page (\begin{titlepage}) and size switches ─────────────────────── */

.titlepage {
  width: 55%;
  margin: 6rem 0 5rem;
}

.titlepage .p, .titlepage p { width: 100%; }
/* the titlepage is already one text column (55%); a figure inside takes all of it */
.titlepage figure { max-width: 100%; margin-left: 0; margin-right: 0; }

.size-small { font-size: 0.85em; }
.size-large { font-size: 1.2em; }
.size-Large { font-size: 1.44em; }
.size-LARGE { font-size: 1.73em; line-height: 1.25; }
.size-huge  { font-size: 2.07em; line-height: 1.15; }
.size-Huge  { font-size: 2.49em; line-height: 1.1; }

@media (max-width: 760px) {
  .titlepage { width: 100%; margin: 3rem 0; }
  .size-huge { font-size: 1.6em; }
  .size-Huge { font-size: 1.9em; }
}

/* ── Headings ────────────────────────────────────────────────────────────── */

h1 {
  font-weight: 400;
  margin-top: 4rem;
  margin-bottom: 1.5rem;
  font-size: 3.2rem;
  line-height: 1;
}

h2 {
  font-style: italic;
  font-weight: 400;
  margin-top: 2.1rem;
  margin-bottom: 1.4rem;
  font-size: 2.2rem;
  line-height: 1;
}

h3 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.7rem;
  margin-top: 2rem;
  margin-bottom: 1.4rem;
  line-height: 1;
}

h4 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.4rem;
  margin-top: 1.8rem;
  margin-bottom: 1rem;
  line-height: 1;
}

p.subtitle {
  font-style: italic;
  margin-top: 1rem;
  margin-bottom: 1rem;
  font-size: 1.8rem;
  display: block;
  line-height: 1;
  color: var(--muted);
}

/* ── Text column ─────────────────────────────────────────────────────────── */

article {
  padding: 2rem 0;
  position: relative;
}

section {
  padding-top: 1rem;
  padding-bottom: 1rem;
}

p, .p, dl, ol, ul {
  font-size: 1.4rem;
  line-height: 2rem;
}

p, .p {
  margin-top: 1.4rem;
  margin-bottom: 1.4rem;
  padding-right: 0;
  vertical-align: baseline;
}

article > p, article > .p, section > p, section > .p,
section > ol, section > ul, section > dl, section > blockquote,
.abstract, .toc, .tags, .chapter-nav, section > .doc-judicial {
  width: 55%;
}

section > ol, section > ul, section > dl {
  -webkit-padding-start: 5%;
  padding-inline-start: 5%;
}

li:not(:first-child) { margin-top: 0.25rem; }
dt { font-style: italic; }
dd { margin-left: 1.5rem; }

a:link, a:visited { color: var(--link); text-underline-offset: 0.1em; text-decoration-thickness: 0.05em; }

.abstract {
  font-style: italic;
  border-left: 1px solid var(--rule);
  padding-left: 1rem;
}

.newthought, .smallcaps {
  font-variant: small-caps;
  letter-spacing: 0.03em;
}

.newthought { font-size: 1.2em; }

/* ── Quotes ──────────────────────────────────────────────────────────────── */

blockquote { font-size: 1.4rem; }
blockquote p { width: 55%; margin-right: 40px; }
/* a quote placed directly in a section already is one 55% column: its paragraphs take all of it */
section > blockquote p, section > blockquote footer { width: 100%; margin-right: 0; }

blockquote footer {
  width: 55%;
  font-size: 1.1rem;
  text-align: right;
}

blockquote footer::before { content: "— "; }

/* ── Notes (tufte-latex \sidenote, \marginnote, \cite) ──────────────────── */

sup.sidenote-ref {
  counter-increment: sidenote-counter;
  font-size: 1rem;
  top: -0.5rem;
  left: 0.1rem;
  position: relative;
  vertical-align: baseline;
  line-height: 0;
}

sup.sidenote-ref::after { content: counter(sidenote-counter); }

.sidenote, .marginnote {
  float: right;
  clear: right;
  margin-right: -60%;
  width: 50%;
  margin-top: 0.3rem;
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.3;
  vertical-align: baseline;
  position: relative;
}

.sidenote--numbered::before {
  content: counter(sidenote-counter) " ";
  font-size: 1rem;
  top: -0.5rem;
  position: relative;
}

.marginnote img, .sidenote img { max-width: 100%; }

/* ── Figures ─────────────────────────────────────────────────────────────── */

figure {
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
  max-width: 55%;
  margin: 0 0 3em 0;
}

figure img, figure .iframe-wrapper { width: 100%; }

figcaption {
  float: right;
  clear: right;
  margin-top: 0;
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.6;
  vertical-align: baseline;
  position: relative;
  max-width: 40%;
  margin-right: -48%;
}

figure.fullwidth { max-width: 90%; }

figure.fullwidth figcaption {
  float: none;
  max-width: 90%;
  margin-right: 24%;
}

.fullwidth { max-width: 90%; clear: both; }
.fullwidth .p, .fullwidth p { width: auto; }

.iframe-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
}

.iframe-wrapper iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

img { max-width: 100%; }

/* ── Tables (booktabs: \toprule, \midrule, \bottomrule) ────────────────── */

.tabular {
  width: 55%;
  overflow-x: auto;
  margin: 1.4rem 0;
}

.fullwidth .tabular, figure.table.fullwidth .tabular { width: 90%; }
figure.table { max-width: 100%; }

.tabular table {
  border-collapse: collapse;
  font-size: 1.1rem;
  line-height: 1.4;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.tabular th, .tabular td {
  padding: 0.3rem 0.8rem;
  text-align: left;
  vertical-align: top;
}

.tabular thead th {
  font-weight: 400;
  font-style: italic;
  border-bottom: 1px solid var(--ink);
}

.tabular ul { font-size: inherit; line-height: inherit; margin: 0; padding-left: 1rem; }

/* ── Code ────────────────────────────────────────────────────────────────── */

code, pre > code {
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1.42;
}

pre.code {
  width: 52.5%;
  margin-left: 2.5%;
  padding: 0.5rem;
  overflow-x: auto;
  background: var(--code-bg);
}

/* ── Lists of contents ───────────────────────────────────────────────────── */

.toc ul { list-style: none; padding-left: 0; }
.toc li { font-size: 1.2rem; }
.toc .toc-level-2 { padding-left: 1.5rem; }
.toc .toc-level-3 { padding-left: 3rem; font-size: 1.1rem; }

.tag {
  font-variant: small-caps;
  margin-right: 0.8rem;
  color: var(--muted);
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  font-size: 1.2rem;
}

ul.recent { list-style: none; padding-left: 0; }
ul.recent time { color: var(--muted); font-variant: tabular-nums; }
ul.recent .summary { font-size: 1.1rem; color: var(--muted); }

/* ── Bibliography (\cite, \bibliography) ─────────────────────────────────── */

.bibliography {
  width: 55%;
  list-style: none;
  padding-left: 0;
  font-size: 1.2rem;
}

.bibliography li {
  padding-left: 2rem;
  text-indent: -2rem;
  margin-bottom: 0.6rem;
}

.cite-missing { color: #a00; }

/* ── Narrow screens: notes and captions fall into the text column ───────── */

@media (max-width: 760px) {
  body {
    width: 84%;
    padding-left: 8%;
    padding-right: 8%;
  }

  .site-header, .site-footer,
  article > p, article > .p, section > p, section > .p,
  section > ol, section > ul, section > dl, section > blockquote,
  blockquote p, blockquote footer, .abstract, .toc, .tags, .chapter-nav,
  section > .doc-judicial, .bibliography, figure, pre.code, .tabular {
    width: 100%;
    max-width: 100%;
  }

  pre.code { margin-left: 0; }

  .sidenote, .marginnote {
    display: block;
    float: left;
    left: 1rem;
    clear: both;
    width: 95%;
    margin: 1rem 2.5%;
    vertical-align: baseline;
    position: relative;
  }

  figcaption, figure.fullwidth figcaption {
    margin-right: 0;
    max-width: none;
    float: none;
  }
}
