/* ─────────────────────────────────────────────────────────────
   Berkshire Hathaway — a bound volume
   Letterpress system: warm ink on cream laid paper.
   ───────────────────────────────────────────────────────────── */

@font-face {
  font-family: "IM Fell English";
  src: url("fonts/im-fell-english.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("fonts/im-fell-english-italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "IM Fell English SC";
  src: url("fonts/im-fell-english-sc.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-roman.woff2") format("woff2");
  font-weight: 400 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/eb-garamond-italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}

:root {
  --paper: #f3ead3;
  --paper-deep: #e9ddc0;
  --ink: #4a3823;            /* warm umber ink — never pure black */
  --ink-soft: #6b5638;
  --ink-faint: #8a744f;
  --ochre: #7c4d1c;
  --rule: rgba(74, 56, 35, 0.38);
  --rule-faint: rgba(74, 56, 35, 0.22);
  --press-hi: rgba(255, 251, 238, 0.85);   /* letterpress highlight */
  --press-lo: rgba(46, 32, 16, 0.28);      /* letterpress shadow   */
  --measure: 37rem;
  --gutter: clamp(1.25rem, 6vw, 5rem);
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --fell: "IM Fell English", Georgia, serif;
  --fell-sc: "IM Fell English SC", "EB Garamond", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--paper-deep);
  color: var(--ink);
  overflow-x: clip;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 0.92rem + 0.55vw, 1.28rem);
  line-height: 1.62;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures discretionary-ligatures historical-ligatures;
  font-variant-numeric: oldstyle-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  /* the sheet */
  background-image: url("paper.png");
  background-size: 512px;
}

/* Focus: visible, quiet, in-palette */
:focus-visible {
  outline: 2px solid var(--ochre);
  outline-offset: 3px;
}

.sc {
  font-family: var(--fell-sc);
  letter-spacing: 0.08em;
  font-variant-caps: normal;   /* the SC face is already small-caps */
}
.onum { font-variant-numeric: oldstyle-nums; }

/* ── leaves & pages ─────────────────────────────────────────── */

.leaf { position: relative; }

.page {
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin-inline: auto;
  padding: clamp(3.5rem, 9vh, 6rem) var(--gutter) clamp(2.5rem, 6vh, 4rem);
}

/* page edge: hairline double rules fore-edge & spine side */
.page::before,
.page::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 3px;
  pointer-events: none;
  border-left: 1px solid var(--rule-faint);
  border-right: 1px solid rgba(255, 251, 238, 0.5);
}
.page::before { left: max(0.6rem, calc(var(--gutter) * 0.28)); }
.page::after  { right: max(0.6rem, calc(var(--gutter) * 0.28)); }

/* running head */
.running-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: clamp(0.72rem, 0.68rem + 0.2vw, 0.85rem);
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule-faint);
  padding-bottom: 0.55rem;
  margin-bottom: clamp(2.2rem, 6vh, 3.6rem);
}

/* folio */
.folio {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: clamp(2.5rem, 7vh, 4.5rem) auto 0;
  padding: 0 var(--gutter);
  color: var(--ink-soft);
}
.folio-rule { flex: 1; border-top: 1px solid var(--rule-faint); }
.folio-num { font-family: var(--fell); font-size: 1.02rem; }

/* ── headings: pressed into the sheet ───────────────────────── */

.impressed {
  font-family: var(--fell);
  font-weight: 400;
  font-size: clamp(2rem, 1.5rem + 2.4vw, 3.1rem);
  line-height: 1.15;
  color: var(--ink);
  text-shadow:
    0 -1px 1px var(--press-lo),
    0 1px 0 var(--press-hi);
  margin: 0.35em 0 0.55em;
  transition: text-shadow 1.4s ease, color 1.4s ease;
}
/* impression deepens once the leaf has settled */
.settled .impressed {
  color: #43311e;
  text-shadow:
    0 -1px 2px rgba(46, 32, 16, 0.42),
    0 1.5px 0 var(--press-hi);
}

.part-label {
  font-size: clamp(0.78rem, 0.72rem + 0.25vw, 0.92rem);
  color: var(--ochre);
  letter-spacing: 0.22em;
}

.section-note {
  font-style: italic;
  color: var(--ink-soft);
  max-width: var(--measure);
  margin-bottom: clamp(1.6rem, 4vh, 2.6rem);
}

.section-tail {
  margin-top: clamp(1.8rem, 5vh, 3rem);
  font-size: 0.86em;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.14em;
}

/* ── I · cover ──────────────────────────────────────────────── */

.cover {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  text-align: center;
}

.cover-imprint {
  font-size: clamp(0.8rem, 0.74rem + 0.3vw, 0.98rem);
  color: var(--ink-soft);
  letter-spacing: 0.3em;
  margin-bottom: clamp(1.5rem, 4vh, 2.6rem);
}

.cover-name {
  font-family: var(--fell);
  font-weight: 400;
  line-height: 0.98;
  color: var(--ink);
  text-shadow:
    0 -2px 2px var(--press-lo),
    0 2px 0 var(--press-hi);
}
.cover-line { display: block; font-size: clamp(3.2rem, 11.5vw, 8.6rem); }
.cover-inc {
  display: block;
  font-size: clamp(1rem, 2.6vw, 1.7rem);
  letter-spacing: 0.34em;
  margin-top: 0.9em;
  color: var(--ink-soft);
}

.cover-marble {
  width: min(30rem, 78vw);
  margin: clamp(1.8rem, 5vh, 3.2rem) auto;
  /* debossed frame */
  padding: 5px;
  border: 1px solid var(--rule-faint);
  box-shadow:
    inset 0 1px 2px var(--press-lo),
    0 1px 0 var(--press-hi);
  background: var(--paper);
}
.cover-marble img {
  display: block;
  width: 100%;
  height: clamp(4.5rem, 11vh, 7.5rem);
  object-fit: cover;
  filter: sepia(0.14) saturate(0.92);
}

.cover-address {
  font-size: clamp(0.78rem, 0.72rem + 0.28vw, 0.94rem);
  color: var(--ink-soft);
  letter-spacing: 0.22em;
}

.scroll-cue {
  margin-top: clamp(2.2rem, 6vh, 3.6rem);
  font-size: 0.78rem;
  letter-spacing: 0.3em;
  color: var(--ink-faint);
}

/* ── II · the annual letter ─────────────────────────────────── */

.letter-dateline {
  font-size: 0.92em;
  color: var(--ink-soft);
  max-width: var(--measure);
  margin-bottom: clamp(1.8rem, 5vh, 3rem);
  border-bottom: 1px solid var(--rule-faint);
  padding-bottom: 1.1rem;
}

.letter-extract { max-width: var(--measure); }

.letter-graf {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  hanging-punctuation: first allow-end;
  margin-bottom: 1.15em;
}
/* opening paragraph carries the drop cap; no first-line indent */
.letter-graf:first-child { text-indent: 0; }

.dropcap {
  float: left;
  font-family: var(--fell);
  font-size: 4.4em;
  line-height: 0.78;
  padding: 0.06em 0.14em 0 0;
  color: var(--ochre);
  text-shadow:
    0 -1px 1px var(--press-lo),
    0 1px 0 var(--press-hi);
}
.dc-runin { letter-spacing: 0.06em; }

.letter-attrib {
  max-width: var(--measure);
  text-align: right;
  font-size: 0.85em;
  color: var(--ink-faint);
  letter-spacing: 0.16em;
  margin-top: 1.4rem;
}

/* ── III · operating companies ──────────────────────────────── */

.colophon-list {
  list-style: none;
  max-width: calc(var(--measure) + 6rem);
}
.colophon-list li {
  display: grid;
  grid-template-columns: minmax(9rem, 14rem) 1fr;
  gap: 0.15rem 1.4rem;
  padding: 0.85rem 0 0.8rem;
  border-bottom: 1px solid var(--rule-faint);
  align-items: baseline;
}
.co-name {
  font-size: 1.04em;
  letter-spacing: 0.1em;
  color: var(--ink);
}
.co-desc { font-style: italic; color: var(--ink-soft); font-size: 0.94em; }
.co-meta {
  grid-column: 2;
  font-size: 0.82em;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}

/* ── IV · owner's manual ────────────────────────────────────── */

.principles {
  list-style: none;
  max-width: calc(var(--measure) + 4rem);
  counter-reset: principle;
}
.principles li {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 0.4rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid var(--rule-faint);
}
.pr-num {
  font-family: var(--fell);
  font-size: 1.25rem;
  color: var(--ochre);
  text-shadow: 0 1px 0 var(--press-hi);
}
.principles p { font-size: 0.95em; text-align: justify; hyphens: auto; }

/* ── V · the library ────────────────────────────────────────── */

.shelf { max-width: calc(var(--measure) + 6rem); }
.shelf-row {
  padding: 1rem 0 0.95rem;
  border-bottom: 1px solid var(--rule-faint);
  /* shelf edge */
  background:
    linear-gradient(to bottom, transparent 78%, rgba(46, 32, 16, 0.045) 100%);
}
.shelf dt { font-size: 1.02em; }
.shelf dd {
  font-style: italic;
  font-size: 0.92em;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}

/* ── VI · the pilgrimage ────────────────────────────────────── */

.pilgrimage-text { max-width: var(--measure); }
.pilgrimage-text p { margin-bottom: 1.15em; text-align: justify; hyphens: auto; }

/* ── VII · colophon ─────────────────────────────────────────── */

.colophon { padding-bottom: clamp(3rem, 8vh, 5rem); }
.colophon-text { max-width: var(--measure); }
.colophon-text p { margin-bottom: 1.1em; text-align: justify; hyphens: auto; }

.web-note {
  margin: 1.6rem 0;
  padding: 1.1rem 1.4rem;
  border-left: 2px solid var(--rule);
  background: rgba(255, 251, 238, 0.35);
  font-style: italic;
  font-size: 0.95em;
  color: var(--ink-soft);
}
.web-note cite {
  display: block;
  font-style: normal;
  font-family: var(--fell-sc);
  letter-spacing: 0.12em;
  font-size: 0.78em;
  margin-top: 0.6rem;
  color: var(--ink-faint);
}

/* the famous unstyled blue — the only blue on the page */
.blue-link {
  color: #0000cc;
  text-decoration: underline;
}

.colophon-block {
  margin-top: clamp(2rem, 6vh, 3.4rem);
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: 0.88em;
  letter-spacing: 0.2em;
  line-height: 2.1;
  color: var(--ink-soft);
}

/* ── paper motion: turning leaves, settling ink ───────────────
   Gated on .js so a scriptless render is fully printed from the start. */

@media (prefers-reduced-motion: no-preference) {
  .js .leaf {
    opacity: 0;
    transform: translateY(2.2rem) rotate(-0.18deg);
    transition:
      opacity 1.15s ease,
      transform 1.15s cubic-bezier(0.22, 0.61, 0.21, 1);
    will-change: opacity, transform;
  }
  .js .leaf.settled {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  /* ink settling: text starts faint, darkens into the sheet */
  .js .leaf .letter-graf,
  .js .leaf .principles p,
  .js .leaf .shelf-row,
  .js .leaf .colophon-list li {
    transition: color 1.6s ease 0.25s;
  }
  .js .leaf:not(.settled) .letter-graf,
  .js .leaf:not(.settled) .principles p,
  .js .leaf:not(.settled) .shelf dt,
  .js .leaf:not(.settled) .shelf dd,
  .js .leaf:not(.settled) .co-desc,
  .js .leaf:not(.settled) .co-name,
  .js .leaf:not(.settled) .co-meta {
    color: color-mix(in srgb, var(--ink) 55%, var(--paper));
  }
  .js .scroll-cue {
    animation: cue-drift 3.2s ease-in-out infinite;
  }
  @keyframes cue-drift {
    0%, 100% { transform: translateY(0); opacity: 0.75; }
    50%      { transform: translateY(0.5rem); opacity: 1; }
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .leaf { opacity: 1; transform: none; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── responsive ─────────────────────────────────────────────── */

@media (max-width: 46rem) {
  .colophon-list li { grid-template-columns: 1fr; gap: 0.1rem; }
  .co-meta { grid-column: 1; }
  .principles li { grid-template-columns: 2.4rem 1fr; }
  .letter-graf, .principles p, .pilgrimage-text p, .colophon-text p { text-align: left; hyphens: auto; }
  .dropcap { font-size: 3.6em; }
}
