/* ============================================================
   Personal site — shared foundation for every page
   tokens · base typography · site header · footer · 3D book
   ============================================================ */

:root {
  color-scheme: light;

  /* the one knob that changes the whole mood of the site */
  --paper: #ffffff;
  --ink: #000;

  --ink-soft: color-mix(in srgb, var(--ink) 65%, transparent);
  --ink-faint: color-mix(in srgb, var(--ink) 35%, transparent);
  --rule: color-mix(in srgb, var(--ink) 12%, transparent);

  /* link underlines and annotation marks */
  --link: #0ba1ff;
  --link-hover: #0778c2;
  --note: #c98210;
  --note-hover: #9a6209;

  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font: 400 var(--size)/1.65 var(--font);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  background: var(--paper);
  color: var(--ink);
  /* the books pages wash this toward the hovered cover */
  transition: background-color 480ms ease;
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--ink) 25%, transparent);
  text-underline-offset: 4px;
  transition: text-decoration-color 120ms ease;
}

a:hover { text-decoration-color: color-mix(in srgb, var(--ink) 85%, transparent); }

.soft { color: var(--ink-soft); }

/* ---------- site header: name, nav row beneath it ---------- */

/* explicit metrics so the header renders identically on every page,
   whatever the surrounding layout does with fonts and line-heights */
.site-head {
  margin-bottom: 56px;
  font-family: var(--font);
  line-height: 1.7;
}

.brand-h1 {
  font-size: inherit;
  font-weight: 400;
  line-height: inherit;
}

.brand {
  display: block;
  width: fit-content;
  font-weight: 400;
  font-size: 24px;
  line-height: 1.3;
  margin-bottom: 16px;
  color: var(--ink);
  text-decoration: none;
}

/* ---------- wordmark: the logo, letter by letter ----------
   Each letter is the same logo.png clipped to its own slice, so it can
   move on its own. On arrival the letters rise out from below the
   baseline in a rolling swell; on hover they bob once like a wave.
   ------------------------------------------------------------ */

.brand-logo { line-height: 0; margin-bottom: 18px; }

/* the viewBox has 24 units of headroom above the letters (0 -24 750 145)
   so the overshoot and hover bob aren't clipped; the negative margin keeps
   the letters themselves exactly where a 28px-tall logo would sit */
.wordmark {
  display: block;
  height: calc(28px * 145 / 121);
  margin-top: calc(-28px * 24 / 121);
  width: auto;
  aspect-ratio: 750 / 145;
  overflow: hidden; /* letters come up from under the bottom edge */
}

.wm-letter,
.wm-bob {
  transform-box: view-box;
  transform-origin: calc(var(--cx) * 1px) 121px;
}

.wm-letter {
  animation: wm-rise 900ms cubic-bezier(0.25, 0.9, 0.3, 1) both;
  animation-delay: calc(150ms + var(--i) * 60ms);
}

@keyframes wm-rise {
  0%   { transform: translateY(135px) rotate(-10deg); }
  55%  { transform: translateY(-10px) rotate(3deg); }
  78%  { transform: translateY(3px) rotate(-1deg); }
  100% { transform: none; }
}

.brand-logo:hover .wm-bob,
.brand-logo:focus-visible .wm-bob {
  animation: wm-bob 650ms ease-in-out both;
  animation-delay: calc(var(--i) * 35ms);
}

@keyframes wm-bob {
  0%, 100% { transform: none; }
  40%      { transform: translateY(-12px) rotate(-3deg); }
  70%      { transform: translateY(2px); }
}

.brand-logo:focus-visible { outline: 2px solid var(--link); outline-offset: 6px; }

.wm-seen .wm-letter { animation: none; }

@media (max-width: 600px) {
  .wordmark { height: calc(24px * 145 / 121); margin-top: calc(-24px * 24 / 121); }
}

@media (prefers-reduced-motion: reduce) {
  .wm-letter, .wm-bob { animation: none !important; }
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  font-size: 17px;
  line-height: 1.7;
}

.site-nav a {
  display: inline-block;
  color: var(--ink-soft);
  text-decoration: none;
}

.site-nav a:hover { color: var(--ink); }

.site-nav a.active {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--ink) 25%, transparent);
  text-underline-offset: 4px;
}

/* Instagram + X, just after the last tab */
.nav-social {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-left: 4px;
}

.site-nav .nav-social a {
  display: inline-flex;
  padding: 2px;
  margin: -2px; /* a slightly bigger hit area without shifting the icons */
  color: var(--ink);
  transition: opacity 120ms ease;
}

.site-nav .nav-social a:hover { opacity: 0.6; }
.nav-social svg { display: block; width: 17px; height: 17px; }
.nav-social a[aria-label="X"] svg { width: 15px; height: 15px; } /* X's mark reads larger than its box */

/* on a phone, tighten the spacing so the icons stay on the tabs' line */
@media (max-width: 600px) {
  .site-nav { column-gap: 18px; }
  .nav-social { margin-left: 0; gap: 12px; }
}

/* ---------- footer ---------- */

.footer {
  margin-top: 64px;
  color: var(--ink-soft);
}

/* ---------- email signup (posts to Ghost via subscribe.js) ---------- */

.subscribe { margin-top: 72px; max-width: 420px; }
.subscribe + .footer { margin-top: 40px; }
.subscribe label { display: block; margin-bottom: 8px; font-style: italic; }
.subscribe-row { display: flex; gap: 8px; }
.subscribe input,
.subscribe button {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 7px 12px;
  background: var(--paper);
}
.subscribe input { flex: 1; min-width: 0; }
.subscribe input::placeholder { color: var(--ink-faint); }
.subscribe input:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.subscribe button { cursor: pointer; }
.subscribe button:hover { background: var(--ink); color: var(--paper); }
.subscribe button:disabled { opacity: .5; cursor: progress; }
.subscribe-status { min-height: 1.65em; margin-top: 8px; font-size: 14px; color: var(--ink-soft); }
.subscribe[data-state="error"] .subscribe-status { color: #b42318; }

/* ---------- 3D book ----------------------------------------
   A cover that swings open on its spine. Pages set --bw/--bh;
   the hover transforms live with whichever page uses them.
   ------------------------------------------------------------ */

.book-scene {
  --bw: 188px;
  --bh: 282px;
  position: relative;
  display: block;
  width: var(--bw);
  height: var(--bh);
}

.book-3d { position: absolute; inset: 0; }

/* the board peeking out behind the cover */
.b-back-cover {
  position: absolute;
  top: 2%;
  left: 2%;
  width: 96%;
  height: 96%;
  z-index: 1;
  background: linear-gradient(90deg, #6e6a64 0%, #8a857e 55%, #7a756e 100%);
  border-radius: 0 6px 6px 0;
  box-shadow: 1px 1px 4px rgb(0 0 0 / 0.18);
}

.b-inside {
  position: absolute;
  top: 3%;
  left: 5%;
  width: 90%;
  height: 94%;
  z-index: 2;
}

/* stacked leaves that fan out a little as the cover opens */
.b-page {
  position: absolute;
  top: 0;
  right: 0;
  width: 98%;
  height: 100%;
  background: #f7f4ee;
  border: 1px solid rgb(0 0 0 / 0.12);
  border-radius: 0 6px 6px 0;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  transform: translateX(0);
  transition: transform 700ms cubic-bezier(0.455, 0.03, 0.515, 0.955);
}

.b-image {
  position: absolute;
  inset: 0;
  z-index: 3;
  /* the typographic fallback sizes its text against this box, so a
     cover reads the same whether it's 96px or 190px wide */
  container-type: inline-size;
  border-radius: 2px 6px 6px 2px;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.08), 0 8px 14px rgb(0 0 0 / 0.06);
  transform: perspective(2000px) translateX(0) rotateY(0deg) scaleX(1);
  transform-origin: left center;
  transition:
    transform 700ms cubic-bezier(0.25, 1, 0.5, 1),
    box-shadow 700ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* promote only the book under the pointer, never a whole shelf at once */
.book-cell:hover .b-image,
.book-scene:hover .b-image { will-change: transform; }

/* real cover photos get a light illustrated pass (toon.js defines the filter) */
img[src^="https://covers.openlibrary.org"],
img[src^="https://coverartarchive.org"] { filter: url(#cover-toon); }

.b-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* Typographic stand-in when a book has no cover image. Deliberately not
   scoped to .b-image — the same jacket is drawn inside a book window,
   where there is no .b-image wrapper. Whatever contains it must declare
   container-type: inline-size for the cqw text sizing to resolve. */
.cover-fallback {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 12% 10%;
  border-radius: inherit;
  background: var(--cover-bg, #6b7f6e);
  color: #fff;
  text-align: left;
  overflow: hidden;
}

.cover-fallback .cf-title {
  font-size: clamp(9px, 10.5cqw, 20px);
  line-height: 1.2;
  text-wrap: balance;
}

.cover-fallback .cf-author {
  font-size: clamp(7px, 6.8cqw, 13px);
  line-height: 1.3;
  opacity: 0.82;
}

/* the shadow cast into the gutter as the cover lifts */
.b-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 9%;
  height: 100%;
  margin-left: 7.3%;
  z-index: 4;
  border-left: 2px solid rgb(0 0 0 / 0.06);
  background: linear-gradient(90deg, rgb(255 255 255 / 0.2), rgb(255 255 255 / 0));
  pointer-events: none;
  transition: margin-left 700ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* the sheen that slides across the cover as it turns */
.b-light {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(90deg, rgb(255 255 255 / 0), rgb(255 255 255 / 0.5));
  opacity: 0.08;
  transform: perspective(2000px) rotateY(0deg);
  transform-origin: left center;
  pointer-events: none;
  transition:
    opacity 700ms cubic-bezier(0.25, 1, 0.5, 1),
    transform 700ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* mouse only — a tap should open the book, not tease the cover */
@media (hover: hover) and (pointer: fine) {
  .book-scene:hover .b-image {
    transform: perspective(2000px) translateX(calc(var(--bw) * -0.027)) rotateY(-12deg) scaleX(0.96);
    box-shadow:
      10px 10px 20px rgb(0 0 0 / 0.25),
      20px 20px 40px rgb(0 0 0 / 0.2),
      40px 40px 60px rgb(0 0 0 / 0.15);
  }

  .book-scene:hover .b-light {
    opacity: 0.2;
    transform: perspective(2000px) rotateY(-12deg);
  }

  .book-scene:hover .b-effect { margin-left: 4.5%; }

  .book-scene:hover .b-page:nth-child(1) { transform: translateX(calc(var(--bw) * 0.018)); }
  .book-scene:hover .b-page:nth-child(2) { transform: translateX(calc(var(--bw) * 0.009)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* ---------- utilities ---------- */

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 999;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--ink);
  color: var(--ink);
  text-decoration: none;
  transition: top 140ms ease;
}

.skip-link:focus { top: 8px; }

/* ---------- the horizon: end of the page, end of the day ----------
   A full-bleed photo at the foot of every page. Its sky fades up into
   the white so the page quietly takes on its colours, and horizon.js
   lifts it into place (--p: 0 arriving → 1 settled) as you reach the
   bottom. The footer sits on the water.
   ------------------------------------------------------------------ */

html { overflow-x: clip; } /* the 100vw bleed must never cause sideways scroll */

.horizon {
  --p: 1;
  position: relative;
  z-index: -1;               /* the sky slides in under the signup above it */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-top: -180px;
  height: clamp(460px, 82vh, 880px);
  overflow: hidden;
}

.horizon-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 2% 100%;  /* keep the palm when narrow screens crop the sides */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgb(0 0 0 / 0.55) 26%, #000 46%);
          mask-image: linear-gradient(to bottom, transparent 0%, rgb(0 0 0 / 0.55) 26%, #000 46%);
  transform: translateY(calc((1 - var(--p)) * 16%));
  transition: transform 700ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* golden-hour glow that warms as the horizon settles */
.horizon::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(90% 32% at 30% 60%, rgb(255 196 150 / 0.45), transparent 70%);
  mix-blend-mode: soft-light;
  opacity: var(--p);
  transition: opacity 700ms ease;
}

.horizon .footer {
  position: absolute;
  z-index: 1;
  left: 48px;
  bottom: 28px;
  margin: 0;
  padding: 0;
  color: #fff;
  text-shadow: 0 1px 10px rgb(0 0 0 / 0.45);
}

@media (max-width: 600px) {
  .horizon { margin-top: -120px; height: clamp(380px, 70vh, 560px); }
  .horizon .footer { left: 20px; bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .horizon-photo, .horizon::after { transform: none; transition: none; }
}
