:root {
  --paper: #f3eee4;
  --paper-deep: #e8dfcf;
  --ink: #1b241f;
  --muted: #6d6458;
  --line: #dccfb8;
  --card: #fffdf8;
  --pine: #1b5c4b;
  --pine-dark: #123f35;
  --gold: #c67b22;
  --oa: #1f7a4d;
  --danger: #9b3a2f;
  --shadow: 0 18px 50px rgba(28, 36, 31, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(27, 92, 75, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(198, 123, 34, 0.08), transparent 45%),
    var(--paper);
}

.page-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 243, 235, 0.92);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 3.4rem;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

.header-collapse {
  align-items: center;
  gap: 0.75rem;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-nav .nav-link {
  color: var(--muted) !important;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  border-radius: 999px;
  padding: 0.38rem 0.7rem !important;
  white-space: nowrap;
}

.header-nav .nav-link:hover {
  color: var(--pine-dark) !important;
  background: rgba(27, 92, 75, 0.08);
}

.header-nav .nav-link.is-active {
  color: var(--pine-dark) !important;
  background: rgba(27, 92, 75, 0.12);
}

.header-aside,
.header-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.header-aside {
  margin-left: auto;
}

.header-user {
  margin-left: auto;
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.header-toggler {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.28rem 0.4rem;
  font-size: 0.85rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-right: 0.15rem;
  font-family: Fraunces, Georgia, serif;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--pine);
  color: #f7f1e4;
  font-size: 0.72rem;
  font-weight: 650;
}

.brand-text {
  color: var(--ink);
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 2px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.header-bar .navbar-brand {
  padding: 0;
  margin: 0;
}

.header-toggler:focus {
  box-shadow: none;
}

.lang-switcher button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.28rem 0.52rem;
  color: var(--muted);
  line-height: 1;
  cursor: pointer;
}

.lang-switcher button.is-active {
  background: var(--pine);
  color: #fff;
}

.user-chip {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip:hover { color: var(--pine-dark); }

.btn-ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.22rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.header-user .btn-ghost {
  padding: 0.22rem 0.7rem;
}

@media (max-width: 1199.98px) {
  .header-collapse {
    width: 100%;
    flex-basis: 100%;
    padding: 0.65rem 0 0.85rem;
    border-top: 1px solid var(--line);
    margin-top: 0.45rem;
  }

  .header-nav {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.15rem;
  }

  .header-nav .nav-link {
    padding: 0.55rem 0.75rem !important;
  }

  .header-user {
    width: 100%;
    margin: 0.65rem 0 0;
    padding: 0.65rem 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    justify-content: space-between;
  }
}

.site-main { flex: 1; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.1rem 0 1.4rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.hero {
  max-width: 820px;
  margin: 0 auto 2.5rem;
  text-align: center;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.78rem;
  color: var(--gold);
  font-weight: 700;
}

h1, h2, h3, .display-title {
  font-family: Fraunces, Georgia, serif;
  letter-spacing: -0.03em;
}

.display-title {
  font-size: clamp(2.1rem, 4vw, 3.4rem);
  margin: 0.4rem 0 0.8rem;
}

.lede {
  color: var(--muted);
  font-size: 1.15rem;
  margin-bottom: 1.6rem;
}

.search-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.search-input,
.form-control, .form-select {
  border-radius: 16px !important;
  border-color: var(--line) !important;
  background: #fff !important;
  padding: 0.85rem 1rem !important;
}

.search-input {
  font-size: 1.08rem !important;
  min-height: 62px;
}

.btn-pine {
  background: var(--pine);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.4rem;
  font-weight: 700;
}

.btn-pine:hover { background: var(--pine-dark); color: #fff; }

.btn-gold {
  background: var(--gold);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
}

.quick-grid, .topic-grid, .continue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.8rem;
}

.chip, .topic-card, .continue-card, .history-item, .paper-card, .soft-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(28, 36, 31, 0.04);
}

.chip {
  display: block;
  text-align: center;
  padding: 0.9rem 0.8rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 650;
}

.search-launch {
  margin: 0;
}

.search-launch-inline {
  display: inline-flex;
}

button.chip,
button.topic-card,
button.history-item {
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  appearance: none;
}

.chip:hover, .topic-card:hover, .continue-card:hover, .paper-card:hover {
  transform: translateY(-2px);
  border-color: #cbb894;
}

.section-title {
  font-size: 1.35rem;
  margin: 2.2rem 0 1rem;
}

.paper-card {
  padding: 1.25rem 1.3rem 1.15rem;
  margin-bottom: 1rem;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(27, 92, 75, 0.1);
  color: var(--pine-dark);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-weight: 700;
  font-size: 0.86rem;
}

.oa-badge {
  color: var(--oa);
  font-weight: 700;
}

.meta-row {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.35rem 0 0.7rem;
}

.keyword {
  display: inline-block;
  background: var(--paper-deep);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin: 0 0.25rem 0.35rem 0;
  font-size: 0.86rem;
}

.why-box {
  background: #f7f1e4;
  border-left: 3px solid var(--gold);
  padding: 0.8rem 1rem;
  border-radius: 0 14px 14px 0;
  margin: 0.8rem 0;
}

.verify-links-notice {
  border: 1px solid rgba(198, 123, 34, 0.38);
  background: #fbf4e8;
  color: var(--ink);
  border-radius: 16px;
}

.verify-links-notice strong {
  display: block;
  margin-bottom: 0.15rem;
  color: #9a5c12;
}

.verify-links-hint {
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0.45rem 0 0.55rem;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.btn-outline-ink {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.btn-outline-ink:hover { border-color: var(--pine); color: var(--pine-dark); }

.filters {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  position: sticky;
  top: 72px;
}

.narrow-card { max-width: 720px; }
.narrow-card-sm { max-width: 640px; }
.display-title-compact { font-size: 2.4rem; }
.modal-content.soft-modal { border-radius: 20px; }

.auth-card {
  max-width: 460px;
  margin: 4vh auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.topic-card, .continue-card, .history-item {
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: inherit;
  display: block;
}

.count-pill {
  color: var(--muted);
  font-size: 0.9rem;
}

.search-loader {
  position: fixed;
  inset: 0;
  background: rgba(243, 238, 228, 0.82);
  display: grid;
  place-items: center;
  z-index: 50;
}

.loader-card {
  text-align: center;
  background: var(--card);
  padding: 2rem;
  border-radius: 24px;
  border: 1px solid var(--line);
}

.pulse-book {
  width: 54px;
  height: 38px;
  margin: 0 auto 1rem;
  border: 3px solid var(--pine);
  border-radius: 4px 10px 10px 4px;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  50% { transform: rotate(-6deg); background: rgba(27, 92, 75, 0.12); }
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.4rem;
}

.status-dot.ok { background: var(--oa); }
.status-dot.bad { background: var(--danger); }

.cite-box {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: #1b241f;
  color: #f4efe6;
  border-radius: 16px;
  padding: 1rem;
  white-space: pre-wrap;
}

.form-check-input { border-color: var(--line); }

@media (max-width: 768px) {
  .filters { position: static; }
  .search-panel { padding: 0.7rem; }
  .display-title { font-size: 2rem; }
}
