:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid-line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --house: #2a78d6;
  --solar: #eb6834;
  --battery: #1baf7a;
  --grid: #898781;
  --good: #0ca30c;
  --critical: #d03b3b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --sky: #dfe8f1;
  --sky-night: #222b40;
  --model: #e4e2dc;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid-line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --house: #3987e5;
    --solar: #d95926;
    --battery: #199e70;
    --sky: #2a3442;
    --sky-night: #0b0f19;
    --model: #6e6c67;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid-line: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --house: #3987e5;
  --solar: #d95926;
  --battery: #199e70;
  --sky: #2a3442;
  --sky-night: #0b0f19;
  --model: #6e6c67;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; }
button {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--ring); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--ink); color: var(--page); border-color: var(--ink); padding: 10px 18px; }

header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
header.top h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
header.top .actions { display: flex; align-items: center; gap: 10px; }
.lang { display: flex; font-size: 13px; }
.lang button { border: 0; border-radius: 0; background: none; padding: 2px 7px; color: var(--muted); }
.lang button + button { border-left: 1px solid var(--axis); }
.lang button[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
.status { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: var(--good); }
.status.stale .dot { background: var(--critical); }

.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; padding: 18px; }
.card h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 16px; margin-bottom: 16px; }
.headline { display: flex; flex-direction: column; justify-content: space-between; gap: 20px; }
.headline .state { font-size: 28px; line-height: 1.15; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.headline .sub { color: var(--ink-2); margin: 6px 0 0; }
.hero .left { display: flex; flex-direction: column; gap: 16px; }
.section-title { grid-column: 1 / -1; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 4px 0 -4px; text-transform: uppercase; letter-spacing: 0.04em; }
.section-title .partial { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.flow svg { width: 100%; height: auto; display: block; }
.flow .wire { fill: none; stroke: var(--grid-line); stroke-width: 2; }
.flow .stream { fill: none; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 2 12; animation: flow 1s linear infinite; }
.flow .stream.idle { visibility: hidden; }
.flow .stream.reverse { animation-direction: reverse; }
@keyframes flow { to { stroke-dashoffset: -28; } }
@media (prefers-reduced-motion: reduce) { .flow .stream { animation: none; stroke-dasharray: none; } }
.flow .node circle { fill: var(--surface); stroke-width: 2; }
.flow .node .label { fill: var(--ink-2); font-size: 12px; text-anchor: middle; }
.flow .node .value { fill: var(--ink); font-size: 15px; font-weight: 600; text-anchor: middle; }
.flow .hub { fill: var(--axis); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; flex: 1; }
.tile { padding: 14px 16px; }
.tile .k { color: var(--ink-2); font-size: 13px; }
.tile .v { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.tile .v small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .key { width: 14px; height: 2px; border-radius: 1px; }
.legend .val { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.plot { width: 100%; min-width: 0; overflow: hidden; }
.uplot { font-family: var(--font); }
.u-axis { color: var(--muted); }
.u-legend { display: none; }
details.table { margin-top: 12px; color: var(--ink-2); font-size: 13px; }
details.table table { border-collapse: collapse; width: 100%; margin-top: 8px; font-variant-numeric: tabular-nums; }
details.table th, details.table td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid-line); }
details.table th:first-child, details.table td:first-child { text-align: left; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.center .card { width: min(380px, 100%); text-align: center; padding: 28px; }
.center h1 { font-size: 20px; margin: 0 0 6px; }
.center p { color: var(--ink-2); margin: 0 0 20px; }
.error { color: var(--critical); min-height: 1.4em; margin-top: 12px; font-size: 14px; }

/* 3D house view (house.js); the SVG above stays as the fallback without WebGL2. */
.flow .house3d { display: none; }
.flow.has-3d { padding: 0; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr); }
.flow.has-3d svg { display: none; }
.flow.has-3d .house3d {
  display: block; position: relative; width: 100%; align-self: stretch; aspect-ratio: 4 / 3; min-height: 300px;
  background: linear-gradient(var(--sky), var(--surface) 80%);
}
.flow.has-3d .house3d.night { background: linear-gradient(var(--sky-night), color-mix(in srgb, var(--sky-night) 55%, var(--surface))); }
.house3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; transition: filter 0.4s; }
.house3d canvas:active { cursor: grabbing; }
.house3d.stale canvas { filter: saturate(0.15) brightness(0.92); } /* old data: faded and still */
.house3d.stale .house-labels { opacity: 0.6; }
.house-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hl-dot, .hl-lead, .hl-chip { position: absolute; left: 0; top: 0; }
.hl-dot.off, .hl-lead.off { display: none; }
.hl-dot { width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--surface); }
.hl-lead { height: 1.5px; margin-top: -0.75px; transform-origin: 0 50%; background: var(--c); opacity: 0.75; }
.hl-chip {
  white-space: nowrap; padding: 4px 9px 5px; border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 96%, transparent); border: 1px solid var(--ring); border-left: 3px solid var(--c);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); color: var(--ink-2); font-size: 11px; line-height: 1.3;
}
.hl-chip .t, .hl-chip .n { display: block; }
.hl-chip .v { display: block; color: var(--ink); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hl-chip .v small { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.hl-chip .n:empty, .hl-chip .v:empty { display: none; }
.hl-chip .arrow { display: none; float: right; margin: 3px 0 0 6px; border: 5px solid transparent; border-right: 0; border-left: 8px solid var(--c); }
.hl-chip.away .arrow { display: block; } /* its point is off screen: an arrow shows the way */
.hl-chip.tag { padding: 2px 7px 3px; font-size: 10.5px; border-left-width: 2px; box-shadow: none; }
.hl-dot.tag { width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; }
.solar { --c: var(--solar); }
.house { --c: var(--house); }
.battery { --c: var(--battery); }
.grid { --c: var(--grid); }
.inverter { --c: var(--muted); }
.compass {
  position: absolute; right: 10px; bottom: 10px; width: 30px; height: 30px; border-radius: 50%; pointer-events: none;
  background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--ring);
}
.compass .rose { position: absolute; inset: 0; }
.compass .needle { position: absolute; left: 50%; top: 3px; margin-left: -4px; border: 4px solid transparent; border-top: 0; border-bottom: 9px solid var(--critical); }
.compass .n { position: absolute; left: 0; right: 0; top: 13px; text-align: center; font-size: 9px; font-weight: 700; color: var(--ink-2); line-height: 1; }
.headline .asof { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.headline .asof:empty { display: none; }

@media (max-width: 760px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  /* On phones: headline, then the live flow, today's tiles, then the appliance advice. */
  .hero .left { display: contents; }
  .hero .headline { order: 0; }
  .hero .flow { order: 1; }
  .hero .tiles { order: 2; }
  .hero .outlook { order: 3; }
  .headline .state { font-size: 24px; }
  .flow.has-3d .house3d { aspect-ratio: 4 / 5; min-height: 0; }
  .hl-chip .v { font-size: 15px; }
  .hl-chip { padding: 3px 7px 4px; }
  .hl-chip.tag, .hl-dot.tag, .hl-lead.tag, .hl-chip .n.panels { display: none; }
}

/* Entity colors: one per thing, the same everywhere. */
.swatch.solar, .legend .key.solar { background: var(--solar); }
.swatch.house, .legend .key.house { background: var(--house); }
.swatch.battery, .legend .key.battery { background: var(--battery); }
.swatch.grid { background: var(--grid); }
#node-solar circle, #stream-solar { stroke: var(--solar); }
#node-house circle, #stream-house { stroke: var(--house); }
#node-battery circle, #stream-battery { stroke: var(--battery); }
#node-grid circle, #stream-grid { stroke: var(--grid); }

/* Forecast card. Status color always comes with an icon and a word. */
.outlook h2 { margin-bottom: 8px; }
.outlook .verdict { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.outlook .sub { color: var(--ink-2); margin: 6px 0 0; }
.outlook .facts { color: var(--ink-2); font-size: 13px; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.outlook .facts .muted { color: var(--muted); }
.badge { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; color: #fff; white-space: nowrap; }
.badge.go { background: var(--good); }
.badge.wait { background: #fab219; color: #0b0b0b; }
.badge.later, .badge.no { background: var(--axis); color: var(--ink); }
.legend .key.dashed.solar { background: repeating-linear-gradient(90deg, var(--solar) 0 4px, transparent 4px 7px); }
.legend .key.dashed.battery { background: repeating-linear-gradient(90deg, var(--battery) 0 4px, transparent 4px 7px); }
