:root {
  --bg: #f8f6f1;
  --paper: #ffffff;
  --paper-alt: #f2eee5;
  --ink: #1a1917;
  --muted: #666057;
  --line: #ddd6c9;
  --accent: #8b261d;
  --accent-soft: #fbf1ef;
  --green: #24663b;
  --green-soft: #edf7f0;
  --shadow: 0 2px 8px rgba(26, 25, 23, 0.05);
  --radius: 8px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page-wrap {
  max-width: 1140px;
  margin: 0 auto;
  padding: 20px 18px 60px;
}

.masthead {
  margin-bottom: 20px;
}

.masthead-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
}

.masthead-edition {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.masthead-title {
  margin: 0;
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 2.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  line-height: 1.05;
}

.masthead-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.session-pill {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
}

.masthead-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 6px 2px;
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-full { width: 100%; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #312f2b; }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-secondary:hover { background: #701d16; }
.btn-outline { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn-outline:hover { border-color: var(--ink); background: var(--paper-alt); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { color: var(--ink); background: var(--paper-alt); }

/* Auth */
.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 28px 0;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}
.auth-card h2 {
  font-family: "Newsreader", Georgia, serif;
  margin: 4px 0 8px;
  font-size: 1.7rem;
}
.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.auth-block { margin-top: 16px; }
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.divider span { padding: 0 10px; }

.details-summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 0;
  color: var(--ink);
}
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 12px;
}
.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
}
input[type="text"], input[type="password"], input[type="search"] {
  font: inherit;
  font-size: 0.92rem;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
input:focus {
  outline: none;
  border-color: var(--ink);
}

.notice {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  border: 1px solid var(--line);
  background: var(--paper-alt);
}
.notice-warn { border-color: #d9b87a; background: #fdf7e7; color: #664912; }
.notice-error { border-color: #d89b96; background: var(--accent-soft); color: var(--accent); }
.notice-ok { border-color: #9dc9ac; background: var(--green-soft); color: var(--green); }

/* Tabs */
.tab-nav {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head h2 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.55rem;
}

/* Live downloads banner */
.download-banner {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.dl-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dl-row + .dl-row {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.dl-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
}
.progress-track {
  width: 100%;
  height: 7px;
  background: var(--paper-alt);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Editions list */
.editions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.edition-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edition-card:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.edition-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.edition-title {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
}
.edition-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--paper-alt);
  color: var(--ink);
  white-space: nowrap;
}
.badge-fav {
  background: var(--accent-soft);
  border-color: #e4bbb7;
  color: var(--accent);
}
.badge-green {
  background: var(--green-soft);
  border-color: #b7dec3;
  color: var(--green);
}
.badge-neutral {
  background: var(--paper-alt);
  color: var(--muted);
}

/* Detail view */
.detail-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.detail-title-wrap h2 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.65rem;
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.search-input {
  flex: 1 1 260px;
  max-width: 440px;
}
.chip-group {
  display: flex;
  gap: 6px;
}
.chip {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.sub-heading {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin: 18px 0 12px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.pdf-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.pdf-card:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.pdf-card.is-fav {
  border-color: #d9a7a1;
  background: #fffdfb;
}
.pdf-thumb-box {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: var(--paper-alt);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pdf-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
.pdf-fallback {
  font-family: "Newsreader", Georgia, serif;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 12px;
}
.fav-ribbon {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
}
.pdf-card-body {
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  justify-content: space-between;
}
.pdf-card-title {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pdf-card-size {
  font-size: 0.76rem;
  color: var(--muted);
}

/* RSS */
.rss-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}
.rss-block {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.rss-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.rss-block-head h3 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.3rem;
}
.rss-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.rss-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: #fdfcfa;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rss-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.rss-item-title {
  font-weight: 600;
  font-size: 0.94rem;
}
.rss-item-meta {
  font-size: 0.79rem;
  color: var(--muted);
}
.rss-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Table */
.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--paper-alt);
}
tr:last-child td { border-bottom: none; }

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}
.panel-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel-box h3 {
  margin: 0 0 4px;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.3rem;
}
.inline-form {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}
.inline-form input { flex: 1; min-width: 0; }
.clean-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.clean-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.clean-list li:last-child { border-bottom: none; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 25, 23, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  padding: 18px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 {
  margin: 2px 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.4rem;
}
.modal-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 0;
}
.inspect-list {
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  flex: 1;
}
.inspect-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.87rem;
}
.inspect-row:last-child { border-bottom: none; }
.inspect-row.is-fav { background: var(--accent-soft); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink);
  color: #fff;
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 0.88rem;
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

@media (max-width: 680px) {
  .masthead-top {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .masthead-actions { justify-content: center; }
  .masthead-bar {
    flex-direction: column;
    gap: 2px;
    text-align: center;
  }
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

/* Stacked multi-version cards & inline expansion drawer */
.pdf-card-stack {
  position: relative;
  text-align: left;
  font: inherit;
  padding: 0;
  cursor: pointer;
  box-shadow:
    3px 3px 0 0 var(--paper),
    4px 4px 0 0 var(--line),
    7px 7px 0 0 var(--paper-alt),
    8px 8px 0 0 var(--line);
}
.pdf-card-stack:hover {
  box-shadow:
    3px 3px 0 0 var(--paper),
    4px 4px 0 0 var(--ink),
    7px 7px 0 0 var(--paper-alt),
    8px 8px 0 0 var(--ink);
}
.pdf-card-stack.is-expanded {
  border-color: var(--accent);
  box-shadow:
    3px 3px 0 0 var(--paper),
    4px 4px 0 0 var(--accent),
    7px 7px 0 0 var(--paper-alt),
    8px 8px 0 0 var(--accent);
}
.stack-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(26, 25, 23, 0.86);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  backdrop-filter: blur(2px);
}
.group-drawer {
  grid-column: 1 / -1;
  background: var(--paper-alt);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  margin: 4px 0 8px;
  box-shadow: var(--shadow);
}
.group-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.group-drawer-head h4 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.25rem;
}

/* Favorite toggle star on PDF cards */
.star-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.star-btn:hover {
  transform: scale(1.08);
  border-color: var(--ink);
  color: var(--ink);
}
.star-btn.is-fav {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffe082;
}
.star-btn.is-fav:hover {
  background: #701d16;
  border-color: #701d16;
  color: #fff;
}
.category-section + .category-section {
  margin-top: 26px;
}
