/* Card index and article pages. Built pages link this file directly; there is
   no CSS build step. */

:root {
  --gray-darker: #444444;
  --gray-dark: #696969;
  --gray: #999999;
  --gray-lighter: #ececec;
  --gray-lightest: #f6f6f6;
  --card: #ffffff;
  /* The one accent: hover rings, hover underlines, # links. */
  --accent: #5cecff;

  /* Type sizes. Each step is 1.25 to 1.6 times the one below, so a heading
     stands clearly above the text it heads. Everything on the site uses one
     of these. */
  --type-small: 0.8rem;   /* bylines under a quote */
  --type-text: 0.875rem;  /* card text, verse, page notes */
  --type-body: 1rem;      /* article text, a quoted post */
  --type-title: 1.25rem;  /* card titles */
  --type-page: 2rem;      /* article titles */
  --type-name: 2.5rem;    /* the name in the header */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The page is a rounded sheet on a dark frame, the way the cards sit on it. */
:root {
  --frame: #1c1c1c;
  --ground: var(--gray-lightest);
  --radius: 0.75rem;
}

/* The page is light unless js/keys.js sets data-theme="dark". The head's
   color-scheme meta allows both so the first paint can match the system;
   this pins the light theme's text and form colors once the CSS loads. */
html {
  color-scheme: light;
  background-color: var(--frame);
}

body {
  box-sizing: border-box;
  min-height: 100vh;
  margin: 0;
  padding: 1rem;
  background-color: var(--ground);
  border-radius: 1.25rem;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* With the rays on (the Space key, js/rays.js) the page pulls in from the
   viewport edges so the frame shows around it, and the rays draw on a canvas
   behind the page. */
:root[data-rays] body {
  min-height: calc(100vh - 3rem);
  margin: 1.5rem;
}

/* On a phone the frame is thin so the cards keep their width. */
@media (max-width: 40rem) {
  :root[data-rays] body {
    min-height: calc(100vh - 1rem);
    margin: 0.5rem;
  }
}

.rays {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

img {
  height: auto;
  max-width: 100%;
  vertical-align: middle;
}


.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Header on every page: name, bio, and one row of profile links, left
   aligned with the first card, closed by a rule. */

.site-header {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid currentColor;
}

@media (min-width: 40rem) {
  .site-header {
    margin: 0 1rem;
  }
}

/* A card in the index header: under the links up to 56rem, then at the
   right of the name and links with its bottom on the header's rule line.
   The card is wide and short, at the 1.91:1 of a link-preview image, with
   its text centered top to bottom. The ratio sets a minimum height, so
   longer text makes the card taller instead of overflowing it. */
.site-header__card {
  max-width: 26rem;
  margin-top: 1rem;
}

/* `overflow: clip` in place of the card's `hidden`: a box that hides
   overflow loses its automatic minimum height, and the ratio would then cut
   off text on a narrow screen. */
.site-header__card .card {
  aspect-ratio: 1.91 / 1;
  overflow: clip;
}

.site-header__card .card__text {
  flex: 0 0 auto;
}

/* The quote is set a step larger so it fills the box. */
.site-header__card .card__text blockquote > p:first-child {
  font-size: var(--type-title);
  line-height: 1.35;
}

@media (min-width: 56rem) {
  /* Next to the card: the name at the top, the links under it in columns
     two icons tall, filled top to bottom then left to right, and the bio
     at the bottom left, level with the card's bottom. */
  .site-header--card {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
  }

  .site-header--card .site-header__main {
    display: flex;
    flex-direction: column;
  }

  .site-header--card .site-header__links {
    display: grid;
    grid-auto-columns: max-content;
    grid-auto-flow: column;
    grid-template-rows: repeat(2, auto);
    justify-content: start;
  }

  .site-header--card .site-header__bio {
    margin-top: auto;
  }

  .site-header__card {
    flex: 0 1 26rem;
    margin-top: 0;
  }
}

.site-header__name {
  margin: 0;
  font-size: var(--type-name);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.site-header__name a,
.site-header__name a:visited,
[data-theme="dark"] .site-header__name a,
[data-theme="dark"] .site-header__name a:visited {
  color: inherit;
  text-decoration: none;
}

/* The bio is one italic line under the links. */
.site-header__bio {
  color: #808080;
  font-size: var(--type-title);
  font-style: italic;
}

.site-header__bio > :first-child {
  margin-top: 0.75rem;
}

.site-header__bio > :last-child {
  margin-bottom: 0;
}

.site-header__links {
  display: flex;
  flex-wrap: wrap;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--type-text);
}

.site-header__links li + li::before {
  content: "|";
  margin: 0 0.5em;
  color: var(--gray);
}

/* Icons are drawn in the muted text color, not the link color, so the row
   stays quiet; hover brings them to full text color. */
.site-header__links:has(.site-header__icon) {
  gap: 0.85rem;
  margin-top: 0.6rem;
}

.site-header__links:has(.site-header__icon) li + li::before {
  content: none;
}

.site-header__links a:has(.site-header__icon),
.site-header__links a:has(.site-header__icon):visited {
  display: block;
  color: var(--gray-dark);
}

.site-header__links a:has(.site-header__icon):hover {
  color: inherit;
}

/* Hover lifts the icon and pops it, overshooting a little before it settles. */
.site-header__icon svg {
  transition: transform 160ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.site-header__links a:hover .site-header__icon svg {
  transform: translateY(-4px) scale(1.35);
}

[data-theme="dark"] .site-header__links a:has(.site-header__icon):hover {
  color: #5cecff;
}

@media (prefers-reduced-motion: reduce) {
  .site-header__icon svg {
    transition: none;
  }
}

/* An account no longer used: a line through the icon, and no pop. */
.site-header__retired .site-header__icon {
  display: block;
  position: relative;
}

.site-header__retired .site-header__icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: -12%;
  right: -12%;
  border-top: 1.75px solid currentColor;
  transform: rotate(45deg);
}

.site-header__links .site-header__retired a:hover .site-header__icon svg {
  transform: none;
}

.site-header__icon svg {
  display: block;
  width: calc(1.65rem - 1px);
  height: calc(1.65rem - 1px);
  stroke-width: 1.75;
}

/* Index */

.cards {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* A card ends at its content instead of stretching to the row's tallest. */
.cards__item {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0;
}

@media (min-width: 40rem) {
  .cards__item {
    padding: 1rem;
  }
}

@media (min-width: 56rem) {
  .cards__item {
    width: 50%;
  }
}

@media (min-width: 72rem) {
  .cards__item {
    width: 33.3333%;
  }
}

.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background-color: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 6px 18px -8px rgb(0 0 0 / 0.18);
  transition: box-shadow 150ms ease-out;
}

.card:hover {
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.1), 0 10px 26px -8px rgb(0 0 0 / 0.28);
}

/* A card that links somewhere as a whole gets an accent ring on hover. */
.card--page:hover,
.card:has(.card__title > a:not(.card__title-inline)):hover {
  box-shadow: 0 0 0 2px var(--accent), 0 2px 4px rgb(0 0 0 / 0.1), 0 10px 26px -8px rgb(0 0 0 / 0.28);
}

/* js/cards.js: a card with a picture is hidden, keeping its space, until
   the picture has loaded. */
.cards-wait .card:has(> .card__image):not(.card--ready) {
  visibility: hidden;
}

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

@media (min-width: 40rem) {
  .card__image {
    aspect-ratio: 3 / 2;
  }
}

.card__content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 1rem;
}

.card__content--flush {
  padding: 0;
}

.card__title {
  margin: 0 0 0.75rem;
  font-size: var(--type-title);
  font-weight: 400;
  line-height: 1.25;
}

/* A linked title reads as a heading; the underline shows on hover. */
.card__title a {
  color: inherit;
  text-decoration: none;
}

.card__title a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Hover underlines take the accent; the text keeps its color. */
a:hover {
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

/* A # after each heading in a page links to that heading. It shows on
   hovering the heading, and always where nothing can hover. */
.section-link {
  margin-left: 0.3em;
  font-size: 0.9em;
  text-decoration: none;
  visibility: hidden;
}

.section-link::before {
  content: "#";
}

.section-link:not(:hover) {
  color: var(--gray);
}

:is(h1, h2, h3, h4, h5, h6):hover > .section-link {
  visibility: visible;
}

@media (hover: none) {
  .section-link {
    visibility: visible;
  }
}

/* A link written inside a title goes somewhere else, so it shows always. */
.card__title a.card__title-inline {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* A page card links as a whole: the title link covers the card, and links
   in the card text stay above it. */
.card--page,
.card:has(> .card__image):has(.card__title a) {
  position: relative;
}

/* A linked card with an image links as a whole too, so the image clicks
   through. */
.card--page .card__title a::after,
.card:has(> .card__image) .card__title a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card--page .card__text a,
.card:has(> .card__image):has(.card__title a) .card__text a {
  position: relative;
  z-index: 1;
}

.card__text {
  flex: 1 1 auto;
  font-size: var(--type-text);
  line-height: 1.5;
}

.card__text > :first-child {
  margin-top: 0;
}

.card__text > :last-child {
  margin-bottom: 0;
}

.card__text pre {
  overflow-x: auto;
}

/* An image in the card text sits on its own line, centered. */
.card__text img,
.card__text .c1-mark {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* Card text that starts with an image puts the image above the title, as on
   a card with an image field. The text box drops out of the layout so its
   first child can move ahead of the title; flex items do not collapse
   margins, so each child keeps only a bottom margin. */
.card__text:has(> :first-child :is(img, iframe)) {
  display: contents;
}

.card__text:has(> :first-child :is(img, iframe)) > * {
  margin-top: 0;
  margin-bottom: 1em;
}

.card__text:has(> :first-child :is(img, iframe)) > :first-child {
  order: -1;
  margin-bottom: 1rem;
}

.card__text:has(> :first-child :is(img, iframe)) > :last-child {
  margin-bottom: 0;
}

.verse {
  font-size: var(--type-text);
}

/* More room under the title of the content-heavy poem card. */
.card:has(.verse) .card__title {
  margin-bottom: 1.1rem;
}

/* Optical margin alignment. A round or slanted capital that starts a line
   looks indented, so .pull-X moves the letter left into the margin. The
   .push-X span before the preceding space adds the same width back; when
   both sit on one line they cancel, and when the line breaks at that space
   the push stays at the end of the previous line. */
.push-C,
.push-O {
  margin-right: 0.06em;
}

.pull-C,
.pull-O {
  margin-left: -0.06em;
}

.push-V,
.push-A {
  margin-right: 0.05em;
}

.pull-V,
.pull-A {
  margin-left: -0.05em;
}

/* Safari: quotes and similar marks at a line's start or end hang outside. */
.card__text,
.article {
  hanging-punctuation: first last;
}

/* A quoted post: its own rounded box, the words a step larger, and the
   attribution under a rule in small gray, as a post's byline row. */
.card__text blockquote {
  margin: 0;
  padding: 0.9rem 1rem 0.7rem;
  border: 1px solid var(--gray-lighter);
  border-radius: var(--radius);
}

.card__text blockquote > p:first-child {
  margin-top: 0;
  font-size: var(--type-body);
  line-height: 1.45;
}

/* A link in the byline keeps the byline's gray; the underline marks it. */
.card__text blockquote > p:last-child:not(:first-child) a,
.card__text blockquote > p:last-child:not(:first-child) a:visited {
  color: inherit;
  text-underline-offset: 0.15em;
}

.card__text blockquote > p:last-child:not(:first-child) {
  margin: 0.75rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--gray-lighter);
  color: var(--gray-dark);
  font-size: var(--type-small);
}

/* The C1 mark: js/c1-mark.js lays a shader canvas over the image and hides
   the image once the canvas draws. */
.c1-mark {
  position: relative;
  width: 6rem;
}

.c1-mark img {
  display: block;
  width: 100%;
}

.c1-mark canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.c1-mark--drawn img {
  visibility: hidden;
}

/* Article pages */

.article {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1rem 0 4rem;
  font-size: var(--type-body);
  line-height: 1.6;
}

.article__nav {
  margin-bottom: 2rem;
  font-size: var(--type-text);
  letter-spacing: 0.02em;
}

/* The arrow doubles as the hint for the ← key (js/keys.js). */
.article__nav a,
.article__nav a:visited {
  color: var(--gray-dark);
  text-decoration: none;
}

.article__nav a:hover {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

[data-theme="dark"] .article__nav a,
[data-theme="dark"] .article__nav a:visited {
  color: #aa00e8;
}

[data-theme="dark"] .article__nav a:hover {
  color: #5cecff;
}

.article h1 {
  margin: 0 0 0.25rem;
  font-size: var(--type-page);
  font-weight: 400;
  line-height: 1.2;
}

.article__meta {
  margin: 0 0 2rem;
  color: var(--gray-dark);
  font-size: var(--type-text);
}

.article code {
  font-size: 0.9em;
}

.article pre {
  overflow-x: auto;
  padding: 0.5rem 0.75rem;
  background: var(--gray-lighter);
  border-radius: 0.25rem;
}

.deck__banner {
  display: block;
  margin: 0 0 1.5rem;
  border-radius: 0.25rem;
  overflow: hidden;
}

.deck__banner img {
  display: block;
  width: 100%;
}

.deck__help {
  color: var(--gray-darker);
  font-size: var(--type-text);
}

/* Margin notes: text about the page rather than part of it. Inline after the
   title on narrow screens; on wide ones the article gives up 15rem of right
   padding and the note floats into it, beside whatever follows it. The
   negative margin equals width plus gap, so the column's text does not wrap
   around it. */
.marginalia {
  line-height: 1.5;
}

.marginalia > p:first-child {
  margin-top: 0;
}

@media (min-width: 68rem) {
  /* The left padding grows with the room past 61rem, up to the 15rem the
     notes take on the right, so once the page is 76rem wide the text column
     sits on the page's center line. */
  .article {
    display: flow-root;
    max-width: 76rem;
    padding-right: 15rem;
    padding-left: clamp(0rem, 100% - 61rem, 15rem);
  }

  .marginalia {
    float: right;
    clear: right;
    width: 13rem;
    margin-right: -15rem;
  }

  /* A tier sets its note beside the tier's first line instead of beside
     whatever follows the note: two columns reaching into the margin, the
     main column first, the note level with its top. */
  .tier {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
    column-gap: 2rem;
    align-items: start;
    margin: 0 -15rem 2rem 0;
  }

  /* Margins do not collapse out of a grid, so the tier carries the space
     under the title line instead. */
  .tier .article__meta {
    margin-bottom: 0;
  }

  .tier > .marginalia {
    width: auto;
    margin-right: 0;
  }
}

/* An embedded talk video: full column width at 16:9. */
.video {
  margin: 1.5rem 0;
}

.video iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

.deck__help kbd {
  padding: 0 0.3em;
  border: 1px solid var(--gray);
  border-radius: 0.2rem;
  font-family: inherit;
  font-size: 0.85em;
}

/* The ? key's list of keys (js/keys.js): a small card over a dimmed page. */
.keys-help {
  padding: 1rem 1.25rem;
  border: 0;
  border-radius: var(--radius);
  background-color: var(--card);
  color: inherit;
  box-shadow: 0 0 0 2px var(--accent), 0 10px 26px -8px rgb(0 0 0 / 0.28);
  font-size: var(--type-text);
  cursor: default;
}

.keys-help::backdrop {
  background-color: rgb(0 0 0 / 0.35);
}

.keys-help dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.6rem 1rem;
  align-items: baseline;
  margin: 0;
}

.keys-help dt {
  justify-self: end;
}

.keys-help dd {
  margin: 0;
}

.keys-help kbd {
  padding: 0 0.35em;
  border: 1px solid var(--gray);
  border-radius: 0.2rem;
  font-family: inherit;
}

[data-theme="dark"] .keys-help {
  background-color: #000000;
  color: #f0f0f0;
}

[data-theme="dark"] .keys-help kbd {
  border-color: #4e4e8f;
}

/* Dark mode: js/keys.js sets data-theme="dark" on <html> (the d key). */

:root[data-theme="dark"] {
  color-scheme: dark;
  --frame: #262626;
  --ground: #000000;
  color: #f0f0f0;
}

[data-theme="dark"] a,
[data-theme="dark"] a:visited {
  color: #5cecff;
}

[data-theme="dark"] .card {
  background-color: #000000;
  border: 1px solid #4e4e8f;
  box-shadow: none;
}

[data-theme="dark"] .card--page:hover,
[data-theme="dark"] .card:has(.card__title > a:not(.card__title-inline)):hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

[data-theme="dark"] .card__image {
  border-bottom: 1px solid #4e4e8f;
}

[data-theme="dark"] .card__title,
[data-theme="dark"] .card__title a {
  color: #f0f0f0;
}

[data-theme="dark"] .card__text blockquote,
[data-theme="dark"] .card__text blockquote > p:last-child:not(:first-child) {
  border-color: #4e4e8f;
}

[data-theme="dark"] .card__text blockquote > p:last-child:not(:first-child) {
  color: #aa00e8;
}

[data-theme="dark"] .article__meta {
  color: #aa00e8;
}

[data-theme="dark"] .article pre {
  background: #111111;
}

[data-theme="dark"] .deck__help {
  color: #c8c8c8;
}

[data-theme="dark"] .deck__help kbd {
  border-color: #4e4e8f;
}

[data-theme="dark"] .deck__banner {
  border-radius: 0;
}
