* { box-sizing: border-box; }

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

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  font-family: serif;
  font-size: 1rem;
  color: #111;
  background: #fff;
}

/* keep the browser's link color, but for visited links too: an author-level
   color always beats the UA's a:visited purple */
a { color: LinkText; }

a:hover {
  background: #eee;
  text-decoration-style: dotted;
}

header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px 16px;
  padding: 16px 1rem;
}

.brand {
  font-size: 22px;
  font-weight: bold;
  color: #000;
  text-decoration: none;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 20px;
}

nav.site { display: flex; flex-wrap: wrap; gap: 2px 16px; font: 15px/1.4 system-ui, sans-serif; }

nav.site a {
  color: #444;
  text-decoration: none;
  padding: 4px 1px;
  border-bottom: 2px solid transparent;
}

nav.site a:hover { text-decoration: underline; }

nav.site a[aria-current="page"] {
  color: #000;
  font-weight: 700;
  border-bottom-color: #000;
}

/* visually hidden, still read by screen readers */
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.forms { display: flex; gap: 10px; }

.forms input,
.save input {
  /* 16px minimum: smaller fonts trigger automatic zoom-on-focus on iOS */
  font: 16px/1.4 system-ui, sans-serif;
  background: #ececec;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  width: 230px;
}

.forms input:focus,
.save input:focus { outline: 3px solid #bbb; }

@media (max-width: 760px) {
  .forms { flex: 1 1 100%; }
  .forms form { flex: 1 1 14rem; min-width: 0; }
  .forms input { width: 100%; }
}

/* segmented pill control, used for tabs and the status toggle */
.tabs { text-align: center; }

/* list tabs invert the toggle look: white capsule, active segment filled */
.tabs .pill-group { background: #fff; box-shadow: 0 0 0 1px #c8c8c8; gap: 0.25rem; }
.tabs .pill { color: #444; text-decoration: underline; }
.tabs .pill.active {
  background: #e4e4e4;
  color: #000;
  font-weight: 700;
  text-decoration: none;
  box-shadow: none;
}

.pill-group {
  display: inline-flex;
  background: #e2e2e2;
  border-radius: 999px;
  padding: 0.25rem;
}

.pill {
  font: 15px system-ui, sans-serif;
  border: 0;
  background: none;
  color: #555;
  padding: 0.125rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
}

.pill.active {
  background: #fff;
  color: #111;
  box-shadow: 0 0 0 1px #ccc;
  cursor: default;
}

.count { margin: 14px 0 18px; }

/* star + up-next toggles, on list rows and in the article sidebar */
.controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  font: 13px/1 system-ui, sans-serif;
}

.controls button {
  background: none;
  border: 0;
  padding: 2px 0;
  font: inherit;
  color: #777;
  cursor: pointer;
}

.controls .star { font-size: 1.2rem; }
.controls .star:hover { color: #b07b00; }
.controls .star.active { color: #b07b00; }

.controls .upnext {
  border: 1px solid #ccc;
  border-radius: 999px;
  padding: 4px 10px;
}

.controls .upnext:hover { border-color: #888; color: #333; }

.controls .upnext.active {
  background: #111;
  border-color: #111;
  color: #fff;
}

.starred-mark { color: #b07b00; }

/* archive list */
.archive { padding: 4px 1rem 48px; }

.grid { columns: 4; column-gap: 36px; }

.grid article {
  break-inside: avoid;
  padding: 8px 0 9px;
  border-bottom: 1px solid #555;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.meta { color: #555; font-size: 0.9rem; margin-top: 3px; }

.dead { color: #c0392b; }
a.dead { text-decoration: none; }

@media (max-width: 1500px) { .grid { columns: 3; } }
@media (max-width: 1100px) { .grid { columns: 2; } }
@media (max-width: 720px)  { .grid { columns: 1; } }

/* reader: in-flow grid with a sticky aside, so the two can never overlap */
.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 0 40px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1rem;
}

.reader {
  grid-column: 1;
  grid-row: 1;
  max-width: 80ch;
  padding: 8px 0 80px;
  font-size: 1.1rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

.reader h1 { font-size: 25px; line-height: 1.25; }
.reader h2 { font-size: 21px; margin-top: 1.6em; }
.reader h3 { font-size: 18px; margin-top: 1.4em; }
.reader img { max-width: 100%; height: auto; }
.reader figure { margin: 1.2em 0; }
.reader iframe, .reader video, .reader embed { max-width: 100%; }

.reader pre {
  background: #f3f3f3;
  border: 1px solid #e0e0e0;
  padding: 12px 14px;
  overflow-x: auto;
  line-height: 1.45;
}

.reader code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.9rem; }

.reader blockquote {
  margin: 0;
  padding-left: 16px;
  border-left: 3px solid #ddd;
  color: #444;
}

.reader table {
  border-collapse: collapse;
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
.reader td, .reader th { border: 1px solid #ddd; padding: 4px 8px; }

.to-top {
  margin: 48px 0 0;
  padding-top: 14px;
  border-top: 1px solid #ddd;
  font: 15px system-ui, sans-serif;
}

.to-top a { color: #555; }

.missing { color: #555; }

/* manual correction of a bad crawl: ✎ swaps the reader body for a form */
.edit-link {
  float: right;
  margin: 0 0 0 20px;
  font: 14px system-ui, sans-serif;
}

.edit-link button {
  background: none;
  border: 0;
  padding: 6px 0;
  font: inherit;
  color: #555;
  text-decoration: underline;
  cursor: pointer;
}

.article-edit input,
.article-edit textarea {
  display: block;
  width: 100%;
  /* 16px minimum: smaller fonts trigger automatic zoom-on-focus on iOS */
  font: 16px/1.5 system-ui, sans-serif;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
}

.article-edit .edit-title {
  font-size: 20px;
  font-weight: 700;
}

.article-edit .edit-url {
  margin-top: 10px;
  color: #333;
}

.article-edit textarea {
  margin-top: 14px;
  min-height: 60vh;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.edit-actions {
  display: flex;
  gap: 12px;
  font: 15px system-ui, sans-serif;
}

.edit-actions button {
  font: inherit;
  padding: 7px 18px;
  border-radius: 999px;
  border: 1px solid #bbb;
  background: #fff;
  cursor: pointer;
}

.edit-actions button[type="submit"] {
  background: #111;
  border-color: #111;
  color: #fff;
  font-weight: 700;
}

aside {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 24px;
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 8px 0 24px;
  font-size: 1rem;
  overflow-wrap: break-word;
}

/* The metadata lives in a closed details element (no scripts: the CSP keeps
   saved pages' leftovers inert, ours included). On desktop, force the content
   visible and hide the summary so it reads as a plain sidebar; browsers
   without ::details-content fall back to the summary as a manual toggle.
   On mobile (media block below) it collapses into a bar above the title. */
@media (width > 900px) {
  @supports selector(details::details-content) {
    .article-meta > summary { display: none; }
    .article-meta::details-content { content-visibility: visible; }
    /* the toc too: its summary reads as a plain heading */
    .toc::details-content { content-visibility: visible; }
    .toc > summary { list-style: none; cursor: default; }
  }
}

aside .site { font-weight: bold; margin: 0 0 10px; }
aside .links { margin: 0 0 14px; }
aside .links a { color: #222; }

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 12px;
  margin: 16px 0;
}

.kv dt { font-weight: bold; }
.kv dd { margin: 0; text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font: 13px system-ui, sans-serif;
  background: #e8e8e8;
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  color: #333;
  text-decoration: none;
}

.toc { margin: 18px 0; }
.toc > summary { font-weight: bold; cursor: pointer; }
.toc nav { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.toc a { color: #222; font-size: 0.9rem; }

.danger {
  margin-top: 22px;
  background: none;
  border: none;
  color: #c0392b;
  cursor: pointer;
}

@media (max-width: 900px) {
  .reader-layout { display: block; }
  .reader { padding-bottom: 40px; }
  aside {
    position: static;
    max-height: none;
    overflow: visible;
    max-width: 80ch;
    margin: 0 auto;
    padding: 14px 0 0;
  }
  .article-meta > summary {
    font: 16px/1.5 system-ui, sans-serif;
    color: #333;
    cursor: pointer;
    padding: 4px 0;
  }
  .article-meta > summary::marker { color: #999; }
  /* the summary already names the site */
  .article-meta .site { display: none; }
  .article-meta[open] {
    border-bottom: 1px solid #ddd;
    padding-bottom: 18px;
  }
  .article-meta[open] > summary { margin-bottom: 14px; }
}

/* search results */
.results { max-width: 720px; margin: 0 auto; padding: 0 24px 60px; }
.results article { padding: 10px 0; border-bottom: 1px solid #ddd; overflow-wrap: anywhere; }
.results article.done > a { color: #555; }
.results .meta a { color: inherit; }
.snippet { color: #444; font-size: 0.9rem; margin: 4px 0 0; }
.snippet mark { background: #ffe89c; padding: 0 1px; }

/* semantic-only matches: in the results on similarity, not exact words */
.vibes {
  font: 12px/1 system-ui, sans-serif;
  background: #f1e7fb;
  color: #5b2d8e;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* home dashboard */
.home { max-width: 1120px; margin: 0 auto; padding: 4px 1rem 60px; }

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 22px;
  margin: 6px 0 4px;
}

.standing { margin: 0; font-size: 1.05rem; }

.surprise { background: #e2e2e2; }
.surprise:hover { background: #d6d6d6; }

/* quiet save form, home page only */
.save { margin-left: auto; }

@media (max-width: 760px) {
  .save { flex: 1 1 100%; margin-left: 0; }
  .save input { width: 100%; }
}

.hint { color: #555; font-size: 0.9rem; margin: 2px 0 12px; }

.home h2 { font-size: 1.15rem; margin: 30px 0 2px; }

/* broadsheet columns: no boxes, just text columns split by rules */
.picks {
  columns: 230px 4;
  column-gap: 36px;
  column-rule: 1px solid #d6d6d6;
  border-top: 2px solid #111;
  display: flex;
  padding-top: 16px;
  overflow-x: scroll;
}

.pick {
  break-inside: avoid;
  margin: 0 0 18px;
  min-width: 200px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pick p { margin: 0; }

.pick .stamp {
  font: 11px/1 system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #777;
  margin-bottom: 8px;
}

.pick > a { font-weight: 700; font-size: 1.1rem; line-height: 1.3; }

.pick .teaser { color: #444; font-size: 0.92rem; line-height: 1.45; margin-top: 8px; }

.pick .meta { margin-top: 8px; }

.home-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0 40px;
  align-items: start;
}

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

.compact li {
  padding: 8px 0 9px;
  border-bottom: 1px solid #ddd;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.compact .meta { display: block; }

.chip-count { color: #666; }

.more { font-size: 0.95rem; margin: 14px 0 0; }
.more a { color: #222; }

/* river timeline */
.river { max-width: 760px; margin: 0 auto; padding: 4px 1rem 60px; }

.river h1 { font-size: 1.5rem; margin: 6px 0 2px; }

/* the saved/read switch sits under the heading, in the text column */
.river .tabs { text-align: left; margin: 8px 0 12px; }

.year-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font: 15px/1.4 system-ui, sans-serif;
  margin: 0 0 14px;
}

.year-nav a { color: #444; padding: 4px 1px; }

.river .year > h2 { font-size: 1.3rem; margin: 26px 0 8px; }

.week {
  position: relative;
  margin: 0 0 0 7px;
  padding: 2px 0 16px 24px;
  border-left: 2px solid #d6d6d6;
}

.week::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #888;
}

.week h3 { font-size: 1rem; margin: 0; }

.week-meta { font-weight: normal; color: #555; font-size: 0.9rem; }

.week ul { list-style: none; margin: 4px 0 0; padding: 0; }

.week li { padding: 5px 0; line-height: 1.35; overflow-wrap: anywhere; }

.week li.done a { color: #555; }

/* Related reads, below the article body */
.reader .related {
  margin-top: 56px;
  border-top: 1px solid #ddd;
  padding-top: 20px;
}

.reader .related h2 { font-size: 1.05rem; margin-top: 0; }

/* Login page */
.login {
  max-width: 20rem;
  margin: 18vh auto 0;
  padding: 0 1rem;
  text-align: center;
}

.login h1 { font-size: 22px; }

.login form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login input {
  /* 16px minimum: smaller fonts trigger automatic zoom-on-focus on iOS */
  font: 16px/1.4 system-ui, sans-serif;
  background: #ececec;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  text-align: center;
}

.login input:focus { outline: 3px solid #bbb; }

.login button {
  font: 16px/1.4 system-ui, sans-serif;
  font-weight: 700;
  padding: 7px 18px;
  border-radius: 999px;
  border: 1px solid #111;
  background: #111;
  color: #fff;
  cursor: pointer;
}

.login-error { font: 15px/1.4 system-ui, sans-serif; color: #a00; }
