:root {
  --paper: #e9edf2;
  --surface: #f6f8fa;
  --ink: #16202c;
  --muted: #586374;
  --rule: #cbd3dd;
  --plank: #2a3644;
  --focus: #1f6feb;

  --t-ai: #3d5cb8;
  --t-infra: #23806e;
  --t-products: #b08a17;
  --t-essays: #6a4ba6;
  --t-fun: #c94a6b;
  --t-nyc: #4e8a33;
  --t-misc: #7c8796;
  --t-new: #1f8fb5;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --measure: 46rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111923;
    --surface: #172130;
    --ink: #e4e9ef;
    --muted: #98a4b4;
    --rule: #283545;
    --plank: #3b4a5d;
    --focus: #79a8ff;

    --t-ai: #6f8fe0;
    --t-infra: #3fb39a;
    --t-products: #e0b83a;
    --t-essays: #a283e0;
    --t-fun: #e46c88;
    --t-nyc: #7cbf5c;
    --t-misc: #8f9aab;
    --t-new: #4cc0e4;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
}

a {
  color: inherit;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- masthead ---------- */
.masthead {
  max-width: 72rem;
  margin: 0 auto;
  padding: 4.5rem 1.25rem 1.5rem;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 4.25rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  max-width: 14ch;
}

.lede {
  max-width: 36rem;
  margin: 0;
  color: var(--muted);
  font-size: 1.0625rem;
}

/* ---------- shelf ---------- */
.shelf-wrap {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0;
}

.shelf {
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding: 1.5rem 0 0.25rem;
  min-height: 15rem;
}

.month {
  flex: none;
  display: flex;
  flex-direction: column;
}

.month-books {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 4px;
  border-bottom: 7px solid var(--plank);
  border-radius: 0 0 2px 2px;
  min-height: 11rem;
}

.month-label {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.month-label b {
  color: var(--ink);
  font-weight: 600;
}

.spine {
  --c: var(--t-misc);
  appearance: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  --h: calc(3.25rem + var(--s, 0.4) * 7.25rem);
  width: 9px;
  height: var(--h);
  background:
    linear-gradient(to bottom, transparent 0 10px, rgb(255 255 255 / 0.28) 10px 12px, transparent 12px),
    var(--c);
  border-radius: 2px 2px 0 0;
  transition: transform 160ms ease, opacity 200ms ease;
  transform-origin: bottom;
}

.spine.wide {
  width: 22px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.spine.wide span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--serif);
  font-size: 0.75rem;
  line-height: 1;
  color: #fff;
  padding: 0.5rem 0 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: calc(var(--h) - 1rem);
}

.spine:hover,
.spine:focus-visible {
  transform: translateY(-6px);
}

.spine.dim {
  opacity: 0.16;
}

@media (prefers-reduced-motion: no-preference) {
  .shelf.rise .spine {
    animation: rise 520ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--i) * 4ms);
  }
}

@keyframes rise {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

/* topic colors */
[data-cat="AI-Agents"] { --c: var(--t-ai); }
[data-cat="Infra-DevOps"] { --c: var(--t-infra); }
[data-cat="Companies-Products"] { --c: var(--t-products); }
[data-cat="Reading"] { --c: var(--t-essays); }
[data-cat="Fun-Curiosities"] { --c: var(--t-fun); }
[data-cat="NYC-Local"] { --c: var(--t-nyc); }
[data-cat="Misc"] { --c: var(--t-misc); }
[data-cat="_root"] { --c: var(--t-new); }

/* ---------- legend / topic filter ---------- */
.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
}

.legend button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.3rem 0.75rem 0.3rem 0.6rem;
  cursor: pointer;
}

.legend button::before {
  content: "";
  width: 0.6rem;
  height: 0.85rem;
  border-radius: 1px;
  background: var(--c, var(--t-misc));
}

.legend button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.legend .count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.legend button[aria-pressed="true"] .count {
  color: inherit;
  opacity: 0.7;
}

/* ---------- log ---------- */
.log {
  max-width: 72rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 2rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  max-width: var(--measure);
  margin-left: auto;
  margin-right: 0;
}

.search {
  flex: 1 1 18rem;
}

.search input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

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

.sort {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}

.sort button {
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
}

.sort button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--surface);
  font-weight: 600;
}

.status {
  max-width: var(--measure);
  margin: 0.75rem 0 0 auto;
  min-height: 1.5em;
  font-size: 0.875rem;
  color: var(--muted);
}

.status button {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.group {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(0, var(--measure));
  gap: 0 2.5rem;
  padding-top: 2.5rem;
}

.group h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.75rem;
  line-height: 1.15;
  margin: 0;
  position: sticky;
  top: 1rem;
  align-self: start;
}

.group h2 small {
  display: block;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 0.25rem;
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.entry {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr);
  gap: 0 1rem;
  padding: 1.1rem 0 1.2rem;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 5rem;
}

.entry.flash {
  animation: flash 1600ms ease-out;
}

@keyframes flash {
  0%,
  30% {
    background: color-mix(in srgb, var(--c) 16%, transparent);
  }
  100% {
    background: transparent;
  }
}

.day {
  font-size: 0.875rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: 0.2rem;
  border-left: 3px solid var(--c, var(--t-misc));
  padding-left: 0.6rem;
  line-height: 1.3;
}

.entry h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.3rem;
  line-height: 1.25;
  margin: 0;
  text-wrap: pretty;
}

.entry h3 a {
  text-decoration: none;
}

.entry h3 a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.85rem;
  margin-top: 0.3rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.meta img {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 0.35rem;
}

.desc {
  margin: 0.5rem 0 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.55;
  max-width: 62ch;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin-top: 0.6rem;
}

.tags button {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.tags button:hover,
.tags button[aria-pressed="true"] {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.empty {
  max-width: var(--measure);
  margin: 3rem 0 0 auto;
  font-family: var(--serif);
  font-size: 1.25rem;
}

/* ---------- tooltip ---------- */
.tip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  max-width: 18rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.8125rem;
  line-height: 1.35;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
}

.tip b {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 0.9375rem;
}

/* ---------- footer ---------- */
.foot {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  font-size: 0.875rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 2rem;
}

.foot p {
  margin: 0;
}

.foot-links {
  display: flex;
  gap: 1.25rem;
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .masthead {
    padding: 2.5rem 1rem 1rem;
  }
  .shelf-wrap,
  .log,
  .foot {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .shelf {
    min-height: 12rem;
  }
  .month-books {
    min-height: 8.5rem;
  }
  .spine {
    --h: calc(2.5rem + var(--s, 0.4) * 5.5rem);
  }
  .group {
    grid-template-columns: 1fr;
    padding-top: 2rem;
  }
  .group h2 {
    position: static;
    margin-bottom: 0.75rem;
  }
  .entry {
    grid-template-columns: 2.75rem minmax(0, 1fr);
    gap: 0 0.75rem;
  }
  .entry h3 {
    font-size: 1.15rem;
  }
}
