:root {
  color-scheme: light;
  --bg: #e8edf2;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --canvas: #0b1118;
  --canvas-2: #121b26;
  --text: #172231;
  --muted: #657386;
  --border: #d4dde8;
  --border-strong: #b8c5d3;
  --blue: #246bfe;
  --cyan: #00a7c7;
  --green: #12a87e;
  --acid: #a7f43d;
  --magenta: #d942b8;
  --shadow: 0 18px 42px rgba(17, 28, 43, 0.08);
  --radius: 8px;
  --chrome: 60px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
@media (min-width: 841px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }
}
body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.78), rgba(255,255,255,0) 180px),
    var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-rows: var(--chrome) minmax(0, 1fr) 34px;
  overflow: hidden;
}

.topbar {
  height: var(--chrome);
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(460px, 720px) 40px;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #06141d;
  background: linear-gradient(135deg, var(--acid), var(--cyan));
  flex: 0 0 auto;
}
.brand-mark svg { width: 22px; height: 22px; }

h1, h2, p { margin: 0; }
h1 { font-size: 15px; line-height: 18px; font-weight: 800; }
h2 { font-size: 13px; line-height: 18px; font-weight: 800; }
.brand p, .preview-header p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.command-bar {
  display: grid;
  grid-template-columns: 160px minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
}

.seed-field, .range-field {
  min-width: 0;
  display: grid;
  gap: 4px;
}
.seed-field span, .range-label span {
  color: var(--muted);
  font-size: 10px;
  line-height: 12px;
  font-weight: 760;
  text-transform: uppercase;
}
.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
output {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 306px minmax(460px, 1fr) 342px;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: 0; }
.section-heading-row, .label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lab-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}

.recipe-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.recipe-button {
  width: 100%;
  display: grid;
  gap: 3px;
  text-align: left;
  min-height: 58px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.recipe-button strong {
  font-size: 12px;
  line-height: 16px;
  font-weight: 820;
}
.recipe-button span {
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
}
.recipe-button:hover, .recipe-button.selected {
  border-color: rgba(0, 167, 199, 0.55);
  background: linear-gradient(90deg, rgba(167,244,61,0.16), rgba(0,167,199,0.08));
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}
.field label, .toggle-row, .flip-grid label {
  color: #314057;
  font-size: 12px;
  line-height: 16px;
  font-weight: 720;
}
select, input[type="text"] {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: #fff;
  outline: none;
}
select:focus, input[type="text"]:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 167, 199, 0.14);
}
input[type="range"] { width: 100%; accent-color: var(--cyan); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--cyan); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.segmented-button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}
.segmented-button.selected {
  color: var(--text);
  background: #fff;
  box-shadow: 0 2px 8px rgba(17, 28, 43, 0.08);
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
}

.genome-list, .process-stack, .transcript-stats {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.gene-card, .process-row {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.gene-card {
  padding: 10px;
  display: grid;
  gap: 8px;
}
.gene-card::before, .process-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--gene-color, var(--cyan));
}
.gene-head, .process-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.gene-name, .process-name {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.gene-name select {
  min-height: 28px;
  padding: 0 7px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 11px;
  line-height: 14px;
  font-weight: 820;
}
.gene-name strong, .process-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 12px;
  line-height: 15px;
  font-weight: 850;
}
.gene-name span, .process-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  line-height: 13px;
}
.gene-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mini-icon, .process-toggle {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel-2);
}
.mini-icon svg {
  width: 15px;
  height: 15px;
}
.gene-card.locked {
  background: linear-gradient(180deg, #fff, #f4f7fa);
}
.gene-card.locked .gene-randomize {
  opacity: 0.45;
}
.gene-field {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 8px;
}
.gene-field label, .gene-field output {
  color: #425168;
  font-size: 10px;
  line-height: 12px;
  font-weight: 820;
  text-transform: uppercase;
}
.gene-field output {
  color: var(--blue);
  text-align: right;
}
.process-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px 9px 9px 12px;
}
.process-toggle {
  position: relative;
  z-index: 1;
  margin-left: 2px;
  padding: 0;
}
.process-toggle svg { width: 15px; height: 15px; }
.process-row.disabled {
  opacity: 0.48;
}
.process-body {
  min-width: 0;
  display: grid;
  gap: 7px;
}
.process-weight {
  display: grid;
  grid-template-columns: minmax(0,1fr) 30px;
  align-items: center;
  gap: 8px;
}
.process-weight output {
  color: var(--blue);
  font-size: 10px;
  line-height: 12px;
  font-weight: 850;
  text-align: right;
}
.process-hint {
  color: var(--muted);
  font-size: 10px;
  line-height: 12px;
  font-weight: 820;
  text-transform: uppercase;
}
.transcript-empty {
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}
.transcript-row {
  display: grid;
  gap: 5px;
}
.transcript-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #34435a;
  font-size: 11px;
  line-height: 14px;
  font-weight: 800;
}
.transcript-label code {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  font-weight: 700;
}
.transcript-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f6;
}
.transcript-bar span {
  display: block;
  height: 100%;
  width: var(--bar-width, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--acid), var(--cyan));
}

.drop-zone {
  margin-top: 12px;
  min-height: 94px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 14px;
  color: var(--muted);
  background: linear-gradient(180deg, #fbfcfd, #f2f6fa);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.drop-zone.dragging {
  border-color: var(--cyan);
  background: #edfbff;
}
.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.drop-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--blue);
  background: #eaf1ff;
}
.drop-title {
  color: var(--text);
  font-size: 12px;
  line-height: 16px;
  font-weight: 800;
}
.drop-copy {
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
}
.sample-list {
  margin-top: 10px;
  display: grid;
  gap: 7px;
}
.sample-button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.sample-button > span:first-child { min-width: 0; }
.sample-button strong, .sample-button span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sample-button strong {
  font-size: 11px;
  line-height: 15px;
  font-weight: 800;
}
.sample-button span {
  color: var(--muted);
  font-size: 10px;
  line-height: 13px;
}
.sample-tag, .chip {
  border-radius: 999px;
  padding: 3px 7px;
  color: #08705c;
  background: #e8f7f3;
  font-size: 10px;
  line-height: 12px;
  font-weight: 820;
}
.sample-button:hover, .sample-button.selected {
  border-color: rgba(36, 107, 254, 0.45);
  background: #f2f6ff;
}
.import-options {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}
.import-options summary {
  cursor: pointer;
  font-weight: 760;
}
.flip-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.flip-grid label {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.preview-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 64px minmax(360px, 1fr) 96px;
  overflow: hidden;
  border: 1px solid #0f1722;
  border-radius: var(--radius);
  background: var(--canvas);
  box-shadow: var(--shadow);
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  color: #f6f9fd;
  background: #131c27;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.preview-header p { color: #a9b5c4; }
.preview-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}
.canvas-wrap {
  min-height: 0;
  position: relative;
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 18%, #1b3042, var(--canvas) 48%);
  background-size: 34px 34px, 34px 34px, auto;
}
#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: #d9e5f2;
  pointer-events: none;
}
.canvas-empty.hidden { display: none; }
.canvas-empty strong { font-size: 15px; line-height: 20px; }
.canvas-empty span {
  max-width: 430px;
  color: #a3afbf;
  font-size: 12px;
  line-height: 18px;
}

.variation-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0,1fr));
  gap: 8px;
  padding: 10px;
  background: #0b1118;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.variation-button {
  min-width: 0;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: end;
  gap: 7px;
  min-height: 64px;
  padding: 8px;
  color: #d8e3ef;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
}
.variation-button span {
  width: 18px;
  border-radius: 4px 4px 2px 2px;
}
.variation-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  font-size: 11px;
  line-height: 13px;
}
.variation-button.selected {
  border-color: rgba(167,244,61,0.65);
  background: rgba(167,244,61,0.12);
}

.stat-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
  font-weight: 760;
}
.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  line-height: 24px;
  font-weight: 850;
}
.bounds-list {
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.bounds-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--panel-2);
}
.bounds-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.bounds-list dd {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.chip-cloud {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  color: #5e6d7d;
  background: #eef2f6;
}
.chip.active {
  color: #08231e;
  background: linear-gradient(135deg, rgba(167,244,61,0.72), rgba(0,167,199,0.26));
}
.contract-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}
.grammar-preview, .json-preview {
  margin: 12px 0 0;
  overflow: auto;
  padding: 12px;
  border-radius: var(--radius);
  color: #dce8f7;
  background: #111822;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 17px;
}
.grammar-preview {
  max-height: 154px;
}
.json-preview {
  max-height: 214px;
}
.material-strip {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.material-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0,0,0,0.16);
  border-radius: 6px;
}
.world-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.console {
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  color: #b4c2d3;
  background: #0a0f15;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}
.console div {
  flex: 0 0 auto;
  white-space: nowrap;
}

.primary-action, .secondary-action, .icon-button, .tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 16px;
  font-weight: 820;
}
.primary-action {
  border: 1px solid #0d8970;
  color: #071611;
  background: linear-gradient(135deg, var(--acid), #4be6c2);
  padding: 0 12px;
}
.secondary-action {
  border: 1px solid var(--border);
  color: var(--text);
  background: #fff;
  padding: 0 12px;
}
.secondary-action:hover {
  border-color: var(--border-strong);
  background: var(--panel-2);
}
.icon-button, .tool-button {
  width: 36px;
  padding: 0;
}
.icon-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: #fff;
}
.tool-button {
  border: 1px solid rgba(255,255,255,0.14);
  color: #e8eef8;
  background: rgba(255,255,255,0.06);
}
.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  font-weight: 820;
  padding: 0;
}
.full { width: 100%; }
.download-section {
  display: grid;
  gap: 9px;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: minmax(210px, 1fr) minmax(420px, 1fr) 40px;
  }
  .workspace {
    grid-template-columns: 286px minmax(0, 1fr);
  }
  .inspector {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto minmax(0,1fr) 44px;
    overflow: visible;
  }
  .topbar {
    height: auto;
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .command-bar {
    grid-template-columns: 1fr 1fr;
  }
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px;
    overflow: visible;
  }
  .preview-column { order: 1; }
  .sidebar { order: 2; }
  .inspector { order: 3; }
  .preview-column {
    min-height: 620px;
    grid-template-rows: auto 420px 100px;
  }
  .preview-header {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }
  .inspector { display: block; }
  .variation-strip { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
