*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--grain), var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

main,
.masthead,
.colophon {
  width: min(1180px, 100% - 2.5rem);
  margin-inline: auto;
}

/* Masthead: the running head of a printed journal. */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 1.1rem 0 0.6rem;
  border-bottom: 3px double var(--ink);
  font: 500 0.75rem var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.masthead strong {
  font: italic 700 1.1rem var(--font-display);
  letter-spacing: 0;
  text-transform: none;
}

.masthead span:nth-child(3) {
  margin-left: auto;
  color: var(--ink-muted);
}

.masthead select {
  padding: 0.15rem 0.3rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  letter-spacing: 0.04em;
}

/* Hero */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.42fr);
  gap: 3rem;
  align-items: end;
  padding: clamp(2.5rem, 7vw, 5.5rem) 0 2.5rem;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3rem, 8.6vw, 7.4rem);
  font-weight: 800;
  font-variation-settings: 'opsz' 144, 'SOFT' 30;
  line-height: 0.92;
  letter-spacing: -0.035em;
}

h1 em {
  color: var(--accent);
  font-weight: 700;
}

.lede {
  margin: 0;
  padding-left: 1.25rem;
  border-left: 1px solid var(--ink);
  font-size: 1.05rem;
  color: var(--ink-soft);
}

/* The index of known species, drifting past like a specimen drawer. */
.species-strip {
  overflow: hidden;
  border-block: 1px solid var(--rule);
  mask-image: linear-gradient(90deg, transparent, black 6%, black 94%, transparent);
}

.species-track {
  display: flex;
  width: max-content;
  animation: drift 60s linear infinite;
}

.species-strip:hover .species-track {
  animation-play-state: paused;
}

@keyframes drift {
  to { transform: translateX(-50%); }
}

.species {
  display: grid;
  justify-items: center;
  width: 9.5rem;
  padding: 0.75rem 0.5rem 0.9rem;
  border-right: 1px solid var(--rule-soft);
}

.species img {
  width: 6.5rem;
  height: 6.5rem;
}

.species span {
  font: italic 600 0.9rem var(--font-display);
}

/* Evidence intake */
.intake {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  gap: 2rem;
  margin: 3.5rem 0 0;
}

.intake-label {
  font: 500 0.75rem/1.5 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.intake-label b {
  display: block;
  font: italic 700 2.2rem/1 var(--font-display);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

textarea,
input {
  width: 100%;
  background: var(--paper-raised);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  font: 0.88rem/1.6 var(--font-mono);
}

textarea {
  display: block;
  min-height: 15rem;
  padding: 1rem 1.1rem;
  resize: vertical;
}

input {
  padding: 0.7rem 0.9rem;
}

textarea:focus-visible,
input:focus-visible,
button:focus-visible,
.track:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea.dragging {
  border-style: dashed;
  border-color: var(--accent);
}

.intake-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-top: 1rem;
}

.intake-bar .primary {
  margin-left: auto;
}

.subjects {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.subjects:not(:empty) {
  margin-top: 0.75rem;
}

/* Opening an export is the main way in on a phone, so it looks like a button. */
.secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink);
  transition: border-color 0.15s, color 0.15s;
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.secondary svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chip {
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 500 0.82rem var(--font-body);
  cursor: pointer;
}

.chip[aria-pressed='false'] {
  border-color: var(--rule);
  color: var(--ink-muted);
  text-decoration: line-through;
}

button {
  font: 600 0.95rem var(--font-body);
  cursor: pointer;
}

.primary {
  padding: 0.85rem 1.6rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  letter-spacing: 0.02em;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.primary:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
}

.primary:active:not(:disabled) {
  transform: translateY(1px);
}

.primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.link {
  padding: 0;
  border: none;
  background: none;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.25em;
}

.link:hover {
  color: var(--accent);
}

.names-form,
.key-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: end;
  margin-top: 1rem;
}

.names-form label {
  grid-column: 1 / -1;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.names-form button,
.key-form button {
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink);
}

.fineprint {
  margin: 0.9rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.error {
  margin: 1rem 0 0;
  font: 0.85rem var(--font-mono);
  color: var(--accent);
}

/* Lab: specimens flicker past while Jev decides. */
.lab {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-block: 1px solid var(--ink);
}

.lab img {
  width: 7rem;
  height: 7rem;
  flex-shrink: 0;
}

.lab-log {
  font: 0.9rem/1.8 var(--font-mono);
  color: var(--ink-soft);
}

.lab-log p {
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  animation: type-in 0.35s steps(18, end);
}

@keyframes type-in {
  from { max-width: 0; }
  to { max-width: 40ch; }
}

/* Results */
.results {
  margin-top: 4rem;
}

.suspect {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: center;
  padding: 2rem 0;
  border-block: 3px double var(--ink);
}

.suspect img {
  width: clamp(8rem, 16vw, 12rem);
  height: auto;
}

.kicker {
  margin: 0;
  font: 500 0.75rem var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.suspect-name {
  margin: 0.25rem 0;
  font: 800 clamp(2.6rem, 6vw, 4.6rem) / 0.95 var(--font-display);
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.suspect-stat {
  margin: 0;
  font: 0.85rem var(--font-mono);
  color: var(--ink-soft);
}

.bars {
  display: grid;
  gap: 0.55rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr 3rem;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.9rem;
}

.bar-row .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row .value {
  text-align: right;
  font: 0.85rem var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.track {
  position: relative;
  height: 8px;
  background: var(--rule-soft);
}

.fill {
  height: 100%;
  width: 0;
  background: var(--ink);
  transition: width 1.1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Measurement scales carry a tick at every level, like a ruler. */
.scale .track {
  background:
    repeating-linear-gradient(90deg, var(--ink-muted) 0 1px, transparent 1px calc(100% / var(--segments))),
    var(--rule-soft);
}

.scale .fill {
  opacity: 0.9;
}

/* Hover tooltips carry the full distribution behind a measurement. */
[data-tip] {
  cursor: help;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 3;
  bottom: calc(100% + 10px);
  left: 0;
  width: max-content;
  max-width: 19rem;
  padding: 0.55rem 0.75rem;
  background: var(--ink);
  color: var(--paper);
  font: 0.72rem/1.55 var(--font-mono);
  white-space: pre;
  pointer-events: none;
}

.plates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr));
  margin-top: 2.5rem;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

/* A specimen plate. Shared borders draw one cabinet around all plates. */
.plate {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem 1.5rem;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: var(--paper-raised);
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: var(--delay, 0ms);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
}

.plate-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 500 0.72rem var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.menace {
  text-align: right;
}

.menace-value {
  display: block;
  font: 800 2.4rem/1 var(--font-display);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.plate-figure {
  position: relative;
  display: grid;
  place-items: center;
  margin: -0.5rem 0 0.5rem;
}

.plate-figure img {
  width: min(15rem, 80%);
  height: auto;
  aspect-ratio: 1;
}

.plate-name {
  margin: 0;
  font: 800 2rem/1.05 var(--font-display);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.plate-type {
  margin: 0.2rem 0 0;
  font: 600 1.05rem var(--font-body);
}

.plate-type small {
  margin-left: 0.4rem;
  font: 0.78rem var(--font-mono);
  color: var(--ink-muted);
}

.plate-species {
  margin: 0;
  font: italic 400 1rem var(--font-display);
  color: var(--ink-soft);
}

.plate-note {
  margin: 0.8rem 0 0;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  font: italic 400 0.95rem/1.45 var(--font-display);
  /* Two lines, so plates side by side line up even when a note is shorter. */
  min-height: calc(2 * 1.45em + 0.8rem + 1px);
}

.measures {
  display: grid;
  gap: 0.95rem;
  margin: 1.25rem 0;
}

.scale-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
}

.scale-top span:last-child {
  font: 0.72rem var(--font-mono);
  color: var(--ink-muted);
}

.scale-level {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.counted {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: auto 0 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

/* Both rows of numbers sit together at the bottom of the plate. */
.counted + .findings {
  margin-top: 0;
}

/* Counted, not judged: set in the mono face so facts read differently from Jev's guesses. */
.counted dd {
  font: 600 1.15rem var(--font-mono);
}

.counted .finding[title] {
  cursor: help;
}

.findings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: auto 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

/* Number above its label, numbers aligned even when a label wraps. */
.finding {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
}

.finding dd {
  margin: 0;
  font: 800 1.5rem var(--font-display);
}

.finding dt {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

/* The rubber stamp, slammed on after its plate settles. */
.stamp {
  position: absolute;
  bottom: 0.75rem;
  right: 0;
  z-index: 1;
  padding: 0.3rem 0.65rem;
  border: 3px solid var(--accent);
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--paper-raised), inset 0 0 0 3px var(--accent);
  color: var(--accent);
  font: 600 0.8rem var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  mix-blend-mode: multiply;
  opacity: 0.88;
  transform: rotate(-11deg);
  animation: stamp 0.45s cubic-bezier(0.5, 1.8, 0.6, 1) both;
  animation-delay: calc(var(--delay, 0ms) + 700ms);
}

@keyframes stamp {
  from { opacity: 0; transform: rotate(-4deg) scale(2.2); }
}

.suspect .stamp {
  top: 1.2rem;
  bottom: auto;
  right: 0;
  font-size: 1rem;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px var(--accent);
}

.records {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr));
  margin-top: 2.5rem;
  border-top: 1px solid var(--ink);
}

.record {
  display: grid;
  align-content: start;
  gap: 0.15rem;
  padding: 1rem 1.25rem 1.1rem 0;
  border-bottom: 1px solid var(--rule);
}

.record span {
  font: 500 0.72rem var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.record strong {
  font: 800 1.7rem/1.1 var(--font-display);
  overflow-wrap: anywhere;
}

.record small {
  font: 0.8rem var(--font-mono);
  color: var(--ink-soft);
}

.results-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

.footnote {
  margin: 0;
  font: 0.75rem var(--font-mono);
  color: var(--ink-muted);
}

/* The share card preview: the image itself, then what can change on it. */
.card-dialog {
  width: min(56rem, 100% - 2rem);
  max-height: calc(100% - 2rem);
  padding: 1.5rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
}

.card-dialog[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.card-dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 55%, transparent);
}

.card-dialog canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
}

.card-controls {
  display: grid;
  gap: 0.75rem;
}

.card-controls fieldset {
  margin: 0 0 0.5rem;
  padding: 0;
  border: none;
}

.card-controls legend {
  margin-bottom: 0.5rem;
  font: 500 0.72rem var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.card-names {
  display: grid;
  gap: 0.4rem;
}

.card-names input {
  padding: 0.45rem 0.7rem;
}

.colophon {
  margin-top: 5rem;
  padding: 1rem 0 2rem;
  border-top: 1px solid var(--ink);
  font: 0.75rem var(--font-mono);
  color: var(--ink-muted);
}

@media (max-width: 820px) {
  .hero,
  .intake {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .suspect {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 1.5rem;
  }

  .suspect .bars {
    grid-column: 1 / -1;
  }

  /* On top of the mascot, where it can't cover the kicker. */
  .suspect .stamp {
    top: 1.5rem;
    right: auto;
    left: -0.25rem;
    font-size: 0.85rem;
  }

  .intake-bar .primary {
    flex-basis: 100%;
    margin-left: 0;
  }

  .masthead span:nth-child(2) {
    display: none;
  }

  .card-dialog[open] {
    grid-template-columns: 1fr;
  }

  .card-dialog canvas {
    width: min(100%, 22rem);
    justify-self: center;
  }
}

/* Fingers need bigger targets than a mouse pointer. */
@media (pointer: coarse) {
  .chip {
    min-height: 2.5rem;
    padding-inline: 1rem;
  }

  .link {
    min-height: 2.75rem;
  }

  .masthead select {
    min-height: 2.25rem;
  }
}

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

  .species-strip {
    overflow-x: auto;
  }
}
