:root {
  color-scheme: light;
  --bg: #eef2ed;
  --panel: #fbfcfb;
  --panel-2: #f4f7f6;
  --ink: #17211f;
  --muted: #5d6f69;
  --line: #cdd8d4;
  --accent: #176b87;
  --accent-2: #b33951;
  --gold: #b48118;
  --green: #30795a;
  --focus: #1f7a9b;
  --empty: #edf1f0;
  --filled: #d9edf1;
  --ease-smooth: cubic-bezier(.22, 1, .36, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

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

.shell {
  display: grid;
  grid-template-columns: 240px minmax(380px, 1fr) minmax(420px, 1.2fr);
  gap: 12px;
  height: 100vh;
  padding: 12px;
  transition: grid-template-columns 650ms var(--ease-smooth), gap 650ms var(--ease-smooth);
}

.panel {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  transition: opacity 650ms var(--ease-smooth), transform 650ms var(--ease-smooth), border-color 650ms var(--ease-smooth);
}

.datasets,
.editor,
.viewer {
  display: flex;
  flex-direction: column;
}

.datasets {
  padding: 14px;
  gap: 16px;
}

.brand h1,
.section-head h2,
.backup h2,
.details h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.05;
}

.brand p,
.section-head p,
.details p,
.details ul,
.backup p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.field.inline {
  grid-auto-flow: column;
  align-items: center;
}

select,
.name-input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 5px 8px;
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.button-row button {
  min-width: 34px;
}

.button-row.wide button,
.button-stack button,
.file-button {
  flex: 1;
}

.button-row.wide .icon-button {
  flex: 0 0 42px;
  min-width: 42px;
  font-size: 18px;
  line-height: 1;
  transition: background 250ms ease, border-color 250ms ease, transform 250ms var(--ease-smooth);
}

.button-row.wide .icon-button:hover {
  transform: translateX(2px);
}

.button-stack {
  display: grid;
  gap: 8px;
}

.file-button {
  display: grid;
  place-items: center;
  position: relative;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.backup {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.backup h2 {
  font-size: 13px;
  margin-bottom: 8px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.section-head h2 {
  font-size: 18px;
}

.grid-wrap {
  overflow: auto;
  min-height: 0;
}

.data-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 620px;
}

.data-grid th,
.data-grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 7px;
  background: #fff;
  vertical-align: middle;
}

.data-grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8faf9;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}

.name-input {
  width: 100%;
  min-width: 130px;
}

.trait-head {
  display: grid;
  gap: 6px;
  min-width: 155px;
}

.trait-actions {
  display: flex;
  gap: 4px;
}

.trait-actions button,
.row-delete {
  min-height: 28px;
  min-width: 28px;
  padding: 3px 7px;
}

.tri-state {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 132px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.tri-state button {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  min-height: 30px;
  padding: 3px 0;
  font-size: 12px;
}

.tri-state button:last-child {
  border-right: 0;
}

.tri-state .active[data-value="true"] {
  background: color-mix(in srgb, var(--green) 18%, white);
  color: #173d2c;
}

.tri-state .active[data-value="false"] {
  background: color-mix(in srgb, var(--accent-2) 14%, white);
  color: #632032;
}

.tri-state .active[data-value="unknown"] {
  background: #e5eae8;
}

.viewer {
  min-width: 0;
}

.shell.editor-expanded {
  grid-template-columns: 240px minmax(0, 1fr) 0fr;
}

.shell.editor-expanded .viewer {
  opacity: 0;
  transform: translateX(28px) scale(.985);
  border-color: transparent;
  pointer-events: none;
}

.shell.editor-expanded .editor {
  min-width: 0;
}

.shell.editor-expanded #expandEditorBtn {
  background: color-mix(in srgb, var(--accent) 12%, white);
  border-color: var(--accent);
}

.shell.editor-expanded #expandEditorBtn:hover {
  transform: translateX(-2px);
}

.viewer-head {
  align-items: flex-start;
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  color: var(--muted);
  font-weight: 650;
}

.trait-picker {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.chip,
.trait-picker select {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 4px 10px;
  color: var(--ink);
}

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

.chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chip-color, var(--accent));
}

.venn-stage {
  min-height: 360px;
  flex: 1;
  padding: 12px;
  background: #f7f9f8;
}

#vennSvg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.universe {
  fill: #fff;
  stroke: var(--line);
  stroke-width: 3;
}

.region {
  fill: var(--empty);
  stroke: #7f918c;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  transition: fill 120ms ease, stroke 120ms ease, opacity 120ms ease;
}

.region.filled {
  fill: var(--filled);
}

.set-fill {
  fill: color-mix(in srgb, var(--set-color) 12%, transparent);
  stroke: none;
  pointer-events: none;
}

.region.dense {
  stroke: transparent;
  stroke-width: .7;
}

.region.active {
  fill: #f6d98d;
  stroke: #73510f;
  stroke-width: 2.4;
}

.set-outline {
  fill: none;
  stroke: var(--set-color);
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  opacity: .95;
  pointer-events: none;
}

.set-label {
  fill: var(--ink);
  font-size: 20px;
  font-weight: 750;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  stroke-linejoin: round;
  pointer-events: none;
}

.count-label {
  fill: #20302c;
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.hover-assist {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.details {
  border-top: 1px solid var(--line);
  padding: 14px;
  flex: 0 0 164px;
  height: 164px;
  background: var(--panel);
  overflow: hidden;
}

.details h3 {
  font-size: 15px;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-height: 36px;
  overflow: hidden;
}

.tag {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
}

.match-line {
  min-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1160px) {
  .shell {
    grid-template-columns: 220px 1fr;
    grid-template-rows: minmax(420px, 1fr) minmax(520px, 1.2fr);
    height: auto;
    min-height: 100vh;
  }

  .viewer {
    grid-column: 1 / -1;
  }

  .shell.editor-expanded {
    grid-template-columns: 220px 1fr;
    grid-template-rows: minmax(520px, 1fr) 0fr;
  }

  .shell.editor-expanded .viewer {
    grid-column: 1 / -1;
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
    padding: 8px;
  }

  .panel {
    margin-bottom: 10px;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

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