/* ============================================================
   READER — design tokens
   ============================================================ */
[hidden] {
  display: none !important;
}

:root {
  /* -- paper / light -- */
  --bg: #F7F5F0;
  --bg-raised: #FFFFFF;
  --bg-sunken: #EFEBE2;
  --ink: #1B1A17;
  --ink-soft: #555047;
  --ink-faint: #757065;
  --line: #E2DDCF;
  --line-strong: #CFC8B4;

  --brass: #8A6D4E;
  --brass-soft: #E7DCC7;
  --pine: #3C6E5C;
  --pine-soft: #DCE8E2;
  --rust: #C7401F;
  --rust-soft: #F6DFD6;

  --focus: #2F6FED;

  --font-display: 'Source Serif 4', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-1: 0 1px 2px rgba(27,26,23,0.06), 0 1px 1px rgba(27,26,23,0.04);
  --shadow-2: 0 4px 16px rgba(27,26,23,0.10), 0 2px 4px rgba(27,26,23,0.06);
  --shadow-3: 0 12px 40px rgba(27,26,23,0.18);

  --pane-feeds-w: 260px;
  --pane-list-w: 380px;

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #15140F;
  --bg-raised: #1D1C16;
  --bg-sunken: #0F0E0A;
  --ink: #EFEBDF;
  --ink-soft: #B5AF9E;
  --ink-faint: #756F5F;
  --line: #322F26;
  --line-strong: #423E31;

  --brass: #D2AE7F;
  --brass-soft: #382D1E;
  --pine: #7FB39E;
  --pine-soft: #1C2C26;
  --rust: #E2694A;
  --rust-soft: #3A2019;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-3: 0 12px 40px rgba(0,0,0,0.55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #15140F; --bg-raised:#1D1C16; --bg-sunken:#0F0E0A; --ink:#EFEBDF; --ink-soft:#B5AF9E; --ink-faint:#8A8471; --line:#322F26; --line-strong:#474235; --brass:#D2AE7F;
    --brass-soft: #382D1E;
    --pine: #7FB39E;
    --pine-soft: #1C2C26;
    --rust: #E2694A;
    --rust-soft: #3A2019;
    color-scheme: dark;
  }
}

html[data-theme="sepia"] {
  --bg: #F1E7D2;
  --bg-raised: #E6DCBE;
  --bg-sunken: #E0D5AF;
  --ink: #3A2E1F;
  --ink-soft: #564834;
  --ink-faint: #75654C;
  --line: #DFCFA9;
  --line-strong: #D1C097;
  --brass: #B57F3A;
  color-scheme: light;
}
html[data-theme="light"] {
  --bg: #FFFFFF; --bg-raised:#FFFFFF; --bg-sunken:#F7F5F0; --ink:#1B1A17; --ink-soft:#554D41; --ink-faint:#70685A; --line:#E7E3D8; --line-strong:#D4CEC1; --brass:#C86C14;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #15140F; --bg-raised:#1D1C16; --bg-sunken:#0F0E0A; --ink:#EFEBDF; --ink-soft:#B5AF9E; --ink-faint:#8A8471; --line:#322F26; --line-strong:#474235; --brass:#D2AE7F;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-sunken);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

button { font-family: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   APP SHELL — three pane grid
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--pane-feeds-w) var(--pane-list-w) 1fr;
  height: 100dvh;
  background: var(--bg-sunken);
  gap: 1px;
}

.pane {
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.only-mobile { display: none; }

/* ---------- Feeds pane ---------- */
.pane-feeds {
  background: var(--bg-sunken);
}
.feeds-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 10px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
}
.brand-mark { color: var(--brass); flex-shrink: 0; }

.feeds-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
}
.folder-list { list-style: none; margin: 0 0 4px; padding: 0; }
.folder-divider {
  height: 1px;
  background: var(--line);
  margin: 10px 4px 10px;
}

.feed-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--ink-soft);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.feed-row:hover { background: var(--bg-raised); color: var(--ink); }
.feed-row.is-active {
  background: var(--brass-soft);
  color: var(--ink);
  font-weight: 600;
}
.feed-row-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
}
.feed-row--all .feed-row-dot { background: var(--brass); }
.feed-row-dot--star { background: var(--rust); }
.feed-favicon {
  width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; object-fit: cover;
  background: var(--bg-raised);
}
.feed-row-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-row-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  min-width: 1.5em;
  text-align: right;
}
.feed-row.is-active .feed-row-count { color: var(--brass); }

.folder-group { margin-bottom: 2px; }
.folder-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 4px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.folder-header svg { transition: transform 150ms ease; flex-shrink: 0; }
.folder-group.is-collapsed .folder-header svg { transform: rotate(-90deg); }
.folder-group.is-collapsed .folder-feeds { display: none; }

.feeds-footer {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-faint);
  padding: 0 2px;
}
.sync-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--pine);
  flex-shrink: 0;
}
.sync-dot.is-syncing { background: var(--brass); animation: pulse 1s ease-in-out infinite; }
.sync-dot.is-error { background: var(--rust); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- List pane ---------- */
.pane-list { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.list-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 14px 10px;
  flex-shrink: 0;
}
.list-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--ink); }
.icon-btn[aria-pressed="true"], .icon-btn.is-active { color: var(--rust); }

.search-bar { padding: 0 14px 10px; }
.search-bar input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  color: var(--ink);
  font-size: 13.5px;
}

.list-filterbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}
.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
}
.chip.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip-sort {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: default;
  background: transparent;
}
.chip-sort select {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12.5px;
  cursor: pointer;
}

.article-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 12px;
}

/* Article item — the "paper stack" signature */
.article-item {
  --stack-depth: 0px;
  position: relative;
  width: 100%;
  display: flex;
  gap: 10px;
  padding: 11px 10px;
  margin: 0 0 3px;
  border: none;
  background: var(--bg-raised);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transform: translateY(0);
  transition: box-shadow 150ms ease, transform 150ms ease, opacity 200ms ease;
}
.article-item.is-unread {
  box-shadow: 0 1px 0 var(--bg-raised), 0 3px 0 -1px var(--bg-sunken), 0 3px 3px -1px rgba(27,26,23,0.10);
}
.article-item.is-unread::before {
  content: "";
  position: absolute;
  left: -3px; top: 2px; bottom: 2px;
  width: 3px;
  border-radius: 3px;
  background: var(--brass);
}
.article-item.is-read { opacity: 0.62; }
.article-item.is-read .article-item-title { font-weight: 500; }
.article-item:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); }
.article-item.is-selected {
  box-shadow: 0 0 0 2px var(--brass) inset, var(--shadow-2);
}

.article-item-thumb {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-sunken);
}
.article-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.article-item-feedline {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-faint);
  min-width: 0;
}
.article-item-feedline .fav { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.article-item-feedline span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-item-title {
  font-family: var(--font-display);
  font-size: 14.5px;
  line-height: 1.32;
  font-weight: 600;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-item-snippet {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-item-star {
  position: absolute;
  top: 8px; right: 8px;
  color: var(--rust);
  opacity: 0;
}
.article-item.is-starred .article-item-star { opacity: 1; }

/* compact view */
.article-list.is-compact .article-item { padding: 8px 10px; }
.article-list.is-compact .article-item-thumb { width: 40px; height: 40px; }
.article-list.is-compact .article-item-snippet { display: none; }
.article-list.is-compact .article-item-title { -webkit-line-clamp: 1; font-size: 13.5px; }

/* ---------- Reader pane ---------- */
.pane-reader { position: relative; background: var(--bg); }
.reader-empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  color: var(--ink-faint);
  font-size: 14px;
}
.reader-article { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.reader-toolbar-spacer { flex: 1; }

.font-panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-sunken);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}
.font-panel-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--ink-soft); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.seg-btn {
  border: none; background: transparent; color: var(--ink-soft);
  padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.seg-btn.is-active { background: var(--ink); color: var(--bg); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--bg-raised); color: var(--ink);
  cursor: pointer; font-size: 12px;
}
.stepper span { font-family: var(--font-mono); font-size: 12px; min-width: 1.5em; text-align: center; }

.reader-meta {
  padding: 28px 16px 0;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}
.reader-feedline {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--ink-faint);
  margin-bottom: 12px;
}
.reader-favicon { border-radius: 3px; }
.reader-dot { opacity: 0.6; }
.reader-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.22;
  margin: 0 0 8px;
  color: var(--ink);
}
.reader-byline { font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }

.reader-content-scroll {
  flex: 1;
  overflow-y: auto;
}
.reader-body {
  padding: 20px 16px 60px;
}
.reader-body-inner,
.reader-body {
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  font-size: var(--reader-font-size, 17px);
  line-height: 1.7;
  color: var(--ink);
}
.reader-body.font-serif { font-family: var(--font-display); }
.reader-body.font-sans { font-family: var(--font-sans); }
.reader-body p { margin: 0 0 1.2em; }
.reader-body img, .reader-body video, .reader-body iframe {
  max-width: 100%; height: auto; border-radius: var(--radius-md); margin: 1.2em 0;
}
.reader-body a { color: var(--brass); text-decoration-thickness: 1px; }
.reader-body h1, .reader-body h2, .reader-body h3 {
  font-family: var(--font-display); line-height: 1.3; margin: 1.6em 0 0.6em;
}
.reader-body blockquote {
  margin: 1.2em 0; padding: 4px 0 4px 16px;
  border-left: 3px solid var(--brass);
  color: var(--ink-soft); font-style: italic;
}
.reader-body pre {
  background: var(--bg-sunken); padding: 14px; border-radius: var(--radius-md);
  overflow-x: auto; font-family: var(--font-mono); font-size: 0.85em;
}
.reader-body code { font-family: var(--font-mono); font-size: 0.9em; background: var(--bg-sunken); padding: 0.15em 0.4em; border-radius: 4px; }
.reader-body ul, .reader-body ol { padding-left: 1.4em; margin: 0 0 1.2em; }
.reader-body figure { margin: 1.2em 0; }
.reader-body figcaption { font-size: 0.8em; color: var(--ink-faint); text-align: center; margin-top: 6px; }

.reader-endcap {
  max-width: 680px; margin: 0 auto; width: 100%;
  padding: 0 16px 40px;
}

/* ============================================================
   Buttons, forms, chips, toast
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 120ms ease, background-color 120ms ease;
}
.btn-primary { background: var(--ink); color: var(--bg); }
html[data-theme="dark"] .btn-primary,
html[data-theme="auto"] .btn-primary { }
.btn-primary:hover { filter: brightness(1.15); }
.btn-secondary { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--bg-sunken); }
.btn-danger { background: transparent; border-color: var(--rust); color: var(--rust); }
.btn-danger:hover { background: var(--rust-soft); }
.btn-block { width: 100%; }
.btn-spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--ink-soft); }
.field input, .text-input {
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  width: 100%;
}
.folder-input-row { display: flex; gap: 8px; }
.folder-input-row select { flex: 1; padding: 9px; border-radius: var(--radius-md); border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); }
.folder-input-row input { flex: 1; }
.field-error { color: var(--rust); font-size: 13px; margin: -6px 0 12px; }

.switch { display: inline-block; cursor: pointer; }
.switch input { display: none; }
.switch-track {
  display: inline-flex; align-items: center;
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--line-strong); padding: 2px; transition: background-color 150ms ease;
}
.switch-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--bg-raised); box-shadow: var(--shadow-1); transition: transform 150ms ease; }
.switch input:checked + .switch-track { background: var(--pine); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  box-shadow: var(--shadow-3);
  z-index: 500;
  animation: toast-in 200ms ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--ink-faint); padding: 40px; text-align: center;
}
.empty-state p:first-of-type { font-size: 14px; font-weight: 600; color: var(--ink-soft); margin: 4px 0 0; }
.empty-sub { font-size: 13px; margin: 0; }

/* ============================================================
   Modals
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,18,14,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 400; padding: 20px;
  animation: fade-in 150ms ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--bg-raised);
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-3);
  max-height: 86vh;
  overflow-y: auto;
  animation: modal-in 180ms cubic-bezier(.2,.8,.3,1);
}
.modal-lg { max-width: 560px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal h2 { font-family: var(--font-display); margin: 0 0 6px; font-size: 20px; }
.modal-sub { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-actions--left { justify-content: flex-start; }

.settings-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.settings-tab {
  border: none; background: transparent; padding: 8px 4px; margin-right: 14px;
  color: var(--ink-faint); font-size: 13.5px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.settings-tab.is-active { color: var(--ink); border-color: var(--brass); }
.settings-panel { min-height: 160px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.settings-row-title { font-size: 13.5px; font-weight: 600; }
.settings-row-sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.settings-row select { padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); }

.manage-feed-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.manage-feed-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-md); background: var(--bg-sunken); }
.manage-feed-row img { width: 18px; height: 18px; border-radius: 3px; }
.manage-feed-row .mf-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.manage-feed-row .mf-meta { font-size: 11px; color: var(--ink-faint); }
.manage-feed-row button { background: none; border: none; color: var(--ink-faint); cursor: pointer; padding: 4px; }
.manage-feed-row button:hover { color: var(--rust); }

/* ============================================================
   RESPONSIVE — collapse to single-pane below 900px
   ============================================================ */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 100%;
    grid-template-rows: 100%;
  }
  .pane { display: none; }
  .app[data-mobile-view="feeds"] .pane-feeds { display: flex; }
  .app[data-mobile-view="list"] .pane-list { display: flex; }
  .app[data-mobile-view="reader"] .pane-reader { display: flex; }
  .pane-feeds, .pane-list, .pane-reader { border: none; }
  .only-mobile { display: inline-flex; }
  .reader-title { font-size: 24px; }
  :root { --pane-feeds-w: 100%; --pane-list-w: 100%; }
}

@media (min-width: 901px) {
  .app { grid-template-columns: var(--pane-feeds-w) var(--pane-list-w) 1fr; }
}
