:root {
  --bg: #f5f1e8;
  --panel: rgba(255, 251, 243, 0.94);
  --panel-strong: #fffaf1;
  --ink: #1f2a33;
  --muted: #66737b;
  --line: rgba(31, 42, 51, 0.12);
  --accent: #9b4d2f;
  --accent-strong: #7b341b;
  --accent-soft: rgba(155, 77, 47, 0.12);
  --teal: #2f6f73;
  --gold: #b1882d;
  --green: #54703c;
  --rose: #9e5d67;
  --shadow: 0 18px 40px rgba(37, 38, 40, 0.08);
  --radius: 18px;
  --shell-pad: 18px;
  --tool-rail-width: 360px;
  --floating-top: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: auto;
  background:
    radial-gradient(circle at top left, rgba(47, 111, 115, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(177, 136, 45, 0.16), transparent 22%),
    linear-gradient(180deg, #fbf6ee, var(--bg));
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  padding: var(--shell-pad);
  overflow: visible;
}

.topbar,
.status-strip,
.panel,
.selection-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: 26px;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar h1,
.panel-header h2 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 12px 24px rgba(123, 52, 27, 0.24);
}

.ghost-btn {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
}

.primary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.file-label {
  display: inline-flex;
  align-items: center;
}

.status-strip {
  border-radius: 18px;
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(47, 111, 115, 0.11);
  color: var(--teal);
  font-weight: 600;
}

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

.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) var(--tool-rail-width);
  gap: 14px;
  align-items: start;
  overflow: visible;
}

.panel {
  border-radius: 24px;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.panel-left,
.panel-right {
  overflow: visible;
}

.panel-left {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: hidden;
}

.panel-reader {
  overflow: visible;
  display: block;
}

.filter-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  padding: 10px 12px;
}

.paper-list,
.entity-list,
.relation-list {
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.paper-item,
.entity-item,
.relation-item,
.compare-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.72);
}

.paper-item {
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease, background 150ms ease;
}

.paper-item:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 111, 115, 0.28);
}

.paper-item.active {
  border-color: rgba(155, 77, 47, 0.36);
  background: rgba(155, 77, 47, 0.08);
}

.paper-item h3,
.entity-item h3 {
  margin: 0 0 4px;
  font-size: 0.92rem;
}

.paper-item p,
.entity-item p,
.relation-item p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.paper-item p {
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.reader-header {
  background: linear-gradient(180deg, var(--panel-strong), rgba(255, 250, 241, 0.9));
}

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

.mini-stat,
.type-chip,
.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.8rem;
  background: rgba(31, 42, 51, 0.06);
}

.selection-card {
  margin: 0;
  border-radius: 18px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
}

.annotation-tools .selection-card {
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
}

.selection-preview {
  min-height: 52px;
  border-radius: 14px;
  background: rgba(155, 77, 47, 0.07);
  padding: 12px;
  line-height: 1.55;
}

.selection-controls {
  display: grid;
  gap: 10px;
}

.annotation-tools .selection-controls {
  gap: 8px;
  justify-items: start;
}

.selection-controls label,
.relation-form label,
.entity-editor label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--muted);
}

.selection-controls label {
  width: 100%;
}

.selection-controls select,
.relation-form select,
.relation-form textarea,
.entity-editor select,
.entity-editor textarea,
.entity-editor input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  padding: 10px 12px;
}

.selection-controls .primary-btn,
.relation-form .primary-btn,
.entity-editor .ghost-btn {
  justify-self: start;
  width: auto;
}

.annotation-tools .selection-preview {
  min-height: 44px;
  padding: 10px 12px;
}

.reader {
  overflow: visible;
  padding: 18px 22px 28px;
  line-height: 1.72;
  min-height: 65vh;
  contain: none;
}

.paper-block {
  margin: 0 0 18px;
  padding: 0 8px;
  color: #2a343d;
}

.paper-block.heading {
  margin-top: 18px;
  font-family: "Fraunces", serif;
  font-size: 1.22rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.paper-block.footnote {
  border-left: 2px solid rgba(177, 136, 45, 0.45);
  padding-left: 14px;
  color: #5f6458;
  font-size: 0.92rem;
}

.entity-highlight {
  border-radius: 6px;
  padding: 0.08em 0.08em;
  cursor: pointer;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.entity-highlight.manual {
  cursor: pointer;
}

.entity-highlight.apg-only {
  background: transparent;
  border-bottom: 2px dashed rgba(47, 111, 115, 0.55);
  border-radius: 0;
  color: #204548;
}

.entity-highlight.overlap-exact {
  background-image: linear-gradient(
    135deg,
    rgba(47, 111, 115, 0.18) 0%,
    rgba(47, 111, 115, 0.18) 45%,
    rgba(177, 136, 45, 0.24) 45%,
    rgba(177, 136, 45, 0.24) 100%
  );
}

.entity-highlight.overlap-partial {
  outline: 2px dotted rgba(177, 136, 45, 0.45);
}

.entity-highlight[data-node-type="ASTRO_OBJECT_ID"] {
  background: rgba(47, 111, 115, 0.18);
  box-shadow: inset 0 -1px 0 rgba(47, 111, 115, 0.4);
}

.entity-highlight[data-node-type="METHOD_NAME"] {
  background: rgba(155, 77, 47, 0.16);
  box-shadow: inset 0 -1px 0 rgba(155, 77, 47, 0.42);
}

.entity-highlight[data-node-type="DATASET_NAME"] {
  background: rgba(177, 136, 45, 0.18);
  box-shadow: inset 0 -1px 0 rgba(177, 136, 45, 0.45);
}

.entity-highlight[data-node-type="FACILITY_NAME"],
.entity-highlight[data-node-type="INSTRUMENT_NAME"] {
  background: rgba(84, 112, 60, 0.18);
  box-shadow: inset 0 -1px 0 rgba(84, 112, 60, 0.45);
}

.entity-highlight[data-node-type="PROPERTY_NAME"],
.entity-highlight[data-node-type="PHENOMENON_NAME"] {
  background: rgba(158, 93, 103, 0.16);
  box-shadow: inset 0 -1px 0 rgba(158, 93, 103, 0.42);
}

.entity-highlight.apg-only[data-node-type] {
  background: transparent;
  box-shadow: none;
}

.entity-highlight.selected {
  outline: 2px solid rgba(31, 42, 51, 0.35);
}

.side-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.52);
  overflow: hidden;
}

.compare-section {
  grid-template-rows: auto auto minmax(0, auto) minmax(0, auto);
}

.panel-right {
  display: block;
  position: relative;
  overflow: visible;
  padding: 0;
}

.annotation-tools {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.tool-rail {
  display: grid;
  gap: 12px;
  padding: 12px;
  position: fixed;
  top: var(--floating-top);
  right: var(--shell-pad);
  width: var(--tool-rail-width);
  overflow: auto;
  max-height: calc(100vh - var(--floating-top) - var(--shell-pad));
  align-content: start;
  z-index: 20;
}

.annotation-toolbox-body {
  display: grid;
  gap: 0;
}

.panel-right .panel-header,
.panel-left .panel-header {
  background: linear-gradient(180deg, var(--panel-strong), rgba(255, 250, 241, 0.92));
}

.compare-card,
.relation-form {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.98), rgba(255, 250, 241, 0.92));
}

.entity-editor {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.98), rgba(255, 250, 241, 0.92));
}

.entity-editor.empty-state {
  color: var(--muted);
}

.entity-editor-actions,
.relation-item-actions,
.entity-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.secondary-link {
  border: 0;
  background: transparent;
  color: var(--teal);
  padding: 0;
  cursor: pointer;
}

.entity-meta,
.relation-meta {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compare-summary {
  line-height: 1.5;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
  color: var(--ink);
}

.toggle-row input {
  inline-size: 16px;
  block-size: 16px;
}

.compare-list:empty {
  display: none;
}

.entity-item.active {
  border-color: rgba(47, 111, 115, 0.34);
  background: rgba(47, 111, 115, 0.08);
}

.match-chip-exact {
  background: rgba(177, 136, 45, 0.22);
}

.match-chip-partial {
  background: rgba(155, 77, 47, 0.16);
}

.apg-chip {
  background: rgba(47, 111, 115, 0.12);
}

.relation-guidance {
  line-height: 1.5;
}

.panel-left,
.panel-reader,
.panel-right {
  min-height: 0;
}

.panel-left {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.compact-section {
  max-height: 28vh;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

@media (max-width: 1240px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .panel-right {
    grid-column: 1 / -1;
    position: static;
    display: block;
  }

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

  .tool-rail {
    position: static;
    width: auto;
    max-height: none;
    right: auto;
  }

  .compact-section {
    max-height: none;
  }
}

@media (max-width: 860px) {
  html,
  body {
    overflow: auto;
  }

  .shell {
    min-height: auto;
    padding: 10px;
    overflow: visible;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .selection-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 16px;
    flex-direction: column;
    align-items: stretch;
  }

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

  .panel-right,
  .reader {
    overflow: visible;
  }

  .panel-right {
    display: block;
  }

  .selection-card,
  .panel-left,
  .tool-rail {
    position: static;
  }

  .tool-rail {
    overflow: visible;
    max-height: none;
    padding: 10px;
    width: auto;
    right: auto;
  }

  .compact-section {
    max-height: none;
  }
}
