/* Intellectio essay. Builds on ../styles.css (fonts, colours, dark mode). */

:root {
  --ink: var(--text);
  --rule: var(--border);
  --wash: #efebe3;
  --glow: #2f8f86;          /* the inhabitants' inner light, darkened for paper */
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --text-w: var(--reading-width);
}

@media (prefers-color-scheme: dark) {
  :root {
    --wash: #232120;
    --glow: #7fe8dc;
  }
}

body.essay-page::before {
  display: none; /* the home page's backdrop would fight the footage */
}

.essay-page footer {
  width: min(var(--text-w), 100% - 2 * var(--gutter));
  padding-top: 48px;
}

/* Layout: the site's reading column, with a wider opening shot. */
.essay {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [text-start] min(var(--text-w), 100% - 2 * var(--gutter))
    [text-end] minmax(var(--gutter), 1fr)
    [full-end];
}

.essay > * {
  grid-column: text;
}

.essay > .full {
  grid-column: full;
}

.crumb {
  width: min(var(--text-w), 100% - 2 * var(--gutter));
  margin: 0 auto;
  padding: 28px 0 0;
  font-size: 15px;
}

.crumb a {
  color: var(--faint);
}

/* Title */
.title {
  padding: 72px 0 40px;
}

.kicker {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.title h1 {
  margin-top: 18px;
  font-size: clamp(44px, 9vw, 72px);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.dek {
  margin-top: 20px;
  max-width: 30ch;
  font-size: clamp(20px, 3vw, 24px);
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--muted);
}

/* Prose */
.essay > p {
  margin: 0 0 1.15em;
  font-size: var(--body-size);
  line-height: var(--body-leading);
  color: var(--ink);
}

.essay > h2 {
  margin: var(--section-gap) 0 24px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-transform: none;
  color: var(--ink);
}

/* Figures */
.essay figure {
  margin: 40px 0 48px;
}

.frame {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: var(--wash);
}

.frame video {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.essay .hero {
  width: min(1040px, calc(100% - 64px));
  justify-self: center;
  margin: 0 0 48px;
}

@media (max-width: 600px) {
  .essay .hero {
    width: calc(100% - 2 * var(--gutter));
  }
}

/* Play/pause for autoplaying clips (shown once a clip plays). */
.toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgb(20 18 16 / 0.45);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.frame:hover .toggle,
.toggle:focus-visible {
  opacity: 1;
}

.toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 10px;
  height: 12px;
  border-left: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

.toggle[data-state="paused"]::before {
  width: 0;
  height: 0;
  border: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  margin-left: 13px;
}

@media (hover: none) {
  .toggle {
    opacity: 0.85;
  }
}

figcaption {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

/* The world's laws: two clips, one above the other. */
.laws {
  display: grid;
  gap: 16px;
  margin: 40px 0 48px;
}

.laws figure {
  margin: 0;
}

/* Footnotes: margin notes on wide screens, tap to open on narrow ones. */
.fn {
  display: inline-block;
  margin-left: 2px;
  font-size: 0.68em;
  font-weight: 600;
  line-height: 1;
  vertical-align: super;
  color: var(--accent);
  cursor: pointer;
}

.fn::before {
  content: "[";
  opacity: 0.5;
}

.fn::after {
  content: "]";
  opacity: 0.5;
}

.fn-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.note {
  display: none;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.note .n {
  margin-right: 4px;
  font-weight: 600;
  color: var(--accent);
}

.note a {
  color: inherit;
}

.fn-toggle:checked + .note {
  display: block;
  margin: 10px 0 6px;
  padding: 10px 14px;
  border-left: 2px solid var(--accent);
  background: var(--wash);
  border-radius: 0 4px 4px 0;
}

/* Keep margin-note height out of the prose's grid row. Grouping notes
   also keeps multiple references from overlapping each other. */
.essay > p:has(.margin-notes) {
  position: relative;
}

@media (min-width: 1180px) {
  .margin-notes {
    position: absolute;
    top: 0;
    left: calc(100% + 36px);
    width: 200px;
    display: grid;
    gap: 16px;
  }

  .note,
  .fn-toggle:checked + .note {
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font-size: 13px;
  }

  .fn {
    cursor: default;
  }
}

.source {
  margin-top: 40px;
}

@media (max-width: 600px) {
  .essay > h2 {
    font-size: 26px;
  }

  .title {
    padding-top: 48px;
  }


}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
