:root {
  --bg: #f2efe6;
  --surface: #fbfaf5;
  --panel: #e7e2d3;
  --ink: #1b1d19;
  --muted: #4a4c44;
  --line: #c4bea9;
  --accent: #1f5c3c;
  --accent-ink: #ffffff;
  --good: #1f6b3f;
  --bad: #a3271b;
  --warn: #8a4b00;
  --focus: #0b57a8;
  --used: #1f5c3c;
  --spare: #8fc4a2;
  --cold: #7fa7cf;
  --held: #d9d3c1;
  --strip: #1b1d19; --strip-ink: #f2efe6;
  --strip-good: #1f5c3c; --strip-tight: #7a4300; --strip-bad: #8f2318;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #8a8778;
  --r: 4px;
  --r2: 10px;
  --num: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --head: Seravek, "Gill Sans Nova", "Gill Sans", Ubuntu, Calibri, "DejaVu Sans", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c100e;
    --surface: #141a17;
    --panel: #1b231f;
    --ink: #ebefe9;
    --muted: #b9c2ba;
    --line: #34413a;
    --accent: #7fd6a3;
    --accent-ink: #08140d;
    --good: #8fdcae;
    --bad: #ff9a8c;
    --warn: #f2b45c;
    --focus: #ffc36b;
    --used: #5cbf86;
    --spare: #2f5f45;
    --cold: #3e6e9b;
    --held: #2b322e;
    --strip: #1b231f; --strip-ink: #e3e8e1;
    --strip-good: #173d29; --strip-tight: #45300f; --strip-bad: #4d1c16;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --s-other: #7d8279;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
main { max-width: 1060px; margin: 0 auto; padding: 0 16px 40px; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--head); line-height: 1.2; letter-spacing: 0.005em; }
h1 { font-size: clamp(1.7rem, 5vw, 2.5rem); margin: 0 0 6px; }
h2 { font-size: 1.3rem; margin: 0 0 12px; }
h3 { font-size: 1.08rem; margin: 22px 0 8px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.top { padding: 22px 0 14px; }
.lede { margin: 0 0 10px; max-width: 62ch; color: var(--muted); }
.quick { margin: 0; padding: 10px 14px; background: var(--strip); color: var(--strip-ink); border-radius: var(--r); font-size: 1rem; }
.quick[data-status="good"] { background: var(--strip-good); }
.quick[data-status="tight"] { background: var(--strip-tight); }
.quick[data-status="short"], .quick[data-status="none"], .quick[data-status="error"] { background: var(--strip-bad); }
.quick a { color: inherit; white-space: nowrap; }
.quick .q-mark { font-weight: 800; }

.tool { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.block { min-width: 0; }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); padding: 16px; }
.banner { margin: 0; padding: 10px 14px; border: 1px solid var(--accent); border-radius: var(--r); background: var(--surface); }
.hint { margin: 4px 0 10px; color: var(--muted); font-size: 1rem; }
.grid3, .grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid3 { grid-template-columns: repeat(3, 1fr); } .grid2 { grid-template-columns: repeat(2, 1fr); } .grid2 .wide { grid-column: 1 / -1; } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-weight: 600; font-size: 1rem; }
input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r); min-height: 44px; padding: 8px 10px; width: 100%; min-width: 0;
}
input { font-family: var(--num); }
input[data-k="name"] { font-family: inherit; }
input[aria-invalid="true"] { border-color: var(--bad); border-width: 2px; }
.with-unit { display: flex; gap: 6px; }
.with-unit input { flex: 1 1 auto; }
.with-unit select { flex: 0 0 4.6em; padding-inline: 6px; }
.err { margin: 2px 0 0; color: var(--bad); font-size: 1rem; font-weight: 600; }

.devs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.dev {
  position: relative; display: grid; gap: 8px 10px; padding: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--r); background: var(--bg);
}
.with-sw { display: flex; align-items: center; gap: 8px; }
.sw { flex: 0 0 14px; width: 14px; height: 14px; border-radius: 3px; background: var(--s-other); }
.dev-head { display: none; }
.dev-sum { display: none; }
.dev-body { display: contents; }
.dev .dt { grid-column: 1 / -1; }
@media (max-width: 559px) {
  /* phones: one summary line per device that opens to edit */
  .dev { padding: 0; gap: 0; }
  .dev-sum {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 8px 12px; grid-column: 1 / -1;
    font: inherit; color: var(--ink); background: none; border: 0; text-align: left; cursor: pointer;
  }
  .dev-sum .sum-n { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
  .dev-sum .sum-f { flex: 0 0 auto; font-family: var(--num); font-size: 0.95rem; white-space: nowrap; }
  .dev-sum .chev { flex: 0 0 auto; width: 9px; height: 9px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin: -4px 4px 0 2px; }
  .dev.open .dev-sum .chev { transform: rotate(-135deg); margin-top: 4px; }
  .dev:not(.open) > .dev-body { display: none; }
  .dev.open { gap: 8px 10px; padding: 0 12px 12px; }
  .dev.open .dev-sum { padding-inline: 0; border-bottom: 1px solid var(--line); }
  .dev.open .nm { padding-right: 52px; }
  .dev.open .nm { grid-row: 2; }
  .dev.open .v { grid-area: 3 / 1; }
  .dev.open .pct { grid-area: 3 / 2; }
  .dev.open .del { top: 82px; right: 12px; }
  .dev .dt { flex-direction: column; }
}
.dev .nm { grid-column: 1 / -1; padding-right: 48px; }
.dev .v { grid-area: 2 / 1; }
.dev .pct { grid-area: 2 / 2; }
.dev .amt, .dev .feed { grid-column: 1 / -1; }
@media (min-width: 560px) and (max-width: 859px) {
  .dev { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dev .v { grid-area: auto; }
  .dev .pct { grid-area: auto; }
  .dev .amt { grid-column: span 2; }
  .dev .feed { grid-column: span 4; }
}
.dev .del {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.dev .src, .dev .err { grid-column: 1 / -1; margin: 0; }
.dev .add-heater { grid-column: 1 / -1; justify-self: start; }
@media (min-width: 560px) {
  .dev .dt { flex-direction: row; align-items: center; gap: 10px; }
  .dev .dt input { width: 7em; flex: 0 0 7em; }
  .dev .field.dt > label { position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal; }
}
.dev .src { color: var(--muted); font-size: 1rem; }
.tag { font-weight: 600; color: var(--ink); }
.tag.guess { color: var(--bad); }
.dev .field label { font-size: 1rem; font-weight: 600; color: var(--muted); }
@media (min-width: 860px) {
  .dev { grid-template-columns: minmax(12em, 2.2fr) 0.8fr 1.4fr 0.9fr 1.5fr 44px; align-items: end; }
  .dev .nm, .dev .amt, .dev .feed { grid-column: auto; padding-right: 0; }
  .dev .v, .dev .pct { grid-area: auto; }
  .dev .del { position: static; grid-row: 1; grid-column: 6; }
  .dev { padding: 8px 10px; }
  .dev .field > label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .dev-head { display: grid; grid-template-columns: minmax(12em, 2.2fr) 0.8fr 1.4fr 0.9fr 1.5fr 44px; gap: 10px; padding: 0 11px 4px; font-size: 1rem; font-weight: 600; color: var(--muted); }
  .dev-head span:first-child { padding-left: 22px; }
}
.none { margin: 6px 0; color: var(--muted); }
.add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.add select { flex: 1 1 16em; width: auto; }

.btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 8px 16px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--accent); background: var(--surface); color: var(--accent);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 40px; padding: 4px 12px; font-size: 0.95rem; }

details.losses { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
details summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; gap: 10px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: ""; flex: 0 0 auto; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); margin-left: 2px;
}
details[open] > summary::before { transform: rotate(45deg); margin-top: -4px; }
details summary:hover { color: var(--accent); }
details.losses .grid2 { margin-top: 6px; }

/* result */
.result { margin-top: 18px; background: var(--surface); border: 2px solid var(--ink); border-radius: var(--r2); padding: 18px 16px; scroll-margin-top: 10px; }
.result:focus { outline: none; }
.figs { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .figs { grid-template-columns: 1fr 1fr; } }
.fig { margin: 0; display: flex; flex-direction: column; }
.fig-l { font-weight: 600; color: var(--muted); }
.fig-n { font-family: var(--num); font-size: clamp(1.9rem, 7vw, 2.6rem); font-weight: 700; line-height: 1.1; }
.fig-s { color: var(--muted); }
.verdict { margin: 14px 0; font-weight: 650; font-size: 1.05rem; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.verdict.tight { color: var(--warn); }
.v-mark { font-weight: 800; }
.spare-note { margin: -6px 0 12px; color: var(--muted); font-size: 1rem; }
.temps tr.tonight th, .temps tr.tonight td { font-weight: 700; background: var(--panel); }
.tn { font-weight: 600; font-size: 0.9em; }

.gauge { margin: 10px 0 4px; }
.g-bar { display: flex; height: 34px; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; background: var(--held); position: relative; }
.g-bar::after { content: ""; position: absolute; right: -8px; top: 8px; width: 6px; height: 14px; background: var(--ink); border-radius: 0 2px 2px 0; }
.g-bar span { display: block; height: 100%; }
.g-bar span + span { border-left: 2px solid var(--surface); }
.g-used { background: var(--used); }
.g-spare { background: var(--spare); }
.g-cold { background: repeating-linear-gradient(135deg, var(--cold) 0 6px, transparent 6px 10px); }
.g-held { background: var(--held); }
.g-short { background: var(--bad); }
.g-key { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 0.98rem; }
.g-key b { font-family: var(--num); font-weight: 600; }
.k { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; border: 1px solid var(--line); }

.stack { display: flex; height: 22px; border-radius: 4px; overflow: hidden; margin: 6px 0 10px; }
.stack span { display: block; height: 100%; min-width: 2px; }
.stack span + span { border-left: 2px solid var(--surface); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.98rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 0.92rem; color: var(--muted); border-bottom: 2px solid var(--ink); }
.n { text-align: right; font-family: var(--num); white-space: nowrap; }
thead .n { font-family: inherit; }
tfoot th, tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
.devtab tbody th { font-weight: 500; }
.devtab small { color: var(--muted); font-size: 0.85em; }
td.out { color: var(--muted); }
@media (max-width: 480px) {
  th, td { padding: 6px 5px; } table { font-size: 0.95rem; }
  /* phones: By device keeps name and Wh; the runtime table keeps temperature, runtime and battery size */
  .devtab .c-x, .temps .c-use, .temps .c-nts { display: none; }
  .temps .tn { display: block; }
}

dl.bat { margin: 0; display: grid; gap: 2px; }
dl.bat div { display: grid; grid-template-columns: minmax(6.5em, 9.5em) 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
dl.bat dt { font-weight: 600; }
dl.bat dd { margin: 0; font-family: var(--num); font-size: 0.97rem; }
.size { margin: 12px 0 0; }
.size b { font-family: var(--num); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 1rem; min-height: 1em; }
.note:empty { display: none; }
.link-out { font-family: var(--num); font-size: 0.9rem; word-break: break-all; padding: 8px; background: var(--bg); border-radius: var(--r); }
.ask { margin-top: 10px; padding: 12px; border: 2px solid var(--bad); border-radius: var(--r); }
.ask p { margin: 0 0 10px; }
.ask .btn.primary { background: var(--bad); border-color: var(--bad); color: #fff; }
.earlier { margin-top: 10px; }
.earlier ul { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 6px; }
.earlier li { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.limits { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 1rem; }

.undo {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; display: flex; gap: 12px; align-items: center;
  background: var(--ink); color: var(--bg); padding: 8px 8px 8px 16px; border-radius: var(--r); max-width: calc(100% - 32px);
}
.undo p { margin: 0; }
.undo .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }

.content { margin-top: 34px; max-width: 72ch; }
.content > section { margin-bottom: 26px; }
.content p, .content li { overflow-wrap: anywhere; }
.faq h3 { margin-top: 18px; }
.sources ul { padding-left: 1.1em; }
.sources li { margin-bottom: 6px; }

.foot { border-top: 1px solid var(--line); padding: 22px 16px 34px; }
.foot .wrap { max-width: 1060px; margin: 0 auto; }
.sb-footer p { margin: 0 0 10px; color: var(--muted); font-size: 0.95rem; }
.sb-more a { color: var(--muted); }
.sb-credit a, .sb-privacy a { color: var(--accent); }

.sheet { display: none; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  main, .foot, .undo, .skip { display: none !important; }
  .sheet { display: block !important; }
  .sheet header .s-title { font-size: 18pt; font-weight: 700; margin: 0 0 2pt; font-family: var(--head); }
  .sheet header p { margin: 0 0 8pt; font-size: 10.5pt; }
  .sheet table { width: 100%; border-collapse: collapse; font-size: 10pt; line-height: 1.25; margin: 6pt 0 8pt; table-layout: fixed; }
  .sheet th, .sheet td { border: 0.6pt solid #555; padding: 3pt 4pt; color: #000; overflow-wrap: anywhere; }
  .sheet thead th { background: none; border-bottom: 1.2pt solid #000; color: #000; font-size: 9.5pt; }
  .sheet tfoot th, .sheet tfoot td { border-top: 1.2pt solid #000; }
  .sheet .n { text-align: right; font-family: var(--num); }
  .sheet thead th.n { white-space: normal; font-family: inherit; }
  .sheet thead th { vertical-align: bottom; }
  .sheet thead th.grp { text-align: center; border-bottom: 0.6pt solid #555; }
  .sheet col.c-name { width: 30%; }
  .sheet col.c-feed { width: 15%; }
  .sheet col.c-fig { width: 10%; }
  .sheet tr { break-inside: avoid; }
  .sheet .s-dev td:first-child { height: 12pt; }
  .sheet p { margin: 4pt 0; }
  .sheet .s-note { font-size: 9.5pt; }
  .sheet .s-foot { break-inside: avoid; }
  .sheet .s-verdict { font-size: 11pt; margin: 6pt 0; }
  .sheet .s-temp tr.tonight td { font-weight: 700; }
  .sheet .s-temp col.t-at { width: 21%; }
  .sheet .s-temp col.t-use { width: 16%; }
  .sheet .s-temp col.t-run { width: 20%; }
  .sheet .s-temp col.t-n { width: 13%; }
  .sheet .s-temp col.t-size { width: 30%; }
  .sheet .s-meter th.s-cap { text-align: left; font-size: 10pt; border-bottom: 0.6pt solid #555; }
  .sheet .s-meter { margin-top: 8pt; }
  .sheet .s-meter td { height: 13pt; }
  .sheet .s-meter { break-inside: avoid; }
  .sheet .s-meter col.c-time { width: 10%; }
  .sheet .s-meter col.c-read { width: 13%; }
  .sheet .s-meter col.c-note { width: 27%; }
  .sheet .s-meter .m-l { border-left: 1.6pt solid #000; }
  .sheet tfoot { display: table-row-group; }
}

@media (max-width: 480px) {
  table.stackable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stackable tr { display: flex; flex-wrap: wrap; gap: 2px 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.stackable th, table.stackable td { display: block; border: 0; padding: 0; text-align: left; }
  table.stackable tr > th:first-child { flex: 1 0 100%; font-weight: 600; }
  table.stackable td.blank { display: none; }
  table.stackable td[data-l]::before { content: attr(data-l) " "; font-family: system-ui, sans-serif; color: var(--muted); font-size: 0.9em; }
  table.stackable td.out { flex: 1 0 100%; }
  table.stackable tfoot tr { border-top: 2px solid var(--ink); border-bottom: 0; }
}
@media print {
  .sheet.dense table { font-size: 9pt; margin: 4pt 0 6pt; }
  .sheet.dense th, .sheet.dense td { padding: 1.5pt 4pt; }
  .sheet.dense p { margin: 3pt 0; }
  .sheet.dense .s-dev td:first-child { height: auto; }
  .sheet.dense .s-meter td { height: 16pt; }
}
.sources summary h2 { margin: 0; }
@media (max-width: 400px) {
  /* narrow phones: device summary on two lines, so names never break mid-word */
  .dev-sum { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; column-gap: 8px; row-gap: 0; }
  .dev-sum .sw { grid-row: 1 / span 2; }
  .dev-sum .sum-n { grid-column: 2; overflow-wrap: normal; }
  .dev-sum .sum-f { grid-column: 2; grid-row: 2; }
  .dev-sum .chev { grid-column: 3; grid-row: 1 / span 2; }
  .temps .n, .devtab .n { font-family: inherit; font-variant-numeric: tabular-nums; }
  .temps thead th { white-space: normal; }
  dl.bat div { grid-template-columns: 1fr; gap: 0; }
}
