:root {
  --ink: #17212b;
  --muted: #647487;
  --page: #f4f7f8;
  --panel: #ffffff;
  --line: #d6dde4;
  --shared: #d9f2e3;
  --shared-border: #2f8f5b;
  --variant: #fff1c7;
  --variant-border: #d69319;
  --missing: #eef1f4;
  --focus: #1769e0;
  --base-width: 8.2px;
  --cell-pad: 20px;
  --gap-width: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 248, 0.94);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
}

.runtime {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.runtime.is-busy::before,
.button-spinner {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid #c8d2dc;
  border-top-color: var(--focus);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

main {
  padding: 20px 24px 34px;
}

.control-strip {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.upload-box {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px dashed #8fa1b3;
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  font-weight: 720;
}

.upload-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

select,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

select {
  min-width: 180px;
  padding: 0 10px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 720;
}

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

button[aria-disabled="true"] {
  opacity: 0.86;
  cursor: progress;
}

button:focus-visible,
select:focus-visible,
.upload-box:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.file-list,
.summary,
.downloads {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.file-pill,
.summary span {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
}

.downloads button {
  min-height: 36px;
}

.button-spinner {
  display: none;
}

#build-button.is-loading .button-spinner {
  display: inline-block;
}

.viewer-shell {
  margin-top: 16px;
}

.legend {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-bottom: 14px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.view-title {
  margin: 16px 0 8px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.2;
  font-weight: 820;
}

.swatch {
  width: 18px;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.swatch.shared {
  background: var(--shared);
  border-color: var(--shared-border);
}

.swatch.variant {
  background: var(--variant);
  border-color: var(--variant-border);
}

.swatch.missing {
  background: var(--missing);
}

.swatch.path {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #db2777, #7c3aed);
}

.matrix {
  display: grid;
  grid-template-columns: 180px max-content;
  overflow: auto;
  max-height: calc(100vh - 280px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(20, 35, 50, 0.08);
}

.corner,
.genome-name {
  position: sticky;
  left: 0;
  z-index: 10;
  background: #fbfcfd;
  border-right: 1px solid var(--line);
}

.corner {
  top: 0;
  z-index: 18;
  padding: 12px 14px;
  font-weight: 780;
  border-bottom: 1px solid var(--line);
}

.axis,
.sequence-row {
  display: grid;
  width: max-content;
  min-width: max-content;
}

.axis {
  position: sticky;
  top: 0;
  z-index: 12;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.axis-block,
.seq-block {
  appearance: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-left: 0;
  border-bottom: 0;
  border-right: 1px solid rgba(99, 114, 130, 0.24);
}

.axis-block {
  display: block;
  padding: 8px 10px;
  border-top: 0;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
}

.axis-block span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 760;
}

.axis-block small {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 12px;
}

.genome-name {
  padding: 14px;
  font-weight: 780;
  border-bottom: 1px solid var(--line);
}

.sequence-row {
  border-bottom: 1px solid var(--line);
}

.seq-block {
  display: block;
  min-width: 0;
  min-height: 52px;
  padding: 10px;
  text-align: left;
  overflow-x: auto;
  overflow-y: hidden;
}

.seq-block.shared {
  background: var(--shared);
  border-top: 3px solid var(--shared-border);
}

.seq-block.variant {
  background: var(--variant);
  border-top: 3px solid var(--variant-border);
}

.seq-block.missing {
  width: var(--gap-width);
  justify-self: center;
  background: var(--missing);
  color: #a0a9b3;
  border-top: 3px solid #c7ced6;
  text-align: center;
  cursor: default;
}

.axis-block:hover,
.seq-block:not(.missing):hover {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.graph-view {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 280px);
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(20, 35, 50, 0.08);
}

.graph-canvas {
  position: relative;
  min-width: 100%;
  background:
    linear-gradient(90deg, rgba(214, 221, 228, 0.34) 1px, transparent 1px) 0 0 / 90px 100%,
    linear-gradient(180deg, #ffffff, #f8fbfa);
}

.graph-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.graph-lane-rail {
  stroke: #dfe6ec;
  stroke-width: 2;
  stroke-dasharray: 6 12;
}

.graph-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
  opacity: 0.72;
  mix-blend-mode: multiply;
}

.graph-lane-label {
  position: sticky;
  left: 0;
  z-index: 8;
  width: 158px;
  transform: translateY(-50%);
  padding: 7px 18px 7px 20px;
  border-right: 1px solid var(--line);
  background: linear-gradient(90deg, #fbfcfd 0 78%, rgba(251, 252, 253, 0));
  color: var(--ink);
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-lane-label::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 5px;
  height: 26px;
  border-radius: 999px;
  background: var(--lane-color);
  transform: translateY(-50%);
}

.graph-node {
  position: absolute;
  z-index: 12;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr 1fr;
  align-items: center;
  column-gap: 8px;
  row-gap: 1px;
  min-height: 0;
  padding: 7px 10px 13px;
  border-radius: 8px;
  text-align: left;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.96),
    0 0 0 5px rgba(255, 255, 255, 0.72),
    0 0 14px 6px rgba(255, 255, 255, 0.46),
    0 6px 16px rgba(20, 35, 50, 0.12);
}

.graph-node.shared {
  border: 2px solid var(--shared-border);
  background: var(--shared);
}

.graph-node.variant {
  border: 2px solid var(--variant-border);
  background: var(--variant);
}

.graph-node:hover {
  outline: 3px solid rgba(23, 105, 224, 0.35);
  outline-offset: 2px;
}

.graph-node .node-port-rail {
  position: absolute;
  inset: auto 8px 5px;
  display: grid;
  grid-template-columns: repeat(var(--support-count), minmax(0, 1fr));
  gap: 3px;
  pointer-events: none;
}

.graph-node .node-port-rail i {
  display: block;
  height: 4px;
  border-radius: 999px;
}

.graph-node .node-id {
  grid-row: 1 / 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  font-weight: 820;
  font-size: 12px;
}

.graph-node code {
  overflow: hidden;
  text-overflow: ellipsis;
}

.graph-node .node-meta {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

code {
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  letter-spacing: 0;
  white-space: pre;
}

.details-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(20, 35, 50, 0.06);
}

.details-empty,
.details-content {
  padding: 16px;
}

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

.details-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.details-head h2 {
  margin: 0;
  font-size: 18px;
}

.details-head p {
  margin: 3px 0 0;
  color: var(--muted);
}

.details-content dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.details-content dt {
  color: var(--muted);
  font-size: 12px;
}

.details-content dd {
  margin: 2px 0 0;
  font-weight: 760;
}

.coordinate-section {
  margin-bottom: 12px;
}

.coordinate-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

#detail-coordinates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#detail-coordinates li {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfd;
}

#detail-coordinates span {
  color: var(--muted);
}

.details-content label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

#detail-sequence {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--ink);
  background: #fbfcfd;
  font: 13px/1.5 "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (max-width: 720px) {
  .app-header,
  main {
    padding-inline: 14px;
  }

  .matrix,
  .graph-view {
    max-height: calc(100vh - 240px);
  }

  .matrix {
    grid-template-columns: 120px max-content;
  }

  .graph-lane-label {
    width: 136px;
    font-size: 13px;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
