:root {
  --bg: #0e0e0e;
  --bg-2: #050505;
  --fg: #e6e6e6;
  --dim: #e6e6e6;    /* same brightness as fg — no unreadable dim text */
  --mute: #a8a8a8;   /* only for least-important info; still readable */
  --line: #2a2a2a;
  --panel: #151515;

  --c-nest: #5aa8ff;
  --c-best: #c8ff4b;
  --c-cuckoo: #ff9f43;
  --c-cuckoo-rejected: #a855f7;
  --c-opt: #ffffff;

  --accent: #c8ff4b;
  --accent-fg: #0a0a0a;
  --ga: #b089ff;
  --sa: #ffcc55;
  --warn: #ff6b6b;

  --overlay-bg: rgba(10, 10, 10, 0.75);
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 32px 1fr 26px;
}

/* ==== BAR ==== */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  min-width: 0;
}
.bar.foot {
  border-top: 1px solid var(--line);
  border-bottom: none;
  color: var(--dim);
}
.bar-l, .bar-r { display: flex; align-items: center; gap: 14px; min-width: 0; }
.bar-l strong { font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; }
.bar-l .logo { color: var(--accent); }
.sep { color: var(--mute); }
.dim { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-r span { color: var(--dim); white-space: nowrap; }
.bar-r b { color: var(--fg); font-weight: 500; margin-left: 4px; }
.foot kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10px;
  color: var(--fg);
  margin: 0 2px;
}

/* ==== GRID ==== */
.grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr 220px;
  gap: 0;
  min-height: 0;
}
.cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.cell.ctrl { border-right: none; overflow-y: auto; }
.cell.chart { grid-column: 1 / 3; border-right: none; border-bottom: none; }

.cell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--dim);
  height: 26px;
  flex-shrink: 0;
  gap: 8px;
}

/* ==== FIELD ==== */
.field-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  background: var(--bg-2);
}
#field {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#field.grabbing { cursor: grabbing; }
.field-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--overlay-bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10px;
  color: var(--dim);
  backdrop-filter: blur(4px);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.lg {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.lg.nest { background: var(--c-nest); }
.lg.best { background: var(--c-best); box-shadow: 0 0 0 1px var(--c-best); }
.lg.cuckoo { background: var(--c-cuckoo); }
.lg.cuckoo-rejected { 
  background: var(--c-cuckoo-rejected); 
  width: 6px; 
  height: 6px; 
  opacity: 0.55;
  margin: 0 2px;
}
.lg.opt {
  width: 11px; height: 11px;
  background: transparent;
  position: relative;
}
.lg.opt::before, .lg.opt::after {
  content: '';
  position: absolute;
  background: var(--c-opt);
}
.lg.opt::before { left: 0; right: 0; top: 50%; height: 1px; transform: translateY(-50%); }
.lg.opt::after { top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%); }

.zoom-ctl {
  pointer-events: auto;
  background: var(--overlay-bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 4px 10px;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-ctl label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 10px;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.zoom-ctl input { accent-color: var(--accent); cursor: pointer; }
.zoom-ctl label:hover { color: var(--accent); }
.zoom-sep { color: var(--mute); font-size: 10px; }
.zoom-fit {
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 10px;
  cursor: pointer;
  padding: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.zoom-fit:hover { color: var(--accent); }
.zoom-hint {
  font-size: 10px;
  color: var(--mute);
  text-transform: lowercase;
}

/* tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  padding: 2px 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* ==== CONTROLS ==== */
.ctrl { padding: 0; }
.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.row-top label { color: var(--fg); font-size: 11px; font-weight: 500; }
.row-top label .k {
  color: var(--mute);
  font-weight: 400;
  margin-left: 4px;
  font-size: 10px;
}
.row-top b {
  color: var(--fg);
  font-weight: 600;
  font-size: 11px;
}
.row-hint {
  font-size: 10px;
  color: var(--mute);
  line-height: 1.4;
  margin-top: 2px;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--line);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--accent);
  border-radius: 0;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.btns {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.btns button {
  padding: 10px 8px;
  background: var(--bg);
  border: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  text-transform: lowercase;
}
.btns button:hover { background: var(--panel); }
.btns button.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btns button.primary:hover { filter: brightness(0.95); }
.btns button:disabled { color: var(--mute); cursor: not-allowed; }
.btns button:disabled:hover { background: var(--bg); }

.mini {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}
.mini div { display: flex; flex-direction: column; gap: 2px; }
.mini span {
  color: var(--mute);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.mini b { color: var(--fg); font-weight: 500; font-size: 13px; }

.cmp-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--dim);
  font-size: 11px;
}
.cmp-toggle input { accent-color: var(--accent); cursor: pointer; }
.cmp-toggle:hover { color: var(--fg); }

/* ==== CHART ==== */
.chart { position: relative; }
#chart {
  width: 100%;
  height: calc(100% - 26px);
  display: block;
}
.legend-chart { display: flex; gap: 14px; font-size: 10px; flex-wrap: wrap; }
.legend-chart em {
  font-style: normal;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.legend-chart em::before {
  content: '';
  width: 10px; height: 2px;
  background: currentColor;
}
.legend-chart em.cs { color: var(--c-best); }
.legend-chart em.ga { color: var(--ga); }
.legend-chart em.sa { color: var(--sa); }

/* ==== RESPONSIVE ==== */
@media (max-width: 920px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 55vh) auto 200px;
  }
  .cell.field { border-right: none; }
  .cell.ctrl { border-bottom: 1px solid var(--line); }
  .cell.chart { grid-column: 1; }
  html, body { overflow: auto; }
  #app { height: auto; min-height: 100vh; min-height: 100dvh; }
  .bar-r { gap: 10px; font-size: 10px; }
  .hide-sm { display: none; }
}

@media (max-width: 540px) {
  html, body { font-size: 11px; }
  #app { grid-template-rows: 40px 1fr 24px; }
  .bar { padding: 0 10px; font-size: 10px; }
  .bar-l { gap: 8px; }
  .bar-l strong { font-size: 11px; }
  .bar-r { gap: 8px; }
  .bar-r b { margin-left: 3px; }
  .cell-head { padding: 5px 10px; font-size: 9px; letter-spacing: 0.1em; }
  .grid { grid-template-rows: 46vh auto 180px; }
  .tabs button { padding: 2px 6px; font-size: 9px; }
  .legend { font-size: 9px; gap: 8px; padding: 5px 8px; }
  .lg { width: 8px; height: 8px; }
  .row {
    grid-template-columns: 68px 1fr 44px;
    padding: 9px 12px;
    gap: 8px;
  }
  .row label, .row b { font-size: 11px; }
  input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; }
  input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
  .btns button { padding: 12px 6px; font-size: 12px; }
  .cmp-toggle { padding: 14px; }
  .cmp-toggle input { width: 16px; height: 16px; }
  .zoom-ctl { padding: 5px 8px; }
  .zoom-ctl input { width: 14px; height: 14px; }
  .field-overlay { padding: 8px; gap: 6px; }
}

@media (max-width: 380px) {
  .bar-r span:nth-child(1) { display: none; }
  .legend { font-size: 8px; gap: 6px; }
}

.compare-settings {
  background: rgba(176, 137, 255, 0.03);
  border-bottom: 1px solid var(--line);
}

.compare-settings .row {
  padding: 8px 14px;
}