* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1d2524;
  background: #f7f3ec;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.match-page {
  height: auto;
  overflow: auto;
}
.topbar {
  flex: 0 0 auto;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: #fffdf8;
  border-bottom: 1px solid #ddd8cc;
}
h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: 0; }
h2 { margin: 0 0 10px; font-size: 16px; }
h3 { margin: 16px 0 8px; font-size: 14px; }
p { margin: 0 0 8px; color: #54605d; }
.controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.controls-extra,
.filter-mobile-head,
.filter-body {
  display: contents;
}
.mobile-toggle {
  display: none;
}
.filter-strip {
  flex: 1 0 100%;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #f8f5ee;
}
.filter-strip label {
  display: grid;
  gap: 4px;
  min-width: 170px;
}
.filter-strip select {
  width: 100%;
  max-width: none;
}
.filter-strip input {
  width: 100%;
}
.compact-field {
  max-width: 130px;
}
.period-field {
  flex: 1 1 320px;
  min-width: 260px;
}
.filter-strip button {
  white-space: nowrap;
}
.filter-strip label span,
.filter-title {
  color: #65706c;
  font-size: 12px;
  font-weight: 700;
}
.filter-title {
  align-self: center;
  color: #2e3835;
  white-space: nowrap;
}
.result-count {
  align-self: center;
  margin-left: 0;
  padding: 6px 9px;
  border: 1px solid #d7d0c4;
  border-radius: 999px;
  background: #fffdf8;
  color: #2e3835;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.filter-status {
  align-self: center;
  flex: 1 1 260px;
  color: #65706c;
  font-size: 12px;
  line-height: 1.35;
}
.filter-status.invalid {
  color: #8f3d2d;
}
input, select, button, .button {
  min-height: 34px;
  border: 1px solid #bfc8c4;
  border-radius: 6px;
  background: #fff;
  color: #1d2524;
  padding: 6px 10px;
  font: inherit;
}
select { max-width: 170px; }
button, .button {
  cursor: pointer;
  text-decoration: none;
  background: #1f6760;
  border-color: #1f6760;
  color: #fff;
}
.layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 390px;
  min-height: 0;
  flex: 1 1 auto;
}
.graph-wrap { position: relative; min-width: 0; overflow: hidden; background: #f7f3ec; }
#cy { width: 100%; height: 100%; display: block; }
.groups-panel {
  overflow: auto;
  padding: 14px;
  background: #fffdf8;
  border-right: 1px solid #ddd8cc;
}
.panel-head {
  padding-bottom: 10px;
  border-bottom: 1px solid #ebe5d8;
}
.group-list {
  display: grid;
  gap: 8px;
  padding-top: 10px;
}
.group-card {
  width: 100%;
  min-height: 74px;
  display: block;
  text-align: left;
  padding: 10px;
  border: 1px solid #ded7ca;
  border-radius: 7px;
  background: #fff;
  color: #1d2524;
  cursor: pointer;
}
.group-card:hover,
.group-card.active {
  border-color: #1f6760;
  background: #f4fbf8;
}
.group-title {
  display: block;
  margin-bottom: 4px;
  font-weight: 750;
}
.group-meta {
  color: #65706c;
  font-size: 12px;
  line-height: 1.35;
}
.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 310px;
  padding: 9px 10px;
  border: 1px solid #cfc8bb;
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: 0 10px 22px rgba(29, 36, 40, 0.14);
  color: #26312e;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}
.panel {
  overflow: auto;
  padding: 16px;
  background: #fffdf8;
  border-left: 1px solid #ddd8cc;
}
.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 250px);
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid #ddd8cc;
  border-radius: 7px;
  font-size: 12px;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.dot.times { background: #26746f; }
.dot.ob-theft { background: #99663d; }
.dot.ob-violent { background: #b24c39; }
.dot.ob-deception { background: #6f79a8; }
.dot.ob-kill { background: #7f4a5f; }
.dot.ob-other { background: #6c7f8f; }
.line { display: inline-block; width: 24px; height: 2px; margin-right: 5px; vertical-align: 3px; }
.line.high { background: #445a70; }
.line.medium { background: #a29178; }
.node { stroke: #fffdf8; stroke-width: 1.2; cursor: pointer; opacity: 0.88; }
.node.times { fill: #0f766e; }
.node.dimmed { opacity: 0.12; }
.node.highlight,
.node.selected { stroke: #101817; stroke-width: 3; opacity: 1; }
.edge {
  stroke: #687a83;
  stroke-opacity: 0.18;
  cursor: pointer;
  pointer-events: stroke;
}
.edge.medium { stroke: #8d7f69; }
.edge.high { stroke: #445a70; }
.edge.dimmed { opacity: 0.04; pointer-events: none; }
.edge.hidden,
.node.hidden { display: none; }
.edge.selected { stroke-opacity: 0.68; }
.edge:hover { stroke-opacity: 0.85; }
.year-label { fill: #7c827f; font-size: 12px; pointer-events: none; }
.section {
  padding: 12px 0;
  border-top: 1px solid #ebe5d8;
}
.kv {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 5px 10px;
  font-size: 13px;
}
.kv b { color: #65706c; font-weight: 600; }
.pill {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e9eee9;
  color: #2e3835;
  font-size: 12px;
}
.pill.high { background: #d9e4ef; }
.pill.medium { background: #eee7d9; }
.small { font-size: 12px; color: #65706c; }
#visibleSummary {
  padding-left: 4px;
  color: #485551;
  font-weight: 650;
}
.list { display: grid; gap: 8px; }
.item {
  padding: 9px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #fff;
}
.item button {
  width: 100%;
  text-align: left;
  background: #fff;
  color: #1d2524;
  border-color: #d7d0c4;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.secondary {
  background: #fff;
  border-color: #bfc8c4;
  color: #1d2524;
}
.raw-json {
  display: none;
}
.raw-json.open {
  display: block;
}
.json-viewer {
  white-space: normal;
  line-height: 1.45;
}
.json-line {
  padding-left: calc(var(--depth) * 16px);
}
.json-key {
  color: #68451f;
  font-weight: 700;
}
.json-string {
  color: #28527a;
}
.json-number,
.json-boolean {
  color: #6f3a73;
}
.json-null {
  color: #7a766d;
  font-style: italic;
}
.json-string-block {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 6px 0 8px;
  padding: 8px;
  border: 1px solid #e4ded2;
  border-radius: 6px;
  background: #f7f4ed;
  color: #2e3835;
}
.pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 420px;
  overflow: auto;
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #fff;
  color: #2e3835;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}
.modal[hidden] {
  display: none;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}
.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(29, 37, 36, 0.45);
}
.modal-card {
  position: absolute;
  inset: 28px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #cfc8bb;
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 24px 60px rgba(29, 36, 40, 0.28);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid #ddd8cc;
}
.modal-content {
  min-width: 0;
  overflow: auto;
  padding: 16px;
}
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
}
.metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #fff;
}
.metric strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
}
.metric span {
  color: #65706c;
  font-size: 12px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.stat-block {
  min-width: 0;
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #fff;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 58px;
  gap: 8px;
  align-items: center;
  margin: 7px 0;
  font-size: 12px;
}
.bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-count {
  text-align: right;
  color: #65706c;
}
.bar-track {
  grid-column: 1 / -1;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece7dc;
}
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: #1f6760;
}
#statsContent {
  padding: 10px;
}
#statsContent .stats-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0;
}
#statsContent .stat-block {
  padding: 7px 8px;
  border-radius: 6px;
}
#statsContent .stat-block h3 {
  margin: 0 0 5px;
  font-size: 12px;
  line-height: 1.2;
}
#statsContent .bar-row {
  grid-template-columns: minmax(64px, 1fr) 40px;
  gap: 4px 6px;
  margin: 3px 0;
  font-size: 11px;
}
#statsContent .bar-track {
  height: 3px;
}
.year-stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.year-stat-card {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #e4ded2;
  border-radius: 6px;
  background: #fff;
}
.year-stat-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}
.year-stat-card h3 {
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
}
.year-stat-card header span {
  color: #65706c;
  font-size: 11px;
  font-weight: 650;
}
.year-stat-list {
  display: grid;
  gap: 3px;
}
.year-stat-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  min-height: 18px;
  font-size: 11px;
}
.year-stat-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.year-stat-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.year-stat-row b {
  font-variant-numeric: tabular-nums;
  color: #1d2524;
}
.year-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  font-size: 12px;
}
.year-table th,
.year-table td {
  padding: 6px 7px;
  border-bottom: 1px solid #ebe5d8;
  text-align: right;
}
.year-table th:first-child,
.year-table td:first-child {
  text-align: left;
}
.unlinked-filters {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 10px;
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.96);
}
.unlinked-filters input {
  min-width: 260px;
  flex: 1 1 280px;
}
.trial-list {
  display: grid;
  gap: 8px;
}
.trial-card {
  padding: 10px;
  border: 1px solid #e4ded2;
  border-radius: 7px;
  background: #fff;
}
.trial-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}
.trial-card strong {
  overflow-wrap: anywhere;
}
.trial-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}
.trial-meta span {
  padding: 2px 7px;
  border-radius: 999px;
  background: #e9eee9;
  color: #2e3835;
  font-size: 12px;
}
.trial-meta .candidate {
  background: #eee7d9;
  color: #68451f;
}
.match-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}
.match-card {
  min-width: 0;
  padding: 16px;
  background: #fffdf8;
  border: 1px solid #ddd8cc;
  border-radius: 8px;
}
.wide { grid-column: 1 / -1; }
@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
    overflow-x: hidden;
  }
  .topbar {
    align-items: flex-start;
    padding: 12px 14px;
  }
  .topbar > div:first-child {
    width: 100%;
    min-width: 0;
  }
  .controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    justify-content: stretch;
    overflow: visible;
    padding-bottom: 0;
  }
  .controls input {
    width: 100%;
    min-width: 0;
    grid-column: span 2;
  }
  .control-toggle {
    display: block;
    grid-column: 1 / -1;
  }
  .controls-extra {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .controls-extra.is-collapsed {
    display: none;
  }
  .controls button,
  .controls .button {
    width: 100%;
    min-width: 0;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }
  .filter-strip {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }
  .filter-mobile-head {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .filter-toggle {
    display: block;
    width: auto;
    min-width: 120px;
  }
  .filter-body {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
  }
  .filter-strip.is-collapsed .filter-body {
    display: none;
  }
  .filter-strip label {
    min-width: 0;
    max-width: none;
    width: 100%;
    flex: none;
  }
  .compact-field {
    max-width: none;
  }
  .period-field {
    min-width: 0;
    grid-column: span 2;
  }
  .filter-strip button {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }
  .filter-status,
  .result-count {
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
    flex: none;
  }
  .result-count {
    margin-left: 0;
    text-align: center;
    white-space: normal;
  }
  .layout {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .graph-wrap {
    order: 1;
    height: 62vh;
    height: 62svh;
    min-height: 420px;
    border-bottom: 1px solid #ddd8cc;
  }
  .groups-panel {
    order: 2;
    max-height: 44vh;
    max-height: 44svh;
    border-right: 0;
    border-bottom: 1px solid #ddd8cc;
  }
  .panel {
    order: 3;
    border-left: 0;
    border-top: 1px solid #ddd8cc;
  }
  .legend { max-width: none; right: 14px; flex-wrap: wrap; }
  .match-layout { grid-template-columns: 1fr; }
  .modal-card { inset: 10px; }
  .modal-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .metrics-grid,
  .stats-grid { grid-template-columns: 1fr; }
  .year-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #statsContent .stats-grid,
  #statsContent .yearly-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .unlinked-filters input {
    min-width: 0;
  }
}
@media (max-width: 560px) {
  .topbar {
    padding: 12px;
  }
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .controls-extra {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .controls input {
    grid-column: 1 / -1;
    order: -1;
  }
  .filter-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding: 10px;
  }
  .filter-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  .period-field {
    grid-column: 1 / -1;
  }
  .legend {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 7px 9px;
    font-size: 11px;
  }
  #visibleSummary {
    flex-basis: 100%;
  }
  .year-stats-grid,
  #statsContent .stats-grid,
  #statsContent .yearly-stats-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 420px) {
  .filter-strip {
    grid-template-columns: 1fr;
  }
  .filter-body {
    grid-template-columns: 1fr;
  }
  .filter-strip > *,
  .filter-body > * {
    grid-column: 1 / -1;
  }
}
