:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1c1a17;
  --muted: #6b665e;
  --faint: #a29c92;
  --border: #e4dfd5;
  --accent: #c2410c;
  --accent-soft: #fdebe1;
  --up: #15803d;
  --up-soft: #dcfce7;
  --down: #b91c1c;
  --down-soft: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1d1b19;
    --surface-2: #262420;
    --text: #ece8e1;
    --muted: #a39d93;
    --faint: #6f6a62;
    --border: #2f2c28;
    --accent: #fb7a3c;
    --accent-soft: #3a2316;
    --up: #4ade80;
    --up-soft: #12301d;
    --down: #f87171;
    --down-soft: #3a1717;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; height: 58px;
}
.brand {
  font: 700 21px/1 var(--serif); letter-spacing: -0.02em; text-decoration: none;
  display: flex; align-items: center; gap: 8px;
}
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font: 700 14px/1 var(--sans);
}
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 8px;
  white-space: nowrap; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.linklike { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.linklike:hover { color: var(--text); }

/* ---------- layout ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 32px; }
.page.single { grid-template-columns: minmax(0, 720px); justify-content: center; }
@media (max-width: 880px) { .page { grid-template-columns: 1fr; } .sidebar { order: -1; } }

h1.view-title { font: 600 28px/1.2 var(--serif); letter-spacing: -0.01em; margin: 0 0 4px; }
.view-sub { color: var(--muted); margin: 0 0 20px; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; align-items: center; }
.search {
  flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
}
.select {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
}
.active-filter {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500; font-size: 14px;
}
.active-filter button { border: 0; background: none; color: inherit; font-size: 16px; line-height: 1; padding: 0 4px; }

/* ---------- story cards ---------- */
.feed { display: flex; flex-direction: column; gap: 12px; }
.story {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px 16px 10px; box-shadow: var(--shadow);
  transition: opacity 0.25s, transform 0.25s;
}
.story.leaving { opacity: 0; transform: translateX(16px); }
.story.voted-down { opacity: 0.55; }
.votes { display: flex; flex-direction: column; align-items: center; gap: 2px; padding-top: 2px; }
.vote {
  width: 34px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: none;
  color: var(--faint); display: grid; place-items: center; transition: background 0.15s, color 0.15s;
}
.vote svg { width: 18px; height: 18px; }
.vote:hover { background: var(--surface-2); color: var(--text); }
.vote.up[aria-pressed="true"] { color: var(--up); background: var(--up-soft); }
.vote.down[aria-pressed="true"] { color: var(--down); background: var(--down-soft); }
.crowd { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 18px; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.meta .pub { font-weight: 600; color: var(--text); }
.cat { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.reason {
  font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.imp { color: var(--accent); font-weight: 600; font-size: 12px; }
.title { font: 600 19px/1.3 var(--serif); margin: 0 0 6px; letter-spacing: -0.005em; }
.title a { text-decoration: none; }
.title a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.title a.visited { color: var(--muted); }
.summary { margin: 0 0 10px; color: color-mix(in srgb, var(--text) 86%, var(--muted)); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag {
  border: 1px solid var(--border); background: none; border-radius: 999px; padding: 2px 10px;
  font-size: 13px; color: var(--muted);
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.also { font-size: 13px; color: var(--muted); margin-left: auto; }
.read-link { font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 500; }
.read-link:hover { text-decoration: underline; }

.more { display: block; margin: 18px auto 0; }
.empty {
  text-align: center; padding: 56px 24px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted);
}
.empty h2 { font: 600 20px/1.3 var(--serif); color: var(--text); margin: 0 0 6px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 8px 14px; border-radius: 9px; font-weight: 500;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--down); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.panel p { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.meter > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s; }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.mini-list li { display: flex; justify-content: space-between; gap: 8px; }
.mini-list .w { font-variant-numeric: tabular-nums; color: var(--muted); }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--up); }
.dot.bad { background: var(--down); }
.dot.busy { background: #d97706; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- interests ---------- */
.section { margin-bottom: 30px; }
.section h2 { font: 600 19px/1.3 var(--serif); margin: 0 0 12px; }
.weights { display: flex; flex-direction: column; gap: 4px; }
.weight-row {
  display: grid; grid-template-columns: 170px 1fr 54px auto; gap: 12px; align-items: center;
  padding: 6px 10px; border-radius: 8px;
}
.weight-row:hover { background: var(--surface); }
.weight-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weight-row .kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin-right: 6px; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; border-radius: 999px; }
.bar.pos > div { background: var(--up); }
.bar.neg > div { background: var(--down); }
.weight-row .w { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; text-align: right; }
.row-actions { display: flex; gap: 4px; }
.chip-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 14px;
}
.chip[aria-pressed="true"].follow { background: var(--up-soft); color: var(--up); border-color: transparent; }
.chip[aria-pressed="true"].mute { background: var(--down-soft); color: var(--down); border-color: transparent; text-decoration: line-through; }
.chip .n { color: var(--faint); font-size: 12px; margin-left: 4px; }
.hint { color: var(--muted); font-size: 14px; margin: -6px 0 12px; }

/* ---------- inbox ---------- */
table.emails { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
table.emails th, table.emails td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.emails th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
table.emails tr:last-child td { border-bottom: 0; }
.subject { font-weight: 500; }
.from { color: var(--muted); font-size: 13px; }
.err { color: var(--down); font-size: 12.5px; margin-top: 2px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.processed { background: var(--up-soft); color: var(--up); }
.badge.failed { background: var(--down-soft); color: var(--down); }
.badge.processing { background: var(--accent-soft); color: var(--accent); }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font: 600 24px/1.2 var(--serif); }
.stat .l { color: var(--muted); font-size: 13px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px; box-shadow: var(--shadow);
}
.auth .brand { font-size: 26px; margin-bottom: 6px; }
.auth p.lede { color: var(--muted); margin: 0 0 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; font-weight: 500; }
.field input { padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); font-weight: 400; }
.auth .btn.primary { width: 100%; padding: 10px; margin-top: 6px; }
.auth .switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.form-error { color: var(--down); font-size: 14px; min-height: 20px; margin: 0 0 4px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); z-index: 50;
}
#toast button { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; }

.skeleton { height: 128px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 600px) {
  .topbar-inner { gap: 12px; padding: 0 12px; }
  .brand-text { display: none; }
  .user .who { display: none; }
  .weight-row { grid-template-columns: 1fr 80px 44px; }
  .weight-row .row-actions { display: none; }
  .story { padding-right: 14px; }
}

/* ---------- inbox filters + rows ---------- */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); margin-bottom: 14px; flex-wrap: wrap; }
.seg-btn { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); font-weight: 500; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.subject-btn { border: 0; background: none; padding: 0; text-align: left; font-weight: 500; color: var(--text); }
.subject-btn:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.row-btns { white-space: nowrap; text-align: right; }
.row-btns .btn + .btn { margin-left: 6px; }

/* ---------- email viewer ---------- */
dialog.viewer {
  width: min(920px, calc(100vw - 32px)); height: calc(100vh - 48px); max-height: none; max-width: none;
  padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.35); overflow: hidden;
}
dialog.viewer[open] { display: flex; flex-direction: column; }
dialog.viewer::backdrop { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(2px); }
.viewer-close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1;
}
.viewer-close:hover { background: var(--surface-2); color: var(--text); }
.viewer-head { padding: 18px 56px 14px 22px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.viewer-skel { height: 64px; }
.viewer-subject { font: 600 20px/1.3 var(--serif); margin: 0; }
.viewer-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13.5px; color: var(--muted); }
.confirm-box { border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; }
.confirm-title { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 8px; }
.confirm-links { display: flex; flex-wrap: wrap; gap: 8px; }
.confirm-links .btn { text-decoration: none; display: inline-flex; align-items: baseline; gap: 8px; }
.confirm-host { font-size: 11.5px; opacity: 0.8; font-weight: 400; }
.viewer-stories { font-size: 13.5px; color: var(--muted); }
.viewer-stories span { color: var(--text); }
.viewer-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.viewer-tools a.btn { text-decoration: none; }
.viewer-tools .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.viewer-note { font-size: 12.5px; color: var(--faint); }
.viewer-frame { flex: 1; width: 100%; border: 0; background: #fff; }

/* ---------- inbox selection + delete ---------- */
.list-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.list-bar .seg { margin-bottom: 0; }
.bulk-bar { display: flex; align-items: center; gap: 12px; padding: 4px 6px 4px 12px; border-radius: 10px; background: var(--accent-soft); }
.bulk-count { font-size: 14px; font-weight: 600; color: var(--accent); }
table.emails th.check, table.emails td.check { width: 36px; padding-right: 0; }
table.emails input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 2px 0 0; }
table.emails tr.selected td { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.btn.icon { padding: 4px 7px; display: inline-grid; place-items: center; vertical-align: top; }
.btn.icon svg { width: 15px; height: 15px; }
.btn.danger:hover:not(:disabled) { border-color: var(--down); background: var(--down-soft); }
.viewer-delete { margin-left: auto; }
