:root {
  --bg: #fbfaf7;
  --fg: #1c1b19;
  --muted: #6b6862;
  --line: #e4e1da;
  --accent: #9a3b1c;
  --fs: 19px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", Charter, "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --fg: #e6e3dc; --muted: #9a968d; --line: #2c2b28; --accent: #e08a5f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --fg: #e6e3dc; --muted: #9a968d; --line: #2c2b28; --accent: #e08a5f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 var(--ui); }
[hidden] { display: none !important; }
a { color: var(--accent); }

button, input, select {
  font: inherit; color: inherit; background: transparent;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.45rem 0.7rem;
}
button { cursor: pointer; white-space: nowrap; }
button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
button:disabled { opacity: 0.5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

section, dialog { max-width: 42rem; margin: 0 auto; }

/* Top bar (list and reader) */
.bar {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 0.4rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 1.15rem; margin: 0; flex: 1; }
.bar .spacer { flex: 1; }
.bar button, .bar a { font-size: 0.875rem; }
#back { text-decoration: none; padding: 0.45rem 0.2rem; }

/* Login */
#login { padding: 18vh 1.25rem 2rem; max-width: 24rem; }
#login form { display: grid; gap: 0.5rem; margin-bottom: 1.25rem; }
#login label, dialog label { font-size: 0.875rem; color: var(--muted); }
#login-msg, #feed-msg, #password-msg { color: var(--muted); font-size: 0.9rem; min-height: 1.3em; }
#login #password { margin-bottom: 0.5rem; }

/* List */
.tabs { display: flex; gap: 0.4rem; padding: 0.75rem 1rem 0.25rem; }
.tabs button { border-radius: 999px; color: var(--muted); }
.tabs button[aria-pressed="true"] { color: var(--bg); background: var(--fg); border-color: var(--fg); }
#status { margin: 0.5rem 1rem; color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
#items { list-style: none; margin: 0; padding: 0 0 env(safe-area-inset-bottom); }
#items li { border-bottom: 1px solid var(--line); }
#items .empty { padding: 3rem 1rem; text-align: center; color: var(--muted); border: 0; }
.item { display: block; padding: 0.9rem 1rem; color: inherit; text-decoration: none; }
.item h2 { font: 600 1.08rem/1.3 var(--serif); margin: 0 0 0.25rem; overflow-wrap: anywhere; }
.item .meta { font-size: 0.8rem; color: var(--muted); margin: 0 0 0.3rem; }
.item .summary {
  font-size: 0.9rem; color: var(--muted); margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item .pct { color: var(--accent); }

/* Reader */
#progress-bar { position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; }
#progress-bar div { height: 100%; width: 0; background: var(--accent); }
#article {
  max-width: 36rem; margin: 0 auto;
  padding: 1.5rem 1.25rem calc(5rem + env(safe-area-inset-bottom));
  font: var(--fs)/1.65 var(--serif); overflow-wrap: break-word;
}
#article h1 { font-size: 1.6em; line-height: 1.2; margin: 0 0 0.5rem; }
#article .byline { font: 0.875rem var(--ui); color: var(--muted); margin: 0 0 2rem; }
#article .note { font: 1rem var(--ui); color: var(--muted); }
#article h2, #article h3, #article h4 { line-height: 1.25; margin: 1.8em 0 0.5em; }
#article h2 { font-size: 1.3em; }
#article h3 { font-size: 1.12em; }
#article p { margin: 0 0 1.1em; }
#article img, #article video, #article svg { max-width: 100%; height: auto; }
#article figure { margin: 1.5em 0; }
#article figcaption { font: 0.8rem var(--ui); color: var(--muted); }
#article blockquote { margin: 1.3em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--muted); }
#article pre { overflow-x: auto; font-size: 0.8em; }
#article table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 0.85em; }
#article td, #article th { border: 1px solid var(--line); padding: 0.3em 0.5em; }
#article hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
#article sup { line-height: 0; }

/* Settings */
dialog { width: calc(100% - 2rem); border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--fg); padding: 1.25rem; }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin: 0 0 1rem; font-size: 1.15rem; }
dialog h3 { margin: 1.25rem 0 0.5rem; font-size: 0.95rem; }
dialog select { display: block; margin-top: 0.3rem; }
#feeds { list-style: none; margin: 0 0 0.75rem; padding: 0; }
#feeds li { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0; font-size: 0.9rem; }
#feeds span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#feeds small { display: block; color: var(--muted); }
#feed-form, #password-form { display: flex; gap: 0.4rem; }
#feed-form input, #password-form input { flex: 1; min-width: 0; }
.dialog-actions { display: flex; justify-content: space-between; margin-top: 1rem; }
