:root {
  color-scheme: light dark;
  --paper: #fffdf8;
  --ink: #17202a;
  --muted: #4b5563;
  --accent: #175a70;
  --accent-dark: #0d3f51;
  --soft: #e8f3f6;
  --line: #b8c5cb;
  --focus: #d97706;
  font-family: Charter, "Noto Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(1rem, 0.97rem + 0.2vw, 1.15rem);
  line-height: 1.68;
}

a { color: #075e83; text-underline-offset: 0.15em; }
a:hover { color: #943b00; }
a:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 10;
  padding: 0.65rem 1rem;
  background: var(--ink);
  color: white;
}
.skip-link:focus { top: 1rem; }

.reader-header {
  padding: clamp(2rem, 7vw, 5.5rem) max(1rem, calc((100vw - 72rem) / 2));
  color: white;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
}
.reader-header h1 { max-width: 23ch; margin: 0.25rem 0; font-size: clamp(2rem, 5vw, 4.5rem); line-height: 1.08; }
.eyebrow { margin: 0; font: 700 0.85rem/1.3 system-ui, sans-serif; letter-spacing: 0.11em; text-transform: uppercase; }
.byline { margin: 0.75rem 0 0; font-family: system-ui, sans-serif; }

.unit-nav {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(0.7rem);
  font: 650 0.9rem/1.4 system-ui, sans-serif;
}

main, footer { width: min(100% - 2rem, 72rem); margin-inline: auto; }
main { padding-block: clamp(1.5rem, 4vw, 3.5rem); }
.chapter, #dukungan-belajar { width: min(100%, 48rem); margin-inline: auto; }

.edition-notice {
  width: min(100%, 60rem);
  margin: 0 auto 3rem;
  padding: 1rem 1.25rem;
  border-inline-start: 0.35rem solid var(--accent);
  background: var(--soft);
  font-family: system-ui, sans-serif;
  font-size: 0.92em;
}
.edition-notice h2 { margin-top: 0; font-size: 1.2rem; }

h2, h3 { line-height: 1.25; scroll-margin-top: 5rem; }
[id] { scroll-margin-top: 5rem; }
.chapter > h2 { margin-top: 2.7em; font-size: clamp(1.5rem, 3vw, 2.15rem); color: var(--accent-dark); }
.chapter > h2[id*="-PRJ"] { text-align: center; }
.chapter > h3 { margin-top: 2em; }
.chapter p { hyphens: auto; }
.chapter li + li { margin-top: 0.45rem; }

.textbox {
  margin-block: 2rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  overflow: clip;
}
.textbox__header { padding: 0.25rem 1.25rem; background: var(--accent-dark); color: white; }
.textbox__header h2 { margin: 0.55rem 0; font-size: 1.25rem; }
.textbox__content { padding: 0.5rem 1.25rem 1.25rem; }

.reader-figure { margin: 2.5rem 0; }
.reader-figure img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  background: #fff;
}
.reader-figure figcaption { margin-top: 0.75rem; color: var(--muted); font: 0.9rem/1.5 system-ui, sans-serif; }

.math {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
  white-space: nowrap;
}
math { font-size: 1.08em; }

.mastery-record {
  margin-block: 1.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
.mastery-record h3 { margin-top: 0; }
details { margin-block: 0.6rem; padding: 0.6rem 0.8rem; background: color-mix(in srgb, var(--soft) 55%, var(--paper)); }
summary { cursor: pointer; font: 700 0.98rem/1.4 system-ui, sans-serif; }
.record-fields { margin: 0.7rem 0 0; }
.record-fields dt { margin-top: 0.8rem; font-weight: 700; }
.record-fields dd { margin-inline-start: 1rem; }

.project-packets {
  width: min(100%, 60rem);
  margin: 3rem auto 0;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: color-mix(in srgb, var(--soft) 50%, var(--paper));
  font-family: system-ui, sans-serif;
}
.project-packets h2 { margin-top: 0; color: var(--accent-dark); }
.project-packets li + li { margin-top: 0.65rem; }

footer {
  padding-block: 2rem 4rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 0.86rem/1.5 system-ui, sans-serif;
}
code { overflow-wrap: anywhere; }

table {
  max-width: 100%;
  border-collapse: collapse;
}
th, td { overflow-wrap: anywhere; }

@media (max-width: 42rem) {
  main, footer { width: min(100% - 1.1rem, 72rem); }
  .chapter, #dukungan-belajar, section { min-width: 0; }
  .unit-nav {
    justify-content: center;
    overflow-x: visible;
    flex-wrap: wrap;
    gap: 0.45rem 1rem;
    font-size: 0.86rem;
  }
  .edition-notice, .textbox__content, .mastery-record, .project-packets { padding-inline: 0.9rem; }
  table.responsive-table {
    display: block;
    width: 100% !important;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (prefers-color-scheme: dark) {
  :root { --paper: #111827; --ink: #edf2f7; --muted: #cbd5e1; --soft: #183444; --line: #536574; --accent: #1d718e; --accent-dark: #164f65; }
  a { color: #7dd3fc; }
}

@media print {
  .unit-nav, .skip-link { display: none; }
  body { color: black; background: white; font-size: 11pt; }
  .reader-header { padding: 2rem 0; color: black; background: white; }
  main, footer, .chapter, #dukungan-belajar { width: 100%; }
  details { break-inside: avoid; }
  details > * { display: block; }
}
