:root,
[data-theme="light"] {
  --bg: #f6f3ec;
  --surface: #fffcf6;
  --ink: #14120f;
  --muted: #4e493f;
  --line: #e3dcd0;
  --accent: #0c5c56;
  --accent-ink: #ffffff;
  --danger: #8d2424;
  --unread: #0c5c56;
  --notice: #efe6d4;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #10120f;
  --surface: #1b1e19;
  --ink: #f4f0e6;
  --muted: #c4bbaa;
  --line: #2e342c;
  --accent: #7ee0d6;
  --accent-ink: #10211f;
  --danger: #ffb4b0;
  --unread: #7ee0d6;
  --notice: #2a261c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

h1, h2, .article-title, #reader-title {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h1 { font-size: 1.55rem; line-height: 1.1; margin: 0; }
h2 { font-size: 1.15rem; margin: 0; }

button, input, select, .upload {
  font: inherit;
  color: inherit;
}

button, .upload {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

button.ghost { background: transparent; }

button:disabled { opacity: 0.55; cursor: not-allowed; }

input, select {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 40;
}

.skip:focus { top: 12px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.banner {
  margin: 0;
  padding: 10px 20px;
  background: var(--notice);
  color: var(--ink);
}

.top {
  display: grid;
  gap: 12px;
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-row, .brand, .brand-actions, .tools, .row, .reader-bar, .library-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.brand-row { justify-content: space-between; }

.top.is-collapsed .lede { display: none; }

.menu { display: grid; gap: 12px; }

.brand { gap: 12px; }

.mark {
  margin: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-weight: 700;
}

.lede, .hint, .meta, .list-meta, .feed-error, .article-meta {
  color: var(--muted);
}

.lede { margin: 4px 0 0; font-size: 0.95rem; }

.add-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

.url-field { flex: 1 1 100%; }

#feed-url { flex: 1 1 220px; min-width: 0; }

.folder-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.folder-field select { min-width: 140px; color: var(--ink); }

.add-form .error, .tools .error { flex: 1 1 100%; margin: 0; }

.tools { align-items: center; }

.search { flex: 1 1 180px; }

.search input { width: 100%; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.hint { flex: 1 1 100%; margin: 0; font-size: 0.9rem; }

.transfer { flex: 1 1 auto; }

.transfer summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.transfer-body {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
}

.upload { position: relative; display: inline-flex; align-items: center; }

.upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.upload:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#theme { display: inline-flex; align-items: center; gap: 8px; }

.switch {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
}

#theme[aria-pressed="true"] .switch { background: var(--accent); }

#theme[aria-pressed="true"] .switch::after {
  transform: translateX(16px);
  background: var(--accent-ink);
}

.error { color: var(--danger); margin: 8px 0 0; }

.replace-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 20px;
  background: var(--notice);
}

.replace-bar p { margin: 0; }

.status {
  min-height: 1.4em;
  margin: 0;
  padding: 6px 20px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "list";
}

.library { grid-area: library; }
.list-pane { grid-area: list; }
.reader { grid-area: list; }

.library, .list-pane, .reader {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.library { padding: 8px 8px 24px; }

.library-head, .pane-head { padding: 12px 12px 8px; }

.library-head {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.pane-head {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

#list-meta { margin: 4px 0 0; }

.scope-btn, .folder-name, .feed-select, .article {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.scope-btn, .folder-name { font-weight: 650; }

.scope-btn[aria-current="true"],
.folder-name[aria-current="true"],
.feed.is-selected .feed-select {
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--accent);
}

.folder { margin-top: 8px; }

.folder-head, .feed {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.folder-name, .feed-select { flex: 1 1 140px; }

.feed-select {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.feed-title { font-weight: 650; }

.feed-url {
  display: block;
  align-self: stretch;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: center;
  padding: 4px 8px 8px;
  min-width: 0;
}

.feed-select, .feed-error, .confirm { grid-column: 1 / -1; }

.feed-error { flex: 1 1 100%; margin: 0 0 4px 12px; font-size: 0.85rem; }

.count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.move { font-size: 0.85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }

.move select { min-height: 36px; color: var(--ink); }

.confirm {
  flex: 1 1 100%;
  display: grid;
  gap: 8px;
  margin: 4px 8px 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.confirm p { margin: 0; }

.rename-form {
  flex: 1 1 100%;
  display: grid;
  gap: 8px;
  margin: 4px 8px;
}

.danger { color: var(--danger); }

.empty, .notice {
  margin: 0;
  padding: 16px;
}

.notice {
  background: var(--notice);
  margin: 0 12px 8px;
  border-radius: 8px;
}

#article-list { list-style: none; margin: 0; padding: 0; }

.article {
  display: grid;
  grid-template-columns: 10px 1fr;
  column-gap: 10px;
  row-gap: 2px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}

.article[aria-current="true"] { background: var(--surface); }

.dot {
  width: 8px;
  height: 8px;
  margin-top: 8px;
  border-radius: 50%;
  background: transparent;
}

.article[data-read="false"] .dot { background: var(--unread); }

.article-title {
  grid-column: 2;
  font-size: 1.08rem;
  line-height: 1.25;
}

.article-meta { grid-column: 2; font-size: 0.88rem; }

.reader {
  background: var(--surface);
  padding: 8px 20px 40px;
}

.reader-bar { padding: 8px 0; gap: 8px; }

.reader-status {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--notice);
}

#reader-retry { margin: 0 0 12px; }

.reader-body {
  max-width: 68ch;
  font-size: 1.05rem;
  line-height: 1.65;
}

.reader-body a { color: var(--accent); }

.reader-body img, .reader-body pre { max-width: 100%; }

.reader-body pre {
  overflow: auto;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
}

.reader-body p { margin: 0 0 1em; }

#reader-title { font-size: 1.8rem; line-height: 1.2; margin: 8px 0; }

#reader-meta { margin-top: 0; }

.backdrop { display: none; }

@media (max-width: 1099px) {
  .library {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(100%, 360px);
    background: var(--bg);
    border-right: 1px solid var(--line);
    transform: translateX(-105%);
  }

  .library.is-open { transform: none; }

  .backdrop {
    display: block;
    position: fixed;
    z-index: 20;
    inset: 0;
    background: rgba(16, 18, 15, 0.45);
  }
}

@media (min-width: 720px) {
  .workspace {
    grid-template-columns: minmax(260px, 400px) minmax(0, 1fr);
    grid-template-areas: "list reader";
  }
  .reader { grid-area: reader; }
  .list-pane { border-right: 1px solid var(--line); }
}

@media (min-width: 1100px) {
  .workspace {
    grid-template-columns: 280px minmax(280px, 380px) minmax(0, 1fr);
    grid-template-areas: "library list reader";
  }
  #open-library, #close-library { display: none; }
  .library {
    position: static;
    transform: none;
    width: auto;
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 719px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  .workspace { display: block; min-height: 60dvh; }
  .list-pane, .reader { overflow: visible; }
  .library { width: 100%; }
  .reader { display: none; }
  body.is-reading .list-pane { display: none; }
  body.is-reading .reader { display: block; }
  .top { padding: 0 12px 12px; }
  .brand-row {
    position: sticky;
    top: 0;
    z-index: 15;
    background: var(--surface);
    padding: 12px 0;
  }
  h1 { font-size: 1.35rem; }
  #reader-title { font-size: 1.45rem; }
}

@media (min-width: 720px) {
  #reader-back { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .library, .switch::after { transition: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .library { transition: transform 160ms ease; }
  .switch::after { transition: transform 160ms ease; }
}
