/* ============================================================================
   Base: reset, type, layout, nav, buttons, reveal, the page-margin "spine", footer
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 12px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1.0625rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  transition: background-color 0.5s var(--ease), color 0.4s var(--ease);
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; }
p, figure { margin: 0; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); }
ul, ol { margin: 0; padding: 0; list-style: none; }
fieldset { border: 0; margin: 0; padding: 0; min-inline-size: 0; }
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.86em; font-variant-ligatures: none; }
code { background: var(--code-bg); padding: 0.1em 0.4em; border-radius: 6px; }
kbd {
  display: inline-block; padding: 0.08em 0.5em 0.12em; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  color: var(--text); font-weight: 600; line-height: 1.35;
}
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.skip {
  position: fixed; left: 12px; top: -60px; z-index: 200; padding: 10px 16px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; transition: top 0.2s;
}
.skip:focus { top: 12px; }

/* paper grain on the whole desk */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 90; pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.25 0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------------ layout */
.wrap { width: min(100% - 2 * var(--gutter), var(--wrap)); margin-inline: auto; }
.sec { padding-block: clamp(88px, 13vw, 190px); position: relative; }
.sec-head { max-width: 760px; margin-bottom: clamp(36px, 5vw, 72px); }
.sec-head .lede { margin-top: 22px; }

/* ------------------------------------------------------------------ type */
.h1 {
  font-size: clamp(2.7rem, 1.2rem + 6.4vw, 5.7rem);
  font-weight: 700; letter-spacing: -0.04em; line-height: 0.96;
  text-wrap: balance;
}
.h2 {
  font-size: clamp(2.05rem, 1rem + 3.9vw, 3.9rem);
  font-weight: 700; letter-spacing: -0.035em; line-height: 1.02;
  text-wrap: balance;
}
.h3 { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem); font-weight: 650; letter-spacing: -0.02em; line-height: 1.12; }
.lede { font-size: clamp(1.06rem, 0.98rem + 0.4vw, 1.3rem); line-height: 1.55; color: var(--text-dim); max-width: 36em; text-wrap: pretty; }
.fine { font-size: 0.9rem; color: var(--text-faint); }
.fine i { font-style: normal; margin-inline: 0.4em; opacity: 0.6; }
.mono { font-family: var(--font-mono); }

/* hand-lettered margin notes */
.hand-note {
  font-family: var(--font-hand); font-weight: 600; font-size: 1.7rem; line-height: 1;
  color: var(--accent); display: inline-flex; align-items: flex-end; gap: 4px; transform: rotate(-4deg);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}
.hand-center { display: block; text-align: center; margin-top: 18px; }

/* ------------------------------------------------------------------ glyphs */
.g { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.g-lg { width: 30px; height: 30px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.6em;
  font: 600 1rem/1 var(--font-ui); letter-spacing: -0.005em; text-decoration: none; white-space: nowrap;
  padding: 0.95em 1.4em; border-radius: 14px; border: 1px solid transparent; cursor: pointer;
  transition: transform 0.3s var(--spring), box-shadow 0.3s var(--ease), background-color 0.2s, border-color 0.2s;
}
.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 14px 30px -12px color-mix(in srgb, var(--accent) 80%, transparent);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 20px 36px -12px color-mix(in srgb, var(--accent) 85%, transparent); }
.btn-primary:active { transform: translateY(1px) scale(0.985); }
.btn-lg { font-size: 1.06rem; padding: 1.05em 1.6em; border-radius: 16px; }
.btn-sm { font-size: 0.92rem; padding: 0.7em 1.05em; border-radius: 11px; }
.btn-ghost { background: color-mix(in srgb, var(--surface-3) 55%, transparent); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-3); transform: translateY(-1px); }
.btn-ghost:active { transform: translateY(1px); }
.btn-link {
  background: none; border: 0; padding: 0.2em 0; cursor: pointer; font-weight: 600; color: var(--text); text-decoration: none;
  background-image: linear-gradient(var(--accent), var(--accent)); background-size: 100% 2px; background-position: 0 100%; background-repeat: no-repeat;
  transition: background-size 0.3s var(--ease), color 0.2s;
}
.btn-link:hover { background-size: 100% 0.45em; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.3s var(--spring);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn-sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn[aria-pressed='true'] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: var(--accent-soft); }

/* ------------------------------------------------------------------ nav */
.nav { position: sticky; top: 0; z-index: 60; height: var(--nav-h); transition: background-color 0.3s, border-color 0.3s, backdrop-filter 0.3s; border-bottom: 1px solid transparent; }
.nav.is-scrolled {
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.3); backdrop-filter: blur(16px) saturate(1.3);
  border-bottom-color: var(--border);
}
.nav-in { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: 1.28rem; letter-spacing: -0.03em; }
.brand img { border-radius: 9px; box-shadow: 0 4px 12px -4px rgba(20, 10, 0, 0.5); transition: transform 0.5s var(--spring); }
.brand:hover img { transform: rotate(-8deg) scale(1.08); }
.nav-links { display: flex; gap: 6px; }
.nav-links a { padding: 8px 12px; border-radius: 10px; text-decoration: none; font-weight: 500; font-size: 0.95rem; color: var(--text-dim); transition: color 0.2s, background-color 0.2s; }
.nav-links a:hover, .nav-links a.is-active { color: var(--text); background: color-mix(in srgb, var(--surface-3) 70%, transparent); }
.nav-end { display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------------------------ reveals */
.js .reveal { opacity: 0; transform: translateY(26px); transition: opacity 0.9s var(--ease-out), transform 0.9s var(--ease-out); transition-delay: var(--d, 0ms); }
.js .reveal.in, .js.safe .reveal { opacity: 1; transform: none; }
.js .rise { opacity: 0; transform: translateY(20px); animation: rise 0.95s var(--ease-out) var(--d, 0ms) forwards; }
@keyframes rise { to { opacity: 1; transform: none; } }

/* word-by-word headline */
.h1 .w { display: inline-block; overflow: hidden; vertical-align: top; padding: 0.04em 0.06em 0.3em; margin: -0.04em -0.06em -0.3em; position: relative; }
.h1 .w > i { display: inline-block; font-style: normal; }
.js .h1 .w > i { transform: translateY(112%) rotate(4deg); transform-origin: 0 100%; animation: word-in 1s var(--ease-out) calc(var(--i) * 75ms + 120ms) forwards; }
@keyframes word-in { to { transform: none; } }
.scribbled .scribble {
  position: absolute; left: 0.04em; right: 0.04em; bottom: 0.2em; width: calc(100% - 0.08em); height: 0.16em; overflow: visible;
  fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.scribbled .scribble path { stroke-dasharray: 1; stroke-dashoffset: 1; }
.js .scribbled .scribble path { animation: draw 0.9s var(--ease-out) 1.15s forwards; }
html:not(.js) .scribbled .scribble path { stroke-dashoffset: 0; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ------------------------------------------------------------------ inks used as typography (the five beacon inks) */
.ink-marker, .ink-under, .ink-dotted, .ink-italic, .ink-todo { position: relative; white-space: nowrap; background: none; color: inherit; }
.ink-marker {
  padding: 0 0.16em; margin: 0 -0.16em;
  background-image: linear-gradient(to bottom, transparent 14%, color-mix(in srgb, var(--b-exam) calc(var(--marker-a) + 12%), transparent) 14% 88%, transparent 88%);
  background-repeat: no-repeat; background-size: 0% 100%; border-radius: 0.4em 0.14em 0.46em 0.18em / 0.5em 0.2em 0.45em 0.2em;
  transition: background-size 0.95s var(--ease-out) 0.15s;
}
.ink-marker.is-on { background-size: 100% 100%; }
.no-js .ink-marker { background-size: 100% 100%; }
.ink-under { background-image: linear-gradient(var(--b-define), var(--b-define)); background-repeat: no-repeat; background-position: 0 96%; background-size: 0% 0.11em; transition: background-size 0.9s var(--ease-out) 0.2s; }
.ink-under.is-on { background-size: 100% 0.11em; }
.ink-dotted, .ink-italic { font-style: italic; }
.ink-dotted::after, .ink-italic::after, .ink-todo::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -0.1em; height: 0.2em; clip-path: inset(0 100% 0 0); transition: clip-path 1s var(--ease-out) 0.2s;
}
.ink-dotted::after { background: radial-gradient(circle, var(--b-example) 0.07em, transparent 0.085em) 0 50% / 0.26em 0.2em repeat-x; }
.ink-italic::after {
  background: var(--b-question);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='8' viewBox='0 0 16 8'%3E%3Cpath d='M0 4 Q4 0 8 4 T16 4' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") 0 50% / 0.34em 0.2em repeat-x;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='8' viewBox='0 0 16 8'%3E%3Cpath d='M0 4 Q4 0 8 4 T16 4' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") 0 50% / 0.34em 0.2em repeat-x;
}
.ink-todo::after { height: 0.1em; bottom: -0.04em; background: var(--b-todo); border-radius: 0.1em; }
:is(.ink-dotted, .ink-italic, .ink-todo).is-on::after, .no-js :is(.ink-dotted, .ink-italic, .ink-todo)::after { clip-path: inset(0 0 0 0); }

/* ------------------------------------------------------------------ the margin spine (scroll progress as ink) */
.spine { position: fixed; z-index: 40; top: 0; bottom: 0; left: max(14px, calc((100vw - var(--wrap)) / 2 - 38px)); width: 2px; pointer-events: none; }
.spine::before { content: ''; position: absolute; inset: 0; background: var(--paper-margin); opacity: 0.55; }
.spine-fill { position: absolute; inset: 0; background: var(--accent); transform-origin: 50% 0; transform: scaleY(var(--p, 0)); will-change: transform; }
.spine-drop {
  position: absolute; left: 50%; top: calc(var(--p, 0) * 100%); width: 11px; height: 11px; margin: -7px 0 0 -5.5px;
  background: var(--accent); border-radius: 0 50% 50% 50%; transform: rotate(45deg); box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent);
}
@media (max-width: 1100px) {
  .spine { left: 0; right: 0; bottom: auto; height: 3px; width: auto; }
  .spine::before { opacity: 0.35; }
  .spine-fill { transform-origin: 0 50%; transform: scaleX(var(--p, 0)); }
  .spine-drop { display: none; }
}

/* ------------------------------------------------------------------ footer */
.foot { border-top: 1px solid var(--border); padding-block: 44px 56px; background: var(--bg-2); position: relative; z-index: 2; }
.foot-in { display: grid; grid-template-columns: 1fr auto; gap: 24px 32px; align-items: center; }
.foot-brand { display: flex; align-items: center; gap: 12px; }
.foot-brand img { border-radius: 8px; }
.foot-brand strong { font-family: var(--font-display); font-size: 1.15rem; letter-spacing: -0.02em; display: block; line-height: 1.1; }
.foot-brand span { font-size: 0.88rem; color: var(--text-faint); font-family: var(--font-mono); }
.foot-links { display: flex; flex-wrap: wrap; gap: 6px 22px; }
.foot-links a { color: var(--text-dim); text-decoration: none; font-weight: 500; }
.foot-links a:hover { color: var(--text); text-decoration: underline wavy var(--accent) 0.07em; text-underline-offset: 0.3em; }
.foot-fine { grid-column: 1 / -1; color: var(--text-faint); font-size: 0.88rem; }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 900px) {
  .nav-links { display: none; }
}
@media (max-width: 560px) {
  .foot-in { grid-template-columns: 1fr; }
  .btn-lg { width: 100%; }
}

/* ------------------------------------------------------------------ reduced motion: everything lands in its final state */
.rm *, .rm *::before, .rm *::after { animation-duration: 0.001ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
.rm .reveal, .rm .rise { opacity: 1 !important; transform: none !important; }
.rm .h1 .w > i { transform: none !important; }
.rm .scribbled .scribble path { stroke-dashoffset: 0 !important; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
