/*
 * Photo essay presentation
 *
 * Narrow windows use stacked captions and photographs. At 1024px, the desktop
 * rules switch to adjacent columns. essay.js fits the actual image inside the
 * space reserved here and applies the source-resolution limit.
 */

/* 1. Theme defaults. content.js can override colors, fonts, and column widths. */
:root {
  --background: #000;
  --foreground: #f2f0eb;
  --muted: #aaa8a3;
  --heading-font: 'Playfair Display', Georgia, serif;
  --body-font: 'Open Sans', sans-serif;
  --stage-width: 1280px;
  --caption-width: 300px;
  --gap: clamp(24px, 4vw, 64px);
  --controls-height: calc(72px + env(safe-area-inset-bottom));
}

/* 2. Page defaults and the scrollable reading area */
* {
  box-sizing: border-box;
}

/* Keep inactive slides hidden even though .slide sets display: grid. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

body {
  font-family: var(--body-font);
}

/* Reserve space below the reader for controls; long captions scroll inside it. */
#essay {
  height: calc(100dvh - var(--controls-height));
  overflow: auto;
  overscroll-behavior: contain;
  outline: none;
}

/* 3. Default layout: caption row above an image row.
 * The 200px minimum keeps the photograph reachable when a long caption requires
 * scrolling. minmax(0, 1fr) lets the column shrink below its content width.
 */
.slide {
  width: min(100%, var(--stage-width));
  height: 100%;
  margin: auto;
  padding: 24px max(16px, env(safe-area-inset-left)) 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(200px, 1fr);
  gap: 24px;
  animation: appear 400ms ease-out;
}

.slide.photo-only {
  grid-template-rows: minmax(200px, 1fr);
}

/* "safe center" avoids placing the beginning of oversized text above the view. */
.caption {
  align-self: safe center;
  text-align: center;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  overflow-wrap: anywhere;
}

/* 4. Typography and caption details */
h1, h2 {
  font-family: var(--heading-font);
  font-weight: 400;
  line-height: 1.12;
  margin: 0 0 20px;
}

h1 {
  font-style: italic;
  font-size: clamp(40px, 6vw, 88px);
}

h2 {
  font-size: clamp(24px, 2.6vw, 38px);
}

p {
  font-size: 16px;
  line-height: 1.7;
  margin: 0;
  white-space: pre-line;
}

.author {
  color: var(--muted);
  font-size: 14px;
  margin-top: 24px;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--muted);
  margin-bottom: 20px;
}

.photo-credit {
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
}

/* 5. Image slot and image rendering */
.photo {
  position: relative;
  margin: 0;
  min-width: 0;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Absolute positioning keeps image dimensions from enlarging the grid slot.
 * This applies only to the photograph: captions stay in normal grid flow.
 * essay.js sets the image width/height from the slot size and source resolution.
 */
.photo img {
  position: absolute;
  display: block;
  object-fit: contain;
  max-width: 100%;
}

.photo-error {
  color: var(--muted);
  text-align: center;
}

.end-label {
  margin-top: 24px;
  color: var(--muted);
  font-style: italic;
}

.caption-source {
  display: inline-block;
  margin-top: 20px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  text-underline-offset: 4px;
}

a:hover { color: var(--foreground); }
a:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }

.research-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}
.research-page h1 { font-size: clamp(40px, 7vw, 64px); margin-top: 32px; }
.research-page h2 { font-size: 28px; }
.research-page p + p { margin-top: 16px; }
.research-page section { margin-top: 48px; scroll-margin-top: 24px; }
.research-page a { color: inherit; text-underline-offset: 4px; }
.research-page .reference { color: var(--muted); font-size: 14px; }
.research-page .research-summary { margin-top: 48px; }
.paper-list { margin: 36px 0 0; padding-left: 24px; }
.paper-list li { padding-left: 8px; line-height: 1.7; scroll-margin-top: 24px; }
.paper-list li + li { margin-top: 28px; }
.paper-list cite { font-family: var(--heading-font); font-size: 20px; font-style: normal; }
.paper-list .reference cite { font-family: inherit; font-size: inherit; font-style: italic; }

/* 6. Navigation controls */
.reader-controls {
  min-height: var(--controls-height);
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.reader-controls nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

button {
  font: inherit;
  font-size: 13px;
  color: var(--foreground);
  background: transparent;
  border: 0;
  cursor: pointer;
  min-height: 44px;
  padding: 8px 12px;
}

button:hover {
  text-decoration: underline;
  text-underline-offset: 5px;
}

button:disabled {
  opacity: .25;
  cursor: default;
  text-decoration: none;
}

button:focus-visible {
  outline: 1px solid var(--foreground);
  outline-offset: 3px;
}

#counter {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .12em;
  color: var(--muted);
  white-space: nowrap;
}

.reader-title, .reader-hint {
  display: none;
}

/* 7. Desktop layouts: photo on the left, caption on the right by default. */
@media (min-width: 1024px) {
  .slide {
    padding: 40px 32px;
    gap: var(--gap);
    grid-template-columns: minmax(0, 1fr) var(--caption-width);
    grid-template-rows: minmax(240px, 1fr);
  }

  .caption {
    grid-column: 2;
    grid-row: 1;
    text-align: left;
  }

  .photo {
    grid-column: 1;
    grid-row: 1;
    min-height: 240px;
  }

  .slide.photo-only {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(240px, 1fr);
  }

  /* The cover reverses the columns, placing its title before the photograph. */
  .slide.cover {
    grid-template-columns: var(--caption-width) minmax(0, 1fr);
  }

  .cover .caption {
    grid-column: 1;
  }

  .cover .photo {
    grid-column: 2;
  }

  /* A per-slide override can keep the stacked layout on desktop too. */
  .slide[data-layout="stacked"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(240px, 1fr);
  }

  .slide[data-layout="stacked"] .caption {
    grid-column: 1;
    grid-row: 1;
    text-align: center;
  }

  .slide[data-layout="stacked"] .photo {
    grid-column: 1;
    grid-row: 2;
  }

  .reader-controls {
    justify-content: space-between;
    padding-left: 40px;
    padding-right: 40px;
  }

  .reader-title, .reader-hint {
    display: block;
    flex: 1;
    font-size: 11px;
    color: var(--muted);
  }

  .reader-title {
    letter-spacing: .08em;
  }

  .reader-hint {
    text-align: right;
  }

}

/* 8. Slide entrance animation and reduced-motion preference */
@keyframes appear {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }

}

@media (prefers-reduced-motion: reduce) {
  .slide {
    animation: none;
  }

}
