/* Surdeigens slektstre — "field microbiology": lab bench, agar dishes, crystal-violet stain. */
:root {
  --bench: #f2f3ef;      /* page background */
  --glass: #fbfbf8;      /* panels */
  --ink: #142221;        /* text, lines, living cultures */
  --ink-soft: #4e5b58;   /* secondary text (6:1 on bench) */
  --dead: #8d9692;       /* deceased cultures: marks only, never text */
  --rule: #d5d8d1;       /* hairlines */
  --agar: #f4e4b5;       /* dishes, cells */
  --land: #e1e5db;
  --accent: #5b3cc4;     /* crystal violet: selection and lineage */
  --accent-tint: rgba(91, 60, 196, 0.12);
  --danger: #a3301f;

  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.125rem;
  --step-2: 1.75rem;
  --step-3: clamp(2rem, 1.2rem + 3vw, 4rem);

  --gutter: 24px;
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bench);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.45;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  row-gap: 16px;
  height: 100dvh;
  padding: 0 var(--gutter) 20px;
}
.masthead { grid-row: 1; }
.tabs { grid-row: 2; }
.views { grid-row: 3; }
.timeline { grid-row: 4; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.lab {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Masthead */
.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "bar bar bar" "title stats action";
  gap: 18px 20px;
  align-items: end;
}
.masthead__bar {
  grid-area: bar;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--rule);
}
.masthead__mark { display: inline-flex; align-items: center; gap: 10px; }
.masthead__mark .lab { color: var(--ink); }
.masthead__home { font-family: var(--mono); font-size: 13px; color: var(--ink); text-underline-offset: 3px; }
.masthead__title { grid-area: title; min-width: 0; }
.masthead h1 {
  font-weight: 600;
  font-size: var(--step-3);
  line-height: 0.95;
  letter-spacing: -0.035em;
  margin: 0;
}
.masthead__lede { margin: 12px 0 0; max-width: 46ch; color: var(--ink-soft); font-size: var(--step-1); }

.stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(5, auto);
  margin: 0;
  background: var(--glass);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
}
.stats > div { padding: 10px 18px; display: flex; flex-direction: column; gap: 6px; border-left: 1px solid var(--rule); }
.stats > div:first-child { border-left: 0; }
.stats dt { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); }
.stats dt .short { display: none; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats__alive dd { color: var(--accent); }
.stats dd small { font-size: 13px; color: var(--ink-soft); margin-left: 2px; }
#open-form { grid-area: action; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  background: var(--glass);
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { background: var(--bench); }
.button--primary { background: var(--ink); border-color: var(--ink); color: var(--glass); }
.button--primary:hover { background: #26393a; }
.button--register { min-height: 52px; padding: 0 24px; font-size: var(--step-0); }
.button[disabled] { opacity: 0.55; cursor: progress; }

/* Views */
.tabs { display: none; }
.views {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}
.views:has(.card:not([hidden])) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 340px; }
.pane {
  position: relative; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
}
.pane__head {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--glass);
}
.pane__head h2 { margin: 0; font-size: var(--step-1); font-weight: 600; }
.pane__badge {
  width: 24px; height: 24px; border-radius: 12px; border: 1px solid var(--ink);
  display: inline-grid; place-items: center;
  font-family: var(--mono); font-size: 12px; font-weight: 600;
}
.map { position: relative; flex: 1 1 0; min-height: 0; }
.tree { display: block; flex: 1 1 0; min-height: 0; width: 100%; height: 100%; cursor: grab; background: var(--glass); }
.tree:active { cursor: grabbing; }

/* Detail card */
.card {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: var(--glass);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  z-index: 500;
}
.card__head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 6px 0 18px;
  background: var(--accent-tint);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(6px);
}
.card__no { margin: 0; color: var(--ink); }
.card__close {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 22px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.card__close:hover { background: var(--glass); }
.card__body { padding: 18px; display: grid; gap: 18px; }
.card h2 { font-weight: 600; font-size: var(--step-2); line-height: 1.05; letter-spacing: -0.02em; margin: 0; overflow-wrap: anywhere; }
.card__chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -8px 0 0; padding: 0; list-style: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 13px;
  border: 1px solid var(--rule);
  font-family: var(--mono); font-size: 12px;
}
.chip--alive { border-color: var(--ink); }
.chip--alive::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--ink); }
.chip--dead { color: var(--ink-soft); border-style: dashed; border-color: var(--dead); }
.chip--dead::before { content: ""; width: 8px; height: 8px; border-radius: 4px; border: 1.4px solid var(--dead); box-sizing: border-box; }
.chip--mixed { border-style: dashed; border-color: var(--ink); }
.card dl { margin: 0; display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px 12px; }
.card dt { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); padding-top: 3px; }
.card dd { margin: 0; overflow-wrap: anywhere; }
.card__section { display: grid; gap: 8px; }
.card__notes { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.card__links { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.card__links button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 44px; padding: 6px 12px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--glass); color: var(--ink); text-align: left; cursor: pointer;
  overflow-wrap: anywhere;
}
.card__links button:hover { border-color: var(--ink); }
.card__links svg { flex: none; }
.card__links .is-external { font-style: italic; }
.card__lineage { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-family: var(--mono); font-size: 12.5px; }
.card__lineage li { color: var(--ink-soft); overflow-wrap: anywhere; }
.card__lineage li + li::before { content: "→"; color: var(--dead); margin-right: 6px; }
.card__lineage li:last-child { color: var(--accent); font-weight: 600; }

/* Timeline: a growth curve of living cultures, with the scrubber under it */
.timeline {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 20px;
  background: var(--glass);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
}
.timeline__play {
  width: 52px; height: 52px; padding: 0; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 26px; background: var(--ink); color: var(--glass); cursor: pointer;
}
.timeline__play:hover { background: #26393a; }
.timeline__info { flex: 0 0 180px; display: grid; gap: 4px; }
.timeline__month { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.timeline__track { flex: 1 1 auto; min-width: 0; display: grid; gap: 4px; }
.timeline__curve { display: block; width: 100%; height: 44px; overflow: visible; }
.timeline__range { width: 100%; margin: 0; accent-color: var(--accent); }
.timeline__scale { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }

.notice {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: 16px 20px; max-width: 32ch; text-align: center;
  background: var(--glass); border: 1px solid var(--ink); border-radius: var(--radius); z-index: 1000;
}

/* Form dialog */
.form-dialog {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--ink); border-radius: 18px;
  background: var(--glass); color: var(--ink);
  box-shadow: 0 24px 60px rgba(20, 34, 33, 0.3);
  overflow: auto; overscroll-behavior: contain;
}
.form-dialog::backdrop { background: rgba(20, 34, 33, 0.55); }
.form { padding: 28px; display: grid; gap: 18px; }
.form h2 { font-weight: 600; font-size: 2rem; line-height: 1; letter-spacing: -0.03em; margin: 0; }
.form__intro { margin: -6px 0 0; color: var(--ink-soft); }
.form__section {
  display: flex; align-items: baseline; gap: 10px;
  margin: 8px 0 0; padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  font-size: var(--step-1); font-weight: 600;
}
.form__section span { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.form__summary:empty { display: none; }
.form__summary { margin: 0; padding: 10px 12px; border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius-sm); font-weight: 600; }
.form__actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.form__actions .button { min-height: 52px; padding: 0 28px; }
.form__dish { display: flex; justify-content: center; }
.field { display: grid; gap: 6px; }
.field > label, .field legend { font-weight: 600; }
.field__hint { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.field__error { margin: 0; font-size: var(--step--1); font-weight: 600; color: var(--danger); }
.field__error:empty { display: none; }
.field__row { display: flex; gap: 8px; }
.field__row > * { flex: 1; min-width: 0; }
.field__chosen { margin: 2px 0 0; font-family: var(--mono); font-size: 13px; color: var(--accent); }
.field__chosen:empty { display: none; }
.field--check { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.field--check label { font-weight: 600; }
.field--check input {
  appearance: none; flex: none; order: 2;
  width: 52px; height: 30px; margin: 0; border-radius: 15px;
  border: 1px solid var(--ink); background: var(--bench);
  position: relative; cursor: pointer;
}
.field--check input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 11px; background: var(--ink);
}
.field--check input:checked { background: var(--accent); border-color: var(--accent); }
.field--check input:checked::after { left: 25px; background: var(--glass); }
@media (prefers-reduced-motion: no-preference) {
  .field--check input::after { transition: left 120ms ease-out; }
}
.field__group { border: 1px dashed var(--ink); border-radius: 12px; padding: 14px; margin: 0; display: grid; gap: 12px; }
.field__group legend { padding: 0 6px; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); }
.form input[type=text], .form input[type=search], .form input[type=email], .form select, .form textarea {
  width: 100%; min-height: 50px; padding: 0 14px;
  border: 1px solid var(--ink); border-radius: var(--radius-sm);
  background: var(--glass); font-size: 16px;
}
.form textarea { padding: 12px 14px; resize: vertical; line-height: 1.45; }
.form input:focus-visible, .form select:focus-visible, .form textarea:focus-visible {
  outline: 3px solid var(--accent-tint); outline-offset: 0; border: 2px solid var(--accent);
}
.form [aria-invalid="true"] { border: 2px solid var(--danger); }
.suggestions { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--ink); border-radius: var(--radius-sm); background: var(--glass); max-height: 240px; overflow: auto; }
.suggestions:empty { display: none; }
.suggestions button { display: grid; width: 100%; min-height: 48px; text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.suggestions button:hover { background: var(--bench); }
.suggestions button[aria-selected="true"] { background: var(--accent-tint); }
.suggestions button span { font-weight: 600; }
.suggestions button[aria-selected="true"] span { color: var(--accent); }
.suggestions small { font-family: var(--mono); color: var(--ink-soft); font-size: 12px; }
.suggestions__empty { padding: 10px; color: var(--ink-soft); font-style: italic; }
.captcha:empty { display: none; }
#f-edit-link { font-family: var(--mono); font-size: 13px; }
@media (max-width: 899px) {
  .form-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .form { padding: 22px 18px calc(28px + env(safe-area-inset-bottom)); }
  .form h2 { font-size: 1.85rem; }
  .form__actions .button[type=submit] { flex: 1; }
}

/* Pedigree */
.tree text { paint-order: stroke; stroke: var(--glass); stroke-width: 4px; stroke-linejoin: round; }
.tree .band { fill: var(--bench); }
.tree .band-label { font-family: var(--mono); font-size: 11px; font-weight: 600; fill: var(--ink-soft); stroke: none; }
.node__name { font-family: var(--sans); font-size: 13px; }
.node__no { font-family: var(--mono); font-size: 10.5px; fill: var(--ink-soft); }
.tree .node { outline: none; }
.tree .node:focus-visible .node__cell { stroke: var(--accent); stroke-width: 3; }

/* Leaflet: grey tiles multiplied over a counting-grid "plate" */
.leaflet-container {
  font-family: var(--sans);
  background-color: #eef1ec;
  background-image:
    linear-gradient(rgba(20, 34, 33, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 34, 33, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(20, 34, 33, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 34, 33, 0.05) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
}
.leaflet-tile-pane { mix-blend-mode: multiply; filter: grayscale(1) contrast(0.82) brightness(1.06); }
/* OSM's standard tiles carry labels and roads: wash them out further so the dishes stay in front. */
.map[data-tiles="osm"] .leaflet-tile-pane { filter: grayscale(1) contrast(0.45) brightness(1.22); opacity: 0.85; }
.leaflet-tooltip { font-family: var(--mono); font-size: 12px; background: var(--ink); color: var(--glass); border: 0; border-radius: 8px; box-shadow: none; padding: 6px 10px; }
.leaflet-tooltip-top::before { border-top-color: var(--ink); }
.leaflet-control-attribution { font-family: var(--mono); font-size: 10px; background: rgba(251, 251, 248, 0.85) !important; }
.leaflet-bar { border: 1px solid var(--ink) !important; border-radius: var(--radius-sm) !important; box-shadow: none !important; overflow: hidden; }
.leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 36px !important; color: var(--ink) !important; background: var(--glass) !important; }
.city-label {
  font-family: var(--mono); font-size: 11px; color: var(--ink); white-space: nowrap;
  text-shadow: 0 0 3px #eef1ec, 0 0 3px #eef1ec, 0 0 3px #eef1ec;
  pointer-events: none;
}
.city-label.is-faded { opacity: 0.3; }
.city-label.is-west { display: block; transform: translateX(-100%); }

/* Phone and narrow tablets */
@media (max-width: 899px) {
  body { padding: 0; row-gap: 0; grid-template-rows: auto auto minmax(300px, 1fr) auto; }
  .masthead {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bar" "title" "stats" "action";
    gap: 12px;
    padding: 0 16px 14px;
  }
  .masthead__bar { padding: 12px 0 10px; }
  .masthead h1 { font-size: 2rem; }
  .masthead__lede { display: none; }
  .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); border-radius: var(--radius-sm); }
  .stats > div { padding: 7px 8px; gap: 3px; }
  .stats dt { font-size: 10px; letter-spacing: 0.06em; }
  .stats dt .long { display: none; }
  .stats dt .short { display: inline; }
  .stats dd { font-size: 16px; letter-spacing: -0.02em; }
  .stats dd small { display: none; }
  #open-form { justify-self: stretch; min-height: 48px; background: var(--agar); color: var(--ink); }
  .tabs {
    display: grid; grid-template-columns: 1fr 1fr;
    margin: 0 16px 12px; padding: 3px;
    border: 1px solid var(--ink); border-radius: 24px; background: var(--glass);
  }
  .tabs button {
    min-height: 40px; border: 0; border-radius: 20px; background: none; cursor: pointer;
    font-size: 15px; font-weight: 500; color: var(--ink);
  }
  .tabs button[aria-selected="true"] { background: var(--ink); color: var(--glass); font-weight: 600; }
  .views, .views:has(.card:not([hidden])) { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .pane { border-radius: 0; border-width: 1px 0; }
  .pane__head { display: none; }
  .views[data-view="map"] .pane--tree,
  .views[data-view="tree"] .pane--map { display: none; }
  .timeline {
    gap: 12px; flex-wrap: wrap;
    border-radius: 0; border-width: 1px 0 0;
    background: var(--bench);
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  }
  .timeline__play { width: 48px; height: 48px; }
  .timeline__info { flex: 1 1 auto; }
  .timeline__track { flex-basis: 100%; }
  .timeline__curve { height: 34px; }
  .card {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh;
    border-radius: 22px 22px 0 0; border-width: 1px 0 0;
    box-shadow: 0 -8px 24px rgba(20, 34, 33, 0.12);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1001;
  }
  .card__head { border-radius: 22px 22px 0 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .card { animation: card-in 160ms ease-out; }
  @keyframes card-in { from { opacity: 0; transform: translateY(6px); } }
}
