:root {
  --bg: #fff;
  --side: #f5f5f5;
  --text: #222;
  --muted: #777;
  --faint: #999;
  --line: #e5e5e5;
  --row-hover: #f6f8fc;
  --row-read: #f7f7f7;
  --sel: #4d90fe;
  --sel-bg: #eef3fe;
  --red: #d14836;
  --red-dark: #b0281a;
  --link: #15c;
  --btn: #f5f5f5;
  --btn-line: #d0d0d0;
  --star: #e8b100;
  --entry: #fff;
  --shadow: 0 4px 16px rgba(0, 0, 0, .18);
  --top-h: 56px;
  --side-w: 260px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1c1e; --side: #232427; --text: #e4e4e4; --muted: #a0a0a0; --faint: #7a7a7a; --line: #34363a;
    --row-hover: #26282c; --row-read: #1f2023; --sel: #6aa2ff; --sel-bg: #22304a; --red: #e0533f; --red-dark: #f06a56;
    --link: #8ab4f8; --btn: #2a2c30; --btn-line: #44464b; --entry: #1f2023; --shadow: 0 4px 20px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1c1e; --side: #232427; --text: #e4e4e4; --muted: #a0a0a0; --faint: #7a7a7a; --line: #34363a;
  --row-hover: #26282c; --row-read: #1f2023; --sel: #6aa2ff; --sel-bg: #22304a; --red: #e0533f; --red-dark: #f06a56;
  --link: #8ab4f8; --btn: #2a2c30; --btn-line: #44464b; --entry: #1f2023; --shadow: 0 4px 20px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--link); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
input[type=text], input[type=password], input[type=search] {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--btn-line); border-radius: 2px; padding: 7px 9px; width: 100%;
}
input:focus { outline: none; border-color: var(--sel); box-shadow: 0 0 0 1px var(--sel) inset; }

.btn {
  display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 12px;
  background: var(--btn); border: 1px solid var(--btn-line); border-radius: 2px;
  font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn.red { background: var(--red); border-color: var(--red-dark); color: #fff; }
.btn.red:hover { background: var(--red-dark); }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--row-hover); color: var(--text); }
.err { color: var(--red); min-height: 0; margin: 6px 0; font-size: 13px; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; font-weight: normal; }

/* Sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login-box { background: var(--bg); padding: 32px; width: 100%; max-width: 340px; border: 1px solid var(--line); box-shadow: var(--shadow); display: grid; gap: 8px; }
.login-box img { justify-self: center; }
.login-box h1 { margin: 0 0 12px; text-align: center; font-size: 24px; font-weight: 400; }
.login-box label { font-weight: 600; font-size: 13px; }
.login-box .btn { justify-content: center; height: 36px; margin-top: 8px; }

/* Layout */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; grid-template-rows: var(--top-h) 1fr; height: 100vh; height: 100dvh; }
.top {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; color: var(--text); text-decoration: none; width: calc(var(--side-w) - 28px); }
.brand img { flex: none; }
.search { flex: 1; max-width: 560px; }
.search input { height: 34px; }
#settings-btn { margin-left: auto; }
.menu-btn { display: none; }

.side { background: var(--bg); overflow-y: auto; padding: 12px 0 24px; border-right: 1px solid var(--line); }
.subscribe { margin: 4px 16px 14px; height: 32px; padding: 0 18px; text-transform: uppercase; letter-spacing: .03em; font-size: 12px; }
.nav-item, .sub, .folder-row {
  display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; height: 30px;
  color: var(--text); text-decoration: none; cursor: pointer; border-left: 3px solid transparent; user-select: none;
}
.nav-item:hover, .sub:hover, .folder-row:hover { background: var(--row-hover); }
.nav-item.active, .sub.active, .folder-row.active { background: var(--sel-bg); border-left-color: var(--sel); }
.nav-ico { width: 16px; text-align: center; color: var(--muted); flex: none; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; }
.has-unread > .name, .has-unread > .count { font-weight: 700; color: var(--text); }
.subs-head { margin: 16px 16px 4px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.folder > .feeds { display: block; }
.folder.closed > .feeds { display: none; }
.twisty { width: 16px; flex: none; text-align: center; color: var(--muted); font-size: 10px; transition: transform .12s; background: none; border: 0; padding: 0; cursor: pointer; height: 100%; }
.folder.closed .twisty { transform: rotate(-90deg); }
.folder .sub { padding-left: 40px; }
.fav { width: 16px; height: 16px; flex: none; border-radius: 2px; }
.feed-err { color: var(--red); font-size: 12px; }
.side-foot { margin: 16px; color: var(--faint); font-size: 12px; }
.scrim { display: none; }

.main { overflow-y: auto; min-width: 0; }
.toolbar { position: sticky; top: 0; z-index: 3; background: var(--bg); padding: 12px 20px 10px; border-bottom: 1px solid var(--line); }
.title-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.title-row h2 { margin: 0; font-size: 20px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.view-site { font-size: 13px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; }
.seg-btn { height: 30px; padding: 0 11px; background: var(--btn); border: 1px solid var(--btn-line); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 0; }
.seg-btn:first-child { border-radius: 2px 0 0 2px; }
.seg-btn:last-child { border-radius: 0 2px 2px 0; }
.seg-btn[aria-pressed="true"] { background: var(--sel-bg); color: var(--text); box-shadow: inset 0 1px 2px rgba(0,0,0,.12); }
.banner { padding: 8px 20px; background: #fff8d6; border-bottom: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a3420; } }
:root[data-theme="dark"] .banner { background: #3a3420; }

/* List view rows */
.items { padding-bottom: 40vh; }
.item { border-bottom: 1px solid var(--line); border-left: 3px solid transparent; }
.item.sel { border-left-color: var(--sel); }
.row { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 16px 0 9px; cursor: pointer; }
.row:hover { background: var(--row-hover); }
.item.read .row { background: var(--row-read); }
.item.read .row:hover { background: var(--row-hover); }
.star { background: none; border: 0; padding: 0; width: 22px; height: 22px; flex: none; cursor: pointer; font-size: 16px; line-height: 1; color: var(--faint); }
.star.on { color: var(--star); }
.star:hover { color: var(--star); }
.src { flex: 0 0 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.line { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .t { font-weight: 700; }
.line .s { color: var(--muted); }
.item.read .src, .item.read .line .t { font-weight: 400; color: var(--muted); }
.date { flex: none; color: var(--muted); font-size: 12px; min-width: 56px; text-align: right; }
.item:not(.read) .date { color: var(--text); }

/* Opened entry */
.entry { padding: 16px 24px 12px 46px; background: var(--entry); border-top: 1px solid var(--line); }
.entry h3 { margin: 0 0 4px; font-size: 20px; line-height: 1.3; font-weight: 600; }
.entry h3 a { color: var(--text); text-decoration: none; }
.entry h3 a:hover { color: var(--link); text-decoration: underline; }
.meta { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.meta a { color: var(--muted); }
.body { font-size: 15px; line-height: 1.6; max-width: 720px; overflow-wrap: anywhere; }
.body img, .body video, .body iframe { max-width: 100%; height: auto; }
.body iframe { aspect-ratio: 16 / 9; width: 100%; border: 0; }
.body pre { overflow-x: auto; background: var(--side); padding: 10px; font-size: 13px; }
.body blockquote { margin: 1em 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.body table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.body td, .body th { border: 1px solid var(--line); padding: 4px 8px; }
.body figure { margin: 1em 0; }
.body figcaption { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 18px; align-items: center; margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.actions button, .actions a { background: none; border: 0; padding: 4px 0; cursor: pointer; color: var(--muted); text-decoration: none; font-size: 13px; }
.actions button:hover, .actions a:hover { color: var(--text); text-decoration: underline; }
.actions .on { color: var(--star); }
.actions .orig { color: var(--link); font-weight: 600; }

/* Expanded view: every item is an opened entry */
.expanded .item { border-bottom: 0; border-left: 0; padding: 8px 20px; }
.expanded .entry { border: 1px solid var(--line); border-left: 3px solid var(--line); padding: 16px 22px 10px; }
.expanded .item.sel .entry { border-left-color: var(--sel); box-shadow: var(--shadow); }
.expanded .item.read .entry h3 a { color: var(--muted); }
.expanded .entry h3 { display: flex; gap: 8px; align-items: flex-start; }
.expanded .entry .star { margin-top: 3px; }

.loading { color: var(--muted); padding: 20px; }
.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .btn { margin-top: 12px; }

/* Dialogs */
.dlg { border: 1px solid var(--line); padding: 0; width: min(460px, calc(100vw - 32px)); background: var(--bg); color: var(--text); box-shadow: var(--shadow); border-radius: 2px; }
.dlg::backdrop { background: rgba(0, 0, 0, .35); }
.dlg > form, .dlg > div { padding: 20px 22px; display: grid; gap: 6px; }
.dlg h3 { margin: 0 0 10px; font-size: 18px; font-weight: 400; }
.dlg h4 { margin: 14px 0 6px; font-size: 13px; }
.dlg label { font-size: 13px; font-weight: 600; margin-top: 6px; }
.dlg section form { display: grid; gap: 6px; }
.dlg section form .btn { justify-self: start; margin-top: 4px; }
.dlg section form label { margin-top: 2px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; align-items: center; }
.spacer { flex: 1; }
.row { margin: 0; }
.dlg .row { display: flex; gap: 8px; flex-wrap: wrap; height: auto; padding: 0; cursor: default; }
.dlg .row:hover { background: none; }
.file-btn { margin: 0 !important; font-size: 13px !important; }
.feed-url { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 13px; }
.keys dt { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }
.keys dd { margin: 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #323232; color: #fff; padding: 10px 18px; border-radius: 2px; box-shadow: var(--shadow); z-index: 20; font-size: 13px; max-width: calc(100vw - 32px); }

/* Phones and narrow windows */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .menu-btn { display: inline-block; margin-left: -8px; }
  .top { padding: 0 8px 0 16px; gap: 6px; }
  .brand { width: auto; }
  .brand { font-size: 0; gap: 0; }
  .side {
    position: fixed; top: var(--top-h); bottom: 0; left: 0; width: min(300px, 85vw); z-index: 10;
    transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow);
  }
  .side-open .side { transform: none; }
  .side-open .scrim { display: block; position: fixed; inset: var(--top-h) 0 0 0; background: rgba(0,0,0,.3); z-index: 9; }
  .toolbar { padding: 10px 16px 8px; }
  .tools { gap: 6px; }
  #sort-btn { display: none; }
  .row { height: auto; min-height: 44px; padding: 8px 12px 8px 6px; align-items: flex-start; flex-wrap: wrap; gap: 2px 8px; }
  .row .star { order: 0; }
  .src { order: 1; flex: 1 1 auto; font-size: 12px; color: var(--muted); }
  .date { order: 2; min-width: 0; }
  .line { order: 3; flex: 1 1 100%; white-space: normal; padding-left: 30px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .line .s { display: none; }
  .entry { padding: 14px 16px 10px; }
  .expanded .item { padding: 6px 8px; }
  .expanded .entry { padding: 14px 14px 8px; }
}
