/* ---------- Tokens ---------- */

:root {
  --bg: #fbfbf8;
  --ink: #1e211c;
  --muted: #676b63;
  --rule: #e3e4dd;
  --accent: #3c6a2e;
  --panel: #ffffff;
  --soft: #eef1e8;

  --font-body: Literata, Georgia, serif;
  --font-mark: Literata, Georgia, serif;
  --leading: 1.68;

  /* 0–4, set from the reader panel; 2 is the default */
  --size-step: 2;
  --size: calc(1.0625rem + var(--size-step) * 0.09375rem);
  --measure: 34em;
  --gutter: 16px;

  color-scheme: light;
}

:root[data-theme="sepia"] {
  --bg: #f5ecd9;
  --ink: #3a2e20;
  --muted: #76664e;
  --rule: #e2d4b6;
  --accent: #8a5818;
  --panel: #fbf4e6;
  --soft: #ecdfc4;
}

:root[data-theme="gray"] {
  --bg: #47494b;
  --ink: #ececea;
  --muted: #bcbdb9;
  --rule: #5d5f61;
  --accent: #bcd99f;
  --panel: #525456;
  --soft: #55584f;
  color-scheme: dark;
}

:root[data-theme="night"] {
  --bg: #000000;
  --ink: #d6d6d3;
  --muted: #92938e;
  --rule: #26272a;
  --accent: #9fc67e;
  --panel: #141516;
  --soft: #1a2016;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #000000;
    --ink: #d6d6d3;
    --muted: #92938e;
    --rule: #26272a;
    --accent: #9fc67e;
    --panel: #141516;
    --soft: #1a2016;
    color-scheme: dark;
  }
}

:root[data-font="newsreader"] { --font-body: Newsreader, Georgia, serif; --leading: 1.66; }
:root[data-font="atkinson"] { --font-body: "Atkinson Hyperlegible Next", system-ui, sans-serif; --leading: 1.56; }
:root[data-font="system"] { --font-body: -apple-system, system-ui, "Segoe UI", sans-serif; --leading: 1.56; }

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--size);
  line-height: var(--leading);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}

@media (max-width: 600px) {
  :root { --size: calc(1rem + var(--size-step) * 0.09375rem); }
}

a { color: inherit; }

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

.skip {
  position: absolute;
  left: var(--gutter);
  top: -3rem;
  background: var(--panel);
  padding: .4em .8em;
  border-radius: 6px;
  z-index: 20;
}
.skip:focus { top: .75rem; }

/* Everything sits in one reading column, left aligned. */
.masthead,
.bar__inner,
.feed,
.pager__inner,
.footer__inner {
  width: min(var(--measure), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

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

.masthead { padding-block: clamp(2.5rem, 9vw, 5.5rem) clamp(1.5rem, 4vw, 2.5rem); }

.wordmark {
  margin: 0;
  font-family: var(--font-mark);
  font-size: clamp(4.25rem, 19vw, 9rem);
  font-weight: 750;
  font-variation-settings: "opsz" 72;
  letter-spacing: -0.045em;
  line-height: .86;
  margin-left: -0.05em; /* optical alignment of the K with the text below */
}
.wordmark a { text-decoration: none; }

.tagline {
  margin: .55em 0 0;
  font-family: var(--font-mark);
  font-style: italic;
  font-size: clamp(1.25rem, 3.6vw, 1.6rem);
  line-height: 1.3;
}

.updated {
  margin: .9rem 0 0;
  color: var(--muted);
  font-size: .8em;
}

/* ---------- Filter bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  transition: background-color .25s ease;
}

.bar__inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.filters {
  display: flex;
  gap: clamp(.9rem, 3vw, 1.6rem);
  overflow-x: auto;
  scrollbar-width: none;
  font-size: .86em;
  /* On narrow screens the strip scrolls; fade the edge so the cut-off tab reads as more to come. */
  padding-right: 1.5rem;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 1.5rem), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 1.5rem), transparent);
}
.filters::-webkit-scrollbar { display: none; }

.filters button {
  padding: .95em 0 .8em;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.filters button:hover { color: var(--ink); }
.filters button[aria-pressed="true"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.reader-toggle {
  flex: none;
  font-family: var(--font-mark);
  font-size: 1.05em;
  font-weight: 600;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
}
.reader-toggle:hover,
.reader-toggle[aria-expanded="true"] { background: var(--soft); }

/* ---------- Reader settings panel ---------- */

.reader {
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  width: min(21rem, 100%);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: 0 12px 40px -12px rgb(0 0 0 / .28);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
}
.reader[hidden] { display: none; }

.reader__row { display: flex; border-bottom: 1px solid var(--rule); }

.reader__size button {
  flex: 1;
  padding: .7rem 0;
  font-family: var(--font-mark);
}
.reader__size button + button { border-left: 1px solid var(--rule); }
.reader__size button:hover { background: var(--soft); }
.small-a { font-size: 15px; }
.big-a { font-size: 24px; }

.reader__themes {
  justify-content: space-between;
  padding: .9rem 1rem;
}
.reader__themes button {
  display: grid;
  justify-items: center;
  gap: .4rem;
  font-size: 12px;
  color: var(--muted);
}
.reader__themes button::before {
  content: "";
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgb(127 127 127 / .45);
}
.reader__themes [data-theme-choice="auto"]::before { background: linear-gradient(135deg, #fbfbf8 50%, #000 50%); }
.reader__themes [data-theme-choice="light"]::before { background: #fbfbf8; }
.reader__themes [data-theme-choice="sepia"]::before { background: #f5ecd9; }
.reader__themes [data-theme-choice="gray"]::before { background: #47494b; }
.reader__themes [data-theme-choice="night"]::before { background: #000; }
.reader__themes [aria-checked="true"] { color: var(--ink); font-weight: 600; }
.reader__themes [aria-checked="true"]::before {
  box-shadow: inset 0 0 0 1px rgb(127 127 127 / .45), 0 0 0 2px var(--panel), 0 0 0 4px var(--accent);
}

.reader__fonts { display: grid; }
.reader__fonts button {
  text-align: left;
  padding: .7rem 1rem;
  font-size: 18px;
}
.reader__fonts button + button { border-top: 1px solid var(--rule); }
.reader__fonts button:hover { background: var(--soft); }
.reader__fonts [aria-checked="true"]::after {
  content: "✓";
  float: right;
  color: var(--accent);
  font-family: system-ui, sans-serif;
}

/* ---------- Feed ---------- */

.feed { padding-bottom: 2rem; }
.feed:focus { outline: none; }

.state {
  color: var(--muted);
  padding-block: 3rem;
}

.day { margin-top: 3.25rem; }

.day__label {
  margin: 0 0 .25rem;
  font-size: .8em;
  font-weight: 600;
  line-height: 1.4;
  color: var(--accent);
}
.day__label span {
  font-weight: 400;
  color: var(--muted);
  margin-left: .35em;
}

.item {
  padding-block: 1.75rem 2rem;
}
.item + .item { border-top: 1px solid var(--rule); }

.item__image {
  display: block;
  margin-bottom: 1.1rem;
  border-radius: 14px;
  overflow: hidden;
  background: var(--soft);
  aspect-ratio: 16 / 9;
}
.item__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .2em .7em;
  margin: 0 0 .5rem;
  font-size: .78em;
  line-height: 1.4;
  color: var(--muted);
}
.meta__source {
  color: var(--ink);
  font-weight: 600;
}

.item__title {
  margin: 0 0 .6rem;
  font-size: 1.5em;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.item p { margin: 0 0 1em; }
.summary p { text-wrap: pretty; hyphens: auto; }

.more {
  color: var(--accent);
  font-size: .86em;
  font-weight: 600;
}
.more:hover { text-decoration: underline; text-underline-offset: .2em; }

.summary__rest { animation: reveal .3s ease; }
.summary__rest[hidden] { display: none; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
}

.keypoints {
  margin: 1.4rem 0 1.25rem;
  padding: 1.1rem 1.25rem 1.1rem 1.25rem;
  background: var(--soft);
  border-radius: 12px;
}
.keypoints h4 {
  margin: 0 0 .4rem;
  font-size: .8em;
  font-weight: 600;
  color: var(--muted);
}
.keypoints ul {
  margin: 0;
  padding-left: 1.1em;
  line-height: 1.45;
}
.keypoints li + li { margin-top: .35em; }
.keypoints li::marker { color: var(--accent); }

.source-link {
  font-size: .86em;
  color: var(--muted);
}
.source-link a {
  color: inherit;
  text-underline-offset: .2em;
  text-decoration-color: var(--rule);
}
.source-link a:hover { color: var(--ink); text-decoration-color: currentColor; }
.item--video .source-link,
.item--social .source-link { display: block; margin-top: .25rem; }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .5rem 1.25rem;
}
.actions .source-link { margin-top: 0; }

/* Video */

.video {
  position: relative;
  margin: 1rem 0 .75rem;
  border-radius: 14px;
  overflow: hidden;
  background: var(--soft);
  aspect-ratio: 16 / 9;
}
.video--short {
  width: min(17rem, 72%);
  aspect-ratio: 9 / 16;
}
.video img,
.video iframe {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 0;
}
.video button {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.video button::after {
  content: "";
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: rgb(0 0 0 / .55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5.5v13l11-6.5z' fill='white'/%3E%3C/svg%3E") 55% 50% / 1.75rem no-repeat;
  backdrop-filter: blur(6px);
  transition: transform .15s ease;
}
.video button:hover::after { transform: scale(1.08); }

/* Social */

.post__author {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: .75rem;
  font-size: .86em;
  line-height: 1.3;
}
.post__author img {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--soft);
}
.post__author strong { display: block; }
.post__author span { color: var(--muted); }

.post__text {
  font-size: 1.12em;
  line-height: 1.5;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.post__images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 1rem;
  border-radius: 14px;
  overflow: hidden;
}
.post__images a { display: block; }
.post__images img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--soft);
}
.post__images--1 { display: block; width: fit-content; }
.post__images--1 img { width: auto; aspect-ratio: auto; max-height: 30rem; }
.post__images--3 a:first-child { grid-row: span 2; }
.post__images--3 a:first-child img { aspect-ratio: auto; height: 100%; }

/* ---------- Pager ---------- */

/* Rules run full width like the filter bar; content stays in the column. */
.pager { border-top: 1px solid var(--rule); }
.pager[hidden] { display: none; }
.pager__inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding-block: 1.4rem;
}
.pager__inner > :last-child { justify-self: end; }
.pager__inner > * { font-size: .86em; }
.pager a {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.pager a:hover { text-decoration: underline; text-underline-offset: .2em; }
.pager__pos { color: var(--muted); }

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

.footer {
  border-top: 1px solid var(--rule);
  line-height: 1.6;
}
.footer__inner { padding-block: 2.5rem 3.5rem; }
/* Shrink the text, not the column: its width is in em, like the feed. */
.footer__author,
.footer__links { font-size: .86em; }
.footer p { margin: 0; }

.footer__author {
  display: flex;
  gap: 1.1rem;
  align-items: flex-start;
}
.footer__photo {
  flex: none;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
}
.footer .footer__name {
  font-weight: 600;
  margin-bottom: .15rem;
}

.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  list-style: none;
  margin: 1.75rem 0 0;
  padding: 0;
}
.footer__links a {
  font-weight: 600;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: .25em;
}
.footer__links a:hover { color: var(--accent); }

.footer .footer__how {
  margin-top: 1.75rem;
  color: var(--muted);
  font-size: .78em;
}

@media (max-width: 600px) {
  /* The wordmark's descender sits close to the tagline at small sizes. */
  .tagline { margin-top: 1em; }
  .actions { flex-direction: column; align-items: flex-start; }
  .footer__links { flex-direction: column; gap: .7rem; }
  .footer__author { flex-direction: column; gap: .9rem; }
}

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