:root {
  --bg: #f9f9f7;
  --panel: #fcfcfb;
  --fg: #0b0b0b;
  --muted: #52514e;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.12);
  --chart-bg: #fcfcfb;
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --s8: #e34948;
  --neutral: #898781;
  --crit: #d03b3b;
  --warn-bg: #fff4dc;
  --seq-lo: #cde2fb;
  --seq-hi: #0d366b;
  --focus: #eda100;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0d;
    --panel: #1a1a19;
    --fg: #f0efec;
    --muted: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.12);
    --chart-bg: #1a1a19;
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #0ca30c;
    --s7: #9085e9;
    --s8: #e66767;
    --neutral: #898781;
    --crit: #e66767;
    --warn-bg: #3a2c0c;
    --seq-lo: #184f95;
    --seq-hi: #cde2fb;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --panel: #1a1a19;
  --fg: #f0efec;
  --muted: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.12);
  --chart-bg: #1a1a19;
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #0ca30c;
  --s7: #9085e9;
  --s8: #e66767;
  --neutral: #898781;
  --crit: #e66767;
  --warn-bg: #3a2c0c;
  --seq-lo: #184f95;
  --seq-hi: #cde2fb;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font:
    14px/1.45 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
}

a {
  color: var(--accent);
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.top h1 {
  margin: 0;
  font-size: 1.35rem;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  max-width: 75ch;
}

.top nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

select,
input[type="number"],
input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  width: 100%;
  min-width: 0;
}

input:invalid {
  border-color: var(--crit);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 500px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.layout > * {
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

fieldset {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
  padding: 10px 0 6px;
  min-width: 0;
}

fieldset:first-child {
  border-top: none;
  padding-top: 0;
}

legend {
  font-weight: 600;
  padding: 0 4px 0 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.86rem;
  color: var(--muted);
}

label.row {
  display: grid;
  grid-template-columns: 9.5em minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

label.file {
  margin-top: 8px;
}

.grid2,
.grid3 {
  display: grid;
  gap: 6px 10px;
  margin: 6px 0;
}

.grid2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.note {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 4px 0;
}

details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86rem;
  margin: 4px 0;
}

.table-wrap {
  overflow-x: auto;
}

/* Fixed layout with percentage columns (see the colgroup in index.html):
   the table is exactly as wide as its box at any width, and the inputs
   shrink instead of pushing the remove column out of view. */
.load-table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  font-size: 0.84rem;
  margin-bottom: 6px;
}

.load-table .c-name {
  width: 26%;
}

.load-table .c-num {
  width: 13%;
}

.load-table .c-hours {
  width: 19%;
}

.load-table .c-base {
  width: 8%;
}

.load-table .c-remove {
  width: 8%;
}

.load-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 2px;
}

.load-table td {
  padding: 2px;
}

.load-table input[type="number"],
.load-table input[type="text"] {
  padding: 3px 4px;
}

/* Spin buttons take a third of a narrow number field; arrow keys still work. */
.load-table input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.load-table input[type="number"]::-webkit-inner-spin-button,
.load-table input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.load-table .hours input[type="number"] {
  padding: 3px 2px;
}

.load-table .hours {
  display: flex;
  align-items: center;
  gap: 2px;
}

.load-table input[type="radio"] {
  margin: 0;
}

.load-table button {
  width: 100%;
  padding: 3px 0;
}

.load-table .swatch {
  margin-right: 2px;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.results h2 {
  font-size: 1rem;
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

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

.summary {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 4px 0 10px;
}

.summary.bad {
  color: var(--crit);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 0;
}

.tiles div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.tiles dt {
  font-size: 0.78rem;
  color: var(--muted);
}

.tiles dd {
  margin: 0;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.warnings {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.warnings li {
  background: var(--warn-bg);
  border-radius: 6px;
  padding: 4px 8px;
  margin-top: 4px;
}

.warnings li::before {
  content: "! ";
  font-weight: 700;
}

.error {
  color: var(--crit);
  font-weight: 600;
}

.chart {
  display: block;
  width: 100%;
  height: 220px;
  background: var(--chart-bg);
}

.chart.short {
  height: 64px;
}

.chart.short2 {
  height: 150px;
}

.chart.tall {
  height: 320px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.s1 {
  background: var(--s1);
}

.s2 {
  background: var(--s2);
}

.crit {
  background: var(--crit);
}

.critlight {
  background: var(--crit);
  opacity: 0.3;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.ring {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
}

.box {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--fg);
}

.dash {
  display: inline-block;
  width: 16px;
  border-top: 2px dashed var(--crit);
}

.tri {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--crit);
}

.ramp-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.ramp {
  display: inline-block;
  width: 120px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--seq-lo), var(--seq-hi));
  margin-right: 12px;
}

.best {
  font-weight: 600;
  margin: 8px 0 4px;
}

.footnote {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 16px;
}

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  max-width: 320px;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.82rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px 16px;
  }

  label.row {
    grid-template-columns: 8em minmax(0, 1fr);
  }

  .chart.tall {
    height: 280px;
  }
}

/* Phones: each load state becomes two lines (name, base, remove; then the
   numbers with their own labels), so nothing has to scroll sideways. */
@media (max-width: 520px) {
  .load-table,
  .load-table tbody {
    display: block;
  }

  .load-table colgroup,
  .load-table thead {
    display: none;
  }

  .load-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.5fr) auto auto;
    gap: 2px 4px;
    padding: 6px 0;
    border-top: 1px solid var(--border);
  }

  .load-table td {
    padding: 0;
  }

  .load-table td:nth-child(1) {
    grid-area: 1 / 1 / 2 / 5;
  }

  .load-table td:nth-child(2) {
    grid-area: 2 / 1;
  }

  .load-table td:nth-child(3) {
    grid-area: 2 / 2;
  }

  .load-table td:nth-child(4) {
    grid-area: 2 / 3;
  }

  .load-table td:nth-child(5) {
    grid-area: 2 / 4 / 3 / 7;
  }

  .load-table td:nth-child(6) {
    grid-area: 1 / 5;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .load-table td:nth-child(n + 2):not(:last-child)::before {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .load-table td:nth-child(6)::before {
    display: inline;
  }

  .load-table td:nth-child(2)::before {
    content: "mA";
  }

  .load-table td:nth-child(3)::before {
    content: "every s";
  }

  .load-table td:nth-child(4)::before {
    content: "for s";
  }

  .load-table td:nth-child(5)::before {
    content: "hours (from-to)";
  }

  .load-table td:nth-child(6)::before {
    content: "base";
  }

  .load-table td:nth-child(7) {
    grid-area: 1 / 6;
  }

  .load-table button {
    width: auto;
    padding: 3px 10px;
  }
}

@media (forced-colors: active) {
  .swatch,
  .dot {
    border: 1px solid CanvasText;
  }
}
