/* TezGK: The Living Textbook. See DESIGN.md. */
@font-face { font-family: "Archivo"; src: url("/fonts/archivo.woff2") format("woff2"); font-weight: 400 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "Literata"; src: url("/fonts/literata.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("/fonts/literata-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --ink: #1C1B19; --page: #FFFFFF; --rule: #D9D6CF; --muted: #57534B;
  --polity: #2B3A8C; --economy: #1E6B47; --world: #A3262E; --science: #0D6670; --sport: #B04A0C; --other: #4A4F57;
  --know-tint: #FFF1DD; --know-frame: #F28C28; --sel: #DDE2F6;
  --band: var(--polity);
  --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --body: "Literata", Georgia, serif;
  --gutter: clamp(16px, 4vw, 40px);
  --measure: 66ch;
}
.s-polity { --band: var(--polity); } .s-economy { --band: var(--economy); } .s-world { --band: var(--world); }
.s-science { --band: var(--science); } .s-sport { --band: var(--sport); } .s-other { --band: var(--other); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--muted) var(--page); }
body { margin: 0; background: var(--page); color: var(--ink); font: 400 1.0625rem/1.6 var(--body); font-optical-sizing: auto; text-rendering: optimizeLegibility; }
::selection { background: var(--sel); color: var(--ink); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 3px solid var(--know-frame); outline-offset: 2px; }
img { max-width: 100%; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); }
.num, time, td.n { font-family: var(--display); font-variant-numeric: tabular-nums; }

/* Running head */
.head { border-bottom: 1px solid var(--rule); }
.head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 56px; }
.mark { font: 850 1.35rem/1 var(--display); font-stretch: 85%; letter-spacing: -0.02em; text-decoration: none; display: inline-flex; align-items: baseline; gap: 0.05em; }
.mark b { color: #C2560E; font-weight: 900; }
.nav { display: flex; gap: clamp(0.75rem, 2.5vw, 1.75rem); align-items: center; font: 650 0.8125rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.06em; }
.nav a { text-decoration: none; }
.nav a:hover { text-decoration: underline; }
@media (max-width: 560px) { .nav .hide-s { display: none; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.6em; min-height: 48px; padding: 0.8em 1.25em; border: 2px solid var(--ink); background: var(--ink); color: var(--page); font: 750 0.875rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.05em; text-decoration: none; cursor: pointer; transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out; }
.btn:hover { background: var(--band); border-color: var(--band); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--page); }
.btn.small { min-height: 40px; padding: 0.6em 0.95em; font-size: 0.75rem; }
.btn svg { width: 1.1em; height: 1.1em; flex: none; }

/* Chapter band and opener */
.band { background: var(--band); color: #fff; }
.opener { display: grid; grid-template-columns: auto 1fr; gap: clamp(1rem, 4vw, 3rem); align-items: end; padding: clamp(2rem, 6vw, 4.5rem) 0 clamp(1.5rem, 4vw, 3rem); }
.opener .chap { font: 850 clamp(5.5rem, 22vw, 12rem)/0.8 var(--display); font-stretch: 72%; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; margin: 0; }
.opener .chap small { display: block; font-size: 0.9rem; font-weight: 700; font-stretch: 100%; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 0.9rem; opacity: 0.92; }
.opener h1 { font: 800 clamp(2.4rem, 7vw, 5rem)/0.95 var(--display); font-stretch: 92%; letter-spacing: -0.03em; margin: 0 0 1rem; text-wrap: balance; }
.opener p { font-size: clamp(1.05rem, 2.2vw, 1.25rem); line-height: 1.5; max-width: 44ch; margin: 0; color: #fff; }
@media (max-width: 640px) { .opener { grid-template-columns: 1fr; align-items: start; } }
@media (prefers-reduced-motion: no-preference) {
  .home .opener .chap span { display: inline-block; animation: turn 900ms cubic-bezier(.16,1,.3,1) both; }
  @keyframes turn { from { clip-path: inset(0 100% 0 0); transform: translateX(-0.08em); } to { clip-path: inset(0 0 0 0); transform: none; } }
}

/* Page body: text column plus margin */
.page { display: grid; grid-template-columns: minmax(0, var(--measure)) minmax(0, 1fr); gap: clamp(1.5rem, 5vw, 4rem); padding-block: clamp(2rem, 5vw, 3.5rem); }
@media (max-width: 900px) { .page { grid-template-columns: 1fr; } }
.page > aside { align-self: start; }
h2 { font: 800 clamp(1.6rem, 3.6vw, 2.25rem)/1.1 var(--display); letter-spacing: -0.02em; margin: 3rem 0 1rem; text-wrap: balance; }
h2 .sec { color: var(--band); font-variant-numeric: tabular-nums; margin-right: 0.35em; }
h3 { font: 750 1.2rem/1.25 var(--display); margin: 2rem 0 0.5rem; }
p { margin: 0 0 1rem; }
.lede { font-size: 1.2rem; line-height: 1.55; }
.muted { color: var(--muted); }

/* Do you know? */
.know { background: var(--know-tint); border: 1px solid var(--know-frame); padding: 1.25rem 1.35rem 1.1rem; margin: 0 0 2rem; }
.know .k { font: 800 0.8rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.1em; color: #8A3E00; margin: 0 0 0.75rem; display: flex; gap: 0.5rem; align-items: center; }
.know .k svg { width: 1.1rem; height: 1.1rem; }
.know p { margin: 0 0 0.6rem; font-size: 1.125rem; line-height: 1.5; }
.know .when { font: 650 0.8rem/1.4 var(--display); color: #6B4A2A; }

/* Join block */
.join { display: grid; gap: 0.75rem; margin: 1.5rem 0 0; }
.join form { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.join input[type=email] { min-height: 48px; padding: 0 0.9rem; border: 2px solid var(--ink); font: 400 1rem var(--body); color: var(--ink); background: #fff; border-radius: 0; }
.join input[type=email]::placeholder { color: #6E6A61; }
.join label.consent { grid-column: 1 / -1; display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.9rem; line-height: 1.45; color: var(--muted); }
.join label.consent input { margin-top: 0.25rem; accent-color: var(--ink); width: 1.05rem; height: 1.05rem; }
@media (max-width: 480px) { .join form { grid-template-columns: 1fr; } }

/* Exercise (works without JavaScript) */
.exercise { border-top: 3px solid var(--ink); padding-top: 1rem; margin: 2.5rem 0; }
.exercise .q { font: 700 1.15rem/1.4 var(--display); margin: 0 0 1rem; }
.exercise .q .n { color: var(--band); margin-right: 0.4em; }
.opts { display: grid; gap: 0.5rem; border: 0; padding: 0; margin: 0 0 0.75rem; }
.opts input { position: absolute; opacity: 0; pointer-events: none; }
.opts label { display: grid; grid-template-columns: 2rem 1fr; align-items: center; min-height: 48px; padding: 0.4rem 0.75rem; border: 1px solid var(--rule); cursor: pointer; font: 500 1rem/1.35 var(--display); transition: border-color 140ms ease-out, background-color 140ms ease-out; }
.opts label:hover { border-color: var(--ink); }
.opts label .l { font-weight: 800; }
.opts input:focus-visible + label { outline: 3px solid var(--know-frame); outline-offset: 2px; }
.opts input:checked + label { border-color: var(--ink); border-width: 2px; }
.opts input.right:checked + label { background: #E4F2EA; border-color: var(--economy); }
.opts input.wrong:checked + label { background: #F8E3E4; border-color: var(--world); }
.feedback { display: none; font-size: 1rem; }
.opts:has(input.right:checked) ~ .fb-right, .opts:has(input.wrong:checked) ~ .fb-wrong { display: block; }
.fb-right strong { color: var(--economy); } .fb-wrong strong { color: var(--world); }
.exercise details { margin-top: 0.5rem; font-size: 0.95rem; color: var(--muted); }
.exercise details summary { cursor: pointer; font: 650 0.85rem var(--display); text-transform: uppercase; letter-spacing: 0.05em; }
@supports selector(:has(*)) { .exercise details.nojs { display: none; } }

/* Textbook table */
table { width: 100%; border-collapse: collapse; margin: 0.5rem 0 1rem; font-size: 0.98rem; }
caption { text-align: left; font: 750 0.85rem/1.3 var(--display); text-transform: uppercase; letter-spacing: 0.06em; padding-bottom: 0.6rem; }
caption .num { color: var(--band); }
th, td { text-align: left; vertical-align: top; padding: 0.65rem 0.5rem 0.65rem 0; border-top: 1px solid var(--rule); }
thead th { border-top: 2px solid var(--ink); font: 700 0.75rem/1.2 var(--display); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 2px solid var(--ink); }
td.n { font-size: 1.35rem; font-weight: 800; white-space: nowrap; padding-right: 1rem; }

/* Pipeline steps (sequence is real) */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 3rem 1fr; gap: 0.25rem 1rem; padding: 1rem 0; border-top: 1px solid var(--rule); }
.steps li::before { content: counter(s); font: 850 2rem/1 var(--display); font-stretch: 75%; color: var(--band); grid-row: span 2; }
.steps h3 { margin: 0; }
.steps p { margin: 0; }

/* Margin notes */
.margin { font-size: 0.95rem; line-height: 1.5; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 0.75rem; margin-bottom: 1.75rem; }
.margin strong { color: var(--ink); font-family: var(--display); }

/* Timeline entries */
.entries { list-style: none; padding: 0; margin: 0; }
.entry { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0 1.25rem; padding: 1.25rem 0; border-top: 1px solid var(--rule); }
.entry time { font: 800 0.95rem/1.3 var(--display); }
.entry time span { display: block; font-weight: 600; color: var(--muted); font-size: 0.8rem; }
.entry h3 { margin: 0 0 0.4rem; font-size: 1.15rem; }
.entry .tag { display: inline-block; font: 700 0.7rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.08em; color: #fff; background: var(--band); padding: 0.3em 0.5em; margin-bottom: 0.5rem; text-decoration: none; }
.entry ul { margin: 0.4rem 0 0.4rem 1.1rem; padding: 0; }
.entry li { margin: 0.2rem 0; }
.entry sup a { text-decoration: none; font: 700 0.75em var(--display); color: var(--band); padding: 0 0.1em; }
@media (max-width: 520px) { .entry { grid-template-columns: 1fr; } .entry time { margin-bottom: 0.3rem; } .entry time span { display: inline; margin-left: 0.4em; } }
.sources { font-size: 0.85rem; line-height: 1.5; color: var(--muted); padding-left: 1.4rem; }
.sources li { margin: 0.3rem 0; word-break: break-word; }

/* Index */
.index { columns: 2 16rem; column-gap: 2.5rem; }
.index .letter { font: 850 1.5rem/1 var(--display); color: var(--band); margin: 1.25rem 0 0.4rem; break-after: avoid; }
.index a { display: flex; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; text-decoration: none; border-bottom: 1px dotted var(--rule); break-inside: avoid; }
.index a:hover { color: var(--band); }
.index a .num { color: var(--muted); font-size: 0.9rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0; list-style: none; }
.chips a { display: inline-block; padding: 0.45rem 0.7rem; border: 1px solid var(--rule); text-decoration: none; font: 600 0.9rem/1.2 var(--display); }
.chips a:hover { border-color: var(--ink); }

/* Footer */
.foot { border-top: 3px solid var(--ink); margin-top: 3rem; padding: 2rem 0 3rem; font-size: 0.92rem; color: var(--muted); }
.foot .wrap { display: grid; gap: 1.25rem; }
.foot .row { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; align-items: baseline; }
.foot a { color: var(--ink); }
.crumbs { font: 650 0.8rem/1.4 var(--display); text-transform: uppercase; letter-spacing: 0.06em; padding-top: 1rem; }
.crumbs a { text-decoration: none; color: #fff; opacity: 0.9; }
.crumbs a:hover { text-decoration: underline; opacity: 1; }

/* Wrapping polish */
p, li, .entry h3 { text-wrap: pretty; }
.entry h3, h3 { text-wrap: balance; }
@media (min-width: 901px) { .page > aside { position: sticky; top: 1.25rem; max-height: calc(100vh - 2.5rem); overflow: auto; } }
