:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e2e2e6;
  --accent: #b3441e;
  --accent-contrast: #ffffff;
  --error-bg: #fdecea;
  --error-text: #7a1f14;
  --grid: #e5e7eb;
  --path-line: #b3441e;
  --zero-line: #6b7280;
  --silhouette: #7c828d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --surface: #1e2025;
    --text: #ececec;
    --muted: #9aa0aa;
    --border: #2e3138;
    --accent: #e07a4e;
    --accent-contrast: #1a1a1a;
    --error-bg: #3a1a16;
    --error-text: #ffb4a6;
    --grid: #2a2d33;
    --path-line: #e07a4e;
    --zero-line: #8a8f98;
    --silhouette: #aeb4bf;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header {
  padding: 2rem 1.5rem 1rem;
  max-width: 960px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

/* Units and angles: set once and left, so small and out of the way. */
.unit-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
}

.unit-switch label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

fieldset,
.section {
  flex: 1 1 200px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem 1rem;
  min-width: 200px;
}

legend,
.section > summary {
  padding: 0 0.4rem;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Above the breakpoint every section is open and the marker would only be
   noise, so the summary reads as a plain heading. */
.section > summary {
  list-style: none;
  margin-bottom: 0.6rem;
}

.section > summary::-webkit-details-marker {
  display: none;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

/* The `hidden` attribute is only `display: none` in the user-agent
   stylesheet, so any author rule that sets `display` beats it - the rule
   above would otherwise keep a hidden label on screen. */
[hidden] {
  display: none !important;
}

input,
select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

button {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.4rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  height: fit-content;
}

button:hover {
  filter: brightness(1.08);
}

section#results {
  margin-top: 2rem;
}

canvas#chart {
  width: 100%;
  height: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: block;
}

.table-wrap {
  margin-top: 1rem;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.5rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody tr:last-child td {
  border-bottom: none;
}

.error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 8px;
}

.animal-panel {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
}

canvas#vitals-canvas {
  width: 320px;
  height: 320px;
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.animal-info {
  flex: 1 1 260px;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

.animal-info h3 {
  margin: 0 0 0.15rem;
  font-size: 1.1rem;
}

.animal-info .scientific-name {
  font-style: italic;
  color: var(--muted);
  font-size: 0.85rem;
}

.hit-badge {
  display: inline-block;
  margin: 0.6rem 0;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.hit-badge.hit {
  background: #16a34a22;
  color: #16a34a;
}

.hit-badge.marginal {
  background: #f59e0b22;
  color: #b45309;
}

.hit-badge.miss {
  background: var(--error-bg);
  color: var(--error-text);
}

.inline-warning {
  margin: -0.3rem 0 0;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: #f59e0b22;
  color: #b45309;
  font-size: 0.8rem;
  line-height: 1.4;
}

.inline-warning .link-button {
  display: block;
  margin-top: 0.3rem;
  color: inherit;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .hit-badge.marginal,
  .inline-warning {
    color: #fbbf24;
  }
}

.animal-info dl {
  margin: 0.5rem 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.9rem;
}

.animal-info dt {
  color: var(--muted);
  font-weight: 600;
}

.animal-info dd {
  margin: 0;
}

.animal-info h4 {
  margin: 0.9rem 0 0.3rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.animal-info ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.9rem;
}

.animal-info li {
  margin-bottom: 0.3rem;
}

.size-row {
  display: flex;
  gap: 0.4rem;
}

.size-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.size-row select {
  flex: 0 0 auto;
}

.presets .size-row button {
  flex: 0 0 auto;
}

.preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 0.2rem;
}

#preset-status {
  overflow-wrap: anywhere;
}

.link-button {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}

canvas#vitals-canvas {
  width: 100%;
  max-width: 460px;
  height: auto;
  flex: 1 1 320px;
}

.unit-suffix {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.hint {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 62ch;
}

canvas#vitals-canvas {
  touch-action: none;
}

.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.5rem 0 0.75rem;
}

.table-controls label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.table-controls input {
  width: 6rem;
}

.column-picker {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0.35rem 0.75rem 0.5rem;
  margin: 0;
}

.column-picker legend {
  font-size: 0.7rem;
}

#column-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
}

.column-toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}

.column-toggle input {
  width: auto;
  margin: 0;
}

.animal-info dd.ok {
  color: #16a34a;
}

.animal-info dd.bad {
  color: var(--error-text);
  font-weight: 600;
}

/* The ammunition shortlist. */
.shortlist-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin: 0.75rem 0 0.5rem;
}

.shortlist-controls button {
  align-self: auto;
  padding: 0.5rem 1rem;
}

.shortlist-filter {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  cursor: pointer;
}

.shortlist-filter input {
  width: auto;
  min-height: 0;
}

#shortlist td:first-child {
  white-space: normal;
  min-width: 14rem;
}

.shortlist-detail {
  color: var(--muted);
  font-size: 0.8rem;
}

.shortlist-why {
  color: var(--error-text);
}

.shortlist-row {
  cursor: pointer;
}

.shortlist-row:hover,
.shortlist-row:focus-visible {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  outline: none;
}

/* A failing load stays in the table rather than being filtered out: seeing
   that your usual round runs out of energy sixty yards short is the answer,
   and hiding it would just look like the catalogue is thin. */
.shortlist-row.bad {
  opacity: 0.72;
}

#shortlist td.ok {
  color: #16a34a;
}

#shortlist td.bad {
  color: var(--error-text);
  font-weight: 600;
}

/* Faded rather than hidden: the numbers are still the last true answer, and
   the note above says what changed. */
#shortlist-wrap.stale {
  opacity: 0.5;
}

/* ---------------------------------------------------------------------------
   Phones.

   The form is long because the app asks for a lot: load, rifle, shot,
   atmosphere and target. On a desktop those sit side by side and the whole
   thing is one screen. Stacked into a single column it ran to roughly three
   screens before the first number appeared, which is no use standing in a
   field. Two changes fix most of it: fold away the groups that are set once
   and left alone, and pack the short numeric fields two to a row.
--------------------------------------------------------------------------- */
@media (max-width: 700px) {
  header {
    padding: 1.25rem 1rem 0.5rem;
  }

  h1 {
    font-size: 1.3rem;
  }

  main {
    padding: 0 1rem 3rem;
  }

  form {
    padding: 0.9rem;
    gap: 0.6rem;
  }

  .section {
    flex: 1 1 100%;
    padding: 0.5rem 0.75rem 0.75rem;
  }

  /* A collapsed section should cost one line, so drop the padding the open
     state needs. */
  .section:not([open]) {
    padding-bottom: 0.5rem;
  }

  .section > summary {
    list-style: revert;
    cursor: pointer;
    margin-bottom: 0;
    padding: 0.35rem 0.2rem;
  }

  .section[open] > summary {
    margin-bottom: 0.5rem;
  }

  .section > summary::-webkit-details-marker {
    display: revert;
  }

  .fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 0.6rem;
  }

  /* Anything with a long label, a composite control or a message of its own
     spans both columns rather than being squeezed. */
  .fields > .wide {
    grid-column: 1 / -1;
  }

  label {
    margin-bottom: 0.5rem;
  }

  /* Comfortably tappable, and 16px stops iOS zooming the page on focus. */
  input,
  select {
    font-size: 16px;
    padding: 0.5rem;
    min-height: 2.6rem;
    width: 100%;
    min-width: 0;
  }

  /* Follows the form down the screen, so Calculate is always a thumb away
     instead of at the bottom of a long scroll. It scrolls out of the way
     once the results are reached, which is when it stops being useful. */
  form > button[type="submit"] {
    position: sticky;
    bottom: 0.6rem;
    z-index: 5;
    width: 100%;
    align-self: stretch;
    box-shadow: 0 2px 10px rgb(0 0 0 / 0.25);
  }

  .preset-actions {
    gap: 0.75rem 1.1rem;
  }

  .table-controls {
    gap: 0.6rem;
  }

  .table-controls label {
    flex: 1 1 auto;
  }

  .table-controls input {
    width: 5rem;
  }

  .column-picker {
    flex: 1 1 100%;
  }

  th,
  td {
    padding: 0.45rem 0.55rem;
    font-size: 0.9rem;
  }

  .animal-panel {
    gap: 1rem;
  }

  canvas#vitals-canvas {
    width: 100%;
    height: auto;
  }

  .animal-info {
    flex: 1 1 100%;
    min-width: 0;
    padding: 0.85rem 1rem;
  }

  .animal-info dl {
    grid-template-columns: 1fr;
    gap: 0 0;
  }

  .animal-info dt {
    margin-top: 0.5rem;
  }

  /* Six columns will not fit a phone, so the table scrolls sideways inside
     its wrapper. The load name is the thing you read down the list, so it
     stays put while the figures slide under it. */
  /* Full width, so the cartridge filter wraps onto its own line instead of
     running off the right edge. */
  .shortlist-controls button {
    flex: 1 1 100%;
  }

  #shortlist td:first-child,
  #shortlist th:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
    min-width: 11rem;
  }

  #shortlist th,
  #shortlist td {
    font-size: 0.85rem;
  }
}

/* ---------------------------------------------------------------------------
   Footer: what the page does, and where to get in touch. Quiet on purpose -
   it is read once, and the form is what the page is for.
--------------------------------------------------------------------------- */
.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer .features {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  columns: 2;
  column-gap: 2rem;
}

.site-footer .features li {
  break-inside: avoid;
  margin-bottom: 0.3rem;
  padding-left: 0.8em;
  text-indent: -0.8em;
}

.site-footer .features li::before {
  content: "\2013\00a0";
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--accent);
}

@media (max-width: 700px) {
  .site-footer {
    padding: 1rem 1rem 1.5rem;
  }

  .site-footer .features {
    columns: 1;
  }
}
