:root {
  color-scheme: dark;

  /* Lab-notebook greens: lifted off black so the page reads as slate-green
     rather than void, but nowhere near white. Every surface is a flat fill —
     there are no gradients anywhere in this stylesheet by design. */
  --bg: #22302a;
  --bg-raised: #2a3a32;
  --bg-raised-2: #33453b;
  --border: #405446;
  --border-strong: #55705e;

  --text: #c6e9d0;
  --text-muted: #97bfa3;
  --text-faint: #7ba98a;

  --accent: #59d98a;
  --accent-ink: #0d2417;

  /* Warm-to-cool scale for guess proximity. Kept distinct in hue so the
     hot/cold signal survives on a green field. */
  --boiling: #ff6f5e;
  --hot: #ff9d4d;
  --warm: #f5cf52;
  --cool: #4fbcd0;
  --cold: #7b9ec4;
  --found: #59d98a;

  /* Light blue used to briefly highlight a newly added guess. */
  --flash: #7dd3fc;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 45px rgba(8, 16, 12, 0.5);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

/* An explicit `display` on a component beats the browser default of
   `[hidden] { display: none }`, so restate it with priority. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

.app {
  width: min(880px, 100% - 2rem);
  margin: 0 auto;
  padding: 1.75rem 0 4rem;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.masthead__sub {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.masthead__actions {
  display: flex;
  gap: 0.5rem;
}

.icon-button {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font: inherit;
  font-size: 0.83rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-raised-2);
}

/* ---------- guess form ---------- */

.guess-form {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.guess-input-wrap {
  position: relative;
  flex: 1;
}

.guess-input {
  width: 100%;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.guess-input::placeholder {
  color: var(--text-faint);
}

.guess-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(89, 217, 138, 0.18);
}

.guess-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.submit-button {
  padding: 0.85rem 1.4rem;
  font: inherit;
  font-weight: 650;
  font-size: 0.95rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.15s, transform 0.06s;
}

.submit-button:hover {
  filter: brightness(1.07);
}

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

.submit-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.feedback {
  min-height: 1.3rem;
  margin: 0.6rem 0 0;
  font-size: 0.87rem;
  color: var(--warm);
}

.feedback a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.give-up-button {
  margin-top: 0.15rem;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  background: none;
  border: none;
  color: var(--text-faint);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.give-up-button:hover {
  color: var(--boiling);
}

/* ---------- suggestions ---------- */

.suggestions {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 15rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.suggestions li {
  padding: 0.5rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.92rem;
}

.suggestions li[aria-selected="true"],
.suggestions li:hover {
  background: rgba(89, 217, 138, 0.15);
}

.suggestions__text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.suggestions .sci {
  color: var(--text-faint);
  font-size: 0.78rem;
  font-style: italic;
  white-space: nowrap;
}

.thumb {
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

/* Any hover target that can show a photo gets a faint affordance. */
[data-preview-sci] {
  cursor: pointer;
}

/* Inline thumbnails are injected only on touch (see speciesThumb in app.js). */
@media (hover: none) {
  .suggestions {
    max-height: min(50vh, 22rem);
  }

  .suggestions li {
    align-items: center;
    gap: 0.65rem;
  }

  .suggestions__thumb {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 6px;
  }

  .suggestions__text {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
  }

  .suggestions .sci {
    white-space: normal;
  }

  .guess-row:has(.guess-row__thumb) {
    grid-template-columns: 3.25rem 1fr 4.2rem 5rem;
  }

  .guess-row__thumb {
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 7px;
  }
}

/* ---------- clade definition tooltip ---------- */

.clade-tip {
  position: fixed;
  z-index: 90;
  width: 250px;
  padding: 0.7rem 0.8rem;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.clade-tip.is-visible {
  opacity: 1;
}

.clade-tip__head {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.clade-tip__name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
}

.clade-tip__rank {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.clade-tip__body {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ---------- hover image preview ---------- */

.preview-card {
  position: fixed;
  z-index: 90;
  width: 220px;
  padding: 0.55rem;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.preview-card.is-visible {
  opacity: 1;
}

.preview-card__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
}

.preview-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.preview-card__img.is-loaded {
  opacity: 1;
}

.preview-card__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: preview-spin 0.7s linear infinite;
}

.preview-card.is-loaded .preview-card__spinner {
  display: none;
}

@keyframes preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.preview-card__caption {
  display: flex;
  flex-direction: column;
  margin-top: 0.45rem;
  line-height: 1.3;
}

.preview-card__name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.preview-card__sci {
  font-size: 0.76rem;
  font-style: italic;
  color: var(--text-faint);
}

.preview-card__credit {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--text-faint);
}

/* ---------- result banner ---------- */

.result-banner {
  margin-top: 1.5rem;
  padding: 1.15rem 1.3rem;
  background: rgba(89, 217, 138, 0.1);
  border: 1px solid rgba(89, 217, 138, 0.34);
  border-radius: var(--radius);
}

.result-banner--lost {
  background: rgba(255, 111, 94, 0.1);
  border-color: rgba(255, 111, 94, 0.34);
}

.result-banner__title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.result-banner__body {
  margin: 0 0 0.9rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.result-banner__body em {
  color: var(--text);
  font-style: italic;
}

.result-banner__actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.15s, border-color 0.15s, color 0.15s;
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
}

.primary-button:hover {
  filter: brightness(1.07);
}

.ghost-button {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}

.ghost-button:hover {
  color: var(--text);
  border-color: var(--accent);
}

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

.table-section {
  margin-top: 2rem;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.table-toolbar__heading {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.count {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.45rem;
  background: var(--bg-raised-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text);
}

.segmented {
  display: inline-flex;
  padding: 0.2rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.segmented button {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.8rem;
  border: none;
  background: transparent;
  color: var(--text-faint);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented button.is-active {
  background: var(--bg-raised-2);
  color: var(--text);
}

.guess-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr 4.2rem 5rem;
  gap: 0.5rem 0.9rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cold);
  border-radius: var(--radius-sm);
  animation: row-in 0.22s ease-out;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.guess-row--found {
  border-color: rgba(89, 217, 138, 0.45);
  border-left-color: var(--found);
  background: rgba(89, 217, 138, 0.12);
}

/* Newly added guess: wash the whole row light blue and fade it out over a
   couple of seconds. A box-shadow overlay (rather than background) leaves each
   row's own background and left-border colour intact underneath. */
.guess-row--flash {
  animation:
    row-in 0.22s ease-out,
    guess-row-flash 2.6s ease-out;
}

@keyframes guess-row-flash {
  0%,
  25% {
    box-shadow:
      inset 0 0 0 100vw rgba(125, 211, 252, 0.32),
      0 0 0 2px rgba(125, 211, 252, 0.7);
  }
  100% {
    box-shadow:
      inset 0 0 0 100vw rgba(125, 211, 252, 0),
      0 0 0 2px rgba(125, 211, 252, 0);
  }
}

.guess-row[data-temperature="boiling"] { border-left-color: var(--boiling); }
.guess-row[data-temperature="hot"] { border-left-color: var(--hot); }
.guess-row[data-temperature="warm"] { border-left-color: var(--warm); }
.guess-row[data-temperature="cool"] { border-left-color: var(--cool); }
.guess-row[data-temperature="cold"] { border-left-color: var(--cold); }
.guess-row[data-temperature="found"] { border-left-color: var(--found); }

.guess-row__main {
  min-width: 0;
}

.guess-row__name {
  font-weight: 600;
  font-size: 0.97rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.guess-row__sci {
  font-size: 0.76rem;
  font-style: italic;
  color: var(--text-faint);
  font-weight: 400;
}

.guess-row__meta {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.guess-row__meta strong {
  color: var(--text);
  font-weight: 600;
}

.guess-row__score {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.guess-row__rank {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- cladogram ---------- */

.tree-card {
  padding: 0.35rem 0.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.clade-tree svg {
  display: block;
  min-width: 420px;
}

.tree-hint {
  font-size: 0.74rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tree__spine {
  stroke: var(--border-strong);
  stroke-width: 2;
  fill: none;
}

.tree__branch {
  stroke-width: 1.6;
  fill: none;
  opacity: 0.75;
}

.tree__node {
  stroke: var(--bg-raised);
  stroke-width: 2;
}

.tree__tip {
  stroke: var(--bg-raised);
  stroke-width: 2;
}

.tree__tip--found {
  filter: drop-shadow(0 0 6px rgba(89, 217, 138, 0.85));
}

.tree__clade {
  font: 600 12px var(--font);
  fill: var(--text);
}

/* Clade labels with a definition invite a hover. */
.tree__clade--info {
  cursor: help;
  text-decoration: underline dotted var(--text-faint);
  text-underline-offset: 2px;
}

.tree__age {
  font: 400 10px var(--font);
  fill: var(--text-faint);
}

.tree__leaf {
  font: 400 12px var(--font);
  fill: var(--text-muted);
}

.tree__leaf--found {
  font-weight: 700;
  fill: var(--found);
}

/* Brief highlight of the just-added guess: an expanding light-blue ring at its
   marker plus a blue label that fades back to normal over a couple of seconds,
   so the eye is drawn to where it landed. */
.tree__ping {
  fill: none;
  stroke: var(--flash);
  stroke-width: 2.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: tree-ping 1.4s ease-out forwards;
  pointer-events: none;
}

@keyframes tree-ping {
  from {
    transform: scale(0.4);
    opacity: 0.95;
  }
  to {
    transform: scale(6);
    opacity: 0;
  }
}

.tree__leaf--flash {
  animation: tree-leaf-flash 2.6s ease-out;
}

@keyframes tree-leaf-flash {
  0% {
    fill: var(--flash);
    font-weight: 700;
  }
  35% {
    fill: var(--flash);
    font-weight: 700;
  }
  100% {
    fill: var(--text-muted);
    font-weight: 400;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tree__ping {
    display: none;
  }
  .tree__leaf--flash,
  .guess-row--flash {
    animation: none;
  }
}

.tree__unknown {
  font: italic 600 12px var(--font);
  fill: var(--text-faint);
}

.tree__score {
  font: 600 11px var(--mono);
}

.empty-state--tree {
  margin: 0.4rem;
  border: none;
  background: transparent;
}

.empty-state {
  margin: 0;
  padding: 1.5rem;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.88rem;
  background: var(--bg-raised);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(10, 18, 13, 0.74);
  backdrop-filter: blur(5px);
}

.modal__panel {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 1.6rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal__panel h2 {
  margin: 0 0 0.8rem;
  font-size: 1.2rem;
}

.modal__panel h3 {
  margin: 1.3rem 0 0.4rem;
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.modal__panel p {
  margin: 0 0 0.7rem;
  font-size: 0.91rem;
  color: var(--text-muted);
}

.modal__panel strong,
.modal__panel em {
  color: var(--text);
}

.modal__close {
  position: absolute;
  top: 0.7rem;
  right: 0.85rem;
  width: 2rem;
  height: 2rem;
  font-size: 1.35rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--text-faint);
  border-radius: 50%;
  cursor: pointer;
}

.modal__close:hover {
  color: var(--text);
  background: var(--bg-raised-2);
}

.legend {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.chip {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 4px;
  flex: none;
}

.chip--boiling { background: var(--boiling); }
.chip--hot { background: var(--hot); }
.chip--warm { background: var(--warm); }
.chip--cool { background: var(--cool); }
.chip--cold { background: var(--cold); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.stat {
  padding: 0.75rem;
  background: var(--bg-raised-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.stat__value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.histogram {
  list-style: none;
  margin: 0 0 1.1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.histogram li {
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.histogram__bar {
  height: 1.1rem;
  min-width: 1.6rem;
  padding: 0 0.4rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: var(--bg-raised-2);
  border-radius: 5px;
  color: var(--text);
  font-size: 0.72rem;
}

.histogram__bar--filled {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

/* ---------- toast + footer ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.75rem;
  transform: translateX(-50%);
  z-index: 80;
  padding: 0.6rem 1.15rem;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.79rem;
  color: var(--text-faint);
}

.footer a {
  color: var(--text-muted);
}

@media (max-width: 560px) {
  .guess-row {
    grid-template-columns: 1fr 3.6rem;
  }

  .guess-row__rank {
    grid-column: 2;
    text-align: right;
  }

  .guess-form {
    flex-direction: column;
  }
}

@media (max-width: 560px) and (hover: none) {
  .guess-row:has(.guess-row__thumb) {
    grid-template-columns: 3rem 1fr 3.6rem;
  }

  .guess-row:has(.guess-row__thumb) .guess-row__rank {
    grid-column: 3;
  }

  .guess-row__thumb {
    width: 3rem;
    height: 3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
