/* ------------------------------------------------------------------
   Low Tech Life — the reading room
   Plain CSS, no framework. Paper, ink, one quiet green.
   ------------------------------------------------------------------ */

:root {
  --paper: #f3eee4;
  --paper-deep: #ebe4d6;
  --ink: #2a2620;
  --ink-soft: #4a443b;
  --muted: #776e60;
  --rule: #d9cfbe;
  --accent: #56653f;
  --accent-soft: #e2e4d2;
  --selection: #dfe2c8;

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 36rem;     /* the reading column */
  --wide: 54rem;        /* covers and the home page */
  --gutter: 1.25rem;

  --text: clamp(1.125rem, 1.02rem + 0.45vw, 1.3rem);
  --leading: 1.65;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1b18;
    --paper-deep: #24221e;
    --ink: #e9e2d4;
    --ink-soft: #cfc7b8;
    --muted: #9e9584;
    --rule: #3a3630;
    --accent: #a9b98c;
    --accent-soft: #2c3124;
    --selection: #3b4330;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #1c1b18;
  --paper-deep: #24221e;
  --ink: #e9e2d4;
  --ink-soft: #cfc7b8;
  --muted: #9e9584;
  --rule: #3a3630;
  --accent: #a9b98c;
  --accent-soft: #2c3124;
  --selection: #3b4330;
  color-scheme: dark;
}

@media (min-width: 48rem) {
  :root { --gutter: 2rem; }
}

/* ---------- base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--text);
  line-height: var(--leading);
  font-optical-sizing: auto;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); }

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none; }
}

/* ---------- the frame ---------- */

.room {
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font-size: 1.15rem;
  font-weight: 500;
  font-style: italic;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.masthead-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.masthead-nav a {
  text-decoration: none;
  color: var(--muted);
}

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

.theme-toggle {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.4rem;
  margin: -0.4rem;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--ink); }

.flash {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border-radius: 4px;
  font-size: 0.95rem;
}

.colophon {
  margin-top: 6rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ---------- type helpers ---------- */

.kicker {
  margin: 0 0 0.75rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.kicker a { color: var(--accent); text-decoration: none; }
.kicker a:hover { text-decoration: underline; text-underline-offset: 3px; }
.kicker .dot { margin: 0 0.45em; }

.display {
  margin: 0;
  font-weight: 400;
  font-size: clamp(2.1rem, 1.4rem + 3vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.lede {
  font-size: 1.15em;
  color: var(--ink-soft);
  max-width: var(--measure);
  text-wrap: pretty;
}

.text-link {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 0.15em;
}

.text-link::after { content: " →"; }

/* ---------- home ---------- */

.welcome { padding: 3.5rem 0 2.5rem; }

.welcome-title {
  max-width: 14ch;
  font-style: italic;
  font-weight: 300;
}

.lead { padding-bottom: 1rem; }

.lead-link { text-decoration: none; display: block; }

.lead-cover,
.piece-cover {
  margin: 0 0 1.75rem;
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper-deep);
}

.lead-cover img,
.piece-cover img { width: 100%; }

.lead-title {
  margin: 0 0 0.6rem;
  font-weight: 400;
  font-size: clamp(1.7rem, 1.25rem + 2vw, 2.5rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.lead-link:hover .lead-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.lead-subtitle {
  margin: 0 0 0.75rem;
  font-style: italic;
  color: var(--ink-soft);
  max-width: var(--measure);
}

.lead-excerpt {
  margin: 0 0 1.5rem;
  max-width: var(--measure);
  color: var(--ink-soft);
}

.shelf {
  margin-top: 4.5rem;
  scroll-margin-top: 2rem;
}

.shelf-heading {
  margin: 0 0 1.25rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.index-entry {
  display: grid;
  gap: 0.2rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}

.index-date {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 0.45rem;
}

.index-title {
  font-size: 1.2em;
  line-height: 1.25;
  text-decoration: none;
}

.index-title:hover { text-decoration: underline; text-underline-offset: 0.18em; }

.index-subtitle {
  margin: 0.2rem 0 0;
  font-style: italic;
  color: var(--muted);
  font-size: 0.95em;
}

@media (min-width: 40rem) {
  .index-entry { grid-template-columns: 8rem 1fr; gap: 1.5rem; }
}

.themes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 40rem) {
  .themes { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 60rem) {
  .themes { grid-template-columns: repeat(3, 1fr); }
}

.theme-card {
  display: block;
  height: 100%;
  padding: 1.1rem 1.2rem 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  text-decoration: none;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.theme-card:hover {
  background: var(--paper-deep);
  border-color: var(--muted);
}

.theme-name {
  display: block;
  font-size: 1.15em;
  font-style: italic;
  margin-bottom: 0.3rem;
}

.theme-blurb {
  display: block;
  font-size: 0.88em;
  line-height: 1.5;
  color: var(--muted);
}

.quiet-page { padding: 3.5rem 0 1rem; }
.quiet-page .display { margin-bottom: 0.75rem; }

.empty { color: var(--muted); font-style: italic; }

.back { margin-top: 3.5rem; }

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

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 10;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.piece-header {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 3.5rem 0 2rem;
}

.piece-title { margin-bottom: 0.9rem; }

.piece-subtitle {
  margin: 0;
  font-size: 1.15em;
  font-style: italic;
  font-weight: 300;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.piece-cover { margin-bottom: 2.75rem; }

/* On phones the cover runs edge to edge. */
@media (max-width: 39.99rem) {
  .piece-cover,
  .lead-cover {
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
    border-radius: 0;
  }
}

.prose {
  max-width: var(--measure);
  margin: 0 auto;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.prose > * + * { margin-top: 1.15em; }
.prose p { margin: 0; text-wrap: pretty; }
.prose p + p { margin-top: 0.9em; }

/* A drop cap on the opening paragraph. */
.prose > p:first-child::first-letter {
  float: left;
  font-size: 4.1em;
  line-height: 0.85;
  font-weight: 400;
  padding: 0.08em 0.1em 0 0;
  color: var(--accent);
}

.prose h2 {
  margin: 2.6em 0 0.5em;
  font-size: 1.3em;
  font-weight: 500;
  font-style: italic;
  line-height: 1.3;
}

.prose h3 {
  margin: 2em 0 0;
  font-family: var(--mono);
  font-size: 0.72em;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.prose a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.prose blockquote {
  margin: 2em 0;
  padding: 0 0 0 1.25rem;
  border-left: 2px solid var(--accent);
  font-size: 1.15em;
  font-style: italic;
  color: var(--ink-soft);
}

.prose blockquote p { margin: 0; }

.prose ul,
.prose ol { padding-left: 1.25em; }

.prose li + li { margin-top: 0.45em; }
.prose li::marker { color: var(--muted); }

.prose hr {
  border: 0;
  margin: 2.75em 0;
  text-align: center;
  height: auto;
}

.prose hr::after {
  content: "· · ·";
  color: var(--muted);
  letter-spacing: 0.6em;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--paper-deep);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.prose figure { margin: 2.5em 0; }

.prose figcaption {
  margin-top: 0.6rem;
  font-size: 0.85em;
  font-style: italic;
  color: var(--muted);
}

/* The sources list at the end of a piece. */
.prose h2:last-of-type + ul,
.prose h2:last-of-type + ol {
  font-size: 0.85em;
  color: var(--muted);
}

.fin {
  max-width: var(--measure);
  margin: 3rem auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 1.2rem;
}

.next-up {
  max-width: var(--measure);
  margin: 4rem auto 0;
  padding: 1.5rem 0 0;
  border-top: 1px solid var(--rule);
}

.next-title {
  font-size: 1.3em;
  line-height: 1.25;
  text-decoration: none;
}

.next-title:hover { text-decoration: underline; text-underline-offset: 0.18em; }

.piece ~ .back {
  max-width: var(--measure);
  margin-left: auto;
  margin-right: auto;
}

@media print {
  .masthead, .colophon, .next-up, .back, .reading-progress, .theme-toggle { display: none; }
  body { background: #fff; color: #000; }
}

/* ---------- connections: the house of ideas ---------- */

.series-line {
  margin: 0 0 0.9rem;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--accent);
}

.stands-on {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.9rem;
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
}

.stands-on-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stands-on a {
  color: var(--ink-soft);
  font-style: italic;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
}

.stands-on a:hover { color: var(--accent); text-decoration-color: currentColor; }

.house {
  max-width: var(--measure);
  margin: 4rem auto 0;
  display: grid;
  gap: 2.25rem;
}

.bricks,
.built-on {
  list-style: none;
  margin: 0;
  padding: 0;
}

.brick {
  display: grid;
  grid-template-columns: 2.25rem 1fr;
  align-items: baseline;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule);
}

.brick-no {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.brick-title { text-decoration: none; line-height: 1.35; }
a.brick-title:hover { text-decoration: underline; text-underline-offset: 0.18em; }

.brick.is-here .brick-no { color: var(--accent); }
.brick.is-here em { font-size: 0.85em; color: var(--muted); }
.brick.is-coming { color: var(--muted); font-style: italic; border-bottom: 0; }

.built-on li { padding: 0.55rem 0; border-bottom: 1px solid var(--rule); }
.built-on a { text-decoration: none; }
.built-on a::before { content: "↑ "; color: var(--accent); }
.built-on a:hover { text-decoration: underline; text-underline-offset: 0.18em; }

.house + .next-up { margin-top: 3rem; }

/* ---------- diagrams inside a piece ---------- */

.prose figure.diagram { margin: 2.6em 0; }

.prose figure.diagram img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--rule);
}

.prose figure.diagram figcaption { text-wrap: pretty; }
.prose figure.diagram figcaption em { font-style: normal; color: var(--accent); }

@media (min-width: 64rem) {
  .prose figure.diagram { margin-left: -4rem; margin-right: -4rem; }
  .prose figure.diagram figcaption { padding: 0 4rem; }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .prose figure.diagram img { filter: brightness(0.9); }
}
:root[data-theme="dark"] .prose figure.diagram img { filter: brightness(0.9); }

/* ---------- listening ---------- */

.listen {
  max-width: var(--measure);
  margin: -1rem auto 2.25rem;
  padding: 0.85rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper-deep);
}

.listen[hidden] { display: none; }

.listen-label {
  margin: 0;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.listen audio {
  width: 100%;
  height: 2.5rem;
  border-radius: 999px;
}

.listen-button,
.listen-small {
  appearance: none;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.listen-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 1.1rem 0.5rem 0.9rem;
  font-size: 1rem;
}

.listen-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.listen-icon {
  display: inline-grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--paper);
}

/* Drawn rather than typed: a text ▶ never sits in the middle of a circle.
   The triangle is nudged right of centre so it looks centred to the eye. */
.listen-icon svg {
  display: block;
  width: 0.95rem;
  height: 0.95rem;
  fill: currentColor;
}

.listen-icon .icon-pause,
[aria-pressed="true"] > .listen-icon .icon-play { display: none; }
[aria-pressed="true"] > .listen-icon .icon-pause { display: inline; }

/* ---------- the floating listen bar ---------- */

.dock {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(calc(100% - 1.5rem), var(--measure));
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem 0.6rem;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.12), 0 1px 3px rgb(0 0 0 / 0.08);
  animation: dock-in 0.25s ease-out;
}

.dock[hidden] { display: none; }

@keyframes dock-in {
  from { opacity: 0; transform: translate(-50%, 0.75rem); }
}

@media (prefers-reduced-motion: reduce) {
  .dock { animation: none; }
}

.dock button {
  appearance: none;
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}

.dock-play {
  flex: none;
  padding: 0.2rem;
  border-radius: 50%;
}

.dock-play .listen-icon { width: 2.4rem; height: 2.4rem; }
.dock-play .listen-icon svg { width: 1.1rem; height: 1.1rem; }

.dock-where {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.15rem 0.3rem;
  text-align: left;
}

.dock-title {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 1rem;
}

.dock-sub {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.dock .dock-small {
  flex: none;
  min-width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.dock .dock-close { font-size: 1.2rem; }

.dock .dock-small:hover,
.dock .dock-where:hover .dock-title { color: var(--accent); }

.dock-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--paper-deep);
}

.dock-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.3s linear;
}

/* Room at the end of the page, so the bar never covers the last lines. */
html.has-dock body { padding-bottom: 5.5rem; }

.listen-small {
  padding: 0.35rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.listen-button:hover,
.listen-small:hover { border-color: var(--muted); }

.listen-small[hidden] { display: none; }

.listen-note,
.listen-link {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--muted);
}

.listen-link { color: var(--accent); text-underline-offset: 0.2em; }

/* The paragraph currently being read aloud. */
.prose .is-speaking,
.piece-header .is-speaking {
  background: var(--selection);
  box-shadow: 0 0 0 0.35em var(--selection);
  border-radius: 3px;
  transition: background-color 0.3s ease;
}

@media print { .listen, .dock { display: none; } }
