:root {
  --bg: #f6f5f1;          /* newsprint */
  --fg: #16181d;
  --muted: #646a73;
  --accent: #1d4ed8;
  --accent-soft: #e3eafc;
  --amber: #b86e00;       /* ticker amber */
  --amber-soft: #fff1d6;
  --good: #17784a;
  --good-soft: #dcf3e6;
  --card: #ffffff;
  --border: #e3e1da;
  --neg: #b0283a;
  --neg-soft: #fbe3e6;
  --bar: #14213d;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317; --fg: #e9eaec; --muted: #9aa1ab; --accent: #7aa2ff; --accent-soft: #1d2a47;
    --amber: #f2b03c; --amber-soft: #3a2c10; --good: #5bd08f; --good-soft: #143222;
    --card: #181c22; --border: #2a3038; --neg: #ff7a8a; --neg-soft: #3a1820; --bar: #0b1220;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-text-size-adjust: 100%; overflow-x: hidden;
}
body.has-tabs { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); }
a { color: var(--accent); }
h2 { margin: .5rem 0 1rem; }
h3 { margin: 0 0 .75rem; font-size: 1.05rem; }
.wrap { max-width: 680px; margin: 0 auto; padding-inline: 1rem; }
main.wrap { padding-block: 1rem; }

.topbar { background: var(--bar); color: #fff; padding-top: env(safe-area-inset-top, 0px); }
.topbar .wrap { display: flex; justify-content: space-between; align-items: center; min-height: 3rem; }
.topbar a, .topbar .link { color: #cfd8ea; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; text-decoration: none; color: #fff !important; }
.brand img { width: 1.75rem; height: 1.75rem; border-radius: 7px; }
.who { display: flex; gap: 1rem; align-items: center; font-size: .9rem; }
.who .me { color: #fff; font-weight: 600; }

.tabs {
  position: fixed; inset: auto 0 0 0; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 10;
}
.tabs a { flex: 1; text-align: center; padding: .45rem 0 .55rem; font-size: .75rem; color: var(--muted); text-decoration: none; position: relative; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.on::before { content: ""; position: absolute; top: -1px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tabs .ic { display: block; font-size: 1.25rem; line-height: 1.3; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 420px; margin: 2rem auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.flash { background: var(--accent-soft); border-radius: 10px; padding: .6rem .8rem; margin-bottom: .75rem; }
.flash.error { background: var(--neg-soft); color: var(--neg); }
.flash.success { background: var(--good-soft); }
.stack > * + * { margin-top: .75rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field + .field { margin-top: .75rem; }
input[type=email], input[type=text], input[type=search], input[type=url], input:not([type]), select, textarea {
  width: 100%; font: inherit; padding: .55rem .65rem; border: 1px solid var(--border);
  border-radius: 9px; background: var(--card); color: var(--fg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: .55rem .9rem;
  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; display: inline-block;
}
button.wide, .btn.wide { width: 100%; text-align: center; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.link { background: none; color: inherit; padding: 0; font-weight: 400; text-decoration: underline; }
button.danger { background: var(--neg); }
button.link.danger { background: none; color: var(--neg); }
button.small, .btn.small { padding: .3rem .6rem; font-size: .85rem; }
form.inline { display: inline; }
.errorlist { color: var(--neg); margin: .25rem 0 0; padding: 0; list-style: none; font-size: .9rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > input { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }

/* Feed header and filters */
.feed-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--card); }
.segmented a { padding: .35rem .85rem; text-decoration: none; color: var(--muted); font-size: .9rem; }
.segmented a.on { background: var(--accent); color: #fff; font-weight: 600; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1rem; }
.filters input[type=search] { grid-column: 1 / -1; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* Feed updates: when it last updated, and the progress of a refresh. */
.update-line { margin: -.35rem 0 .6rem; }
.refresh-banner {
  display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; padding: .6rem .85rem;
  border-radius: 10px; background: var(--accent-soft); color: var(--fg); font-size: .9rem;
}
.refresh-banner.done { background: var(--good-soft); }
.refresh-banner.failed { background: var(--neg-soft); }
.refresh-banner > span:not(.mini-spinner):not(.done-mark):not(.warn-mark) { flex: 1; }
.refresh-banner .btn.small { padding: .25rem .75rem; }
.refresh-banner .dismiss { color: var(--muted); text-decoration: none; }
.done-mark { color: var(--good); font-weight: 700; }
.warn-mark { color: var(--neg); font-weight: 700; }
.mini-spinner { flex: none; width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; }

/* Briefing */
.briefing { border-left: 4px solid var(--amber); }
.briefing summary { cursor: pointer; font-weight: 700; }
.briefing ol { margin: .75rem 0 0; padding-left: 1.2rem; }
.briefing li + li { margin-top: .5rem; }
.briefing li a { font-weight: 600; text-decoration: none; color: var(--fg); }
.briefing .src { color: var(--muted); font-size: .8rem; }

/* Feed items */
/* Card: topic label, headline, summary, byline; image on the right; story and actions share the footer. */
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .9rem; padding: .85rem 1rem .45rem; }
.item .body { min-width: 0; }
.item .thumb { grid-column: 2; grid-row: 1; align-self: start; margin-top: 1.25rem; width: 88px; height: 88px;
  object-fit: cover; border-radius: 8px; background: var(--border); }
.kicker { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; min-height: 1rem; margin-bottom: .25rem; }
.kicker-topic { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
  text-decoration: none; }
.kicker-topic:hover { text-decoration: underline; }
.kicker-topic.new-topic { color: var(--amber); }
.kicker .tag { font-size: .66rem; padding: 0 .4rem; line-height: 1.5; }
.item h3 { margin: 0; font-size: 1.05rem; line-height: 1.3; }
.item h3 a { color: var(--fg); text-decoration: none; }
.item h3 a:hover { text-decoration: underline; }
.item .why { font-size: .9rem; line-height: 1.4; color: var(--fg); opacity: .78; margin: .3rem 0 0; }
.byline { font-size: .78rem; color: var(--muted); margin: .4rem 0 0; }
.byline .source { font-weight: 600; color: var(--fg); opacity: .85; }
.byline a { color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--border); }
.byline a:hover { color: var(--accent); }
.foot { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; min-height: 2.25rem; margin-top: .55rem;
  padding-top: .35rem; border-top: 1px solid var(--border); }

/* The story an article belongs to, when there are several articles on it. */
.story-link {
  display: inline-flex; align-items: center; gap: .4rem; min-width: 0; max-width: 60%;
  padding: .15rem .3rem .15rem .5rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: .78rem; text-decoration: none;
}
.story-link:hover { border-color: var(--accent); color: var(--accent); }
.story-link .icon { width: 15px; height: 15px; color: var(--accent); }
.story-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.story-count { flex: none; min-width: 1.4rem; padding: 0 .35rem; border-radius: 999px; background: var(--card);
  color: var(--muted); font-size: .72rem; font-weight: 600; text-align: center; }
.item.read .story-link { opacity: .7; }

/* Card actions: quiet line icons, right-aligned; they show their colour on hover or when active. */
.item .actions { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.icon-row { display: flex; gap: .1rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; padding: 0;
  background: none; border: 0; border-radius: 8px; color: var(--muted); opacity: .7; cursor: pointer; list-style: none;
  transition: background .15s, color .15s, opacity .15s;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg); color: var(--fg); opacity: 1; }
.icon-btn.on { color: var(--accent); opacity: 1; }
.icon-btn.on .icon { fill: currentColor; fill-opacity: .18; }
.icon-btn:active { transform: scale(.92); }
.icon { display: block; flex: none; }
.item .actions button.follow {
  display: inline-flex; align-items: center; gap: .3rem; margin-right: .25rem; padding: .2rem .6rem .2rem .45rem;
  background: none; border: 1px solid var(--amber); color: var(--amber); font-size: .8rem; font-weight: 600; border-radius: 999px;
}
.item .actions button.follow .icon { width: 14px; height: 14px; }
.item .actions button.follow:hover { background: var(--amber-soft); }
details.menu { position: relative; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { background: var(--bg); color: var(--fg); opacity: 1; }
.menu-list {
  position: absolute; right: 0; bottom: calc(100% + .25rem); z-index: 5; min-width: 13rem; padding: .25rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .12);
}
.menu-list button {
  display: flex; align-items: center; gap: .55rem; width: 100%; padding: .5rem .6rem; text-align: left;
  background: none; color: var(--fg); font-weight: 500; font-size: .88rem; border-radius: 7px;
}
.menu-list button:hover { background: var(--bg); }
.menu-list .icon { width: 16px; height: 16px; color: var(--muted); }
.item.discovery { border-color: var(--amber); }
/* Already opened: dimmed, so what's left to read stands out. */
.item.read { background: var(--bg); box-shadow: none; }
.item.read h3 a, .briefing li.read a { color: var(--muted); font-weight: 500; }
.item.read .thumb { opacity: .5; filter: grayscale(.6); }
.item.read .why { opacity: .55; }
.tag.read-tag { background: var(--border); color: var(--muted); }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.tag.topic { background: var(--accent-soft); color: var(--accent); }
.tag.new-topic { background: var(--amber-soft); color: var(--amber); }
.tag.fresh { background: var(--good-soft); color: var(--good); }
.score { font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 2rem 1rem; }
.more { text-align: center; margin: 1rem 0; }
.more .small-spinner { width: 1.5rem; height: 1.5rem; border-width: 3px; margin: .75rem auto; }
.more.htmx-request .btn { display: none; }
a.tag { text-decoration: none; }
a.tag:hover { filter: brightness(.95); text-decoration: underline; }
.read-bar { margin: -.25rem 0 .75rem; min-height: 1.2em; }
.topic-head h2 { margin: 0; }
.topic-head p { margin: .35rem 0 0; }

/* Settings */
.list-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-top: 1px solid var(--border); }
.list-row:first-of-type { border-top: 0; }
.list-row .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list-row.off .name { color: var(--muted); text-decoration: line-through; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .65rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: .9rem; }
.chip button { background: none; color: var(--muted); padding: 0 .1rem; font-weight: 400; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; }
.stat { background: var(--bg); border-radius: 10px; padding: .6rem .75rem; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }

/* Admin */
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: .35rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
table.kv td:last-child { text-align: right; white-space: nowrap; padding-left: 1rem; }
table.kv.cols td + td { text-align: right; padding-left: .75rem; white-space: nowrap; }
h4 { margin: 1rem 0 .4rem; font-size: .9rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--neg-soft); color: var(--neg); }
.warn { color: var(--amber); font-weight: 600; }
.person-row { padding: .75rem 0; border-top: 1px solid var(--border); }
.person-row:first-of-type { border-top: 0; }
.person-row > * + * { margin-top: .25rem; }
.person-row.off { opacity: .6; }
.person-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .4rem; }
.limit-form { display: inline-flex; gap: .35rem; align-items: center; }
.limit-form input { width: 5.5rem; padding: .3rem .45rem; }

/* Setup wizard */
.progress { display: flex; gap: .3rem; margin-bottom: 1rem; }
.progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.progress span.done { background: var(--accent); }
.area + .area { margin-top: 1rem; }
.area h4 { margin: 0 0 .4rem; font-size: .9rem; color: var(--muted); }
.pick { display: flex; flex-wrap: wrap; gap: .4rem; }
.pick label { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-size: .92rem; }
.pick label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pick input { margin: 0; }
.found { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem 0; border-top: 1px solid var(--border); }
.found:first-child { border-top: 0; }
.found .bad { color: var(--neg); font-size: .85rem; }
.wizard-nav { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: 1rem; }
.spinner { width: 2.5rem; height: 2.5rem; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 1.5rem auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 20; max-width: calc(100% - 2rem); }

@media (max-width: 420px) {
  .item .thumb { width: 64px; height: 64px; }
  .story-link { max-width: 52%; }
}
