:root {
  --app-bg: #10160F;
  --app-card: #1A2218;
  --app-card2: #212B1F;
  --app-ink: #EAF0E2;
  --app-muted: #8A9484;
  --app-line: #2C3629;
  --sun: #F0A63C;
  --sun-soft: rgba(240, 166, 60, 0.14);
  --batt: #63B56B;
  --ev: #5AA3D8;
  --grid-c: #D4674C;
}
@media (prefers-color-scheme: light) {
  :root {
    --app-bg: #F2F4EE;
    --app-card: #FFFFFF;
    --app-card2: #E9EDE3;
    --app-ink: #232B20;
    --app-muted: #6C755F;
    --app-line: #DDE3D6;
    --sun: #D98F1E;
    --sun-soft: rgba(217, 143, 30, 0.14);
    --batt: #3F8F49;
    --ev: #33749F;
    --grid-c: #BC4C31;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
#app { display: flex; flex-direction: column; height: 100dvh; }
#views {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(10px + env(safe-area-inset-top)) 16px 18px;
  max-width: 520px; margin: 0 auto; width: 100%;
}

.num { font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace; font-variant-numeric: tabular-nums; }

.apphead { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 2px 12px; }
.apphead .brand { font-weight: 700; font-size: 19px; }
.apphead .brand span { color: var(--sun); }
.apphead .day { font-size: 12px; color: var(--app-muted); }

.banner {
  background: var(--sun-soft); border: 1px solid var(--sun); color: var(--app-ink);
  border-radius: 14px; padding: 10px 14px; font-size: 13px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.banner.err { border-color: var(--grid-c); background: rgba(212, 103, 76, 0.12); }
.banner button {
  border: 0; background: transparent; color: var(--sun); font-weight: 700;
  cursor: pointer; font-family: inherit; font-size: 13px; padding: 4px;
}

.card {
  background: var(--app-card); border: 1px solid var(--app-line);
  border-radius: 18px; padding: 14px 16px; margin-bottom: 12px;
}
.card h4 {
  margin: 0 0 10px; font-size: 11px; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--app-muted); font-weight: 600;
}
.cardnote { font-size: 13px; color: var(--app-muted); margin: 0 0 12px; }

.flow svg { display: block; width: 100%; height: auto; }
.flow text { font-family: ui-monospace, Menlo, monospace; }
.nodelabel { font-size: 10px; fill: var(--app-muted); letter-spacing: 0.08em; }
.nodeval { font-size: 13px; font-weight: 600; fill: var(--app-ink); }
.edge { fill: none; stroke-width: 2.5; stroke-linecap: round; }
.edge.animated { stroke-dasharray: 3 9; animation: flowdash 1.1s linear infinite; }
.edge.rev { animation-direction: reverse; }
.edge.idle { stroke: var(--app-line) !important; stroke-dasharray: 2 6; opacity: 0.55; animation: none; }
@keyframes flowdash { to { stroke-dashoffset: -12; } }
@media (prefers-reduced-motion: reduce) {
  .edge.animated { animation: none; }
  .pill-live::before { animation: none; }
}

.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat .lab { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--app-muted); }
.stat .val { font-size: 20px; font-weight: 600; margin-top: 2px; }

.chartwrap { position: relative; margin-bottom: 12px; }
.chartwrap svg { display: block; width: 100%; height: 110px; }
.chartlegend { display: flex; gap: 14px; font-size: 11px; color: var(--app-muted); margin-top: 4px; }
.chartlegend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.socline { display: flex; align-items: center; gap: 12px; }
.socbar { flex: 1; height: 10px; border-radius: 5px; background: var(--app-line); position: relative; overflow: visible; }
.socbar .fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0%; background: var(--batt); border-radius: 5px; transition: width 0.6s; }
.socbar .tick { position: absolute; top: -3px; bottom: -3px; left: 40%; width: 2px; background: var(--sun); }
.soclegend { display: flex; justify-content: space-between; font-size: 11px; color: var(--app-muted); margin-top: 6px; }
.soclegend b { color: var(--app-ink); }

.pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600;
  padding: 4px 11px; border-radius: 999px; background: var(--app-card2); color: var(--app-muted);
  white-space: nowrap;
}
.pill.live { background: var(--sun-soft); color: var(--sun); }
.pill.live::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

.rowline { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--app-line); font-size: 13.5px; }
.rowline .k { color: var(--app-muted); flex-shrink: 0; }
.rowline span:last-child { text-align: right; }

.setrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--app-line); }
.setrow:first-of-type, .setrow.noline { border-top: 0; }
.setrow .name { font-size: 13.5px; }
.setrow .hint { font-size: 11px; color: var(--app-muted); margin-top: 1px; }
.stepper { display: flex; align-items: center; gap: 2px; background: var(--app-card2); border-radius: 10px; padding: 3px; flex-shrink: 0; }
.stepper button {
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent;
  color: var(--app-ink); font-size: 18px; cursor: pointer; line-height: 1; font-family: inherit;
}
.stepper button:active { background: var(--app-line); }
.stepper .v { min-width: 64px; text-align: center; font-size: 13.5px; font-weight: 600; }
.stepper .v.dirty { color: var(--sun); }

.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--app-line);
  transition: background 0.2s; cursor: pointer;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--app-ink); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--batt); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--sun); outline-offset: 2px; }
.switch.dirty span { box-shadow: 0 0 0 2px var(--sun); }

.cta {
  width: 100%; border: 0; border-radius: 14px; padding: 14px; font-size: 15px; font-weight: 700;
  background: var(--sun); color: #221805; cursor: pointer; font-family: inherit;
}
.cta.secondary { background: var(--app-card2); color: var(--app-ink); border: 1px solid var(--app-line); }
.cta:disabled { opacity: 0.45; cursor: default; }
.cta:not(:disabled):active { transform: translateY(1px); }

.chips { display: flex; gap: 8px; }
.chip {
  border: 1px solid var(--app-line); background: var(--app-card2); color: var(--app-ink);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.chip.on { background: var(--sun); border-color: var(--sun); color: #221805; }

.formstatus { min-height: 18px; font-size: 13px; color: var(--app-muted); text-align: center; margin: 10px 0 0; }
.formstatus.err { color: var(--grid-c); }
.formstatus.ok { color: var(--batt); }

.nav {
  flex-shrink: 0; display: flex; border-top: 1px solid var(--app-line);
  background: var(--app-card); padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.navbtn {
  flex: 1; border: 0; background: transparent; color: var(--app-muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; padding: 6px 0; border-radius: 10px;
  font-family: inherit;
}
.navbtn.on { color: var(--sun); }
.navbtn svg { width: 22px; height: 22px; }

#login { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.login { width: 100%; max-width: 340px; }
.login .mark { text-align: center; margin-bottom: 26px; }
.login h2 { text-align: center; margin: 10px 0 4px; font-size: 24px; }
.login .sub { text-align: center; color: var(--app-muted); font-size: 13px; margin: 0 0 26px; }
.fieldwrap { margin-bottom: 12px; }
.fieldwrap label { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--app-muted); margin-bottom: 5px; }
.fieldwrap input {
  width: 100%; background: var(--app-card); border: 1px solid var(--app-line); color: var(--app-ink);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; font-family: inherit;
}
.fieldwrap input:focus-visible, button:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
