/* Tokens and rules are documented in docs/design.md; change both together. */

@font-face {
  font-family: "IBM Plex Serif";
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-serif-latin-300-normal.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Serif";
  font-style: italic;
  font-weight: 300;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-serif-latin-300-italic.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-serif-latin-400-normal.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-sans-latin-400-normal.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-sans-latin-500-normal.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/ibm-plex-mono-latin-400-normal.woff2) format("woff2");
}

:root {
  color-scheme: light dark;

  --paper: #fbfaf7;
  --ink: #141414;
  --muted: #63615c;
  --line: #e4e2dc;
  --thread: #c9c6bf;
  --accent: #1e3a66;
  --field: #ffffff;
  --shadow: 0 6px 18px rgb(20 20 20 / 0.06);
  --scrim: rgb(20 20 20 / 0.18);

  --serif: "IBM Plex Serif", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --reading-weight: 400;

  --step-meta: 0.75rem;
  --step-small: 0.8125rem;
  --step-ui: 0.9375rem;
  --step-reading: 1.25rem;
  --step-title: 2.125rem;
  --step-display: 3rem;

  --type-display: 300 var(--step-display) / 1.1 var(--serif);
  --type-title: 300 var(--step-title) / 1.15 var(--serif);
  --type-section: 300 var(--step-reading) / 1.3 var(--serif);
  --type-reading: var(--reading-weight) var(--step-reading) / 1.6 var(--serif);
  --type-day: italic 300 var(--step-reading) / 1.3 var(--serif);
  --type-ui: 400 var(--step-ui) / 1.5 var(--sans);
  --type-ui-strong: 500 var(--step-ui) / 1.3 var(--sans);
  --type-small: 400 var(--step-small) / 1.4 var(--sans);
  --type-meta: 400 var(--step-meta) / 1.4 var(--mono);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 5.5rem;

  --measure-reading: 40rem;
  --measure-tool: 55rem;
  --measure-sheet: 32rem;
  --radius: 4px;
  --radius-token: 12px;
  --control-height: 2.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161718;
    --ink: #ecebe7;
    --muted: #a3a29d;
    --line: #2e2f31;
    --thread: #4a4c50;
    --accent: #9fb2d1;
    --field: #1c1d1f;
    --shadow: 0 6px 18px rgb(0 0 0 / 0.4);
    --scrim: rgb(0 0 0 / 0.5);
    --reading-weight: 300;
  }
}

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

body {
  --measure: var(--measure-tool);
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: var(--type-ui);
  overflow-wrap: break-word;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

.reading {
  --measure: var(--measure-reading);
}

.popup {
  --measure: var(--measure-sheet);
}

main,
.site-header {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

main {
  padding-block: var(--space-6) var(--space-8);
}

h1,
h2 {
  margin: 0 0 var(--space-4);
}

h1 {
  font: var(--type-title);
  letter-spacing: -0.01em;
}

h2 {
  font: var(--type-section);
}

p {
  margin: 0 0 var(--space-4);
}

a {
  color: var(--accent);
}

:where(a, .link) {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Quiet links: no underline until hovered. */
.site-nav a,
.link,
.suggestions a,
.row-title,
.row-side a,
.collecting a,
.actions a {
  text-decoration: none;
}

.site-nav a:hover,
.link:hover,
.suggestions a:hover,
.row-title:hover,
.row-side a:hover,
.collecting a:hover,
.actions a:hover {
  text-decoration: underline;
}

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

label {
  display: block;
  margin-bottom: var(--space-2);
}

label,
small,
.hint,
.count,
.empty {
  color: var(--muted);
  font: var(--type-small);
}

.notice {
  color: var(--muted);
}

.error {
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

input,
select {
  height: var(--control-height);
  padding: 0 var(--space-3);
}

textarea {
  padding: var(--space-3);
  resize: vertical;
}

input.url {
  font: var(--type-meta);
}

button {
  height: var(--control-height);
  padding: 0 var(--space-5);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.divided {
  margin-bottom: var(--space-5);
}

.divided > li {
  padding: var(--space-3) 0;
}

.divided > li + li {
  border-top: 1px solid var(--line);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  padding-top: var(--space-6);
}

.wordmark {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  color: var(--ink);
  text-decoration: none;
  font: italic 300 1.375rem / 1 var(--serif);
}

.wordmark svg {
  flex-shrink: 0;
  width: 23px;
  color: var(--accent);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-5);
  font: var(--type-small);
  white-space: nowrap;
}

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

.site-nav a[aria-current="page"] {
  color: var(--ink);
}

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

.link {
  height: auto;
  padding: 0;
  border: 0;
  color: var(--muted);
}

.stack {
  margin-bottom: var(--space-5);
}

.stack label:not(:first-child) {
  margin-top: var(--space-4);
}

.stack button {
  margin-top: var(--space-3);
}

.url-line {
  font: var(--type-meta);
  overflow-wrap: anywhere;
}

.add {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.add input {
  flex: 1;
  min-width: 0;
}

.filter {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--ink);
}

.filter label {
  margin: 0;
}

.filter input {
  flex: 1;
  min-width: 0;
  height: 2.5rem;
  padding: 0;
  border: 0;
  background: transparent;
}

.filter:has(input:focus-visible) {
  border-bottom-color: var(--accent);
  box-shadow: 0 1px 0 var(--accent);
}

.filter input:focus-visible {
  outline: none;
}

.filter input::-webkit-search-cancel-button {
  appearance: none;
}

.suggestions {
  position: absolute;
  z-index: 1;
  top: calc(100% + var(--space-2));
  left: var(--space-8);
  width: 17.5rem;
  padding: var(--space-2) 0;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.suggestions a {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  color: var(--ink);
}

.day {
  margin-bottom: var(--space-6);
}

.day-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}

.day-heading h2 {
  margin: 0;
  font: var(--type-day);
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-5);
  padding: var(--space-3) 0;
}

.row-main {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
  white-space: nowrap;
}

.row-title {
  overflow: hidden;
  color: var(--ink);
  font: var(--type-ui-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title.untitled {
  color: var(--muted);
}

.host {
  color: var(--muted);
  font: var(--type-meta);
}

.row-side {
  display: flex;
  gap: var(--space-3);
  font: var(--type-small);
  white-space: nowrap;
}

.row-side a {
  color: var(--muted);
}

.page-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
}

.collecting {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
  font: var(--type-small);
}

.collecting label {
  margin: 0;
}

.collecting-end {
  display: flex;
  gap: var(--space-4);
  margin-left: auto;
}

.row-actions {
  display: flex;
  gap: var(--space-3);
  margin-left: var(--space-3);
}

/* Actions are ink and information is muted, wherever they share a line. */
.row-side .row-actions a,
.toggle .link,
.collecting a,
.collecting .link,
.actions a,
.actions .link {
  color: var(--ink);
}

/* Wide enough for "Added", so the row doesn't shift when it toggles. */
.toggle {
  min-width: 2.75rem;
  text-align: right;
}

.toggle .added {
  color: var(--muted);
}

.forest-list p {
  margin: var(--space-1) 0 0;
}

.editor-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.editor-bar .actions {
  align-items: center;
  min-height: 2rem;
  margin: 0;
}

.editor-state {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 2rem;
  font: var(--type-small);
}

.visibility-form {
  display: contents;
}

/* View and Edit swap places as you switch pages. Both labels share one grid
   cell, with the other page's hidden, so the link keeps the same width. */
.mode-link {
  display: inline-grid;
}

.mode-link > * {
  grid-area: 1 / 1;
}

.mode-link > [aria-hidden] {
  visibility: hidden;
}

.collecting select,
.editor-state select {
  width: auto;
  max-width: 16rem;
  height: 2rem;
}

.quiet-select {
  padding: 0 var(--space-1);
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font: var(--type-small);
  cursor: pointer;
}

.quiet-select:hover {
  border-color: var(--line);
}

/* htmx marks the old status while it's being replaced and the new one as it settles. */
.save-state {
  transition: opacity 400ms ease-in-out;
}

.save-state.htmx-swapping,
.save-state.htmx-added {
  opacity: 0;
}

.save-state.htmx-swapping {
  transition-duration: 250ms;
}

.field {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: var(--space-4);
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  field-sizing: content;
}

.field:hover {
  border-bottom-color: var(--line);
}

/* The underline is the focus mark, so the field stays as quiet as the text. */
.field:focus-visible {
  outline: none;
  border-bottom-color: var(--muted);
}

.field::placeholder {
  color: var(--muted);
}

/* Display type's tight line height lets descenders hang below the line box,
   which would make a field scroll. The padding makes room for them, and the
   margins (less the field's 1px underline) keep the text where the published
   heading puts it. */
.forest-editor .forest-title {
  margin-top: -0.15em;
  margin-bottom: calc(var(--space-5) - 0.15em - 1px);
  padding-block: 0.15em;
}

.char-count[hidden] {
  display: none;
}

.char-count {
  display: block;
  margin: calc(-1 * var(--space-3)) 0 var(--space-4);
  text-align: right;
}

/* Fields grow with their text, by CSS where it's supported and by
   forest-editor.js elsewhere, so they never need to scroll. */
@supports (field-sizing: content) {
  .field {
    overflow: hidden;
    resize: none;
  }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-4);
  margin: var(--space-2) 0 var(--space-4);
  font: var(--type-small);
}

.actions button {
  margin-top: 0;
}

.slug-field {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
}

.slug-field input {
  flex: 1;
  min-width: 0;
}

.sharing {
  margin: var(--space-7) 0 var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

.sharing .actions {
  margin-bottom: 0;
}

.forest-title {
  margin-bottom: var(--space-5);
  font: var(--type-display);
  letter-spacing: -0.01em;
}

.forest-text {
  font: var(--type-reading);
  white-space: pre-line;
}

.citations {
  margin: var(--space-6) 0;
  padding: 0;
  list-style: none;
  counter-reset: entry;
}

.citation {
  --number-top: 0.375rem;
  position: relative;
  padding: 0 0 var(--space-6) var(--space-6);
  counter-increment: entry;
}

.citation.no-note {
  --number-top: -0.0625rem;
}

/* The thread runs from this entry's number into the next one's, which hides
   the overlap behind its paper background. */
.citation:not(:last-child)::after {
  content: "";
  position: absolute;
  top: var(--number-top);
  bottom: -0.375rem;
  left: 0;
  border-left: 1px dotted var(--thread);
}

/* --number-top is measured so the number's baseline meets the first line's:
   the note in Reading, or the title in UI strong when there's no note. */
.citation::before {
  content: counter(entry);
  position: absolute;
  z-index: 1;
  top: var(--number-top);
  left: 0;
  padding-block: var(--space-1);
  background: var(--paper);
  color: var(--accent);
  font: var(--type-small);
  transform: translateX(-50%);
}

.citation-title {
  font: var(--type-ui-strong);
}

.citation .url-line {
  margin: var(--space-1) 0;
}

.citation .count {
  margin: 0;
}

.forest-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.forest-footer p {
  margin-bottom: var(--space-2);
}

.sheet {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(var(--measure-sheet), 100%);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.sheet::backdrop {
  background: var(--scrim);
}

.sheet[open] {
  animation: sheet-in 200ms ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateX(100%);
  }
}

.sheet-inner {
  min-height: 100%;
  padding: var(--space-5) var(--space-6) var(--space-7);
}

.sheet-close {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-4);
}

@media (max-width: 40rem) {
  .row {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-3);
  }

  .row-main,
  .row-side {
    display: contents;
  }

  /* The line break after the title and actions, which are ordered before it. */
  .row::after {
    content: "";
    flex-basis: 100%;
    height: var(--space-1);
    order: -1;
  }

  .row-title {
    flex: 1 1 0;
    max-width: max-content;
    order: -1;
  }

  .row-actions {
    margin-left: auto;
    order: -1;
  }
}

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