:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-soft: #ece8df;
  --ink: #17202a;
  --muted: #68717a;
  --line: #c8c3b9;
  --grid: #d8d3ca;
  --current: #1d6e72;
  --current-soft: #a9d4d2;
  --added: #14815a;
  --removed: #c35046;
  --match: #e29d2d;
  --processing-key: #7653aa;
  --device-key: #b97817;
  --covered: #467b96;
  --uncovered: #d78b75;
  --focus: #7b4acb;
  --shadow: 0 18px 50px rgb(48 45 38 / 10%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121718;
    --surface: #192123;
    --surface-soft: #232d2f;
    --ink: #edf3f1;
    --muted: #a8b2b0;
    --line: #3b4749;
    --grid: #2d383a;
    --current: #6bb7b6;
    --current-soft: #315f60;
    --added: #62c79b;
    --removed: #ef8175;
    --match: #f1b84c;
    --processing-key: #b494e7;
    --device-key: #efb54f;
    --covered: #6ba7c1;
    --uncovered: #d97d69;
    --focus: #b692f6;
    --shadow: 0 18px 50px rgb(0 0 0 / 24%);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--current) 12%, transparent), transparent 28rem),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"] {
  min-height: 2.65rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--surface);
  color: var(--ink);
}

button {
  padding: 0.6rem 0.95rem;
  cursor: pointer;
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
  outline-offset: 2px;
}

select,
input[type="text"] {
  padding: 0.55rem 0.7rem;
}

code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.site-header,
main,
footer {
  width: min(1500px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 3rem 0 1.8rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.1rem, 6vw, 4.8rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  font-weight: 600;
}

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.header-note {
  max-width: 35rem;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

main {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

main > section {
  padding: 1.4rem;
  border-bottom: 1px solid var(--line);
}

.controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 1rem 1.3rem;
  background: var(--surface-soft);
}

.controls label:not(.check-control),
.entry-picker,
.viewport-controls label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.version-picker {
  flex: 0 0 auto;
}

.history-picker {
  flex: 0 0 auto;
}

#history-select {
  width: 9rem;
  max-width: 100%;
}

#version-select {
  width: 7.25rem;
  max-width: 100%;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.65rem;
  color: var(--ink);
  font-size: 0.88rem;
}

.check-control input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--current);
}

.step-buttons {
  display: flex;
  gap: 0.4rem;
}

.device-search {
  display: grid;
  flex: 1 1 28rem;
  gap: 0.35rem;
  min-width: min(100%, 24rem);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.device-search > div {
  display: flex;
  gap: 0.4rem;
}

.device-search input {
  flex: 1 1 12rem;
  min-width: 8rem;
}

.device-search output {
  min-height: 1.1rem;
  font-weight: 500;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding-block: 1rem;
}

.summary > div {
  display: grid;
  gap: 0.25rem;
  padding: 0.2rem 1rem;
  border-right: 1px solid var(--line);
}

.summary > div:last-child {
  border-right: 0;
}

.summary span {
  color: var(--muted);
  font-size: 0.78rem;
}

.summary strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
  font-weight: 400;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.heading-actions {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.65rem 0.9rem;
}

.collapse-toggle {
  min-width: 5.5rem;
}

.collapsible-content[hidden] {
  display: none;
}

section:has(> .collapsible-content[hidden]) > .section-heading {
  margin-bottom: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.65rem 1rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.15rem;
  background: var(--current);
}

.swatch.covered { background: var(--covered); }
.swatch.uncovered { background: var(--uncovered); }
.swatch.added { background: var(--added); }
.swatch.removed { background: var(--removed); }
.swatch.match { background: var(--match); transform: rotate(45deg); }
.swatch.family-center { background: var(--current); border-radius: 50%; }
.swatch.family-u { background: var(--added); }
.swatch.family-v { background: var(--removed); transform: rotate(45deg); }
.swatch.processing-key { background: var(--processing-key); }
.swatch.device-key { background: var(--device-key); }

.coverage-map,
#tree-overview,
#subset-tree,
#family-tree {
  display: block;
  width: 100%;
  height: auto;
  color: var(--ink);
}

.family-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.45rem;
}

.family-controls label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.family-legend {
  justify-content: start;
  margin-bottom: 0.5rem;
}

.family-tree {
  max-height: 46rem;
}

.family-details {
  display: grid;
  grid-template-columns: minmax(13rem, 0.32fr) minmax(0, 1fr);
  gap: 1.2rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.family-details h3 {
  margin: 0 0 0.35rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 400;
}

.family-details p {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.family-details code {
  color: var(--ink);
}

.family-key-records {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.55rem;
}

.family-key-record {
  padding: 0.6rem 0.7rem;
  border-left: 3px solid var(--processing-key);
  background: var(--surface-soft);
  font-size: 0.75rem;
  line-height: 1.5;
}

.family-key-record.device {
  border-left-color: var(--device-key);
}

.family-key-record strong,
.family-key-record code {
  display: block;
}

.viewport-controls {
  display: grid;
  grid-template-columns: minmax(10rem, 0.7fr) minmax(14rem, 1.3fr) auto;
  align-items: end;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.viewport-controls label span {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.viewport-controls input[type="range"] {
  width: 100%;
  accent-color: var(--current);
}

.tree-frame {
  position: relative;
}

.tooltip {
  position: absolute;
  z-index: 3;
  display: none;
  max-width: 22rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.75rem;
  line-height: 1.45;
  pointer-events: none;
}

.chart-caption,
.muted {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(15rem, 0.36fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.entry-picker {
  min-width: min(100%, 25rem);
}

.entry-details {
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border-left: 3px solid var(--current);
  background: var(--surface-soft);
}

.entry-details h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 400;
}

.entry-details dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.45rem 0.9rem;
  margin: 0;
  font-size: 0.8rem;
}

.entry-details dt {
  color: var(--muted);
}

.entry-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.status-badge {
  width: fit-content;
  padding: 0.18rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 99rem;
  color: var(--current);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge.added { color: var(--added); }
.status-badge.removed { color: var(--removed); }
.status-badge.match { color: var(--match); }

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  padding: 0.65rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td:nth-child(-n + 3) {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.load-error {
  margin: 0;
  padding: 0 1.4rem;
  color: var(--removed);
  font-weight: 650;
}

footer {
  padding: 1.2rem 0 2rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
}

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

svg text {
  fill: var(--muted);
  font-family: inherit;
  font-size: 11px;
}

svg .grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

svg .axis-line {
  stroke: var(--line);
  stroke-width: 1;
}

svg .entry-link {
  fill: none;
  stroke: var(--current);
  stroke-width: 1;
  opacity: 0.38;
  vector-effect: non-scaling-stroke;
}

svg .entry-u {
  fill: var(--current);
  opacity: 0.52;
}

svg .entry-v {
  fill: var(--surface);
  stroke: var(--current);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

svg .entry-group.added .entry-link,
svg .entry-group.added .entry-v { stroke: var(--added); }
svg .entry-group.added .entry-u { fill: var(--added); }
svg .entry-group.removed .entry-link,
svg .entry-group.removed .entry-v { stroke: var(--removed); }
svg .entry-group.removed .entry-u { fill: var(--removed); }
svg .entry-group.is-match .entry-link,
svg .entry-group.is-match .entry-v { stroke: var(--match); }
svg .entry-group.is-match .entry-u { fill: var(--match); opacity: 0.9; }
svg .entry-group.is-selected .entry-link { stroke-width: 3; opacity: 1; }
svg .entry-group.is-selected .entry-u { opacity: 1; }
svg .entry-group.is-selected .entry-v { stroke-width: 3; }

svg .tree-node {
  fill: var(--surface);
  stroke: var(--current);
  stroke-width: 2;
}

svg .tree-node.excluded {
  stroke: var(--removed);
  stroke-width: 3;
}

svg .tree-node.covered-sibling {
  fill: color-mix(in srgb, var(--current) 20%, var(--surface));
}

svg .tree-edge {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
}

svg .tree-edge.path {
  stroke: var(--current);
}

svg .family-edge {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

svg .family-node {
  cursor: pointer;
}

svg .family-node rect.node-surface {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

svg .family-node:hover rect.node-surface {
  fill: var(--surface-soft);
  stroke: var(--current);
}

svg .family-node.is-center rect.node-surface {
  fill: color-mix(in srgb, var(--current) 16%, var(--surface));
  stroke: var(--current);
  stroke-width: 3;
}

svg .family-node.is-selected-u rect.node-surface {
  stroke: var(--added);
  stroke-width: 3;
}

svg .family-node.is-selected-v rect.node-surface {
  stroke: var(--removed);
  stroke-width: 3;
}

svg .family-node .processing-mark {
  fill: var(--processing-key);
}

svg .family-node .device-mark {
  fill: var(--device-key);
}

svg .family-node .node-title {
  fill: var(--ink);
  font-weight: 650;
}

svg .family-node .node-meta {
  fill: var(--muted);
  font-size: 9px;
}

svg .coverage-covered { fill: var(--covered); }
svg .coverage-uncovered { fill: var(--uncovered); }

@media (max-width: 900px) {
  .site-header {
    display: grid;
    padding-top: 2rem;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary > div:nth-child(2) {
    border-right: 0;
  }

  .summary > div:nth-child(-n + 2) {
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--line);
  }

  .summary > div:nth-child(n + 3) {
    padding-top: 0.8rem;
  }

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

  .family-details {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 650px) {
  .site-header,
  main,
  footer {
    width: min(100% - 1rem, 1500px);
  }

  main > section {
    padding: 1rem;
  }

  .section-heading,
  .overview-heading {
    align-items: start;
    flex-direction: column;
  }

  .heading-actions {
    justify-content: start;
  }

  .family-controls {
    justify-content: start;
  }

  .legend {
    justify-content: start;
  }

  .viewport-controls {
    grid-template-columns: 1fr;
  }

  .device-search > div {
    flex-wrap: wrap;
  }

  .device-search input {
    flex-basis: 100%;
  }

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

  .summary > div,
  .summary > div:nth-child(2) {
    padding: 0.65rem 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary > div:last-child {
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
