/*
 * power.dx2-66.com (worker/power.js). The site's paper and ink, light or dark
 * as the OS says, and its display face, Archivo, served by the Worker. One
 * bold thing: yesterday's kWh on a seven-segment display, the same segments as
 * the site's favicon. Everything else stays quiet.
 *
 * Chart colours were checked with the dataviz validator (lightness band,
 * chroma, colour-blind separation, contrast) against each mode's paper: amber
 * for solar, teal for the cars.
 */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/archivo.woff2') format('woff2');
}

:root {
  color-scheme: light dark;
  --paper: light-dark(#f2f3ef, #0f1311);
  --ink: light-dark(#17201b, #d3d9d4);
  --ink-2: light-dark(#4b5750, #a5b0a8);
  --ink-3: light-dark(#616964, #88908a);
  --rule: light-dark(#d6dbd4, #252d29);
  --sun: light-dark(#b47506, #c4851a);
  --car: light-dark(#0c909c, #11a3ad);
  /* Where the power came from: the battery in violet, the grid as neutral context. */
  --bat: light-dark(#7d43dd, #9a72f0);
  --grid: light-dark(#616964, #7c847f);
  /* The display window: smoked glass in both modes. */
  --bezel: #0a0d0c;
  --bezel-edge: light-dark(#2b332f, #29322d);
  --led: #ffb31f;
  --led-off: rgb(255 179 31 / 0.07);
  --font: 'Archivo', 'Arial Narrow', system-ui, sans-serif;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header,
main {
  max-width: 46rem;
  margin: 0 auto;
  padding-inline: max(1rem, 4vw);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-block: 1.25rem;
  font-size: 0.9375rem;
}

a {
  color: inherit;
  text-decoration-color: var(--sun);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--sun);
}

a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 3px;
  border-radius: 2px;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  text-decoration: none;
}

main {
  padding-bottom: 4rem;
}

h1 {
  margin: clamp(1.5rem, 6vw, 3.5rem) 0 0.5rem;
  font-size: clamp(2.5rem, 9vw, 4.75rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.sub {
  margin: 0 0 clamp(2rem, 6vw, 3rem);
  color: var(--ink-2);
  max-width: 34em;
}

h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.005em;
}

/* Yesterday */

.bezel {
  display: flex;
  align-items: flex-end;
  gap: clamp(0.75rem, 3vw, 1.5rem);
  width: fit-content;
  max-width: 100%;
  padding: clamp(1.1rem, 4vw, 1.75rem) clamp(1.25rem, 5vw, 2.25rem);
  background: var(--bezel);
  border: 1px solid var(--bezel-edge);
  border-radius: 1.25rem;
  box-shadow: inset 0 2px 14px rgb(0 0 0 / 0.65);
}

.digits {
  display: block;
  height: clamp(5.5rem, 24vw, 9.5rem);
  width: auto;
  max-width: 100%;
  /* The LED glow, on the whole display so it follows the segments' shapes. */
  filter: drop-shadow(0 0 4px rgb(255 150 0 / 0.4));
}

.digits .off {
  fill: var(--led-off);
}

.digits .on {
  fill: var(--led);
  animation: power-on 1.1s ease-out both;
}

.unit {
  color: rgb(255 179 31 / 0.6);
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 600;
  line-height: 1;
  padding-bottom: 0.15em;
}

/* The one moment of motion: the display warming up, with a single flicker. */
@keyframes power-on {
  0% { opacity: 0; }
  35% { opacity: 1; }
  45% { opacity: 0.35; }
  60%, 100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .digits .on {
    animation: none;
  }
}

.when {
  margin: 1rem 0 0;
  color: var(--ink-2);
}

.stale {
  display: block;
  margin-top: 0.25rem;
  color: var(--sun);
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.75rem, 3vw, 2rem);
  margin: clamp(1.75rem, 5vw, 2.5rem) 0 0;
}

.facts div {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
}

.facts dd {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.facts dt {
  margin-top: 0.35rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
  line-height: 1.3;
}

.facts.small dd {
  font-size: clamp(1.35rem, 4.5vw, 1.85rem);
}

/* Last 30 days */

.month,
.since {
  margin-top: clamp(3.5rem, 10vw, 5rem);
}

.head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
  margin-bottom: 1rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--ink-2);
  font-size: 0.875rem;
}

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

.key {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
}

.key.sun {
  background: var(--sun);
}

.key.car {
  background: var(--car);
}

.key.trend {
  width: 1rem;
  height: 2px;
  border-radius: 1px;
  background: var(--ink);
}

.key.est {
  background: repeating-linear-gradient(-45deg, var(--sun) 0 2px, transparent 2px 4px);
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .sun {
  fill: var(--sun);
}

.chart .car {
  fill: var(--car);
}

.chart .sun.est {
  fill: url(#hatch-sun);
}

.chart .car.est {
  fill: url(#hatch-car);
}

.hatch-sun {
  fill: var(--sun);
}

.hatch-car {
  fill: var(--car);
}

.chart .gap {
  fill: var(--rule);
}

.chart .grid {
  stroke: var(--rule);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart .grid.zero {
  stroke: var(--ink-3);
}

.chart .trend {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.chart .axis {
  fill: var(--ink-3);
  font-family: var(--font);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.chart .hit {
  fill: transparent;
}

/* Hovering a day dims the others: the tooltip is the bar's title. */
.chart:hover g .sun,
.chart:hover g .car {
  opacity: 0.45;
}

.chart g:hover .sun,
.chart g:hover .car {
  opacity: 1;
}

/* Since the first day */

.since h2 {
  margin-bottom: 0.25rem;
}

.since .facts {
  margin-top: 1rem;
}

.count {
  margin: 1rem 0 0;
  color: var(--ink-3);
  font-size: 0.875rem;
}

/* Folded detail */

details {
  margin-top: 2.5rem;
  border-top: 1px solid var(--rule);
}

details + details {
  margin-top: 0;
}

details:last-of-type {
  border-bottom: 1px solid var(--rule);
}

summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block: 1rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: '+';
  color: var(--ink-3);
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
}

details[open] summary::after {
  content: '−';
}

.table {
  overflow-x: auto;
  padding-bottom: 1rem;
}

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

th,
td {
  padding: 0.45rem 0.6rem;
  text-align: right;
  white-space: nowrap;
}

th:first-child {
  text-align: left;
  padding-left: 0;
}

thead th {
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-weight: 500;
}

tbody tr + tr {
  border-top: 1px solid var(--rule);
}

tbody th {
  font-weight: 500;
}

tr.est td {
  color: var(--ink-2);
  font-style: italic;
}

.notes {
  margin: 0;
  padding: 0 0 1.25rem 1.1rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

.notes li + li {
  margin-top: 0.6rem;
}

/* Comparisons */

.likes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 1.75rem 0 0;
  padding: 1.1rem 0 0;
  border-top: 1px solid var(--rule);
  list-style: none;
  color: var(--ink-2);
  font-size: 0.9375rem;
  line-height: 1.3;
}

.likes li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.likes b {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: -0.1rem;
  fill: none;
  stroke: var(--sun);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* More charts */

.defs {
  position: absolute;
}

.hatch-bat {
  fill: var(--bat);
}

.hatch-mains {
  fill: var(--grid);
}

.chart .bat {
  fill: var(--bat);
}

.chart .mains {
  fill: var(--grid);
}

.chart .bat.est {
  fill: url(#hatch-bat);
}

.chart .mains.est {
  fill: url(#hatch-mains);
}

.key.bat {
  background: var(--bat);
}

.key.mains {
  background: var(--grid);
}

.chart .area.sun,
.chart .area.car {
  opacity: 0.85;
}

.chart .edge {
  fill: none;
  stroke: var(--paper);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart .edge.top {
  stroke: var(--sun);
}

.chart .end {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
}

.scale {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  color: var(--ink-2);
  font-size: 0.875rem;
}

.scale .key {
  margin-inline: 0.05rem;
}

.scale .key:first-child {
  margin-left: 0.4rem;
}

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

.calendar {
  display: block;
  max-width: none;
}

.calendar .axis {
  fill: var(--ink-3);
  font-family: var(--font);
  font-size: 12px;
}

.cell.none {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1;
}

.l1 { fill: color-mix(in oklab, var(--sun) 22%, var(--paper)); background: color-mix(in oklab, var(--sun) 22%, var(--paper)); }
.l2 { fill: color-mix(in oklab, var(--sun) 42%, var(--paper)); background: color-mix(in oklab, var(--sun) 42%, var(--paper)); }
.l3 { fill: color-mix(in oklab, var(--sun) 62%, var(--paper)); background: color-mix(in oklab, var(--sun) 62%, var(--paper)); }
.l4 { fill: color-mix(in oklab, var(--sun) 82%, var(--paper)); background: color-mix(in oklab, var(--sun) 82%, var(--paper)); }
.l5 { fill: var(--sun); background: var(--sun); }

.cell.est {
  stroke: var(--ink-2);
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
}

.calendar rect:hover {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-dasharray: none;
}
