:root {
  --bg: #f2eee6;
  --bg-accent: #e8dfd1;
  --surface: #fffefb;
  --surface-soft: #f8f4eb;
  --text: #1d1a16;
  --muted: #61594d;
  --border: #d2c7b6;
  --accent: #845937;
  --accent-soft: #ede2d1;
  --shadow: 0 10px 30px rgba(61, 48, 32, 0.1);
}

body.theme-dark {
  --bg: #131415;
  --bg-accent: #1f2225;
  --surface: #1a1d20;
  --surface-soft: #22262a;
  --text: #ece8df;
  --muted: #beb5a8;
  --border: #3b4046;
  --accent: #d7ac7f;
  --accent-soft: #2c2b29;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 10%, color-mix(in srgb, var(--bg-accent) 85%, transparent), transparent 42%),
    radial-gradient(circle at 88% 5%, color-mix(in srgb, var(--accent-soft) 75%, transparent), transparent 36%),
    var(--bg);
  font-family: "Atkinson Hyperlegible", "Noto Sans SC", sans-serif;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
}

.skip-link {
  position: absolute;
  left: 14px;
  top: -40px;
  z-index: 20;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  text-decoration: none;
}

.skip-link:focus-visible {
  top: 12px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 28px 20px;
}

.header-topline {
  margin: 0 0 6px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.powered-by-link {
  color: inherit;
  text-decoration: none;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.85;
  transition: color 0.2s ease, opacity 0.2s ease;
}

.powered-by-link:hover {
  color: var(--accent);
  opacity: 1;
  text-decoration: underline;
}

.powered-by-link:focus-visible {
  color: var(--accent);
  opacity: 1;
  text-decoration: underline;
  outline: none;
}

.header-main h1 {
  margin: 0;
  font-family: "Crimson Pro", "Noto Serif SC", serif;
  font-weight: 600;
  font-size: clamp(1.75rem, 1.25rem + 1.2vw, 2.55rem);
  line-height: 1.22;
}

.header-meta {
  margin: 10px 0 0;
  color: var(--muted);
}

.report-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.report-stats p {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-soft) 88%, transparent);
  color: var(--muted);
}

.report-stats span {
  color: var(--text);
  font-weight: 700;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: flex-start;
  gap: 10px;
}

.header-actions button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.header-actions button:hover,
.header-actions button:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 64%, transparent);
  outline: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 28px 40px;
}

.sidebar {
  position: sticky;
  top: 18px;
  align-self: start;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow);
  padding: 16px;
  max-height: calc(100dvh - 36px);
  overflow: auto;
}

.sidebar-title {
  margin: 0;
  font-family: "Crimson Pro", "Noto Serif SC", serif;
  font-size: 1.2rem;
}

.sidebar-note {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-link {
  display: block;
  border: 1px solid transparent;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.nav-link-title {
  display: block;
  font-size: 0.93rem;
  line-height: 1.35;
}

.nav-link-meta {
  display: block;
  margin-top: 2px;
  font-size: 0.82rem;
  color: color-mix(in srgb, var(--muted) 88%, transparent);
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-link.is-active {
  border-color: var(--border);
  background: color-mix(in srgb, var(--accent-soft) 72%, transparent);
  color: var(--text);
  outline: none;
}

.content {
  min-width: 0;
}

.query-section {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.query-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.query-header h2 {
  margin: 0;
  font-family: "Crimson Pro", "Noto Serif SC", serif;
  font-size: clamp(1.3rem, 1.1rem + 0.5vw, 1.65rem);
  line-height: 1.25;
}

.query-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.query-content {
  display: grid;
  gap: 14px;
}

.paper-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-soft) 82%, transparent);
  padding: 14px 16px;
}

.paper-head {
  max-width: 76ch;
}

.paper-index {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.paper-title {
  margin: 5px 0 10px;
  font-family: "Crimson Pro", "Noto Serif SC", serif;
  font-weight: 600;
  font-size: clamp(1.1rem, 1rem + 0.35vw, 1.34rem);
  line-height: 1.34;
}

.paper-authors {
  margin: 0 0 5px;
  color: var(--muted);
}

.paper-meta-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.meta-item {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0;
}

.meta-item span {
  display: inline-block;
  margin-right: 2px;
  color: var(--text);
  font-weight: 700;
}

.primary-tag {
  display: inline-block;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 2px 9px;
  margin-right: 4px;
}

.paper-tldr {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent-soft) 58%, transparent);
  font-size: 0.9rem;
  color: var(--text);
}

.paper-tldr span {
  display: inline-block;
  margin-right: 6px;
  font-weight: 700;
  color: var(--accent);
}

.paper-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.paper-links.no-links {
  display: none;
}

.paper-link {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  padding: 4px 10px;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.paper-link:hover,
.paper-link:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 65%, transparent);
  outline: none;
}

.paper-details {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.details-summary {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  cursor: pointer;
  padding: 10px 36px 10px 12px;
  font-weight: 700;
}

.details-summary::-webkit-details-marker {
  display: none;
}

.details-summary::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 10px;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.paper-details[open] .details-summary::after {
  transform: rotate(180deg);
}

.summary-hint {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 400;
}

.detail-block {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
}

.detail-block h4 {
  margin: 0 0 6px;
  font-family: "Crimson Pro", "Noto Serif SC", serif;
  font-size: 1.02rem;
}

.detail-block p {
  margin: 0;
  color: var(--text);
  max-width: 72ch;
}

.empty-state {
  margin: 4px 0 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-soft) 78%, transparent);
}

@media (max-width: 1024px) {
  .page-header {
    flex-direction: column;
    padding: 24px 20px 16px;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 0 20px 28px;
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .report-stats {
    display: grid;
    grid-template-columns: 1fr;
  }

  .header-actions button {
    padding: 8px 12px;
    font-size: 0.88rem;
  }

  .query-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .skip-link,
  .header-actions,
  .sidebar,
  .summary-hint {
    display: none !important;
  }

  .layout,
  .query-content {
    display: block;
  }

  .page-header {
    padding: 0 0 14px;
  }

  .query-section,
  .paper-card {
    box-shadow: none;
    border-color: #999;
    break-inside: avoid;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
