:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e242c;
  --line: #2a323d;
  --text: #e6eaef;
  --muted: #98a2b3;
  --accent: #4c9aff;
  --low: #3f8f5f;
  --elevated: #c9a227;
  --high: #e0803a;
  --severe: #d64545;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-2: #eef2f7;
    --line: #d8e0ea;
    --text: #16202c;
    --muted: #5c6b7f;
  }
}

* { box-sizing: border-box; }

/* A class rule with `display` beats the browser's [hidden] default, and the
   PWA bars below are toggled by that attribute alone. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.brand a { color: var(--text); }
.brand .version {
  font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 6px;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px;
  vertical-align: 2px;
}
.brand .region { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 8px; }
.topbar .stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.topbar .stats .danger { color: var(--high); }
.topbar nav { margin-left: auto; display: flex; gap: 14px; align-items: center; }

main { max-width: 1040px; margin: 0 auto; padding: 20px; }

button, .filters select, .filters input[type="search"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; font: inherit;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
form.inline { display: inline; }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 14px;
}
.filters input[type="search"] { flex: 1 1 220px; }
.filters .check { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.filters .reset { font-size: 13px; color: var(--muted); }

/* The panel is permanently open on wide screens; only the narrow layout below
   collapses it behind this toggle. */
.filter-toggle { display: none; }

.resultline { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.feed { display: flex; flex-direction: column; gap: 10px; }

/* Grid rather than flex: the thumbnail has to occupy a right-hand column on
   desktop and reflow between headline and teaser text on narrow screens, and
   those two positions are not siblings in a single flex row. Empty areas
   collapse to zero height, so a card without a summary still lines up. */
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "head    thumb"
    "title   thumb"
    "summary thumb"
    "foot    thumb";
  align-content: start;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--low); border-radius: var(--radius); padding: 12px 14px;
}
.card-head { grid-area: head; }
.card h2 { grid-area: title; }
.card .summary { grid-area: summary; }
.card-foot { grid-area: foot; }

.thumb {
  grid-area: thumb;
  /* stretch spans every row, so the image is as tall as the card's text. */
  align-self: stretch; position: relative;
  /* Margin instead of column-gap so a card without a thumbnail leaves no
     dangling gutter. */
  width: 148px; min-height: 96px; margin-left: 14px; display: block;
  border-radius: 8px; overflow: hidden; background: var(--panel-2);
}
/* Absolute rather than height:100%: the image must not contribute any height
   of its own, otherwise it would grow the card it is supposed to match. */
.thumb img {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%; object-fit: cover; border: 0;
}
.card.risk-elevated { border-left-color: var(--elevated); }
.card.risk-high { border-left-color: var(--high); }
.card.risk-severe { border-left-color: var(--severe); }
.card.is-read { opacity: .55; }

.card-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.card h2 { font-size: 17px; margin: 6px 0; line-height: 1.35; }
.card h2 a { color: var(--text); }
.summary { margin: 0 0 8px; color: var(--muted); font-size: 14px; }

.badge { border-radius: 999px; padding: 2px 8px; font-weight: 600; background: var(--panel-2); }
.risk-low .risk-badge { color: var(--low); }
.risk-elevated .risk-badge { color: var(--elevated); }
.risk-high .risk-badge { color: var(--high); }
.risk-severe .risk-badge { color: var(--severe); }

.card-foot { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.tag.geo { border-color: var(--accent); color: var(--accent); }
.tag.risk { border-color: var(--high); color: var(--high); }

/* --- Swipe gestures ----------------------------------------------------
   The wrapper stands still and holds the two labels; only the card moves, and
   because it carries an opaque background it hides whichever label is not
   being uncovered. Positioned siblings paint in document order, so the card
   needs no z-index to stay on top of them. */
/* Clipped: the card slides out of sight at the wrapper's edge instead of over
   the page margin, which would hand the document a horizontal scrollbar. */
.swipe { position: relative; overflow: hidden; border-radius: var(--radius); }
.swipe-label {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
}
/* Each label sits at the edge the card uncovers on its way: dragging left
   reveals the right-hand one. */
.swipe-label.read { right: 16px; color: var(--low); }
.swipe-label.later { left: 16px; color: var(--accent); }
/* Armed — letting go now would act. */
.swipe-label.is-armed { padding: 3px 9px; border-radius: 999px; background: var(--panel-2); }

/* pan-y leaves vertical scrolling to the browser and horizontal drags to us,
   so a swipe never fights the feed's own scrolling. */
.swipe .card { touch-action: pan-y; }
.card.is-dragging { user-select: none; cursor: grabbing; }
/* Only while springing back: during the drag the card follows the finger and
   must not lag behind it. */
.card.is-settling { transition: transform .18s ease-out; }

/* The gap the dismissed card leaves closes rather than jumping shut. */
.swipe.is-gone { overflow: hidden; opacity: 0; transition: height .22s ease, opacity .22s ease; }

/* Only worth saying where there is no pointer to use the buttons with. */
.swipehint { display: none; }
@media (hover: none) and (pointer: coarse) {
  .swipehint { display: block; color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .card.is-settling, .swipe.is-gone { transition: none; }
}

.actions { display: flex; gap: 6px; }
.actions .icon { padding: 3px 9px; color: var(--muted); }
.actions .icon.on { color: var(--accent); border-color: var(--accent); }

.pager { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }
.empty { color: var(--muted); padding: 30px; text-align: center; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.panel h1 { font-size: 18px; margin-top: 0; }
.panel h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hint { color: var(--muted); font-size: 13px; }
.kv { list-style: none; padding: 0; color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.row-error td { background: rgba(214, 69, 69, .08); }
.row-off { opacity: .55; }
.url { font-size: 12px; color: var(--muted); word-break: break-all; }
.err { color: var(--severe); font-size: 12px; margin-top: 4px; }

/* --- Editing the sources ------------------------------------------------ */

.err.banner {
  font-size: 14px; padding: 10px 12px; margin: 12px 0 0;
  border: 1px solid var(--severe); border-radius: 8px;
  background: rgba(214, 69, 69, .08);
}
.banner.notice {
  font-size: 14px; padding: 10px 12px; margin: 12px 0 0;
  border: 1px solid var(--low); border-radius: 8px;
  background: rgba(63, 143, 95, .1);
}

.sources .muted { color: var(--muted); font-size: 12px; }
.sources td.actions { white-space: nowrap; text-align: right; }
/* The editor sits in its own full-width row directly under its source, so the
   separator between the two belongs to the pair, not between them. */
.sources tr:has(+ .edit-row) td { border-bottom: 0; }
.sources .edit-row td { padding-top: 0; }
.sources summary {
  cursor: pointer; display: inline-block; color: var(--accent); font-size: 13px; margin-top: 6px;
}

.source-form {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
  margin-top: 10px; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel-2);
  white-space: normal;
}
.source-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.source-form input:not([type="checkbox"]) {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font: inherit;
  min-width: 130px;
}
/* The URL is the one field that regularly runs long. */
.source-form label.wide { flex: 1 1 320px; }
.source-form label.wide input { width: 100%; }
.source-form label.check { flex-direction: row; align-items: center; gap: 6px; }
.source-form .form-actions { display: flex; gap: 8px; margin-left: auto; }
.source-form .hint { flex-basis: 100%; margin: 0; }
button.danger { border-color: var(--severe); color: var(--severe); }

.region-editor { margin-top: 18px; }
.region-editor > summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.region-form textarea {
  width: 100%; resize: vertical;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Leading whitespace carries meaning in YAML — never soft-wrap it away. */
  white-space: pre; overflow-wrap: normal; overflow-x: auto; tab-size: 2;
}
.region-form .form-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 20px; }

/* --- Progressive web app ------------------------------------------------ */

/* Installed on iOS the app draws under the status bar and the home indicator,
   so both bars have to pad themselves out of the way. The insets are 0 in a
   normal browser tab, which leaves the layout untouched there. */
.topbar {
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}
footer { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

.topbar nav #install { font-size: 13px; padding: 5px 10px; border-color: var(--accent); color: var(--accent); }

.offline-bar {
  background: var(--panel-2); border-bottom: 1px solid var(--high);
  color: var(--high); font-size: 13px; text-align: center; padding: 7px 12px;
}

/* Fixed rather than in flow: the update offer must not push the article the
   reader is looking at out from under the cursor. */
.update-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

/* Both bars are fixed to the same spot; when the update offer is up, the
   toast moves above it instead of landing on top of it. */
.update-bar:not([hidden]) ~ .toast { bottom: calc(74px + env(safe-area-inset-bottom)); }

.offline-panel { max-width: 520px; margin: 12vh auto 0; text-align: center; }
.offline-panel h1 { margin-bottom: 8px; }

@media (max-width: 640px) {
  .topbar .stats { order: 3; width: 100%; }
  .topbar nav { margin-left: 0; }
  /* Single column: the image reads as a banner directly under the headline,
     ahead of the teaser text. */
  .card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "head" "title" "thumb" "summary" "foot";
  }
  /* Back to flow layout: as a banner the image sets its own height again. */
  .thumb { position: static; width: 100%; min-height: 0; margin: 4px 0 8px; }
  .thumb img { position: static; height: auto; aspect-ratio: 16 / 9; }

  /* Collapsed, the filters cost one line instead of half the screen — and the
     bar sticks below the topbar, so they stay one tap away however far the
     reader has scrolled into the feed. --topbar-h is measured in app.js
     because the topbar wraps to a different height on every screen width. */
  .filterbox {
    position: sticky; top: var(--topbar-h, 0px); z-index: 9;
    margin-bottom: 14px;
  }
  .filter-toggle {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    width: 100%; padding: 9px 12px; border-radius: var(--radius);
    background: var(--panel); font-weight: 600;
  }
  .filter-toggle .chevron { color: var(--muted); }
  .filterbox.is-open .filter-toggle .chevron { transform: rotate(180deg); }

  .filterbox .filters { display: none; margin-bottom: 0; }
  /* Opens over the feed rather than pushing it down, and scrolls internally so
     the submit button is reachable even on a short screen. */
  .filterbox.is-open .filters {
    display: flex; margin-top: 6px;
    max-height: calc(100vh - var(--topbar-h, 0px) - 90px); overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  }
}

/* --- Accounts ------------------------------------------------------------ */

.topbar nav .account {
  color: var(--muted); font-size: 13px; max-width: 14ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The signed-out pages have no topbar, so the card carries the whole layout. */
.auth-main { max-width: 420px; padding-top: 8vh; }
.auth-panel { padding: 24px; }
.auth-brand { font-size: 24px; margin: 0 0 4px; }
.auth-brand .version {
  font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 8px;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px;
  vertical-align: 4px;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-form input {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font: inherit;
}
.auth-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form > button { padding: 10px; font-weight: 600; }
/* Inside a panel that already has its own headings, the form is one block
   among several rather than the whole page. */
.inline-form { max-width: 360px; }

.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12px; margin: 18px 0 14px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

/* A link that has to look like the submit button beside it. */
.button {
  display: block; text-align: center; padding: 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; font-weight: 600;
}
.button:hover { border-color: var(--accent); text-decoration: none; }

.auth-alt { margin-top: 18px; text-align: center; }
