:root {
  --bg: #f6f6ef;
  --text: #5a5a5a;
  --text-soft: #8f8f87;
  --nav-active: #000000;
  --nav-muted: #5a5a5a;
  /* Original flex row gap was clamp(1.25rem, 3.5vw, 2.25rem); keep 2× that between nav and main */
  --nav-main-gap: clamp(2.5rem, 7vw, 4.5rem);
}

* {
  box-sizing: border-box;
}

html {
  /* Avoid horizontal jump when scrollbar appears on taller pages */
  scrollbar-gutter: stable;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: Outfit, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-weight: 300;
  font-size: clamp(14px, 0.9rem + 0.35vw, 17px);
  line-height: 1.52;
  letter-spacing: -0.01em;
}

/*
 * Three-column grid: equal 1fr sides + fixed reading column.
 * Main stays horizontally centered; nav sits at the inner edge of the left column (beside the text),
 * with gap = 2× the old flex-row spacing—not flush to the viewport edge.
 */
.wrap {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr);
  grid-template-rows: auto;
  /* Start from a fixed vertical rhythm so short vs long pages don’t re-center and jump */
  align-content: start;
  align-items: start;
  column-gap: var(--nav-main-gap);
  padding: clamp(2rem, 10vmin, 5.5rem) clamp(1.25rem, 5vw, 2.5rem) clamp(1.25rem, 3vh, 2rem);
  box-sizing: border-box;
}

.side-nav {
  grid-column: 1;
  justify-self: end;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55em;
  padding-top: 0.05em;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

.side-nav a {
  color: var(--nav-muted);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.side-nav a:hover {
  opacity: 0.82;
}

.side-nav a.is-active {
  color: var(--nav-active);
  font-weight: 500;
}

main {
  grid-column: 2;
  width: 100%;
  min-width: 0;
}

.bodytext p {
  margin: 0 0 1em;
}

.bodytext p:last-child {
  margin-bottom: 0;
}

.bodytext a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.bodytext a:hover {
  opacity: 0.85;
}

.opennote-host {
  display: block;
}

.opennote-lead {
  display: block;
}

.opennote-panel-outer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.38s ease;
}

.opennote-host.is-open .opennote-panel-outer {
  grid-template-rows: 1fr;
}

.opennote-trigger {
  font: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.opennote-trigger:hover {
  opacity: 0.85;
}

.opennote-trigger:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.opennote-panel {
  min-height: 0;
  overflow: hidden;
}

.opennote-panel-inner {
  display: block;
  padding-top: 0;
  color: var(--text-soft);
  opacity: 0;
  transition:
    opacity 0.24s ease,
    padding-top 0.36s ease;
}

.opennote-host.is-open .opennote-panel-inner {
  padding-top: 0.45em;
  opacity: 1;
  transition:
    opacity 0.34s ease 0.08s,
    padding-top 0.36s ease;
}

.bodytext .opennote-panel a {
  color: var(--text);
}

.bodytext .opennote-panel a:hover {
  opacity: 0.85;
}

.opennote-panel-line {
  display: block;
}

.opennote-panel-line + .opennote-panel-line {
  margin-top: 0.3em;
}

.subpage-lead {
  margin: 0 0 1em;
}

.bodytext .reading-list {
  margin: 0 0 1em;
  padding-left: 1.2em;
}

.bodytext .reading-list li {
  margin-bottom: 0.55em;
}

.bodytext .reading-list li:last-child {
  margin-bottom: 0;
}

.bodytext .reading-list cite {
  font-style: italic;
}

.book-line {
  display: block;
}

.book-trigger {
  font: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.book-trigger:hover {
  opacity: 0.85;
}

.book-trigger:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.book-panel-outer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.34s ease;
}

.book-item.is-open .book-panel-outer {
  grid-template-rows: 1fr;
}

.book-panel {
  min-height: 0;
  overflow: hidden;
}

.book-panel-inner {
  display: block;
  padding-top: 0;
  color: var(--text-soft);
  opacity: 0;
  transition:
    opacity 0.22s ease,
    padding-top 0.32s ease;
}

.book-item.is-open .book-panel-inner {
  padding-top: 0.25em;
  opacity: 1;
  transition:
    opacity 0.3s ease 0.06s,
    padding-top 0.32s ease;
}

.bodytext .book-panel a {
  color: var(--text);
}

.bodytext .book-panel a:hover {
  opacity: 0.85;
}

.book-panel-line {
  display: block;
}

.book-panel-line + .book-panel-line {
  margin-top: 0.12em;
}

.library-section .library-heading {
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--nav-muted);
  margin: 2.6em 0 0.85em;
  line-height: 1.35;
}

.library-section:first-of-type .library-heading {
  margin-top: 1.6em;
}

.library-section .reading-list {
  margin-bottom: 0;
}

.library-back {
  margin: 0 0 0.75em;
}

.soccer-timeline {
  margin: 0;
}

.soccer-timeline p:last-child {
  margin-bottom: 0;
}

.timeline-stage {
  color: inherit;
}

.timeline-detail {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.library-archive-link {
  margin: 0;
}

.bodytext .reading-list--archive li {
  margin-bottom: 0.45em;
}

.site-footer {
  margin-top: 1.65em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(0.65rem, 2.8vw, 1.15rem);
}

.site-footer a {
  color: var(--text);
  text-decoration: none;
}

.site-footer a:hover {
  opacity: 0.72;
}

.footer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
}

.footer-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  fill: currentColor;
  filter: grayscale(1);
  opacity: 0.92;
}

.footer-icon.mail svg {
  width: 1.24rem;
  height: 1.24rem;
}

@media (max-width: 640px) {
  .wrap {
    grid-template-columns: 1fr;
    column-gap: 0;
    row-gap: 1.25rem;
    align-content: start;
    /* Pin content to top; respect iPhone safe areas */
    padding-top: max(0.65rem, calc(env(safe-area-inset-top, 0px) + 0.35rem));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(clamp(1rem, 3vh, 1.75rem), env(safe-area-inset-bottom, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
  }

  .side-nav {
    grid-column: 1;
    justify-self: start;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1.25rem;
    width: 100%;
    max-width: 100%;
    padding-top: 0;
  }

  main {
    grid-column: 1;
  }
}

@media (max-height: 720px) {
  body {
    font-size: clamp(13.5px, 0.85rem + 0.32vw, 16px);
  }

  .bodytext p,
  .subpage-lead {
    margin-bottom: 0.92em;
  }
}

/* Short desktop/laptop windows only — don’t override mobile padding */
@media (max-height: 720px) and (min-width: 641px) {
  .wrap {
    padding-top: 1rem;
  }
}
