/* styles.css — dark by default, because a tree diagram on black reads like a
 * chart of the night sky and the photos sit better against it.
 */

:root {
  /* Committed to a single dark look rather than following the host theme: the
     tree and the photos both need a dark ground. Telling the browser so keeps
     native controls (search fields, selects, scrollbars) dark to match. */
  color-scheme: dark;

  --bg: #0b0f14;
  --bg-raised: #121821;
  --bg-sunken: #080b0f;
  --line: #1e2732;
  --line-soft: #172030;
  --ink: #e6edf5;
  --ink-dim: #9aa8ba;
  --ink-faint: #64748b;

  /* Rank colours: cool and receding at the deep clades, warm at the living tips. */
  --rank-kingdom: #7c9cff;
  --rank-phylum: #58b3d6;
  --rank-class: #4fc3a1;
  --rank-order: #8ec36a;
  --rank-family: #c9bd57;
  --rank-genus: #dda15e;
  --rank-species: #f4f1ea;

  --shot: #ffc857;      /* photographed: the one saturated colour in the app */
  --shot-soft: rgba(255, 200, 87, 0.22);
  --accent: #6ea8fe;

  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { display: flex; flex-direction: column; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.sci { font-style: italic; color: var(--ink-dim); }

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand h1 { font-size: 19px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-faint); }

.progress { min-width: 180px; }
.progress-track {
  height: 5px;
  background: var(--bg-sunken);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--shot);
  transition: width 0.3s ease;
}
.progress p { margin: 5px 0 0; font-size: 12px; color: var(--ink-dim); }
.progress strong { color: var(--shot); }

.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 380px; }

input[type="search"], input[type="text"], select {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  max-height: 340px;
  overflow: auto;
}
#search-results li {
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
#search-results li:hover { background: var(--line-soft); }
#search-results em { color: var(--ink-dim); font-size: 13px; }
#search-results .where { margin-left: auto; font-size: 11px; color: var(--ink-faint); }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  padding: 8px 15px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 99px;
  color: var(--ink-dim);
  font-size: 14px;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--bg-sunken); border-color: var(--line); color: var(--ink); }

button.ghost {
  padding: 6px 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--ink-dim);
  font-size: 13px;
  cursor: pointer;
}
button.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }

.warning {
  margin: 0;
  padding: 9px 20px;
  background: #3a2a10;
  border-bottom: 1px solid #5a4318;
  color: #f0d9a8;
  font-size: 13px;
}

/* ---------------- panes ---------------- */

main { flex: 1; min-height: 0; position: relative; }
.pane { display: none; height: 100%; }
.pane.active { display: flex; flex-direction: column; }

/* ---------------- tree ---------------- */

.tree-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; flex: 1; }
.crumb {
  background: transparent;
  border: 0;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--ink-dim);
  font-size: 13px;
  cursor: pointer;
}
.crumb:hover { background: var(--line-soft); color: var(--ink); }
.crumb.current { color: var(--ink); font-weight: 600; }
.crumb-sep { color: var(--ink-faint); font-size: 11px; }
.tree-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.tree-canvas {
  flex: 1;
  min-height: 0;
  overflow: hidden; /* pan and zoom instead of scrollbars */
  background: radial-gradient(circle at 50% 30%, #0e141c 0%, var(--bg) 70%);
  touch-action: none;
}
.tree-svg { display: block; cursor: grab; }
.tree-svg:active { cursor: grabbing; }

.link {
  stroke: var(--line);
  stroke-width: 1.2;
  transition: stroke 0.15s, stroke-width 0.15s;
}
.link.rank-phylum { stroke: #2a3a4d; stroke-width: 1.6; }
.link.has-photo { stroke: var(--shot-soft); }
.link.on-hover-path { stroke: var(--accent); stroke-width: 2; }

/* ---- node tiles: a mosaic of what lives under this branch ---- */

.node { cursor: pointer; }

.node .tile-bg { fill: var(--bg-sunken); }
.node .tile-frame {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.2;
  transition: stroke 0.15s, stroke-width 0.15s;
}
.node.rank-kingdom .tile-frame { stroke: var(--rank-kingdom); }
.node.rank-phylum .tile-frame { stroke: var(--rank-phylum); }
.node.rank-class .tile-frame { stroke: var(--rank-class); }
.node.rank-order .tile-frame { stroke: var(--rank-order); }
.node.rank-family .tile-frame { stroke: var(--rank-family); }
.node.rank-genus .tile-frame { stroke: var(--rank-genus); }
.node.rank-species .tile-frame { stroke: #3a444f; }

/* Stock reference photos are held back so your own work is the only colour
   on the page; a species you have shot comes forward at full saturation. */
.cell.stock { filter: grayscale(1) contrast(0.92) brightness(0.78); opacity: 0.85; }
.cell.mine { filter: none; }

.node.leaf.has-photo .tile-frame { stroke: var(--shot); stroke-width: 2; }
.node.clade.partly-photographed .tile-frame { stroke: var(--shot-soft); }

.node text {
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3.5px;
  stroke-linejoin: round;
  pointer-events: none;
}
.node .node-name { font-size: 11.5px; fill: var(--ink-dim); }
.node .node-sub { font-size: 9.5px; fill: var(--ink-faint); }
.node.leaf .node-sub { font-style: italic; }

.node.rank-kingdom .node-name { font-size: 15px; fill: var(--ink); font-weight: 600; }
.node.rank-phylum .node-name { font-size: 13px; fill: var(--ink); }
.node.leaf.has-photo .node-name { fill: var(--shot); }

.node.hovered .tile-frame { stroke: var(--accent); stroke-width: 2; }
.node.hovered .node-name { fill: var(--ink); }
.node.selected .tile-frame { stroke: var(--accent); stroke-width: 2.4; }
.node.selected .node-name { fill: var(--ink); font-weight: 600; }

/* one click, all the way down to the species */
.drill-btn circle { fill: var(--bg-raised); stroke: var(--line); stroke-width: 1.2; }
.drill-btn text { font-size: 11px; fill: var(--ink-dim); stroke: none; pointer-events: none; }
.drill-btn:hover circle { fill: var(--accent); stroke: var(--accent); }
.drill-btn:hover text { fill: #06121f; }

.tree-legend {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 20px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--ink-faint);
  flex-wrap: wrap;
}
.tree-legend span { display: flex; align-items: center; gap: 6px; }
.tree-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(135deg, #7f8c99, #46515e);
  flex: none;
}
.tree-legend .swatch.mine { background: linear-gradient(135deg, var(--shot), #c9822c); }
.tree-legend .swatch.drill {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-style: normal;
  font-size: 10px;
  line-height: 12px;
  text-align: center;
  color: var(--ink-dim);
}
.legend-note { max-width: 620px; line-height: 1.4; }

/* ---------------- table ---------------- */

#table-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.table-controls {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
  align-items: center;
}
.table-controls input[type="search"] { max-width: 260px; }
.table-controls select { width: auto; min-width: 130px; }
.table-count { margin-left: auto; font-size: 13px; color: var(--ink-faint); }

.table-scroll { flex: 1; overflow: auto; }

.species-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.species-table th {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
}
.species-table th.sorted { color: var(--ink); }
.species-table th.sorted::after { content: ' \2191'; }
.species-table th.sorted.desc::after { content: ' \2193'; }

.species-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-dim);
  white-space: nowrap;
}
.species-table td.thumb { width: 54px; padding: 4px 0 4px 12px; }
.row-thumb {
  width: 44px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  filter: grayscale(1) brightness(0.8);
}
.row-thumb.mine { filter: none; box-shadow: 0 0 0 1.5px var(--shot); }

.species-table td:nth-child(2) { color: var(--ink); font-weight: 500; }
.species-table td.sci { font-style: italic; }
.species-table td.wide { white-space: normal; min-width: 190px; font-size: 12.5px; }
.species-table td.centre { text-align: center; }
.species-table tbody tr { cursor: pointer; }
.species-table tbody tr:hover td { background: var(--line-soft); }
.species-table tbody tr.shot td.thumb { box-shadow: inset 3px 0 0 var(--shot); }

.pill {
  display: inline-block;
  min-width: 26px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.pill.yes { background: var(--shot); color: #2a1c00; font-weight: 600; }
.pill.no { color: var(--ink-faint); }

/* ---------------- trips ---------------- */

#trips-pane { height: 100%; overflow: auto; }
.trips-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.trips-controls .hint { font-size: 12px; color: var(--ink-faint); }
.trips-controls label { margin-left: auto; font-size: 13px; color: var(--ink-dim); display: flex; gap: 8px; align-items: center; }
.trips-controls select { width: auto; }

.trip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  padding: 18px 20px 40px;
  align-items: start;
}
.trip-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.trip-card header { padding: 14px; cursor: pointer; }
.trip-card h3 { font-size: 15px; margin-bottom: 9px; }
.trip-meter { height: 4px; background: var(--bg-sunken); border-radius: 99px; overflow: hidden; }
.trip-meter span { display: block; height: 100%; background: var(--shot); }
.trip-strip {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  border-radius: 4px;
  overflow: hidden;
}
.trip-strip img {
  width: 100%;
  min-width: 0;
  height: 34px;
  object-fit: cover;
  filter: grayscale(1) brightness(0.78);
}
.trip-strip img.mine { filter: none; }

.trip-stats { margin: 8px 0 0; font-size: 12px; color: var(--ink-faint); }
.trip-stats strong { color: var(--ink); font-size: 14px; }
.trip-stats .sep { margin: 0 6px; opacity: 0.4; }

.trip-body { display: none; border-top: 1px solid var(--line-soft); padding: 10px 14px 14px; }
.trip-card.open .trip-body { display: block; }
.trip-actions { margin-bottom: 8px; }

.trip-species { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.trip-species li {
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding: 4px 2px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
}
.trip-species li:hover { background: var(--line-soft); }
.trip-species .tick { color: var(--ink-faint); width: 14px; }
.trip-species li.done .tick { color: var(--shot); }
.trip-species li.done .nm { color: var(--shot); }
.trip-species em { color: var(--ink-faint); font-size: 12px; }

/* ---------------- drawer ---------------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 92vw;
  padding: 22px;
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  transform: translateX(102%);
  transition: transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
  z-index: 60;
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
}
.drawer.open { transform: none; }
.drawer h2 { font-size: 20px; }
.drawer h3 {
  margin: 20px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
}
.drawer p { margin: 0; font-size: 14px; color: var(--ink-dim); }
.drawer .note { color: var(--ink); }

.drawer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.drawer-close:hover { color: var(--ink); }

.stock-shot { margin: 16px 0 0; }
.stock-shot img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
}
.stock-shot figcaption {
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--ink-faint);
  line-height: 1.35;
}

.lineage { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lin-row { display: flex; gap: 10px; padding: 6px 11px; font-size: 13px; }
.lin-row:nth-child(odd) { background: var(--bg-sunken); }
.lin-rank { width: 66px; color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 2px; }
.lin-name { color: var(--ink); }
.lin-row:last-child .lin-name { font-style: italic; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.region-chip {
  padding: 4px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--ink-dim);
  font-size: 12px;
  cursor: pointer;
}
.region-chip:hover { border-color: var(--accent); color: var(--ink); }

.upload-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.upload-btn {
  padding: 7px 14px;
  background: var(--shot);
  border-radius: 99px;
  color: #2a1c00;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.upload-btn:hover { filter: brightness(1.08); }

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.photos .empty { grid-column: 1 / -1; font-size: 13px; color: var(--ink-faint); }
.shot { position: relative; margin: 0; }
.shot img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}
.shot-caption {
  margin-top: 4px;
  padding: 4px 7px;
  font-size: 11.5px;
  background: var(--bg-sunken);
}
.shot-delete {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  background: rgba(8, 11, 15, 0.8);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-dim);
  cursor: pointer;
  line-height: 1;
}
.shot-delete:hover { color: #ff8787; }

.fineprint { margin-top: 18px !important; font-size: 11.5px !important; color: var(--ink-faint) !important; }

/* ---------------- narrow screens ---------------- */

@media (max-width: 760px) {
  .topbar { gap: 12px; padding: 10px 14px; }
  .progress { order: 3; flex: 1; }
  .tabs { order: 2; margin-left: auto; }
  .search-wrap { order: 4; max-width: none; }
  .drawer { width: 100%; }
  .tree-legend .legend-note { display: none; }
  .species-table td.wide { min-width: 140px; }
}

/* ---------------- cloud scrapbook ---------------- */

.tab-link {
  margin-left: 6px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--shot);
  color: #2a1c00;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  align-self: center;
}
.tab-link:hover { filter: brightness(1.08); }

.ghost-link {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--ink-dim);
  font-size: 13px;
  text-decoration: none;
}
.ghost-link:hover { color: var(--ink); border-color: var(--ink-faint); }

.upload-status {
  margin-top: 8px !important;
  font-size: 12.5px !important;
  color: var(--shot) !important;
}
.upload-status.bad { color: #ffb4b4 !important; }

.shot-meta {
  display: block;
  margin-top: 4px;
  min-height: 15px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-faint);
}
.shot.remote img { border-color: var(--shot-soft); }
.shot.remote a { display: block; }
