:root {
    color-scheme: light dark;

    /* ── Palette ── */
    --bg:            light-dark(#f5f0e8, #0c0c0c);
    --surface:       light-dark(#ede7d9, #1a1919);
    --surface-alt:   light-dark(#e6dece, #151515);
    --surface-hover: light-dark(#e0d8c8, #2a2828);
    --border:        light-dark(#d0c8b8, #2a2828);
    --text:          light-dark(#1c1812, #faf9f6);
    --text-muted:    light-dark(rgba(28,24,18,0.75), rgba(250,249,246,0.8));
    --link:          light-dark(#7a4f1e, wheat);
    --shadow:        light-dark(rgba(180,160,120,0.2), rgba(0,0,0,0.25));
}

body {
    margin: 0;
    color: var(--text);
    background-color: var(--bg);
    font-family: "Libertinus Math", system-ui;
    font-size: clamp(1rem, 2.5vw, 1.25rem);
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.4s ease;
}

body::before {
    background-image: url('/fundo_livros_leibowitzcodex.png');
    opacity: 0.90;
}

body::after {
    background-image: url('/fundo_livros_leibowitzcodex_dm.png');
    opacity: 0;
}

body.dark::before {
    opacity: 0;
}

body.dark::after {
    opacity: 0.20;
}

/* ensure main content sits above the pseudo-layer */
.main {
    position: relative;
    z-index: 1;
}

/* ---------- Layout ---------- */
.main {
    width: 100%;
    max-width: min(900px, 92vw);
    margin: clamp(32px, 8vh, 96px) auto;
    padding: 0 20px;
}

/* ---------- Header ---------- */
header {
    border-radius: 15px;
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    background-color: var(--surface-alt);
    padding: 16px;
}

header h1 {
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    margin: 0;
    text-align: center;
}

/* ---------- Navigation ---------- */
.nav-back {
    margin: 16px 0 32px 0;
}

button {
    background-color: var(--surface);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 12px 20px;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s;
}

button:hover {
    color: var(--text);
    background-color: var(--surface-hover);
}

/* ---------- Book Content ---------- */
.book-content {
    padding-top: 12px;
    text-align: justify;
}

.book-content p {
    line-height: 1.7;
    margin-bottom: 1em;
}

.book-content h1,
.book-content h2,
.book-content h3,
.book-content h4,
.book-content h5,
.book-content h6 {
    margin-top: 1.6em;
    margin-bottom: 0.6em;
}

/* ---------- Images ---------- */
.book-content img {
    width: min(100%, 520px);
    margin: 24px auto;
    display: block;
}

/* ---------- MathJax ---------- */
mjx-container[display="true"] {
    font-size: clamp(1.1rem, 3vw, 1.4rem) !important;
}

/* ---------- Callouts ---------- */
aside,
.callout-box-table,
table {
    padding: 20px;
    margin: 24px auto;
    border: 2px solid var(--border);
    background-color: var(--bg);
    box-shadow: 4px 4px 8px var(--shadow);
    max-width: 100%;
    min-width: 95%;
}

blockquote {
    padding: 20px;
    margin: 24px auto;
    border: 2px solid var(--border);
    background-color: var(--bg);
    box-shadow: 4px 4px 8px var(--shadow);
    max-width: 100%;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
    .book-content {
        text-align: left;
    }
}

/* latex formatting */

.math-display {
  text-align: center;
  margin: 1.5em 0;
}

.math-display mjx-container {
  font-size: 1.1em;
}

/* links */
a {
    color: var(--link);
    text-decoration: none;
}

/* table of contents */
.toc {
  background: var(--bg-paper, #f5f0e8);
  border: 1px solid var(--border, #c8b99a);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}

.toc-title {
  display: block;
  font-family: 'Libertinus Math', serif;
  font-size: 1.4rem;
  margin-bottom: 0.6rem;
  color: var(--text, #2a2a2a);
}

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

.toc li {
  line-height: 1.7;
}

.toc-h1 { padding-left: 0; }
.toc-h2 { padding-left: 1.2rem; }
.toc-h3 { padding-left: 2.4rem; }

.toc a {
  text-decoration: none;
  color: var(--link, #5a4a2a);
  font-size: 1.2rem;
  transition: color 0.2s;
}

.toc a:hover,
.toc a.toc-active {
  color: var(--accent, #8a6a2a);
  text-decoration: underline;
}

body.dark .toc {
  background-color: var(--bg);
  border-color: var(--border);
}

.smiles {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
  margin: 1em auto;
}