* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  background: #fafaf7;
  color: #1f2933;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
header {
  background: #ffffff;
  color: #14181d;
  padding: 22px 32px;
  border-bottom: 1px solid #e4e1d6;
}
header h1 {
  margin: 0;
  font-family: 'Crimson Pro', 'Times New Roman', serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #14181d;
}
header .subtitle { color: #5b6770; font-size: 13px; margin-top: 3px; font-style: italic; }

.layout {
  display: flex;
  min-height: calc(100vh - 70px);
}

.sidebar {
  width: 280px;
  padding: 24px 22px;
  background: #ffffff;
  border-right: 1px solid #e4e1d6;
  flex-shrink: 0;
}
.sidebar h3 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  color: #5b6770;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'JetBrains Mono', monospace;
}
.sidebar section { margin-bottom: 26px; }
.sidebar label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
  color: #2d3640;
  cursor: pointer;
}
.sidebar label.opt { color: #5b6770; font-size: 13px; margin-top: 6px; }

.extract-mode .mode-pill {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  margin-bottom: 8px;
  border: 1px solid #e4e1d6;
  border-radius: 5px;
  cursor: pointer;
  background: #ffffff;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.extract-mode .mode-pill:hover { border-color: #b8b3a3; }
.extract-mode .mode-pill:has(input:checked) {
  border-color: #14181d;
  background: #ecebe2;
  box-shadow: inset 2px 0 0 #14181d;
}
.extract-mode .mode-pill input {
  margin: 3px 0 0 0;
  flex-shrink: 0;
  accent-color: #14181d;
}
.extract-mode .mode-pill span { font-size: 13px; line-height: 1.4; color: #2d3640; }
.extract-mode .mode-pill strong { color: #14181d; font-weight: 600; font-family: 'Crimson Pro', serif; font-size: 15px; }
.extract-mode .mode-pill small { display: block; color: #5b6770; font-size: 11.5px; margin-top: 3px; font-family: 'JetBrains Mono', monospace; }

.sidebar input[type="file"] {
  width: 100%;
  font-size: 12px;
  padding: 6px 0;
  color: #2d3640;
}
.sidebar button {
  width: 100%;
  padding: 10px 14px;
  font-family: 'Crimson Pro', serif;
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  background: #14181d;
  border: 1px solid #14181d;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.sidebar button:hover { background: #2d3640; }
.sidebar button:disabled { background: #b8b3a3; border-color: #b8b3a3; color: #ecebe2; cursor: not-allowed; }
.sidebar button.secondary { background: #ffffff; color: #14181d; border-color: #d6d3c8; }
.sidebar button.secondary:hover { background: #ecebe2; }
.sidebar .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ── Academic / paper-style benchmark section ── */
#benchmark-section.paper {
  margin: 20px 24px 32px;
  padding: 32px 36px 28px;
  background: #fafaf7;            /* warm off-white, like a printed page */
  border: 1px solid #d6d3c8;
  border-radius: 6px;
  color: #1f2933;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02), 0 6px 20px -10px rgba(31,41,51,0.12);
}

.paper-header { border-bottom: 1px solid #e4e1d6; padding-bottom: 18px; margin-bottom: 22px; }
.paper-tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.06em;
  color: #5b6770;
  background: #ecebe2;
  border-radius: 3px;
  margin-bottom: 10px;
}
.paper-title {
  font-family: 'Crimson Pro', 'Times New Roman', serif;
  font-weight: 600;
  font-size: 28px;
  line-height: 1.2;
  margin: 0 0 6px;
  color: #14181d;
  letter-spacing: -0.01em;
}
.paper-authors {
  font-size: 13px;
  color: #5b6770;
  margin-bottom: 12px;
  font-style: italic;
}
.paper-abstract {
  font-size: 14px;
  line-height: 1.65;
  color: #2d3640;
  text-align: justify;
  hyphens: auto;
  border-left: 3px solid #c8c3b0;
  padding-left: 14px;
  margin: 8px 0;
}

.paper-section {
  font-family: 'Crimson Pro', 'Times New Roman', serif;
  font-weight: 600;
  font-size: 18px;
  color: #1a2027;
  margin: 24px 0 12px;
  letter-spacing: 0.005em;
}

.paper-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.paper-table thead th {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-top: 1.5px solid #14181d;
  border-bottom: 1px solid #14181d;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #14181d;
}
.paper-table .num-col { text-align: right; }
.paper-table tbody td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid #ece9dd;
  vertical-align: middle;
}
.paper-table tbody tr:last-child td { border-bottom: 1.5px solid #14181d; }
.paper-table .pipeline-cell {
  font-family: 'Crimson Pro', serif;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}
.paper-table .pipeline-cell .swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle;
}
.paper-table .backend-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: #4a5560;
}
.paper-table td.num-col {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: #14181d;
}
.paper-table .delta-positive { color: #166534; font-weight: 600; }
.paper-table .delta-negative { color: #991b1b; font-weight: 600; }
.paper-table-empty {
  text-align: center;
  color: #8b95a1;
  font-style: italic;
  padding: 20px 0;
}

.paper-figure {
  margin: 12px 0 18px;
  text-align: center;
}
.paper-figure figcaption {
  font-size: 13px;
  color: #4a5560;
  margin-top: 10px;
  text-align: justify;
  line-height: 1.5;
}

.paper-method {
  font-size: 14px;
  line-height: 1.7;
  color: #2d3640;
  padding-left: 22px;
  margin: 0 0 8px;
}
.paper-method li { margin-bottom: 6px; text-align: justify; }
.paper-method code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: #ecebe2;
  padding: 1px 5px;
  border-radius: 3px;
}

.paper-foot {
  font-size: 12px;
  color: #5b6770;
  text-align: center;
  margin: 24px 0 0;
  padding-top: 14px;
  border-top: 1px solid #e4e1d6;
  font-style: italic;
}
.bench-chart-wrap {
  margin-top: 16px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.bench-chart-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}
.bench-svg {
  display: block;
  width: 100%;
  height: auto;
  background: #ffffff;
  border: 1px solid #d6d3c8;
  border-radius: 4px;
}
.bs-frame { fill: none; stroke: #14181d; stroke-width: 1; }
.bs-axis  { fill: #4a5560; font-size: 11px; font-family: 'JetBrains Mono', monospace; }
.bs-axis-label {
  fill: #14181d; font-size: 12px;
  font-family: 'Crimson Pro', 'Times New Roman', serif;
  font-style: italic;
}
.bs-grid   { stroke: #ece9dd; stroke-width: 1; }
.bs-grid-x { stroke: #f1efe5; }
.bs-legend {
  fill: #14181d; font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
}
.bench-legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin-top: 12px;
  padding: 10px 14px;
  background: #fafaf2;
  border: 1px solid #ece9dd;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: #14181d;
}
.bench-legend-grid .item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1.5;
  white-space: nowrap;
}
.bench-legend-grid .swatch {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.bench-legend-grid .name { font-weight: 600; }
.bench-legend-grid .stats { color: #4a5560; }
.bench-method {
  margin: 16px 0 0;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  font-size: 13px;
  color: #2d3640;
}
.bench-method summary {
  cursor: pointer;
  color: #14181d;
  font-weight: 600;
  user-select: none;
  outline: none;
  font-family: 'Crimson Pro', serif;
}
.bench-method summary:hover { color: #4a5560; }
.bench-method ul {
  margin: 10px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}
.bench-method li { margin-bottom: 4px; }
.bench-method strong { color: #14181d; }

main {
  flex: 1;
  padding: 24px;
  overflow-x: hidden;
}

.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.sample-card {
  background: #ffffff;
  border: 1px solid #e4e1d6;
  border-radius: 4px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.sample-card:hover {
  border-color: #14181d;
  box-shadow: 0 2px 6px rgba(20,24,29,0.06);
}
.sample-card .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #14181d;
  background: #ecebe2;
  border: 1px solid #d6d3c8;
  margin-bottom: 8px;
  font-family: 'JetBrains Mono', monospace;
}
.sample-card .badge.inv { color: #1e3a8a; background: #eaf1fb; border-color: #cfdef4; }
.sample-card .badge.po  { color: #7c2d12; background: #fbf1e8; border-color: #f0d9c1; }
.sample-card .name {
  font-size: 12px;
  color: #4a5560;
  font-family: 'JetBrains Mono', monospace;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.metric {
  background: #ffffff;
  border: 1px solid #e4e1d6;
  border-radius: 4px;
  padding: 14px;
  text-align: center;
}
.metric .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #5b6770;
  margin-bottom: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.metric .value {
  font-size: 22px;
  font-weight: 600;
  color: #14181d;
  font-family: 'Crimson Pro', serif;
}

.two-col {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
}
.canvas-wrap, .fields-wrap {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
}
.canvas-wrap h3, .fields-wrap h3 {
  margin: 0 0 12px;
  font-size: 15px;
}
#page-canvas {
  width: 100%;
  height: auto;
  border: 1px solid #e5e7eb;
  display: block;
}

.field-group {
  margin-bottom: 14px;
}
.field-group-header {
  padding: 6px 12px;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field-row {
  padding: 4px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
}
.field-row .k { color: #6b7280; font-weight: 500; }
.field-row .v { color: #1e1e1e; font-family: 'SF Mono', Menlo, monospace; word-break: break-all; }

details {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 12px;
}
details summary { cursor: pointer; font-weight: 600; font-size: 13px; }
details[open] { padding-bottom: 12px; }
details pre {
  background: #1e1e1e;
  color: #e5e5e5;
  padding: 12px;
  border-radius: 4px;
  overflow: auto;
  font-size: 11px;
  max-height: 300px;
  margin-top: 8px;
}
details table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  margin-top: 8px;
}
details table th, details table td {
  padding: 4px 8px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}
details table th { background: #f3f4f6; }

.relabel-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.relabel-form select {
  flex: 1;
  padding: 6px;
  font-size: 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}
.relabel-form button {
  width: auto;
  padding: 6px 12px;
  font-size: 12px;
}

#loading {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #4338ca;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error {
  background: #fef2f2;
  border: 1px solid #ef4444;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}
.hidden { display: none !important; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid #e5e7eb; }
  .two-col { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
