:root {
  color-scheme: dark;
  --bg: #101214;
  --ink: #eeece5;
  --muted: #a3a39e;
  --accent: #f26445;
  --line: #26292c;
  --line-strong: #3a3d40;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --shell: min(1140px, calc(100% - 48px));
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
h1, h2, h3 { overflow-wrap: break-word; }
.hidden { display: none !important; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }

.shell { width: var(--shell); margin-inline: auto; }
.skip-link { position: fixed; top: 12px; left: 12px; z-index: 100; padding: 10px 14px; background: var(--ink); color: var(--bg); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }

/* Header ------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar-inner {
  width: var(--shell);
  margin-inline: auto;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 22px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-style: italic;
}
.brand-accent { color: var(--accent); }
.feed-tabs {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 26px;
  overflow-x: auto;
  scrollbar-width: none;
}
.feed-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.82rem;
  letter-spacing: 0.005em;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); }
.tab-count { margin-left: 2px; color: var(--accent); font-size: 0.68rem; vertical-align: 2px; }
.settings-button {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.settings-button:hover { border-color: var(--line-strong); color: var(--ink); }
.settings-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }

/* Masthead ----------------------------------------------------------- */
.masthead { padding-top: 58px; padding-bottom: 36px; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.2rem, 5.5vw, 5rem);
  line-height: 0.98;
  font-weight: 400;
  letter-spacing: -0.045em;
}

/* Loading / states ---------------------------------------------------- */
.loading { min-height: 300px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 7px; }
.loading span { width: 6px; height: 6px; background: var(--accent); animation: pulse 0.9s infinite alternate; }
.loading span:nth-child(2) { animation-delay: 0.14s; }
.loading span:nth-child(3) { animation-delay: 0.28s; }
.loading p { width: 100%; margin-top: -110px; text-align: center; color: var(--muted); font-size: 0.8rem; }
@keyframes pulse { to { opacity: 0.2; transform: translateY(-4px); } }

/* Paper of the day ---------------------------------------------------- */
.content { padding-bottom: 110px; }
.lead { margin-top: 44px; border-top: 1px solid var(--line-strong); }
.lead-ribbon {
  padding: 18px 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
}
.lead-ribbon span { color: var(--accent); font-family: var(--serif); font-size: 0.95rem; font-style: italic; letter-spacing: 0; }
.lead-body { padding-top: 34px; }
.topic-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.topic { color: var(--muted); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.topic:first-child { color: var(--accent); }
.lead h2 {
  max-width: 1000px;
  margin: 24px 0 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 4.3vw, 4.2rem);
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: -0.04em;
}
.lead-authors { max-width: 860px; margin: 20px 0 0; color: var(--muted); font-size: 0.88rem; }
.lead-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.lead-meta > span + span::before { content: "·"; margin-right: 8px; color: var(--line-strong); }
.lead-meta .difficulty { text-transform: capitalize; }
.lead-meta .lead-picked::before { content: "|"; margin-right: 8px; color: var(--line-strong); }
.lead-meta .lead-topics { color: var(--ink); }
.lead-summary { max-width: 860px; margin-top: 28px; margin-bottom: 0; font-size: 1.05rem; line-height: 1.7; }
.lead-how { max-width: 860px; margin-top: 22px; }
.lead-how summary { display: inline-flex; align-items: center; gap: 8px; width: fit-content; color: var(--muted); cursor: pointer; font-size: 0.8rem; list-style: none; }
.lead-how summary::-webkit-details-marker { display: none; }
.lead-how summary::before { content: "+"; color: var(--accent); font-size: 0.9rem; }
.lead-how[open] summary::before { content: "–"; }
.lead-how summary:hover { color: var(--ink); }
.lead-how ul { margin: 14px 0 0; padding: 0; list-style: none; }
.lead-how li { position: relative; margin: 8px 0; padding-left: 18px; color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.lead-how li::before { content: ""; position: absolute; left: 0; top: 0.72em; width: 8px; height: 1px; background: var(--accent); }
.lead-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 32px; }
.read-button, .primary-button {
  min-height: 44px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #16100e;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.read-button:hover, .primary-button:hover { background: transparent; color: var(--accent); }
.save-button {
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
}
.save-button:hover { border-color: var(--ink); }
.save-button.saved { border-color: var(--accent); color: var(--accent); }
.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-left: 10px; color: var(--muted); font-size: 0.78rem; }
.feedback button { padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.78rem; text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line-strong); }
.feedback button:hover { color: var(--ink); }
.feedback button.active { color: var(--accent); text-decoration-color: var(--accent); }

/* Stream -------------------------------------------------------------- */
.stream { margin-top: 90px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.section-heading h2 { margin: 0; font-family: var(--serif); font-size: clamp(2rem, 3.4vw, 3rem); font-weight: 400; line-height: 1.05; letter-spacing: -0.04em; }
.section-heading > p { margin: 0; color: var(--muted); font-size: 0.76rem; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 48px; row-gap: 0; border-top: 1px solid var(--line-strong); }
.story-card { display: flex; flex-direction: column; padding-block: 38px; border-bottom: 1px solid var(--line); }
.story-head { display: flex; align-items: baseline; gap: 14px; }
.story-index { flex: none; color: var(--accent); font-family: var(--serif); font-size: 0.85rem; font-style: italic; }
.story-card h3 { margin: 16px 0 0; font-family: var(--serif); font-size: clamp(1.4rem, 2.1vw, 1.85rem); font-weight: 400; line-height: 1.14; letter-spacing: -0.03em; }
.story-card h3 a { text-decoration: none; }
.story-card h3 a:hover { color: var(--accent); }
.story-summary { margin: 14px 0 26px; color: var(--muted); font-size: 0.92rem; line-height: 1.6; }
.story-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: auto; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; }
.story-age::before { content: "·"; margin-right: 10px; color: var(--line-strong); }
.story-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.mini-save, .arrow-link { border: 0; background: transparent; color: var(--muted); text-decoration: none; cursor: pointer; font-size: 0.85rem; line-height: 1; }
.mini-save::before { content: "Save"; letter-spacing: 0.08em; font-size: 0.68rem; }
.mini-save.saved::before { content: "Saved"; color: var(--accent); }
.mini-save:hover, .arrow-link:hover { color: var(--ink); }

.empty-state { padding: 70px 0; border-bottom: 1px solid var(--line); }
.empty-state h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 2rem; font-weight: 400; letter-spacing: -0.03em; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }
.empty-state button, .error button { min-height: 42px; padding: 0 18px; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); cursor: pointer; font-size: 0.82rem; }
.empty-state button:hover, .error button:hover { border-color: var(--ink); }
.error { padding-block: 90px 120px; }
.error h2 { margin: 0 0 10px; font-family: var(--serif); font-size: clamp(2rem, 3.4vw, 2.8rem); font-weight: 400; letter-spacing: -0.04em; }
.error p { max-width: 560px; margin: 0 0 24px; color: var(--muted); }

.footer { min-height: 96px; display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.72rem; }
.footer p { margin: 0; }
.footer p:first-child { color: var(--ink); }
.footer p:nth-child(2) { text-align: center; }

/* Preferences panel ---------------------------------------------------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.6); }
.panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(430px, 100%);
  height: 100dvh;
  padding: 32px;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--line-strong);
  transform: translateX(103%);
  transition: transform 0.25s ease;
}
.panel.open { transform: translateX(0); }
.panel-head { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.panel h2 { margin: 0; font-family: var(--serif); font-size: 2.2rem; font-weight: 400; letter-spacing: -0.04em; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.icon-button:hover { border-color: var(--ink); color: var(--ink); }
.panel-copy { margin: 18px 0 28px; color: var(--muted); font-size: 0.92rem; }
.interest { padding: 14px 0; border-top: 1px solid var(--line); }
.interest:last-child { border-bottom: 1px solid var(--line); }
.interest-top { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.interest-top label { font-size: 0.86rem; }
.interest-top output { color: var(--accent); font-size: 0.74rem; }
.interest input { width: 100%; accent-color: var(--accent); cursor: pointer; }
.panel-note { margin: 26px 0; padding-left: 16px; border-left: 1px solid var(--line-strong); }
.panel-note span { color: var(--muted); font-size: 0.64rem; font-weight: 600; letter-spacing: 0.14em; }
.panel-note p { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; }
.panel .primary-button { width: 100%; justify-content: center; }
.text-button { display: block; margin: 14px auto 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 4px; font-size: 0.8rem; }

/* Responsive ----------------------------------------------------------- */
@media (max-width: 1024px) {
  .masthead { padding-top: 46px; padding-bottom: 30px; }
  .lead { margin-top: 38px; }
  .stream { margin-top: 76px; }
}

@media (max-width: 760px) {
  :root { --shell: min(1140px, calc(100% - 40px)); }
  .topbar-inner { gap: 16px; }
  .feed-tabs { justify-content: flex-start; gap: 20px; }
  .masthead { padding-top: 36px; padding-bottom: 26px; }
  .masthead h1 { font-size: clamp(2.6rem, 12vw, 3.4rem); }
  .lead h2 { font-size: clamp(2.4rem, 9vw, 3rem); }
  .lead-summary { font-size: 1rem; }
  .lead-actions { gap: 12px; }
  .lead-meta .lead-picked { width: 100%; margin-top: 4px; }
  .lead-meta .lead-picked::before { content: none; }
  .feedback { width: 100%; margin-left: 0; }
  .stream { margin-top: 64px; }
  .section-heading { flex-direction: column; align-items: start; gap: 6px; }
  .cards { grid-template-columns: 1fr; column-gap: 0; }
  .story-card { padding-block: 32px; }
  .content { padding-bottom: 80px; }
  .footer { grid-template-columns: 1fr auto; padding-block: 26px; }
  .footer p:nth-child(2) { grid-column: 1 / -1; grid-row: 2; text-align: left; }
  .panel { padding: 26px 20px; }
}

@media (max-width: 420px) {
  .brand { font-size: 0.88rem; }
  .lead h2 { font-size: 2.4rem; }
  .read-button, .save-button { flex: 1 1 auto; justify-content: center; text-align: center; }
}

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