:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1a1f2c;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --unread: #2563eb;
  --read: #9ca3af;
  --danger: #dc2626;
  --hover-bg: #f3f4f6;
  --active-bg: #eef2ff;
  --btn-hover: #f3f4f6;
  --btn-fg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --list-width: 38%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --panel: #0a0a0a;
    --text: #a8b0bc;
    --muted: #5d6470;
    --border: #1d1d22;
    --accent: #6b85a8;
    --accent-hover: #829ab9;
    --unread: #829ab9;
    --read: #3a3f4a;
    --danger: #c97070;
    --hover-bg: #131316;
    --active-bg: #161821;
    --btn-hover: #131316;
    --btn-fg: #0a0a0a;
    --shadow: 0 1px 3px rgba(0,0,0,.6), 0 1px 2px rgba(0,0,0,.4);
  }
  button { background: var(--panel); color: var(--text); }
  button:hover { background: var(--btn-hover); }
  .item__btn.ghost-btn, .ghost-btn { background: transparent; }
  .feed-list__item.is-empty .dot { background: var(--read); }
  ::placeholder { color: var(--muted); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text);
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--btn-hover); }

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--btn-fg);
}
.primary-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.ghost-btn {
  background: transparent;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 6px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--btn-hover); color: var(--text); }

.hidden { display: none !important; }

.muted { color: var(--muted); font-size: 12px; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login__box {
  background: var(--panel);
  padding: 32px 28px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
.login__box h1 { margin: 0 0 4px; font-size: 22px; }
.login__box input {
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit;
}
.login__box button { padding: 10px 12px; }
.login__err { color: var(--danger); font-size: 13px; margin: 0; min-height: 1em; }

/* ---------- App layout ----------
   Default = stack: opening an item replaces the list with a full-width detail.
   .app.split-view = side-by-side list + detail with a draggable resizer.
*/
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  width: 100%;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
  overflow: hidden;
}
.sidebar__head {
  display: flex; align-items: center; gap: 4px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar__head h2 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__close { display: inline-flex; }

.feed-list {
  list-style: none; padding: 6px 8px; margin: 0;
  border-bottom: 1px solid var(--border);
}
.feed-list__item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  cursor: pointer; user-select: none;
}
.feed-list__item:hover { background: var(--hover-bg); }
.feed-list__item.active { background: var(--active-bg); }
.feed-list__item .feed-list__title {
  flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.feed-list__item .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.feed-list__item.is-empty .dot { background: var(--read); }
.badge {
  background: var(--active-bg); color: var(--accent);
  font-size: 11px; padding: 2px 7px; border-radius: 10px;
  min-width: 22px; text-align: center;
}

#feed-list {
  flex: 1; overflow-y: auto;
  padding: 6px 8px;
}

.sidebar__foot {
  border-top: 1px solid var(--border);
  padding: 12px; display: flex; gap: 8px;
  flex-shrink: 0;
}
.sidebar__foot .primary-btn { flex: 1; }
.sidebar__foot .ghost-btn { padding: 6px 12px; }

/* ---------- Main ---------- */
.main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--bg);
}
.main__head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
#sidebar-show { display: none; }
.main__head-title { flex: 1; min-width: 0; }
.main__head h2 { margin: 0 0 2px; font-size: 16px; }
.main__head-actions {
  display: flex; align-items: center; gap: 10px;
}
.check { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.main__body {
  flex: 1;
  display: flex;
  flex-direction: column;  /* stack panes vertically by default */
  min-height: 0;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.pane--list { flex: 1 1 auto; }
.pane--detail { flex: 0 0 auto; display: none; }

.item-list {
  list-style: none; margin: 0; padding: 12px 18px;
  overflow-y: auto; flex: 1;
  min-height: 0;
}
.item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.item:hover { border-color: var(--accent); }
.item.is-active {
  border-color: var(--accent);
  background: var(--active-bg);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.item__row1 {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
}
.item__feed {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.item__date {
  font-size: 11px; color: var(--muted);
}
.item__title {
  font-weight: 600;
  font-size: 14px;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item__summary {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item__actions {
  display: flex; gap: 6px; margin-top: 8px;
}
.item__btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
}
.item.is-read { opacity: .55; }
.item.is-read .item__title { font-weight: 400; color: var(--muted); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}

.item-list__footer {
  list-style: none;
  display: flex;
  justify-content: center;
  padding: 16px 0 8px;
}
.item-list__footer button { min-width: 220px; }

/* ---------- Detail ---------- */
.detail {
  background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
  overflow: hidden;
  flex: 1;
}
.detail__head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-start;
  flex-shrink: 0;
}
#detail-close { font-size: 22px; padding: 2px 10px; }
.detail__head-text { flex: 1; min-width: 0; }
.detail__head h2 { margin: 0; font-size: 16px; line-height: 1.4; }
.detail__body {
  padding: 24px 32px;
  overflow-y: auto; flex: 1;
  line-height: 1.7;
  font-size: 15px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.detail__body img { max-width: 100%; height: auto; border-radius: 6px; margin: 12px 0; }
.detail__body pre { white-space: pre-wrap; word-break: break-word; background: var(--hover-bg); padding: 12px; border-radius: 6px; }
.detail__body blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 16px 0; color: var(--muted); }
.detail__body h1, .detail__body h2, .detail__body h3 { margin-top: 1.4em; line-height: 1.3; }
.detail__body h1 { font-size: 22px; }
.detail__body h2 { font-size: 19px; }
.detail__body h3 { font-size: 16px; }
.detail__body p { margin: 0 0 1em; }
.detail__body a { color: var(--accent); }
.detail__body ul, .detail__body ol { padding-left: 1.5em; }
.detail__foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 8px;
  flex-shrink: 0;
  background: var(--panel);
}

/* ---------- Resizer ---------- */
.resizer {
  display: none;
  flex: 0 0 5px;
  background: transparent;
  cursor: col-resize;
  position: relative;
  user-select: none;
  touch-action: none;
}
.resizer::before {
  content: '';
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
  transition: background .12s;
}
.resizer::after {
  /* Larger hit area for easier grabbing */
  content: '';
  position: absolute;
  inset: 0 -5px;
}
.resizer:hover::before,
.resizer.is-dragging::before { background: var(--accent); }

/* ---------- Stack mode (default) ---------- */
/* Detail open  -> list hidden, detail full width of main */
.app:not(.split-view).detail-open .pane--list { display: none; }
.app:not(.split-view).detail-open .pane--detail { display: flex; flex: 1 1 auto; }

/* ---------- Split view (opt-in) ---------- */
/* In split mode, both panes are always visible.
   Detail pane shows the article when an item is open,
   or a placeholder when nothing is selected. */
.app.split-view .main__body { flex-direction: row; }
.app.split-view .pane--list {
  flex: 0 0 var(--list-width, 38%);
  min-width: 240px;
  max-width: 70%;
  border-right: 1px solid var(--border);
}
.app.split-view .pane--detail {
  display: flex;
  flex: 1 1 0;
  min-width: 320px;
}
.app.split-view .resizer { display: block; }

#detail-placeholder { display: none; }
.app.split-view:not(.detail-open) #detail-placeholder { display: flex; }
.app.detail-open #detail-placeholder { display: none; }

.detail-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
  background: var(--bg);
}

/* Split toggle icon swap + active highlight */
.icon-stack { display: inline-block; }
.icon-split { display: none; }
.app.split-view .icon-stack { display: none; }
.app.split-view .icon-split { display: inline-block; }
.app.split-view #split-toggle {
  background: var(--active-bg);
  color: var(--accent);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal__box {
  background: var(--panel); border-radius: 12px;
  padding: 24px;
  width: 420px; max-width: calc(100% - 32px);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.modal__box h3 { margin: 0; font-size: 16px; }
.modal__box input {
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit;
}
.modal__actions {
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ---------- QR login modal ---------- */
.modal__box--qr {
  width: 360px;
  text-align: center;
}
.modal__box--qr h3 { text-align: left; }
.modal__box--qr .muted { text-align: left; }
.qr-frame {
  background: #fff;
  padding: 12px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px 0 8px;
  border: 1px solid var(--border);
}
.qr-frame img { display: block; width: 280px; height: 280px; }
.qr-fallback { text-align: left; margin-top: 4px; }
.qr-fallback summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  user-select: none;
  padding: 4px 0;
}
.qr-fallback__hint { font-size: 12px; margin-top: 4px; }
.qr-url {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 6px;
  margin: 6px 0 0;
}
#qr-countdown { font-variant-numeric: tabular-nums; }

/* ---------- Sidebar collapsed (user toggle) ---------- */
.app.sidebar-collapsed { grid-template-columns: 0 1fr; }
.app.sidebar-collapsed .sidebar {
  width: 0;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}
.app.sidebar-collapsed #sidebar-show { display: inline-flex; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 220px 1fr; }
  .item-list { padding: 10px 12px; }
  .detail__body { padding: 20px 22px; }
}

@media (max-width: 640px) {
  /* On phones: hide sidebar by default, force stack layout */
  .app:not(.sidebar-open) { grid-template-columns: 0 1fr; }
  .app:not(.sidebar-open) .sidebar {
    width: 0; border-right: none;
    opacity: 0; pointer-events: none;
  }
  .app:not(.sidebar-open) #sidebar-show { display: inline-flex; }

  .app.sidebar-open .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 280px; z-index: 80;
    box-shadow: var(--shadow);
    opacity: 1; pointer-events: auto;
  }
  .app.sidebar-open #sidebar-show { display: none; }
  .app.sidebar-open .sidebar__close { display: inline-flex; }

  #split-toggle { display: none; }
  .app.split-view .resizer { display: none; }
  .app.split-view .pane--list,
  .app.split-view .pane--detail {
    flex-basis: auto;
    min-width: 0;
    max-width: none;
    border-right: none;
  }

  .main__head { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .main__head h2 { font-size: 14px; }
  .main__head-actions { gap: 8px; flex-wrap: wrap; }
  .check { display: none; }
  /* On mobile, when reading an article, the main head (feed title, Mark all
     read) is redundant with the detail head. Drop it so the article gets
     the whole screen. The detail__head keeps × for back navigation. */
  .app.detail-open .main__head { display: none; }

  /* Mobile feed row: tap = select, swipe left = reveal edit/delete.
     Desktop keeps the hover-reveal behavior via the @media (hover: hover)
     rules above; here we override for touch devices. */
  .feed-list__item {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
  }
  .feed-list__item .feed-actions {
    display: flex;
    position: absolute;
    right: 0; top: 0; bottom: 0;
    align-items: center;
    padding: 0 8px;
    gap: 4px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.18s ease;
  }
  .feed-list__item.is-swiped {
    transform: translateX(-80px);
    transition: transform 0.18s ease;
  }
  .feed-list__item.is-swiped .feed-actions {
    transform: translateX(0);
  }
  .detail__head { padding: 10px 12px; }
  .detail__body { padding: 16px 16px; font-size: 14px; }
  .detail__foot { padding: 10px 12px; }
  .item-list { padding: 8px 10px; }
  .item { padding: 10px 12px; }
}

/* ---------- Feed row inline edit / actions ---------- */
.feed-list__item .feed-actions {
  display: none;
  gap: 4px;
  flex-shrink: 0;
}
.feed-list__item:hover .feed-actions,
.feed-list__item:focus-within .feed-actions {
  display: flex;
}
.feed-action {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.feed-action:hover { background: var(--btn-hover); color: var(--text); }
.feed-action.is-danger:hover { color: var(--danger); }
.feed-list__title-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
.feed-list__title-input:focus { box-shadow: 0 0 0 2px var(--active-bg); }
