/* ------------------------------------------------------------------ *
 *  base.css — structure + behavior chrome, parameterized by variables.
 *
 *  Owns: layout skeleton, the sidenote, the rewrite toolbar, the toast,
 *  the decay animation. Each skin's style.css supplies the variables
 *  (palette, fonts, measure) and the decorative personality.
 * ------------------------------------------------------------------ */

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

html,
body {
  margin: 0;
  padding: 0;
}

:root {
  --measure: 34rem;
  --gutter: 15rem;
  --gutter-gap: 2.6rem;
  --pad: clamp(1.25rem, 5vw, 3rem);
  --transition: 240ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-text, inherit);
}

a {
  color: inherit;
}

/* --------------------------- chrome ------------------------------- */

.site-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  width: min(var(--measure), 100% - 2 * var(--pad));
  margin: 0 auto;
  padding: clamp(1.4rem, 4vw, 2.6rem) 0 0;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: var(--wordmark-weight, 600);
  font-size: 1.02rem;
  letter-spacing: var(--wordmark-tracking, 0);
  text-decoration: none;
  color: var(--text);
}

.site-nav {
  display: flex;
  gap: 1.4rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.nav-link {
  color: var(--text-soft);
  text-decoration: none;
  transition: color var(--transition);
}
.nav-link:hover,
.nav-link.is-active {
  color: var(--text);
}

.site-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: calc(var(--measure) + var(--gutter) + var(--gutter-gap));
  margin: clamp(4rem, 12vw, 8rem) auto 0;
  padding: 1.6rem var(--pad) 2.4rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  color: var(--text-faint);
}
.site-foot a {
  color: var(--text-faint);
  text-decoration: none;
  transition: color var(--transition);
}
.site-foot a:hover {
  color: var(--text);
}
.site-foot .dot {
  margin: 0 0.5rem;
  opacity: 0.5;
}
.moon {
  cursor: default;
  opacity: 0.35;
  font-size: 0.95rem;
  transition: opacity var(--transition);
  user-select: none;
}
.moon:hover {
  opacity: 0.85;
}

/* --------------------------- landing ------------------------------ */

.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--pad);
}
.landing-inner {
  max-width: 32rem;
  margin: auto;
  width: 100%;
}
.landing--min .landing-inner {
  text-align: var(--min-align, left);
}
.name {
  font-family: var(--font-display);
  font-weight: var(--name-weight, 600);
  font-size: clamp(1.9rem, 5vw, var(--name-size, 2.7rem));
  letter-spacing: var(--name-tracking, -0.01em);
  line-height: 1.05;
  margin: 0;
}
.tagline {
  font-size: 1.12rem;
  line-height: 1.55;
  color: var(--text-soft);
  margin: 1.1rem 0 1.8rem;
  max-width: 30rem;
}
.tagline em {
  color: var(--text);
  font-style: italic;
}
.landing-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.3rem;
  margin-top: 1.9rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.landing-links a {
  color: var(--text-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color var(--transition), border-color var(--transition);
}
.landing-links a:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.links-sep {
  width: 1px;
  height: 0.9rem;
  background: var(--rule);
}
.landing .site-foot {
  margin-top: clamp(3rem, 10vw, 6rem);
  border-top: none;
  padding-bottom: 0;
}

/* ---------------------------- index ------------------------------- */

.index {
  width: min(var(--measure), 100% - 2 * var(--pad));
  margin: 0 auto;
  padding: clamp(2.5rem, 8vw, 5rem) 0 clamp(4rem, 12vw, 7rem);
}
/* email capture at the top of the Writing page — quiet, no box */
.subscribe {
  border: none;
  background: none;
  padding: 0;
  margin: 0 0 clamp(2.4rem, 6vw, 3.4rem);
}
.subscribe-label {
  font-size: 0.9rem;
  color: var(--text-soft);
  margin: 0 0 0.55rem;
  max-width: 30rem;
}
.subscribe-form {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  max-width: 23rem;
  border-bottom: 1px solid var(--rule);
  transition: border-color var(--transition);
}
.subscribe-form:focus-within {
  border-color: var(--text-soft);
}
.subscribe-form:has(.subscribe-input--err) {
  border-color: var(--accent);
}
.subscribe-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 0.98rem;
  color: var(--text);
  background: none;
  border: none;
  padding: 0.35rem 0;
}
.subscribe-input:focus {
  outline: none;
}
.subscribe-input::placeholder {
  color: var(--text-faint);
}
.subscribe-input--err::placeholder {
  color: var(--accent);
}
.subscribe-btn {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.88rem;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0.35rem 0;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--transition);
}
.subscribe-btn:hover {
  opacity: 0.6;
}
.subscribe-done {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-soft);
}
.subscribe-note {
  color: var(--text-faint);
  font-size: 0.84rem;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.post-item a {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 1.5rem;
  padding: 1.15rem 0;
  text-decoration: none;
  border-top: 1px solid var(--rule);
  transition: background var(--transition);
}
.post-item:first-child a {
  border-top: none;
}
.post-item:last-child a {
  border-bottom: 1px solid var(--rule);
}
.post-date {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-faint);
  padding-top: 0.25rem;
}
.post-title {
  font-family: var(--font-display);
  font-weight: var(--title-weight, 600);
  font-size: 1.18rem;
  color: var(--text);
  transition: color var(--transition);
}
.post-dek {
  display: block;
  color: var(--text-soft);
  font-size: 0.96rem;
  margin-top: 0.2rem;
}
.post-item a:hover .post-title {
  color: var(--accent);
}
.post-flag {
  display: inline-block;
  margin-left: 0.6rem;
  font-family: var(--font-ui);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  vertical-align: middle;
  border: 1px solid var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

/* ---------------------------- article ----------------------------- */

.article-wrap {
  position: relative;
  width: min(var(--measure), 100% - 2 * var(--pad));
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 4.5rem) 0 clamp(4rem, 12vw, 7rem);
}
.article {
  min-width: 0;
}
.eyebrow {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-faint);
  text-decoration: none;
  margin-bottom: 2rem;
  transition: color var(--transition);
}
.eyebrow:hover {
  color: var(--text);
}
.article-date {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-faint);
  margin: 0 0 0.6rem;
}
.article-title {
  font-family: var(--font-display);
  font-weight: var(--title-weight, 600);
  font-size: clamp(1.8rem, 4.5vw, var(--title-size, 2.5rem));
  line-height: 1.1;
  letter-spacing: var(--title-tracking, -0.015em);
  margin: 0 0 0.7rem;
}
.article-dek {
  font-size: 1.1rem;
  color: var(--text-soft);
  font-style: var(--dek-style, italic);
  margin: 0 0 2.8rem;
}
.prose {
  font-size: var(--prose-size, 1.12rem);
  line-height: var(--prose-leading, 1.72);
}
.prose p {
  margin: 0 0 1.4rem;
}
.prose em {
  font-style: italic;
  color: var(--text);
}
.prose strong {
  font-weight: 600;
  color: var(--text);
}

/* section headings within a post (the post title is the h1) */
.prose h2 {
  font-family: var(--font-display);
  font-weight: var(--title-weight, 600);
  font-size: 1.5rem;
  line-height: 1.22;
  letter-spacing: -0.01em;
  margin: 2.5rem 0 0.9rem;
}
.prose h3 {
  font-family: var(--font-display);
  font-weight: var(--title-weight, 600);
  font-size: 1.18rem;
  line-height: 1.3;
  margin: 2rem 0 0.6rem;
}

/* blockquote */
.prose blockquote {
  margin: 1.7rem 0;
  padding: 0.1rem 0 0.1rem 1.2rem;
  border-left: 2px solid var(--accent-soft);
  color: var(--text-soft);
  font-style: italic;
}
.prose blockquote p:last-child {
  margin-bottom: 0;
}

/* lists */
.prose ul,
.prose ol {
  margin: 1.3rem 0;
  padding-left: 1.4rem;
}
.prose li {
  margin: 0.45rem 0;
  padding-left: 0.2rem;
}
.prose li::marker {
  color: var(--text-faint);
}

/* divider */
.prose hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.6rem 0;
}

/* callout — a soft Notion-style box, with an optional label */
.prose .callout {
  margin: 1.8rem 0;
  padding: 1rem 1.2rem;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}
.prose .callout p:last-child {
  margin-bottom: 0;
}
.prose .callout-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.45rem;
}

/* inline + block code */
.prose code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.08em 0.34em;
}
.prose pre {
  margin: 1.6rem 0;
  padding: 1rem 1.15rem;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* images / figures */
.prose figure {
  margin: 1.9rem 0;
}
.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.prose figcaption {
  margin-top: 0.55rem;
  font-size: 0.82rem;
  color: var(--text-faint);
  text-align: center;
}

/* footnote markers */
.fn {
  font-family: var(--font-ui);
  font-size: 0.62em;
  line-height: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 0 0.1em 0 0.12em;
  vertical-align: super;
  transition: color var(--transition);
}
.fn:hover,
.fn.fn-active {
  color: var(--accent);
  background: var(--accent-wash);
  border-radius: 2px;
}

/* the sidenote gutter — floats to the right of the centered article */
.margin {
  position: absolute;
  top: 0;
  left: 100%;
  margin-left: var(--gutter-gap);
  width: var(--gutter);
  height: 100%;
}
.sidenote {
  position: absolute;
  left: 0;
  right: 0;
  font-family: var(--sidenote-font, var(--font-body));
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-soft);
  opacity: 0;
  transform: translateY(2px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.sidenote.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.sidenote-num {
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 0.62rem;
  margin-right: 0.4rem;
  vertical-align: super;
}

/* inline footnote fallback (narrow screens) */
.sidenote-inline {
  font-size: 0.92rem;
  color: var(--text-soft);
  border-left: 2px solid var(--accent-soft);
  padding: 0.4rem 0 0.4rem 0.9rem;
  margin: 0.2rem 0 1.4rem;
}
.sidenote-inline sup {
  color: var(--accent);
  margin-right: 0.3rem;
}

/* clickable multi-version lines — a persistent dotted underline says
   "click me to flip through phrasings" */
.prose .rw {
  cursor: pointer;
  border-radius: 2px;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: background 200ms ease, text-decoration-color 200ms ease;
}
.prose .rw:hover {
  text-decoration-color: var(--accent);
}
.prose .rw:focus {
  outline: none;
}
/* keyboard focus is shown by deepening the underline/highlight, not a box */
.prose .rw:focus-visible {
  outline: none;
  text-decoration-color: var(--accent);
}
.prose .rw-active {
  background: var(--accent-wash);
  text-decoration-color: var(--accent);
}
/* the line currently controlled by the arrowheads */
.prose .rw-open {
  background: var(--accent-wash);
  text-decoration-color: var(--accent);
}

/* ------------------ version arrowhead control --------------------- */

.ver-ctrl {
  position: absolute;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.1rem;
  transform: translate(-50%, -100%) scale(0.96);
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  box-shadow: var(--ui-shadow);
  padding: 0.12rem 0.25rem;
  font-family: var(--font-ui);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}
.ver-ctrl.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -100%) scale(1);
}
.ver-ctrl::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 7px;
  height: 7px;
  background: var(--ui-bg);
  border-right: 1px solid var(--ui-border);
  border-bottom: 1px solid var(--ui-border);
  transform: translateX(-50%) rotate(45deg);
}
.ver-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ui-text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.18rem 0.4rem;
  border-radius: 999px;
  transition: background 140ms ease, color 140ms ease;
}
.ver-btn:hover {
  background: var(--accent-wash);
  color: var(--accent);
}
.ver-count {
  font-size: 0.68rem;
  color: var(--text-faint);
  min-width: 2.3rem;
  text-align: center;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

/* ------------------------ right-click menu ------------------------ */

.ctx-menu {
  position: fixed;
  z-index: 90;
  min-width: 11rem;
  background: var(--ui-bg);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius, 9px);
  box-shadow: var(--ui-shadow);
  padding: 0.3rem;
  font-family: var(--font-ui);
  opacity: 0;
  transform: scale(0.97);
  transform-origin: top left;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}
.ctx-menu.is-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border-radius: calc(var(--ui-radius, 9px) - 3px);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.ctx-item:hover {
  background: var(--accent-wash);
  color: var(--accent);
}
.ctx-ico {
  width: 1.1em;
  text-align: center;
  opacity: 0.9;
}

/* the Styles stepper that the menu turns into */
.ctx-styles {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0.05rem;
}
.ctx-arrow,
.ctx-tick {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ui-text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.25rem 0.45rem;
  border-radius: calc(var(--ui-radius, 9px) - 3px);
  transition: background 140ms ease, color 140ms ease;
}
.ctx-arrow:hover,
.ctx-tick:hover {
  background: var(--accent-wash);
  color: var(--accent);
}
.ctx-tick {
  color: var(--accent);
  margin-left: 0.2rem;
}
.ctx-skin-label {
  min-width: 6.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ui-text);
  letter-spacing: 0.01em;
}

/* the Contact panel */
.ctx-contact {
  display: flex;
  flex-direction: column;
  min-width: 15.5rem;
  padding: 0.05rem;
}
.ctx-crow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  text-decoration: none;
  background: none;
  border: none;
  color: var(--ui-text);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.5rem 0.55rem;
  border-radius: calc(var(--ui-radius, 9px) - 3px);
  cursor: pointer;
  transition: background 140ms ease;
}
.ctx-crow:hover {
  background: var(--accent-wash);
}
.ctx-cico {
  flex: 0 0 1.55rem;
  height: 1.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  font-style: normal;
}
.ctx-cval {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctx-chint {
  flex: 0 0 auto;
  font-size: 0.68rem;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}
.ctx-crow:hover .ctx-chint {
  color: var(--accent);
}

/* ----------------------------- toast ------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translate(-50%, 8px);
  background: var(--ui-bg);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  box-shadow: var(--ui-shadow);
  padding: 0.5rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  z-index: 80;
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast--tiny {
  padding: 0.4rem 0.7rem;
  font-size: 1rem;
}

/* ----------------------------- about ------------------------------ */

.about {
  width: min(var(--measure), 100% - 2 * var(--pad));
  margin: 0 auto;
  padding: clamp(5rem, 18vw, 12rem) 0 clamp(4rem, 12vw, 7rem);
}
.about-line {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: var(--title-weight, 600);
  line-height: 1.25;
  margin: 0 0 1.4rem;
  letter-spacing: -0.01em;
}
.about-sub {
  font-size: 1.05rem;
  color: var(--text-soft);
  max-width: 30rem;
  line-height: 1.6;
  margin: 0;
}

/* --------------------------- responsive --------------------------- */

/* below this width there isn't room for the margin column beside a centered
   article, so footnotes fall back to inline-on-tap */
@media (max-width: 70rem) {
  .margin {
    display: none;
  }
}
