:root {
    --bg: #0e1116;
    --bg-2: #161b22;
    --bg-3: #1e242c;
    --line: #2d333b;
    --line-2: #3a424c;
    --text: #e6edf3;
    --text-dim: #8b949e;
    --text-mute: #6e7681;
    --accent: #f78166;
    --accent-2: #ffa657;
    --geneal: #56d364;
    --pop:    #db6d28;
    --link:   #58a6ff;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
  }
  code, .mono, input[type=search] { font-family: 'IBM Plex Mono', monospace; }

  header {
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
    display: flex; align-items: center; gap: 20px;
  }
  header .brand { font-weight: 700; font-size: 18px; }
  header .brand span { color: var(--accent); }
  header .sub {
    color: var(--text-dim); font-size: 12px;
    text-transform: uppercase; letter-spacing: .1em;
  }
  header .search { flex: 1; max-width: 460px; margin-left: auto; position: relative; }
  header .search input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line-2);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
  }
  header .search input:focus { border-color: var(--accent); }
  .autocomplete {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-2); border: 1px solid var(--line-2);
    border-top: none; max-height: 300px; overflow-y: auto;
    display: none; z-index: 1500;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
  }
  .autocomplete.open { display: block; }
  .autocomplete .ac-item {
    padding: 8px 14px; cursor: pointer; font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    border-bottom: 1px solid var(--line);
  }
  .autocomplete .ac-item:hover, .autocomplete .ac-item.active { background: var(--bg-3); color: var(--accent); }
  .autocomplete .ac-item small { color: var(--text-mute); margin-left: 8px; font-family: 'IBM Plex Sans', sans-serif; }

  main {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 0;
    height: calc(100vh - 55px);
  }

  .sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 20px;
  }

  .empty-hero {
    color: var(--text-dim);
    text-align: center;
    padding: 60px 20px;
  }
  .empty-hero h2 { color: var(--text); margin: 0 0 12px; font-weight: 600; }
  .empty-hero .examples { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
  .empty-hero .examples button {
    background: var(--bg-3); border: 1px solid var(--line-2); color: var(--link);
    padding: 8px 14px; border-radius: 4px; cursor: pointer;
    font-family: 'IBM Plex Mono', monospace; font-size: 13px;
    text-align: left;
  }
  .empty-hero .examples button:hover { border-color: var(--accent); color: var(--accent); }

  .ladder-head {
    color: var(--text-dim); font-size: 11px;
    text-transform: uppercase; letter-spacing: .1em;
    margin-bottom: 10px; font-weight: 600;
  }
  .ladder-head b { color: var(--text); }

  .ladder {
    display: flex; flex-direction: column; gap: 2px;
    margin-bottom: 24px;
    border-left: 2px solid var(--line);
    padding-left: 0;
  }
  .rung {
    position: relative;
    padding: 10px 12px 10px 24px;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
    transition: background .1s;
    border-left: 3px solid transparent;
    margin-left: -2px;
  }
  .rung::before {
    content: ''; position: absolute; left: -6px; top: 50%; transform: translateY(-50%);
    width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); border: 2px solid var(--bg-2);
  }
  .rung:hover { background: var(--bg-3); }
  .rung.current {
    background: var(--bg-3);
    border-left-color: var(--accent);
  }
  .rung.current::before { background: var(--accent); }
  .rung .id {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600; color: var(--text);
    font-size: 14px;
  }
  .rung.current .id { color: var(--accent); }
  .rung .meta {
    display: flex; gap: 12px; font-size: 11px;
    color: var(--text-mute); margin-top: 3px;
    align-items: center; flex-wrap: wrap;
  }
  .rung .tmrca { color: var(--text-dim); }
  .rung .cnt {
    display: inline-flex; align-items: center; gap: 4px;
    background: var(--bg); padding: 1px 8px; border-radius: 10px;
    font-family: 'IBM Plex Mono', monospace; font-size: 10px;
    color: var(--text-dim);
  }
  .rung .cnt.samples { color: var(--text-mute); }
  .rung .cnt.samples.has { color: var(--geneal); background: rgba(86,211,100,.1); font-weight: 600; }
  .rung.current .cnt.samples.has { color: var(--accent-2); background: rgba(255,166,87,.15); }
  .rung.deeper { padding-left: 32px; }
  .rung.deeper::before { left: 2px; }

  .ladder-sep {
    color: var(--text-mute); font-size: 10px;
    text-align: center; padding: 8px 0;
    text-transform: uppercase; letter-spacing: .12em;
  }

  .mode-panel {
    background: var(--bg-3); border: 1px solid var(--line);
    padding: 14px 16px; border-radius: 6px;
    margin-bottom: 16px;
  }
  .mode-panel .mode-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .12em;
    color: var(--text-mute); margin-bottom: 4px;
  }
  .mode-panel .mode-val {
    font-family: 'IBM Plex Mono', monospace; font-weight: 600;
    font-size: 15px;
  }
  .mode-panel.geneal .mode-val { color: var(--geneal); }
  .mode-panel.trans  .mode-val { color: var(--accent-2); }
  .mode-panel.pop    .mode-val { color: var(--pop); }
  .mode-panel .mode-desc { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }

  /* Right pane: map + empty-slot overlay */
  .stage {
    position: relative;
    background: var(--bg);
    overflow: hidden;
  }
  #map { position: absolute; inset: 0; }
  .leaflet-tile-pane { filter: brightness(.55) invert(.94) contrast(.9) hue-rotate(180deg) saturate(.65); }
  .stage-overlay {
    position: absolute; inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(14,17,22,.35) 0%, transparent 30%, transparent 70%, rgba(14,17,22,.5) 100%);
  }
  .stage-badge {
    position: absolute; top: 16px; right: 16px;
    background: rgba(22, 27, 34, .92);
    backdrop-filter: blur(6px);
    border: 1px solid var(--line-2);
    padding: 12px 16px;
    border-radius: 6px;
    max-width: 360px;
    z-index: 500;
    font-size: 13px;
  }
  .stage-badge .id { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 16px; color: var(--accent); }
  .stage-badge .snps { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--text-mute); margin-top: 6px; word-break: break-all; }
  .stage-cta {
    position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: rgba(22, 27, 34, .95);
    border: 1px dashed var(--line-2);
    padding: 14px 22px;
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 13px; text-align: center;
    max-width: 500px; z-index: 500;
    pointer-events: auto;
  }
  .stage-cta b { color: var(--accent); font-family: 'IBM Plex Mono', monospace; }
  .stage-cta button {
    display: block; margin: 10px auto 0;
    background: var(--accent); color: var(--bg);
    border: none; padding: 8px 18px;
    border-radius: 4px; cursor: pointer; font-weight: 600;
    font-family: inherit;
  }
  .stage-cta button:hover { background: var(--accent-2); }

  .loading {
    position: fixed; inset: 0;
    background: var(--bg); display: flex; align-items: center; justify-content: center;
    z-index: 9999; font-family: 'IBM Plex Mono', monospace; color: var(--text-dim);
  }
  .loading.hidden { display: none; }

  /* modal */
  .modal-back {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,.7); backdrop-filter: blur(3px);
    display: none; align-items: flex-start; justify-content: center;
    padding: 40px 16px; overflow-y: auto;
  }
  .modal-back.open { display: flex; }
  .modal {
    background: var(--bg-2); border: 1px solid var(--line-2);
    max-width: 520px; width: 100%; padding: 24px 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
    position: relative; border-radius: 8px;
  }
  .modal h2 {
    margin: 0 0 4px; font-size: 20px; color: var(--text);
    padding-bottom: 12px; border-bottom: 1px solid var(--line);
  }
  .modal .sub { color: var(--text-dim); font-size: 12px; margin-bottom: 16px; }
  .modal-close {
    position: absolute; top: 10px; right: 14px;
    background: transparent; border: none; font-size: 24px;
    color: var(--text-dim); cursor: pointer; line-height: 1;
  }
  .modal-close:hover { color: var(--text); }
  .modal label {
    display: block; margin-top: 14px; font-size: 11px;
    text-transform: uppercase; letter-spacing: .08em;
    font-weight: 600; color: var(--text-mute);
  }
  .modal label .req { color: var(--accent); }
  .modal input, .modal textarea, .modal select {
    width: 100%; padding: 9px 12px; margin-top: 4px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--line-2); border-radius: 4px;
    font-size: 14px; font-family: inherit; outline: none;
  }
  .modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--accent); }
  .modal textarea { min-height: 60px; resize: vertical; }
  .modal .hint { font-size: 11px; color: var(--text-mute); margin-top: 4px; }
  .modal .hint a { color: var(--link); }
  .modal .form-actions {
    margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
    display: flex; gap: 10px; flex-wrap: wrap;
  }
  .modal .btn {
    background: var(--bg-3); color: var(--text); border: 1px solid var(--line-2);
    padding: 10px 20px; border-radius: 4px; cursor: pointer;
    font-family: inherit; font-size: 14px;
  }
  .modal .btn:hover { border-color: var(--accent); color: var(--accent); }
  .modal .btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
  .modal .btn.primary:hover { background: var(--accent-2); color: var(--bg); }
  .modal .err {
    background: rgba(215,58,32,.15); border: 1px solid var(--pop);
    color: var(--accent-2); padding: 8px 12px; border-radius: 4px;
    font-size: 13px; margin-top: 12px;
  }
  .modal .coords-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
  .modal .coords-row button {
    background: var(--bg-3); color: var(--link); border: 1px solid var(--line-2);
    padding: 8px 12px; border-radius: 4px; cursor: pointer;
    font-family: inherit; font-size: 12px; white-space: nowrap;
    height: 37px; margin-top: 4px;
  }
  .modal .coords-row button:hover { border-color: var(--link); }

  /* map markers */
  .yd-marker {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid var(--bg); box-shadow: 0 0 0 1px rgba(255,255,255,.5), 0 2px 6px rgba(0,0,0,.6);
  }
  .yd-marker.user       { background: var(--accent); }
  .yd-marker.historical { background: var(--link); }
  .yd-marker.adna       { background: var(--geneal); }
  .yd-marker.exact { box-shadow: 0 0 0 2px var(--accent-2), 0 2px 6px rgba(0,0,0,.6); }
  .leaflet-popup-content-wrapper {
    background: var(--bg-2) !important; color: var(--text) !important;
    border: 1px solid var(--line-2); border-radius: 6px !important;
  }
  .leaflet-popup-content { font-family: inherit; font-size: 13px; }
  .leaflet-popup-content b { color: var(--accent); font-family: 'IBM Plex Mono', monospace; }
  .leaflet-popup-tip { background: var(--bg-2) !important; }

  .legend {
    position: absolute; bottom: 16px; right: 16px; z-index: 500;
    background: rgba(22,27,34,.9); backdrop-filter: blur(4px);
    border: 1px solid var(--line-2); border-radius: 6px;
    padding: 10px 14px; font-size: 11px; color: var(--text-dim);
  }
  .legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
  .legend .dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--bg); }
  .legend .dot.user       { background: var(--accent); }
  .legend .dot.historical { background: var(--link); }
  .legend .dot.adna       { background: var(--geneal); }
  .legend .dot.exact      { box-shadow: 0 0 0 2px var(--accent-2); }

  .disclaimer {
    padding: 12px 16px; background: var(--bg-3);
    border-left: 3px solid var(--accent-2); font-size: 12px;
    color: var(--text-dim); border-radius: 0 4px 4px 0;
    margin-bottom: 20px;
  }
  .disclaimer b { color: var(--text); }

/* ============ mobile ============ */
@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 55px);
  }
  .stage {
    order: 1;
    min-height: 55vh;
  }
  .sidebar {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--line);
    max-height: none;
    padding: 16px;
  }
  header {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
  }
  header .search {
    order: 3;
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    flex-basis: 100%;
  }
  header .brand { font-size: 16px; }
  .stage-badge {
    top: 8px; right: 8px; left: 60px;   /* leave space for zoom control */
    max-width: none;
    padding: 8px 12px;
    font-size: 12px;
  }
  .stage-badge .id { font-size: 14px; }
  .stage-badge .snps { display: none; }
  .stage-cta {
    left: 8px; right: 8px; bottom: 8px;
    transform: none;
    max-width: none;
    padding: 10px 14px;
    font-size: 12px;
  }
  .legend { display: none !important; }  /* JS sets inline style; media query must override */
  .empty-hero { padding: 30px 12px; }
  .empty-hero h2 { font-size: 18px; }
  .modal-back { padding: 12px 8px; }
  .modal { padding: 20px 16px; }
  .modal h2 { font-size: 18px; }
  .loading { font-size: 13px; padding: 20px; text-align: center; }
}

@media (max-width: 480px) {
  header .brand .sub { display: none; }
  .stage { min-height: 50vh; }
  .rung { padding: 8px 12px 8px 20px; }
  .rung .id { font-size: 13px; }
}
