/* ==========================================================================
   Tufte CSS — Edward Tufte Layout Engine for Static Books & Manuscripts
   ========================================================================== */

:root {
  --font-serif: "ETBook", "Cardo", "Palatino", "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  
  --bg-color: #fffff8;
  --text-color: #111111;
  --text-muted: #555555;
  --accent-color: #1976d2;
  --border-color: #e5e5dd;
}

html {
  font-size: 15px;
  background-color: var(--bg-color);
  color: var(--text-color);
  scroll-behavior: smooth;
}

body {
  width: 87.5%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 0%;
  font-family: var(--font-serif);
  background-color: var(--bg-color);
  color: var(--text-color);
  max-width: 1400px;
  counter-reset: sidenote-counter;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.book-mode {
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

h1 {
  font-weight: 400;
  margin-top: 2rem;
  margin-bottom: 1.5rem;
  font-size: 2.4rem;
  line-height: 1.2;
}

h2 {
  font-style: italic;
  font-weight: 400;
  margin-top: 2.2rem;
  margin-bottom: 1.2rem;
  font-size: 1.7rem;
  line-height: 1.25;
}

h3 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.3rem;
  margin-top: 1.8rem;
  margin-bottom: 0.8rem;
  line-height: 1.3;
}

hr {
  display: block;
  height: 1px;
  width: 55%;
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
  padding: 0;
}

p.subtitle {
  font-style: italic;
  margin-top: 1rem;
  margin-bottom: 1rem;
  font-size: 1.2rem;
  display: block;
  line-height: 1.4;
}

.numeral {
  font-family: var(--font-serif);
}

.danger {
  color: #dc2626;
}

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

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

p, ol, ul {
  font-size: 1.15rem;
  line-height: 1.75;
}

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

/* Chapter Column Width */
p, footer, table {
  width: 55%;
}

div.table-wrapper {
  overflow-x: auto;
  width: 100%;
}

@media (max-width: 760px) {
  p, footer, table {
    width: 100%;
  }
}

li {
  margin-bottom: 0.5rem;
}

ol, ul {
  width: 55%;
  -webkit-padding-start: 5%;
  -webkit-padding-end: 0%;
}

@media (max-width: 760px) {
  ol, ul {
    width: 90%;
  }
}

blockquote {
  font-size: 1.1rem;
}

blockquote p {
  width: 55%;
  margin-right: 40px;
}

blockquote footer {
  text-align: right;
}

/* Tufte Links */
a:link, a:visited {
  color: var(--accent-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Figures and Breakouts */
figure {
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
  max-width: 55%;
  -webkit-margin-start: 0;
  -webkit-margin-end: 0;
  margin: 1.5em 0;
}

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

figure.fullwidth figcaption {
  margin-right: 0%;
}

img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

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

/* Tufte Tables */
table {
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
}

table th {
  font-style: italic;
  font-weight: 600;
  border-bottom: 1px solid var(--text-color);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

/* Sidenotes & Marginnotes */
.sidenote, .marginnote {
  float: right;
  clear: right;
  margin-right: -60%;
  width: 50%;
  margin-top: 0.3rem;
  margin-bottom: 0;
  font-size: 0.9rem;
  line-height: 1.4;
  vertical-align: baseline;
  position: relative;
  color: var(--text-muted);
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number:after, .sidenote:before {
  font-family: var(--font-serif);
  position: relative;
  vertical-align: baseline;
}

.sidenote-number:after {
  content: counter(sidenote-counter);
  font-size: 0.75rem;
  top: -0.5rem;
  left: 0.1rem;
}

.sidenote:before {
  content: counter(sidenote-counter) " ";
  top: -0.5rem;
}

input.margin-toggle {
  display: none;
}

label.sidenote-number {
  display: inline-block;
  max-height: 2rem;
}

label.margin-toggle:not(.sidenote-number) {
  display: none;
}

/* Mobile Tufte Adaptations */
@media (max-width: 760px) {
  body {
    width: 92%;
    padding-left: 4%;
    padding-right: 4%;
  }

  p, footer, figure, table {
    width: 100%;
  }

  figure {
    max-width: 100%;
  }

  figcaption {
    float: none;
    clear: both;
    display: block;
    margin-right: 0%;
    margin-top: 0.5rem;
    max-width: 100%;
  }

  label.margin-toggle:not(.sidenote-number) {
    display: inline;
    cursor: pointer;
  }

  .sidenote, .marginnote {
    display: none;
  }

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