@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151918;
  --bg-2: #19201c;
  --surface: #1d2421;
  --text: #edf1e9;
  --muted: #aebbb1;
  --accent: #a7c99b;
  --accent-2: #bdd8b3;
  --on-accent: #151918;
  --rule: #35423a;
  --soft-green: #29372d;
  --danger: #e6a496;
  --sticky: rgb(21 25 24 / 90%);
  --backdrop: rgb(5 10 7 / 64%);
  --shadow: 0 22px 90px rgb(0 0 0 / 30%);
  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: Georgia, "Times New Roman", serif;
  --bg2: var(--bg-2);
  --fg: var(--text);
  --accent2: var(--accent-2);
  --border: var(--rule);
  --good: var(--accent);
  --bad: var(--danger);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ee;
  --bg-2: #eeeee5;
  --surface: #fbfaf6;
  --text: #202923;
  --muted: #606b61;
  --accent: #355b42;
  --accent-2: #294a34;
  --on-accent: #fbfaf6;
  --rule: #d9ddd2;
  --soft-green: #e5eadf;
  --danger: #974c3e;
  --sticky: rgb(246 244 238 / 90%);
  --backdrop: rgb(24 36 28 / 48%);
  --shadow: 0 22px 90px rgb(17 32 22 / 22%);
}

/* Keep shared UI primitives on the same editorial palette. */
.card, .stat, .chip, .badge {
  background: var(--surface);
  color: var(--text);
  border-color: var(--rule);
  box-shadow: none;
}

input, select, textarea,
.field input, .field select, .field textarea {
  min-height: 44px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--rule);
}

input::placeholder, textarea::placeholder,
.muted, .story-footer {
  color: var(--muted);
}

.btn.ghost:hover { background: var(--soft-green); }
.btn.danger { color: var(--danger); border-color: var(--rule); }
.btn:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .field input:focus-visible,
.field select:focus-visible, .field textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-color: var(--accent);
  box-shadow: none;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 16px;
  z-index: 110;
  padding: 10px 16px;
  background: var(--surface);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.app.stack { gap: 0; }
.status-row { padding: 8px 0; }
.status-row p { margin: 0; }
.feed-controls .topic-strip { flex-wrap: nowrap; }
.feed-controls .controls-row { min-width: 0; }
.story-footer { margin-top: 14px; font-size: 11px; }
.source-list { margin: 16px 0; }
.source-row { overflow-wrap: anywhere; }
.empty-state { background: var(--bg); }
.empty-state.error, #feed-status.error { color: var(--danger); }
#feed > .story--no-photo:first-child .story-body > p { max-width: none; }

@media (max-width: 700px) {
  .feed-controls .controls-row > #search { flex: 1 1 140px; width: 0; }
  .feed-controls .topic-strip { flex: 0 0 100%; }
  .status-row > .row { flex-wrap: wrap; }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  scroll-padding-top: 150px;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-width: 300px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden],
dialog[hidden],
#sources-panel[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button,
.btn,
input[type="checkbox"],
label:has(input[type="checkbox"]) {
  touch-action: manipulation;
}

button,
.btn {
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 16px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  box-shadow: none;
  transition: background-color 160ms ease, border-color 160ms ease;
}

button:hover,
.btn:hover {
  background: var(--soft-green);
  border-color: var(--accent);
}

button:active,
.btn:active {
  background: var(--soft-green);
}

button:disabled,
.btn:disabled {
  cursor: default;
  opacity: 0.5;
}

button.primary,
.btn.primary,
#remember {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

button.primary:hover,
.btn.primary:hover,
#remember:hover {
  background: var(--accent-2);
}

button.ghost,
.btn.ghost {
  background: transparent;
}

button.danger,
.btn.danger,
#reset-seen {
  color: var(--danger);
  border-color: var(--rule);
}

a {
  color: var(--accent);
  text-underline-offset: 4px;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

::selection {
  background: var(--soft-green);
  color: var(--text);
}

.app,
body > header,
body > main,
body > footer {
  width: min(1100px, calc(100% - 64px));
  max-width: 1100px;
  margin-inline: auto;
}

.app {
  padding: 0;
}

.app > header,
body > header,
.masthead {
  position: relative;
  padding: 24px 0 18px;
  border-bottom: 1px solid var(--text);
  background: var(--bg);
}

header h1,
.masthead h1,
.brand,
.wordmark {
  margin: 0;
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(52px, 8.7vw, 104px);
  font-weight: 400;
  letter-spacing: -0.065em;
  line-height: 1;
}

header h1 a,
.brand a,
a.brand {
  color: inherit;
  text-decoration: none;
}

header p,
.masthead p,
.descriptor,
.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.025em;
}

#today {
  display: inline-block;
  margin-top: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.header-top,
.masthead-top,
.header-actions,
.controls-row,
.toolbar-row,
.status-row,
.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.header-actions {
  justify-content: flex-end;
}

.controls,
.toolbar,
.feed-controls,
#controls {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  background: var(--sticky);
  backdrop-filter: blur(14px);
}

.controls .row,
.toolbar .row,
.feed-controls .row {
  flex-wrap: wrap;
  gap: 10px;
}

.topics,
.topic-strip,
.topic-tabs,
.categories,
nav:has([data-category]) {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding: 3px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  overscroll-behavior-x: contain;
}

[data-category] {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 10px 17px;
  border-color: transparent;
  border-radius: 24px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

[data-category][aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

[data-category][aria-pressed="true"]:hover {
  background: var(--accent-2);
}

#search {
  width: min(100%, 280px);
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
  font-size: 12px;
}

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

.search,
.search-field,
label:has(> #search) {
  display: block;
  min-width: 180px;
}

#sources-button,
#refresh {
  white-space: nowrap;
}

#sync-status,
#source-health,
#updated,
#feed-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

#sync-status,
#source-health,
#updated {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#updated[data-success="true"]::before,
#updated.is-fresh::before,
.live-dot[data-active="true"],
.live-dot.is-active {
  content: "";
  display: inline-block;
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.live-dot:not([data-active="true"]):not(.is-active) {
  display: none;
}

#feed-status {
  margin: 8px 0;
}

#feed-status:empty {
  display: none;
}

#feed {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

#feed > li {
  list-style: none;
}

.story {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.5fr);
  align-items: center;
  gap: 34px;
  width: 100%;
  margin: 0;
  padding: 32px 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.story-photo {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
}

img.story-photo,
.story-photo img,
.story-photo picture,
.story-photo picture img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

img.story-photo {
  height: auto;
  object-fit: cover;
}

.story > a:has(> img.story-photo),
.story > figure,
.story-photo-link {
  display: block;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
}

.story-body {
  min-width: 0;
}

.story-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 10px;
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.065em;
  text-transform: uppercase;
}

.story-meta a {
  color: var(--accent);
  text-decoration: none;
}

.source-pill,
.story-source,
.story-meta .source,
.story-meta .badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--soft-green);
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.story-body > h2,
.story-title {
  margin: 0;
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(27px, 2.9vw, 36px);
  font-weight: 400;
  line-height: 1.17;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.story-title a,
a.story-title,
.story-link {
  color: inherit;
  text-decoration: none;
}

.story-title a:hover,
a.story-title:hover,
.story-link:hover .story-title {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

.story-body > p,
.story-excerpt,
.excerpt {
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

.story-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.mark-seen {
  min-height: 44px;
  margin-top: 12px;
  padding: 8px 0;
  border-color: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
}

.mark-seen:hover {
  padding-inline: 10px;
}

.story-actions .mark-seen {
  margin-top: 0;
}

.seen:not(.story),
.seen-badge,
.seen-label {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--muted);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.story.seen .story-meta,
.story.seen .story-footer {
  color: var(--muted);
}

.story--no-photo {
  grid-template-columns: minmax(0, 1fr);
}

.story--no-photo > .story-photo,
.story--no-photo > .story-photo-link,
.story--no-photo > figure {
  display: none;
}

.story--no-photo .story-body,
#feed > .story--no-photo:first-child .story-body {
  max-width: none;
}

.illustration-label {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.035em;
}

.story-photo .illustration-label {
  position: absolute;
  right: 9px;
  bottom: 9px;
  left: auto;
  max-width: calc(100% - 18px);
  margin: 0;
  padding: 4px 7px;
  border-radius: 3px;
  background: var(--sticky);
  color: var(--text);
}

/* Keep media understandable while remote photography loads or fails. */
.story-photo .photo-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
}
.story-photo.photo-loading img { opacity: 0; }
.story-photo [hidden] { display: none !important; }

#feed > .story:first-child,
#feed > li:first-child > .story {
  grid-template-columns: minmax(0, 1fr);
  gap: 23px;
  padding-top: 22px;
  padding-bottom: 36px;
}

#feed > .story:first-child .story-photo,
#feed > li:first-child > .story .story-photo {
  aspect-ratio: 16 / 9;
}

#feed > .story:first-child .story-body,
#feed > li:first-child > .story .story-body {
  max-width: 920px;
}

#feed > .story:first-child .story-body > h2,
#feed > li:first-child > .story .story-body > h2,
#feed > .story:first-child .story-title,
#feed > li:first-child > .story .story-title {
  font-size: clamp(34px, 4.7vw, 57px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

#feed > .story:first-child .story-body > p,
#feed > li:first-child > .story .story-body > p {
  max-width: 740px;
  font-size: 14px;
}

.loading-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 420px;
  margin: 22px 0 30px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 30px;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
}

.loading-card > * {
  position: relative;
  z-index: 1;
}

.loading-card img {
  opacity: 0.45;
  object-fit: cover;
}

.loading-card > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.loading-card h2,
.loading-card h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(27px, 4vw, 43px);
  font-weight: 400;
  line-height: 1.15;
}

.loading-card p,
.loading-card .muted,
.loading-card .illustration-label {
  color: var(--muted);
}

.loading-card,
.skeleton,
.skeleton::before,
.skeleton::after {
  animation: none !important;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 290px;
  padding: 48px 24px;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  text-align: center;
}

.empty-state h2,
.empty-state h3 {
  margin: 0 0 12px;
  color: var(--text);
  font-family: var(--display);
  font-size: 32px;
  font-weight: 400;
  line-height: 1.2;
}

.empty-state p {
  max-width: 440px;
  margin: 0 0 18px;
}

#load-more {
  display: block;
  min-width: 190px;
  margin: 34px auto 46px;
  padding-inline: 28px;
}

dialog,
#sources-panel {
  width: min(610px, calc(100% - 32px));
  max-width: 610px;
  max-height: 85vh;
  max-height: 85dvh;
  margin: auto;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 28px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(4px);
}

dialog header,
#sources-panel header,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 0;
  border: 0;
}

dialog h2,
#sources-panel h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 34px;
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

dialog p,
#sources-panel > p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

#sources-close {
  flex-shrink: 0;
  min-width: 44px;
}

#sources-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 22px 0;
  padding: 0;
  border-top: 1px solid var(--rule);
  list-style: none;
}

.source-row {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  min-height: 72px;
  padding: 16px 0;
  border-bottom: 1px solid var(--rule);
}

.source-row label {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  cursor: pointer;
}

label.source-row {
  cursor: pointer;
}

.source-row > div {
  flex: 1;
  min-width: 0;
}

.source-row input[type="checkbox"],
input[data-source] {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 3px 3px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.source-row strong,
.source-row b {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.source-row p,
.source-row small,
.source-description {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.source-state {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.source-state.error,
.source-state[data-state="error"],
.source-state[data-ok="false"] {
  color: var(--danger);
}

.source-state.ok,
.source-state[data-state="ok"],
.source-state[data-ok="true"] {
  color: var(--accent);
}

#reset-seen {
  margin-top: 3px;
}

#credits,
footer {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}

footer,
#credits:not(footer *) {
  margin-top: 34px;
  padding-top: 22px;
  padding-bottom: 32px;
  border-top: 1px solid var(--rule);
}

#credits a,
footer a {
  color: var(--accent);
}

#toast,
.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: auto;
  width: max-content;
  max-width: min(430px, calc(100vw - 40px));
  padding: 13px 18px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 8px 30px rgb(20 38 25 / 16%);
}

#toast:empty {
  display: none;
}

@media (min-width: 800px) {
  .masthead > #today,
  .app > header > #today,
  body > header > #today {
    position: absolute;
    top: 24px;
    right: 0;
    margin: 0;
  }

  .controls,
  .toolbar,
  .feed-controls {
    gap: 12px;
  }
}

@media (max-width: 700px) {
  html {
    scroll-padding-top: 165px;
  }

  .app,
  body > header,
  body > main,
  body > footer {
    width: calc(100% - 40px);
  }

  .app > header,
  body > header,
  .masthead {
    padding-top: 18px;
    padding-bottom: 16px;
  }

  header h1,
  .masthead h1,
  .brand,
  .wordmark {
    font-size: clamp(43px, 12vw, 76px);
    letter-spacing: -0.06em;
  }

  header p,
  .masthead p,
  .descriptor,
  .tagline {
    font-size: 11px;
  }

  #today {
    font-size: 9px;
    letter-spacing: 0.1em;
  }

  .controls,
  .toolbar,
  .feed-controls,
  #controls {
    padding-top: 9px;
    padding-bottom: 9px;
  }

  .header-actions,
  .controls-row,
  .toolbar-row {
    gap: 8px;
  }

  #search {
    width: 100%;
    min-width: 0;
  }

  .search,
  .search-field,
  label:has(> #search) {
    flex: 1;
    min-width: 120px;
  }

  [data-category] {
    padding-inline: 14px;
    font-size: 11px;
  }

  .status-row,
  .feed-meta {
    gap: 4px 12px;
  }

  #sync-status,
  #source-health,
  #updated,
  #feed-status {
    font-size: 10px;
  }

  .story,
  #feed > .story:first-child,
  #feed > li:first-child > .story {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    padding-top: 24px;
    padding-bottom: 26px;
  }

  .story-photo,
  #feed > .story:first-child .story-photo,
  #feed > li:first-child > .story .story-photo {
    aspect-ratio: 16 / 10;
  }

  .story-body > h2,
  #feed > .story:first-child .story-body > h2,
  #feed > li:first-child > .story .story-body > h2,
  .story-title,
  #feed > .story:first-child .story-title,
  #feed > li:first-child > .story .story-title {
    font-size: 25px;
    line-height: 1.2;
    letter-spacing: -0.02em;
  }

  #feed > .story:first-child .story-body > h2,
  #feed > li:first-child > .story .story-body > h2,
  #feed > .story:first-child .story-title {
    font-size: clamp(30px, 8vw, 38px);
    line-height: 1.12;
  }

  .story-meta {
    gap: 6px 8px;
    margin-bottom: 10px;
    font-size: 9px;
  }

  .story-body > p,
  #feed > .story:first-child .story-body > p,
  #feed > li:first-child > .story .story-body > p {
    margin-top: 12px;
    font-size: 12px;
    line-height: 1.75;
  }

  .loading-card {
    min-height: 340px;
    margin-top: 20px;
    padding: 23px;
  }

  dialog,
  #sources-panel {
    padding: 22px 20px;
    border-radius: 10px;
  }

  dialog h2,
  #sources-panel h2 {
    font-size: 29px;
  }

  .source-row {
    gap: 11px;
  }

  #toast,
  .toast {
    right: 20px;
    left: 20px;
    width: auto;
    max-width: none;
  }
}

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

@media print {
  body {
    background: white;
    color: black;
  }

  .controls,
  .toolbar,
  .feed-controls,
  #sources-button,
  #refresh,
  #remember,
  #load-more,
  #sources-panel,
  #toast,
  .mark-seen {
    display: none !important;
  }

  .app,
  body > header,
  body > main,
  body > footer {
    width: 100%;
  }

  .story {
    break-inside: avoid;
  }
}
