:root {
  color-scheme: dark;
  --ink: #f3f0e8;
  --muted: #aaa393;
  --panel: #181914;
  --panel-2: #20221b;
  --line: #3a3d30;
  --field: #10120f;
  --gold: #e1b84d;
  --teal: #39b9a7;
  --red: #d45d4c;
  --green: #91c95e;
  --shadow: rgba(0, 0, 0, 0.35);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: #10110e;
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  height: 100vh;
  width: 100vw;
}

.sim-pane {
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 18% 22%, rgba(225, 184, 77, 0.08), transparent 28%),
    #090a08;
}

#universe {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.control-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel), #11120f);
  box-shadow: -18px 0 40px var(--shadow);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.03;
  font-weight: 840;
}

.tick-readout {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--field);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px;
}

.app-shell:fullscreen {
  background: #10110e;
}

.app-shell.fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #10110e;
}

.app-shell.controls-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.controls-hidden .control-pane {
  display: none;
}

.show-controls {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 80;
  display: none;
  min-width: 116px;
  background: rgba(18, 49, 45, 0.94);
  backdrop-filter: blur(8px);
}

.app-shell.controls-hidden + .show-controls {
  display: block;
}

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

button {
  padding: 0 10px;
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: rgba(225, 184, 77, 0.85);
  background: #282a22;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  border-color: rgba(57, 185, 167, 0.7);
  background: #12312d;
}

.warning-panel {
  display: grid;
  gap: 5px;
  padding: 10px 11px;
  border: 1px solid rgba(225, 184, 77, 0.58);
  border-radius: 6px;
  background: rgba(225, 184, 77, 0.08);
}

.warning-panel strong {
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0;
}

.warning-panel span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.field,
.range-field,
.toggle-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field span,
.range-field span,
.toggle-field span,
.metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0;
}

select {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  appearance: auto;
  background: var(--field);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.segmented button {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: var(--field);
}

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

.segmented button.active {
  color: #10110e;
  background: var(--gold);
}

.range-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.range-field input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--teal);
}

.range-field output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.toggle-field {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.toggle-field input {
  width: 42px;
  height: 22px;
  margin: 0;
  accent-color: var(--teal);
  cursor: pointer;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.metrics div {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.metrics output {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lineage-panel {
  display: grid;
  gap: 8px;
  min-height: 132px;
  max-height: 216px;
  min-width: 0;
}

.lineage-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lineage-panel span,
.lineage-panel output {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0;
}

.lineage-panel output {
  font-variant-numeric: tabular-nums;
}

.rule-lineage {
  display: grid;
  gap: 4px;
  min-height: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.lineage-node {
  display: grid;
  grid-template-columns: 10px 42px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  padding-left: calc(var(--depth) * 9px);
}

.lineage-swatch {
  width: 10px;
  height: 10px;
  border: 1px solid rgba(243, 240, 232, 0.32);
  border-radius: 50%;
}

.lineage-node .lineage-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lineage-rule {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lineage-node .lineage-visits,
.lineage-omitted {
  color: var(--gold);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.lineage-omitted {
  padding: 2px 0 5px;
  text-align: left;
}

@media (max-width: 860px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52vh, 1fr) auto;
    min-height: 100vh;
    height: auto;
  }

  .sim-pane {
    min-height: 52vh;
  }

  .control-pane {
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: 0 -14px 32px var(--shadow);
  }
}

@media (max-width: 460px) {
  .control-pane {
    padding: 14px;
  }

  .control-row,
  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  h1 {
    font-size: 21px;
  }
}
