/*
  Strange Chances
  Less, but better. Warm paper, hairlines, one circle, one line.
*/

:root {
  color-scheme: light dark;
  --paper: #f5f4f0;
  --paper-lit: #fbfaf7;
  --ink: #1d1d1b;
  --secondary: #62615b;
  --tertiary: #7a7973;
  --rule: rgba(29, 29, 27, .09);
  --rule-strong: rgba(29, 29, 27, .28);
  --wash: rgba(29, 29, 27, .035);

  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --serif: Charter, "Iowan Old Style", "Source Serif Pro", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --unit: 8px;
  --gutter: clamp(20px, 5vw, 64px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141413;
    --paper-lit: #1b1b19;
    --ink: #ebe9e3;
    --secondary: #a3a199;
    --tertiary: #827f78;
    --rule: rgba(235, 233, 227, .09);
    --rule-strong: rgba(235, 233, 227, .26);
    --wash: rgba(235, 233, 227, .04);
  }
}

@media (prefers-contrast: more) {
  :root { --ink: #000; --secondary: #333; --tertiary: #555; --rule: #999; --rule-strong: #000; --paper: #fff; --paper-lit: #fff; }
}

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

html { background: var(--paper); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a, button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  font: 400 14px/1.55 var(--font);
  letter-spacing: -.005em;
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Controlled light: a soft fall from above, no harder than daylight on plaster. */
  background:
    radial-gradient(120% 60% at 50% -10%, var(--paper-lit) 0%, transparent 70%) no-repeat,
    var(--paper);
}

::selection { background: var(--ink); color: var(--paper); }

a { color: inherit; text-decoration: none; }

:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; border-radius: 1px; }

[hidden] { display: none !important; }

/* ---------- Layout ---------- */

.site {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: calc(var(--unit) * 6);
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(var(--unit) * 7) var(--gutter) calc(var(--unit) * 6);
}

@media (min-width: 900px) {
  .site {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    column-gap: calc(var(--unit) * 10);
    padding-top: clamp(64px, 12vh, 128px);
    min-height: 100vh;
    min-height: 100svh;
  }
  .masthead { position: sticky; top: clamp(64px, 12vh, 128px); align-self: start; }
  main { grid-column: 2; }
  footer { grid-column: 1 / -1; }
}

/* ---------- Masthead ---------- */

.mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -.025em;
  line-height: 1;
}

/* Small details speak in mono: handle, counts, dates. */
.handle, .count, .when, .note, footer {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .02em;
}
.handle { margin: 10px 0 0 23px; color: var(--tertiary); }
.mark { white-space: nowrap; }

/* One perfect circle. Its lit half turns with the local hour. */
.orb {
  --sun: 180deg;
  position: relative;
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--ink);
  background: linear-gradient(var(--sun), var(--ink) 50%, transparent 50%);
  transition: transform .9s var(--ease);
}
.mark:hover .orb { transform: rotate(180deg); }

.masthead nav {
  display: flex;
  gap: 28px;
  margin-top: calc(var(--unit) * 4);
}

.masthead nav a {
  position: relative;
  color: var(--secondary);
  font-size: 13px;
  padding: 4px 0;
  transition: color .2s var(--ease);
}
.masthead nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .35s var(--ease);
}
.masthead nav a:hover { color: var(--ink); }
.masthead nav a[aria-current="page"] { color: var(--ink); }
.masthead nav a[aria-current="page"]::after { transform: scaleX(1); }

@media (min-width: 900px) {
  .masthead nav { flex-direction: column; gap: 10px; margin-top: calc(var(--unit) * 7); }
  .masthead nav a { align-self: flex-start; padding: 2px 0 2px 23px; }
  /* Desktop: the active marker becomes a small dot, aligned under the orb. */
  .masthead nav a::after {
    left: 3px; right: auto; top: 50%; bottom: auto;
    width: 5px; height: 5px; border-radius: 50%;
    transform: translateY(-50%) scale(0);
    transition: transform .35s var(--ease);
  }
  .masthead nav a[aria-current="page"]::after { transform: translateY(-50%) scale(1); }
}

/* ---------- Panels ---------- */


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

/* ---------- Shelves ---------- */

.shelf + .shelf { margin-top: calc(var(--unit) * 10); }

.shelf h2 {
  margin: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule-strong);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -.005em;
}
.count { margin-left: 8px; color: var(--tertiary); }

.works { list-style: none; margin: 0; padding: 0; }

.works li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: 32px;
  padding: 13px 0 14px;
  border-bottom: 1px solid var(--rule);
}

/* Title then author, flowing like an entry in an index. */
.entry { min-width: 0; text-wrap: pretty; overflow-wrap: anywhere; }
/* Titles set like books: a reading serif, upright. */
.title { font-family: var(--serif); font-style: normal; font-size: 16px; line-height: 1.45; letter-spacing: -.005em; }
.author { margin-left: 12px; font-size: 13px; color: var(--secondary); white-space: nowrap; }

.when { color: var(--tertiary); white-space: nowrap; }

/* Progress: a hairline rod with a circle riding along it. Registered so a live update glides. */
@property --p { syntax: "<number>"; inherits: true; initial-value: 0; }
.meter {
  --p: 0;
  position: relative;
  display: block;
  width: 56px;
  height: 7px;
  align-self: center;
  transition: --p 1.2s var(--ease);
}
.meter::before,
.meter::after { content: ""; position: absolute; top: 3px; left: 0; height: 1px; }
.meter::before { right: 0; background: var(--rule-strong); opacity: .5; }
.meter::after { width: calc(var(--p) * (100% - 7px)); background: var(--ink); }
.meter i {
  position: absolute;
  top: 0;
  left: calc(var(--p) * (100% - 7px));
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--ink);
}

/* ---------- Now reading ---------- */

.now { margin-bottom: calc(var(--unit) * 10); }
.now h2 { margin: 0 0 20px; font-size: 13px; font-weight: 400; color: var(--secondary); }
.now-body { display: grid; justify-items: start; gap: 6px; }
.now-title {
  font-family: var(--serif);
  font-style: normal;
  font-size: clamp(26px, 3.4vw, 34px);
  line-height: 1.15;
  letter-spacing: -.02em;
  text-wrap: balance;
  max-width: 22ch;
}
.now-author { font-size: 14px; color: var(--secondary); }
.meter--long { width: min(100%, 320px); height: 9px; margin-top: 22px; }
.meter--long::before, .meter--long::after { top: 4px; }
.meter--long::after { width: calc(var(--p) * (100% - 9px)); }
.meter--long i { width: 9px; height: 9px; left: calc(var(--p) * (100% - 9px)); }
.now-meta { margin-top: 6px; font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }

/* Live: a small circle breathing, slowly. */
.note { display: flex; align-items: center; gap: 10px; }
.pulse { display: none; width: 5px; height: 5px; border-radius: 50%; background: var(--ink); }
.note.is-live .pulse { display: block; animation: breathe 3.2s ease-in-out infinite; }

/* Loading */
.works .placeholder { display: block; padding: 20px 0; }
.placeholder span {
  display: block;
  height: 10px;
  width: 46%;
  border-radius: 999px;
  background: var(--wash);
  animation: breathe 1.6s ease-in-out infinite;
}
.placeholder:nth-child(2) span { width: 62%; }
.placeholder:nth-child(3) span { width: 38%; }
@keyframes breathe { 50% { opacity: .4; } }

.works .message { display: block; padding: 24px 0; color: var(--secondary); }

.note { margin: calc(var(--unit) * 4) 0 0; color: var(--tertiary); }

/* ---------- Empty states ---------- */

.empty {
  display: grid;
  justify-items: start;
  gap: 24px;
  padding: calc(var(--unit) * 6) 0 calc(var(--unit) * 10);
  border-top: 1px solid var(--rule-strong);
}
.empty a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.empty p { margin: 0; color: var(--secondary); font-size: 13px; }
.empty-mark {
  width: 56px;
  height: 56px;
  margin-top: 16px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--rule-strong);
}
.empty-mark--line {
  width: 56px;
  height: 56px;
  border-radius: 0;
  box-shadow: none;
  background: linear-gradient(var(--rule-strong), var(--rule-strong)) center / 100% 1px no-repeat;
}

/* ---------- Photos ---------- */

/* One sequence, square tiles: the grid stays calm whatever the shape of each photo. */
.gallery {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
}
.tile button { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; background: var(--wash); cursor: zoom-in; overflow: hidden; }
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* The grid arrives once, as one object, when its first photos are ready; after that it holds still. */
.gallery { opacity: 0; transition: opacity .4s ease-out; }
.gallery.is-ready { opacity: 1; }
/* The first photo leads at double size; the rest follow in step. */
.tile:first-child { grid-column: span 2; grid-row: span 2; }
.gallery .message { grid-column: 1 / -1; color: var(--secondary); }

/* Viewer (PhotoSwipe): the photo alone on paper, Close above, the caption and steps below. */
.pswp {
  --pswp-bg: var(--paper);
  --pswp-placeholder-bg: var(--wash);
  --pswp-icon-color: var(--secondary);
  --pswp-icon-color-secondary: var(--paper);
  --pswp-preloader-color: var(--rule-strong);
  --pswp-preloader-color-secondary: var(--secondary);
  --pswp-error-text-color: var(--secondary);
  color: var(--ink);
  font: 400 13px/1.5 var(--font);
}
.pswp__top-bar { justify-content: flex-end; padding: 0 var(--gutter); height: 56px; align-items: center; }
.pswp__button--close { width: auto; height: auto; margin: 0; padding: 6px 8px; opacity: 1; color: var(--secondary); font: inherit; }
.pswp__button--close:hover { color: var(--ink); }
.pswp__foot { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 var(--gutter) 22px; text-align: center; pointer-events: none; transition: opacity var(--pswp-transition-duration, .333s) cubic-bezier(.4, 0, .22, 1); }
.pswp-caption { margin: 0 auto 10px; max-width: 40ch; font-family: var(--serif); font-size: 15px; letter-spacing: -.005em; color: var(--ink); text-wrap: balance; }
.pswp-steps { display: flex; justify-content: center; align-items: center; gap: 28px; pointer-events: auto; }
.pswp-step { appearance: none; border: 0; background: none; color: var(--secondary); font: inherit; font-size: 13px; padding: 6px 8px; cursor: pointer; }
.pswp-step:hover { color: var(--ink); }
.pswp-count { font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
/* The controls arrive with the photo and leave with it, like PhotoSwipe's own. */
.pswp--ui-visible .pswp__foot { opacity: 1; }
.pswp:not(.pswp--ui-visible) .pswp__foot { opacity: 0; }

/* ---------- Writings ---------- */

/* A meditation reads like a poem: the reading serif, short lines, room between stanzas. */
.piece { max-width: 30rem; padding-top: calc(var(--unit) * 1); }
.piece-kind { margin: 0 0 10px; font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
.piece-title { margin: 0 0 calc(var(--unit) * 4); font-family: var(--serif); font-weight: 400; font-size: 20px; line-height: 1.3; letter-spacing: -.01em; }
.piece-body p { margin: 0 0 1.1em; font-family: var(--serif); font-size: 15px; line-height: 1.7; color: var(--ink); text-wrap: pretty; }
.piece-body p:last-child { margin-bottom: 0; }
/* One small circle closes a piece, the same circle as the orb and the centre of the diagram. */
.piece-body::after { content: ""; display: block; width: 7px; height: 7px; margin: calc(var(--unit) * 5) auto 0; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--tertiary); }
@media (min-width: 900px) { .piece { margin: 0 auto; } }
/* A two-by-two drawn the site's way: two hairlines crossing, one small circle where they meet. */
.matrix {
  position: relative;
  display: grid;
  grid-template-columns: 1.6em 1fr 1fr;
  grid-template-rows: auto auto auto;
  margin: 2.4em 0;
}
.matrix-axis { font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
.matrix-col { padding: 0 0 12px 20px; }
.matrix-col:first-child { grid-column: 2; }
.matrix-row { grid-column: 1; writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; align-self: center; }
.piece-body .matrix-cell { margin: 0; padding: 22px 20px 24px; font-size: 14px; line-height: 1.6; color: var(--secondary); }
/* The cross: a vertical hairline left of the right column, a horizontal one above the bottom row. */
.matrix-cell:nth-of-type(2), .matrix-cell:nth-of-type(4) { border-left: 1px solid var(--rule-strong); }
.matrix-cell:nth-of-type(3), .matrix-cell:nth-of-type(4) { border-top: 1px solid var(--rule-strong); }
.matrix-cell--centre { position: relative; }
.matrix-cell--centre::before {
  content: ""; position: absolute; left: -4px; top: -4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--paper); box-shadow: inset 0 0 0 1px var(--ink);
}

/* Writings index: the Read list's rhythm, each title a link. */
.writings-list { border-top: 1px solid var(--rule-strong); }
.writings-list .entry { color: inherit; text-decoration: none; }
.writings-list .summary { display: block; margin-top: 4px; font-size: 13px; line-height: 1.5; color: var(--secondary); }
.writings-list .entry:hover .title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* Listening: a record sleeve. Numbers hang in the margin so titles align. */
.tracks .entry { position: relative; padding-left: 36px; color: inherit; text-decoration: none; }
.tracks .entry:hover .title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.track-no { position: absolute; left: 0; top: .2em; font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
.tracks { border-top: 1px solid var(--rule-strong); }
.listen-intro { margin: 0 0 16px; font-size: 13px; color: var(--secondary); }
.note--plain { display: block; }
.listen-intro .spotify { color: var(--secondary); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; text-decoration-color: var(--rule-strong); }
.listen-intro .spotify:hover { color: var(--ink); text-decoration-color: currentColor; }

/* A piece on its own page. */
.piece-meta, .pager span { font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
.piece-meta { margin: -24px 0 calc(var(--unit) * 4); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: calc(var(--unit) * 8); padding-top: 18px; border-top: 1px solid var(--rule); }
.pager a { display: grid; gap: 4px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 15px; }
.pager a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.pager-next { grid-column: 2; text-align: right; }

/* * * * between movements of a piece. */
/* A closing verse, set on the centre line like the breaks. */
.piece-capstone { margin: calc(var(--unit) * 8) 0 0; padding: 0; text-align: center; }
.piece-body .piece-capstone p { margin: 0; font-family: var(--serif); font-style: italic; font-size: 14px; line-height: 1.75; color: var(--secondary); }
.piece-capstone footer { display: block; margin-top: 14px; font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--tertiary); }
.piece-capstone cite { font-style: normal; }
.piece-break { border: 0; margin: 2.2em 0; height: auto; text-align: center; }
.piece-break::after { content: "* * *"; font-family: var(--serif); font-size: 15px; letter-spacing: .4em; padding-left: .4em; color: var(--tertiary); }

/* ---------- Motion ---------- */

/* Tabs: a short cross-fade of the content; the masthead holds still. */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; animation-timing-function: ease-out; }
.is-switching .masthead { view-transition-name: masthead; }
::view-transition-group(masthead), ::view-transition-new(masthead) { animation: none; }
::view-transition-old(masthead) { display: none; }

/* ---------- Footer ---------- */

footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: calc(var(--unit) * 8);
  font-size: 12px;
  color: var(--tertiary);
}
footer .elsewhere { display: flex; gap: 16px; }
footer a { color: inherit; text-decoration: none; transition: color .2s var(--ease); }
footer a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
footer .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  body { font-size: 13px; }
  .site { gap: calc(var(--unit) * 5); padding-top: calc(var(--unit) * 5); }
  .shelf + .shelf { margin-top: calc(var(--unit) * 7); }
  .now { margin-bottom: calc(var(--unit) * 7); }
  .works li { column-gap: 20px; padding: 12px 0 13px; }
  .title { font-size: 15px; }
  .masthead { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 12px; }
  .handle { margin: 0; }
  .masthead nav { grid-column: 1 / -1; }
  .author { display: block; margin: 2px 0 0; font-size: 12px; white-space: normal; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  /* On a phone the sequence opens and closes at full width. */
  .tile:last-child:nth-child(even) { grid-column: 1 / -1; }
}

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