:root {
  color-scheme: light;
  --bg: #f6f8f4;
  --panel: #ffffff;
  --panel-soft: #eef3eb;
  --ink: #1d211d;
  --muted: #646b62;
  --faint: #8a9288;
  --line: #d9e0d6;
  --line-strong: #c1cabd;
  --accent: #156c5c;
  --accent-soft: #dcebe4;
  --warn: #a6533b;
  --gold: #88670f;
  --code-bg: #f0f2ef;
  --shadow: 0 18px 50px rgba(29, 33, 29, 0.08);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(246, 248, 244, 0.95), rgba(242, 245, 239, 0.95)),
    var(--bg);
  color: var(--ink);
  overflow: hidden;
}

body.image-focus-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.library-close-button,
.library-backdrop {
  display: none;
}

.library-toggle-button {
  position: fixed;
  z-index: 70;
  left: 16px;
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(21, 108, 92, 0.35);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 30px rgba(21, 108, 92, 0.24);
  font-weight: 700;
}

.app-tabs {
  position: fixed;
  z-index: 70;
  top: 14px;
  left: 50%;
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(76px, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 28px rgba(29, 33, 29, 0.08);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.app-tab-button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.app-tab-button:last-child {
  border-right: 0;
}

.app-tab-button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.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;
}

.app-shell {
  display: grid;
  grid-template-columns: 0 minmax(0, 1fr) 0;
  height: 100vh;
  min-height: 0;
  transition: grid-template-columns 180ms ease;
}

.library-drawer-open .app-shell {
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr) 0;
}

.inspector-open .app-shell {
  grid-template-columns: 0 minmax(0, 1fr) minmax(280px, 320px);
}

.library-drawer-open.inspector-open .app-shell {
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr) minmax(280px, 320px);
}

@supports (height: 100dvh) {
  .app-shell {
    height: 100dvh;
  }
}

.library-panel,
.inspector-panel {
  min-height: 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

.library-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: none;
  padding: 18px;
  border-right: 1px solid var(--line);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.library-drawer-open .library-panel {
  opacity: 1;
  pointer-events: auto;
}

.library-close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.library-backdrop {
  display: none;
}

.library-backdrop[hidden] {
  display: none;
}

.library-header {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
}

.library-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.library-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.stats-strip div {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
}

.stats-strip div:last-child {
  border-right: 0;
}

.stats-strip strong {
  font-size: 19px;
  line-height: 1;
}

.stats-strip span {
  color: var(--faint);
  font-size: 12px;
}

.search-block {
  position: relative;
}

.search-block input {
  width: 100%;
  min-height: 42px;
  padding: 0 42px 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: 0;
}

.search-block input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(21, 108, 92, 0.32);
  outline-offset: 2px;
}

.icon-button {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.icon-button:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.filter-grid label,
.sort-label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.filter-grid span {
  color: var(--faint);
  font-size: 12px;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 10px;
  align-items: center;
}

.segment-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.segment-button {
  min-width: 0;
  height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.filter-chip,
.tag,
.status-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.status-new {
  border-color: rgba(21, 108, 92, 0.24);
  background: var(--accent-soft);
  color: var(--accent);
}

.status-queued,
.status-running {
  border-color: rgba(136, 103, 15, 0.26);
  background: #fff6d8;
  color: var(--gold);
}

.status-imported {
  border-color: rgba(43, 104, 64, 0.22);
  background: #e4f2e7;
  color: #2b6840;
}

.status-failed {
  border-color: rgba(166, 83, 59, 0.28);
  background: #fbefeb;
  color: var(--warn);
}

.status-muted {
  color: var(--faint);
}

.query-pill-row {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.filter-chip button {
  margin-left: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}

.paper-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  padding-right: 2px;
  overflow: auto;
}

.paper-card {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
  box-shadow: none;
}

.paper-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 8px 24px rgba(29, 33, 29, 0.06);
}

.paper-card.is-active {
  border-color: rgba(21, 108, 92, 0.5);
  background: #f8fbf8;
}

.paper-card-top,
.paper-card-meta,
.paper-card-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.paper-card-top {
  justify-content: space-between;
}

.paper-id {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.paper-card h3 {
  margin: 0;
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.paper-card-meta {
  flex-wrap: wrap;
  color: var(--faint);
  font-size: 12px;
}

.paper-card p {
  margin: 0;
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.paper-card-tags {
  flex-wrap: wrap;
}

.mini-mark {
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.reader-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--panel);
}

.reader-progress {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
}

.reader-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warn));
  transition: width 160ms ease;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 14px 22px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.reader-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.action-button,
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.action-button:hover,
.action-link:hover,
.action-button.is-on {
  border-color: rgba(21, 108, 92, 0.35);
  background: var(--accent-soft);
  color: var(--accent);
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.danger-button {
  min-height: 34px;
  border: 1px solid rgba(166, 83, 59, 0.28);
  border-radius: 8px;
  background: #fff8f5;
  color: var(--warn);
  font-size: 13px;
}

.danger-button:hover {
  border-color: rgba(166, 83, 59, 0.52);
  background: #fbefeb;
}

.danger-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.reader-scroll {
  min-height: 0;
  overflow: auto;
  scroll-behavior: smooth;
}

.newspaper-view {
  min-height: 0;
  overflow: auto;
  padding: 82px 32px 48px;
  background: var(--bg);
}

.newspaper-view[hidden] {
  display: none;
}

.newspaper-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto 20px;
}

.newspaper-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.newspaper-header h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.newspaper-header p:last-child {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.newspaper-header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.newspaper-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  max-width: 1320px;
  margin: 0 auto;
}

.query-panel,
.candidate-panel {
  min-width: 0;
}

.query-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 130px);
  overflow: auto;
}

.query-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.query-panel-title h3 {
  margin: 0;
  font-size: 15px;
}

.query-panel-title span {
  color: var(--faint);
  font-size: 12px;
}

.query-list {
  display: grid;
  gap: 8px;
}

.query-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
}

.query-card:hover,
.query-card.is-active {
  border-color: rgba(21, 108, 92, 0.4);
  background: #f8fbf8;
}

.query-select-button {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.query-card-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.query-card-top strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
}

.query-raw {
  padding-top: 2px;
  color: var(--faint);
  font-size: 12px;
}

.query-raw summary {
  width: fit-content;
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.query-card code,
.query-raw code {
  display: block;
  margin-top: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  overflow-wrap: anywhere;
  color: #29423b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
}

.query-meta {
  color: var(--faint);
  font-size: 12px;
}

.candidate-panel {
  display: grid;
  gap: 12px;
}

.candidate-toolbar {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
}

.candidate-search input {
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.candidate-list {
  display: grid;
  gap: 10px;
}

.candidate-section {
  display: grid;
  gap: 10px;
}

.candidate-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
}

.candidate-section-header h3 {
  margin: 0;
  font-size: 15px;
}

.candidate-section-header span {
  color: var(--faint);
  font-size: 12px;
}

.candidate-section-list {
  display: grid;
  gap: 10px;
}

.candidate-card {
  display: grid;
  gap: 9px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.candidate-card-header,
.candidate-actions,
.candidate-meta,
.candidate-queries {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.candidate-card-header {
  justify-content: space-between;
}

.candidate-id {
  margin-right: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.candidate-date,
.candidate-meta {
  color: var(--faint);
  font-size: 12px;
}

.candidate-meta span {
  padding: 2px 0;
}

.candidate-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
}

.candidate-authors,
.candidate-summary,
.candidate-error,
.candidate-job,
.candidate-reason {
  margin: 0;
  line-height: 1.55;
}

.candidate-authors {
  color: var(--muted);
  font-size: 13px;
}

.candidate-summary {
  color: var(--ink);
  font-size: 14px;
}

.candidate-reason,
.candidate-job {
  color: var(--muted);
  font-size: 12px;
}

.candidate-job {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
}

.candidate-summary {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.candidate-error {
  padding: 9px 10px;
  border: 1px solid rgba(166, 83, 59, 0.24);
  border-radius: 8px;
  background: #fbefeb;
  color: var(--warn);
  font-size: 12px;
}

.empty-reader {
  max-width: 720px;
  margin: 18vh auto 0;
  padding: 0 28px;
}

.empty-reader h2 {
  margin: 0 0 8px;
  font-size: 26px;
}

.empty-reader p {
  margin: 0;
  color: var(--muted);
}

.paper-header {
  padding: 30px 44px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f8faf7);
}

.paper-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--faint);
  font-size: 13px;
}

.paper-meta-line span:not(:empty)::after {
  content: "";
}

.paper-header h2 {
  max-width: 980px;
  margin: 12px 0 12px;
  font-size: 36px;
  line-height: 1.08;
  letter-spacing: 0;
}

.paper-authors,
.paper-affiliation {
  max-width: 980px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.paper-insight {
  max-width: 980px;
  margin: 18px 0 0;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.7;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 980px;
  margin-top: 16px;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(0, 860px);
  gap: 30px;
  align-items: start;
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 34px 72px;
}

.reader-layout.toc-collapsed {
  grid-template-columns: minmax(0, 980px);
  max-width: 1048px;
}

.toc {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 4px;
  max-height: calc(100vh - 110px);
  padding-right: 6px;
  overflow: auto;
}

.toc[hidden] {
  display: none;
}

.toc-title {
  margin: 0 0 8px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 700;
}

.toc button {
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0 8px 8px 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 13px;
  line-height: 1.35;
}

.toc button:hover,
.toc button.is-active {
  border-left-color: var(--accent);
  background: var(--panel-soft);
  color: var(--ink);
}

.toc .level-3 {
  padding-left: 18px;
  font-size: 12px;
}

.markdown-body {
  min-width: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.78;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--ink);
  letter-spacing: 0;
  scroll-margin-top: 86px;
}

.markdown-body h1 {
  font-size: 30px;
  line-height: 1.2;
}

.markdown-body h2 {
  margin: 36px 0 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 24px;
  line-height: 1.25;
}

.markdown-body h3 {
  margin: 28px 0 10px;
  font-size: 19px;
  line-height: 1.35;
}

.markdown-body h4 {
  margin: 24px 0 8px;
  font-size: 16px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body table,
.markdown-body pre,
.markdown-body figure {
  margin: 0 0 18px;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.35em;
}

.markdown-body li {
  margin: 6px 0;
}

.markdown-body blockquote {
  padding: 12px 14px;
  border-left: 3px solid var(--line-strong);
  border-radius: 0 8px 8px 0;
  background: var(--panel-soft);
  color: var(--muted);
}

.markdown-body code {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--code-bg);
  color: #29423b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.math-display {
  max-width: 100%;
  margin: 20px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.markdown-body mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.markdown-body mjx-container[display="true"] {
  padding: 6px 0;
}

.markdown-body pre {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #20251f;
  color: #f5f7f1;
  line-height: 1.55;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow: auto;
  border-collapse: collapse;
  border-spacing: 0;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  vertical-align: top;
}

.markdown-body th {
  background: var(--panel-soft);
  text-align: left;
}

.markdown-body img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.markdown-body img[data-focus-image] {
  cursor: zoom-in;
}

.markdown-body img[data-focus-image]:hover {
  border-color: var(--accent);
}

.markdown-body figcaption {
  margin-top: 7px;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.markdown-body hr {
  height: 1px;
  margin: 28px 0;
  border: 0;
  background: var(--line);
}

.load-state,
.error-state {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
}

.error-state {
  border-color: rgba(166, 83, 59, 0.35);
  background: #fbefeb;
  color: #7c3d2d;
}

.inspector-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-left: 1px solid var(--line);
  overflow: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.inspector-open .inspector-panel {
  opacity: 1;
  pointer-events: auto;
}

.side-section {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.side-section:last-child {
  border-bottom: 0;
}

.side-section h2 {
  margin: 0;
  font-size: 14px;
}

.snapshot-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.snapshot-item {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 8px;
}

.snapshot-item strong {
  color: var(--faint);
  font-weight: 600;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 150px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  line-height: 1.55;
}

.note-status {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}

.related-list,
.view-links {
  display: grid;
  gap: 8px;
}

.related-card,
.view-links a {
  display: block;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}

.related-card:hover,
.view-links a:hover {
  border-color: var(--line-strong);
  background: #f9fbf8;
}

.related-card strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.related-card span {
  display: block;
  margin-top: 4px;
  color: var(--faint);
  font-size: 12px;
}

.image-focus-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(13, 17, 14, 0.86);
}

.image-focus-viewer[hidden] {
  display: none;
}

.image-focus-stage {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 100%;
  max-height: 100%;
}

.image-focus-img {
  display: block;
  max-width: min(100%, 1600px);
  max-height: calc(100vh - 112px);
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  object-fit: contain;
}

.image-focus-caption {
  max-width: min(100%, 900px);
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.image-focus-close {
  position: fixed;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 28px;
  line-height: 1;
}

.image-focus-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 1180px) {
  .app-shell,
  .inspector-open .app-shell {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .library-drawer-open .app-shell,
  .library-drawer-open.inspector-open .app-shell {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  }

  .inspector-panel {
    position: fixed;
    z-index: 65;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    width: min(360px, 92vw);
    max-width: 100vw;
    border-left: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.97);
    box-shadow: -18px 0 48px rgba(29, 33, 29, 0.18);
    opacity: 1;
    pointer-events: none;
    transform: translateX(105%);
    transition: transform 180ms ease;
  }

  .inspector-open .inspector-panel {
    pointer-events: auto;
    transform: translateX(0);
  }

  .newspaper-layout {
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow: auto;
  }

  body.library-drawer-open,
  body.inspector-open,
  body.image-focus-open {
    overflow: hidden;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100svh;
  }

  .app-tabs {
    top: 10px;
  }

  .newspaper-view {
    padding: 64px 16px 88px;
  }

  .newspaper-header {
    display: grid;
    align-items: start;
  }

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

  .newspaper-header h2 {
    font-size: 25px;
  }

  .newspaper-layout,
  .candidate-toolbar {
    grid-template-columns: 1fr;
  }

  .query-panel {
    position: static;
    max-height: none;
  }

  .library-panel {
    position: fixed;
    z-index: 60;
    top: 0;
    left: 0;
    width: min(92vw, 420px);
    height: 100svh;
    gap: 10px;
    min-height: 0;
    max-height: none;
    padding: 12px 14px 14px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 18px 0 48px rgba(29, 33, 29, 0.18);
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .library-drawer-open .library-panel {
    transform: translateX(0);
  }

  .library-toggle-button {
    left: 12px;
    bottom: 14px;
    padding: 0 13px;
  }

  .library-close-button {
    top: 10px;
    right: 10px;
  }

  .library-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: rgba(13, 17, 14, 0.38);
  }

  .library-backdrop[hidden] {
    display: none;
  }

  .library-header {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 13px;
  }

  .library-header h1 {
    font-size: 16px;
  }

  .library-header p {
    font-size: 12px;
  }

  .stats-strip {
    display: none;
  }

  .search-block input {
    min-height: 40px;
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .filter-grid label,
  .sort-label {
    gap: 4px;
  }

  select {
    min-height: 40px;
    font-size: 13px;
  }

  .toolbar-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .segment-button {
    min-height: 40px;
  }

  .paper-list {
    flex: 1 1 auto;
    gap: 7px;
    min-height: 280px;
    padding-right: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .paper-card {
    gap: 6px;
    padding: 10px;
  }

  .paper-card h3 {
    font-size: 13px;
  }

  .paper-card p {
    -webkit-line-clamp: 1;
  }

  .paper-card-tags {
    display: none;
  }

  .reader-panel {
    min-height: auto;
    overflow: visible;
  }

  .reader-toolbar {
    position: sticky;
    z-index: 20;
    top: 3px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 12px 14px;
  }

  .reader-actions {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: 100%;
    gap: 7px;
    justify-content: stretch;
  }

  .action-button,
  .action-link {
    min-height: 40px;
    min-width: 0;
    padding: 0 7px;
    font-size: 12px;
  }

  .reader-scroll {
    overflow: visible;
  }

  .reader-progress {
    position: sticky;
    top: 0;
    background: rgba(217, 224, 214, 0.72);
  }

  .empty-reader {
    margin: 72px auto;
    padding: 0 18px;
  }

  .paper-header {
    padding: 22px 18px 18px;
  }

  .paper-header h2 {
    font-size: 26px;
    line-height: 1.14;
  }

  .reader-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding: 20px 18px 86px;
  }

  .reader-layout.toc-collapsed {
    grid-template-columns: minmax(0, 1fr);
    max-width: 1048px;
  }

  .toc {
    position: relative;
    top: auto;
    max-height: none;
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }

  .toc[hidden] {
    display: none;
  }

  .toc button {
    padding: 8px 7px;
  }

  .markdown-body {
    font-size: 15px;
    line-height: 1.72;
  }

  .markdown-body h2 {
    scroll-margin-top: 128px;
    margin-top: 30px;
    font-size: 21px;
  }

  .markdown-body h3 {
    scroll-margin-top: 128px;
    font-size: 18px;
  }

  .markdown-body pre,
  .math-display,
  .markdown-body mjx-container {
    max-width: calc(100vw - 36px);
  }

  .markdown-body table {
    max-width: calc(100vw - 36px);
  }

  .inspector-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: min(82svh, 680px);
    border-top: 1px solid var(--line);
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -18px 48px rgba(29, 33, 29, 0.18);
    transform: translateY(105%);
    -webkit-overflow-scrolling: touch;
  }

  .inspector-open .inspector-panel {
    transform: translateY(0);
  }

  textarea {
    min-height: 130px;
  }
}

@media (max-width: 520px) {
  .library-panel {
    width: min(94vw, 390px);
    height: 100svh;
    min-height: 0;
    max-height: none;
    padding: 10px;
  }

  .filter-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filter-grid span {
    font-size: 11px;
  }

  .segment-button {
    font-size: 12px;
  }

  .reader-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-button,
  .action-link {
    font-size: 12px;
  }

  .paper-header {
    padding: 18px 14px 16px;
  }

  .paper-header h2 {
    font-size: 23px;
  }

  .paper-insight {
    margin-top: 14px;
    font-size: 14px;
    line-height: 1.6;
  }

  .reader-layout {
    padding: 18px 14px 82px;
  }

  .markdown-body table {
    max-width: calc(100vw - 28px);
  }

  .markdown-body pre,
  .math-display,
  .markdown-body mjx-container {
    max-width: calc(100vw - 28px);
  }

  .inspector-panel {
    max-height: min(84svh, 680px);
    border-radius: 14px 14px 0 0;
  }

  .image-focus-viewer {
    padding: 14px;
  }

  .image-focus-img {
    max-height: calc(100vh - 92px);
  }

  .image-focus-close {
    top: 10px;
    right: 10px;
  }
}
