:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-humidity: #2a78d6;
  --series-temperature: #eb6834;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a198;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-humidity: #3987e5;
    --series-temperature: #d95926;
    --good-ink: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #a3a198;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-humidity: #3987e5;
  --series-temperature: #d95926;
  --good-ink: #0ca30c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.page { max-width: 960px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); font-size: 14px; }
.label { margin: 0; color: var(--ink-2); font-size: 14px; }
.unit { font-size: 0.5em; color: var(--ink-2); font-weight: 400; }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.brand { margin: 0; font-size: 20px; font-weight: 600; }
.filter { display: flex; flex-wrap: wrap; gap: 4px; }
.filter button {
  font: inherit; font-size: 14px; color: var(--ink-2);
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; min-height: 36px; cursor: pointer;
}
.filter button:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.filter button[aria-pressed="true"] { color: var(--ink); border-color: var(--ink-2); font-weight: 600; }
.filter button:focus-visible, summary:focus-visible { outline: 2px solid var(--series-humidity); outline-offset: 2px; }

.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 24px; align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 16px;
}
.hero-value { margin: 0; font-size: 64px; line-height: 1.05; font-weight: 600; }
.stat-value { margin: 0; font-size: 32px; line-height: 1.2; font-weight: 600; }
.hero .muted { grid-column: 1 / -1; margin: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 8px; margin: 8px 0 0;
  padding: 4px 12px 4px 4px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.badge .icon {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font-size: 14px; color: #0b0b0b; background: var(--muted);
}
.badge[data-level="ok"] .icon { background: var(--good); }
.badge[data-level="warn"] .icon { background: var(--warning); }
.badge[data-level="alarm"] .icon { background: var(--critical); color: #fff; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.card h2 { margin: 0; font-size: 16px; font-weight: 600; }
.sub { margin: 0 0 8px; color: var(--ink-2); font-size: 14px; }
.chart { position: relative; min-height: 260px; transition: opacity 0.15s; }
.chart.loading { opacity: 0.5; }
.chart .empty { display: grid; place-items: center; min-height: 260px; color: var(--muted); }
.tip {
  position: absolute; top: 8px; z-index: 5; pointer-events: none; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); font-size: 13px; white-space: nowrap;
}
.tip strong { display: block; font-size: 16px; color: var(--ink); }
.tip span { color: var(--ink-2); }
.tip i { display: inline-block; width: 12px; height: 2px; margin-right: 6px; vertical-align: middle; border-radius: 1px; }

.u-legend { display: none; }
.uplot .u-cursor-x, .uplot .u-cursor-y { border-color: var(--axis); }

details { margin-top: 8px; }
summary { cursor: pointer; color: var(--ink-2); font-size: 14px; padding: 6px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
th { color: var(--ink-2); font-weight: 600; }
footer { margin-top: 8px; }

#offset-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 16px; margin: 8px 0; }
#offset-form label { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }
#offset-form .field { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
#offset-form input {
  font: inherit; width: 96px; padding: 6px 8px; min-height: 36px;
  color: var(--ink); background: var(--plane); border: 1px solid var(--axis); border-radius: 8px;
}
#offset-form button {
  font: inherit; font-size: 14px; min-height: 36px; padding: 6px 16px; cursor: pointer;
  color: var(--ink); background: transparent; border: 1px solid var(--ink-2); border-radius: 8px; font-weight: 600;
}
#offset-form button:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
#offset-form input:focus-visible, #offset-form button:focus-visible { outline: 2px solid var(--series-humidity); outline-offset: 2px; }
#offset-msg { flex-basis: 100%; margin: 0; min-height: 21px; }

@media (max-width: 520px) {
  .hero { grid-template-columns: 1fr; }
  .hero-value { font-size: 52px; }
}
@media (forced-colors: active) {
  .badge .icon { forced-color-adjust: none; }
}

/* ---- boxing ring: mold against the dehumidifier ---- */
@font-face {
  font-family: "Press Start 2P";
  src: url("/vendor/press-start-2p.woff2") format("woff2");
  font-display: swap;
}
.ring-card { padding: 0; overflow: hidden; background: #14122b; }
.ring-caption { background: var(--surface); margin: 0; padding: 12px 16px; font-size: 15px; border-top: 1px solid var(--border); min-height: 3.6em; }
.ring {
  --s-bg: #14122b; --line: #e9fffb; --lw: 2.2; --mat: #2a1f5c; --mat2: #3b2c85;
  --rope1: #ff3d81; --rope2: #35f0ff; --post: #7c6cff; --mold: #3e8a24; --mold2: #2b6a18;
  --glove: #ff3d81; --opp: #35c8ff; --opp2: #1b86c4; --crowd: #0b0a1c; --fx: #ffe14d; --fxink: #14122b; --hud: #35f0ff;
  max-width: 720px; margin: 0 auto;
}
.ring svg { display: block; width: 100%; height: auto; }
.scene { --p: 0; }
.scene text { font-family: "Press Start 2P", ui-monospace, monospace; font-size: 9px; }
.scene text.small { font-size: 7px; fill: var(--hud); }
.scene .burst text { font-size: 12px; }
.scene .bgr { fill: var(--s-bg); }
.scene .line { stroke: var(--line); stroke-width: var(--lw); stroke-linejoin: round; stroke-linecap: round; }
.scene .nofill { fill: none; }
.scene .crowd circle, .scene .crowd path { fill: var(--crowd); }
.scene .post { fill: var(--post); }
.scene .rope { stroke-width: 5; stroke-linecap: round; fill: none; }
.scene .mat { fill: var(--mat); }
.scene .mat2 { fill: var(--mat2); }
.scene .shadow { fill: rgba(0, 0, 0, 0.28); }
.scene .f-mold { fill: var(--mold); }
.scene .f-mold2 { fill: var(--mold2); }
.scene .f-glove { fill: var(--glove); }
.scene .f-opp { fill: var(--opp); }
.scene .f-opp2 { fill: var(--opp2); }
.scene .white { fill: #fff; }
.scene .ink { fill: #14122b; }
.scene .mouth { fill: #3a1d1d; }
.scene .water { fill: #3b9ee8; }
.scene .screen { fill: #174a5e; }
.scene .hpframe { fill: rgba(0, 0, 0, 0.35); stroke: var(--hud); stroke-width: 2; }
.scene .hpfill { transition: width 0.6s ease; }
.scene .hud text { fill: var(--hud); }

/* movement: transforms live on the wrappers, animations on the inner groups */
.scene .opp-wrap, .scene .mold-wrap { transform-origin: 0 0; transition: transform 0.7s cubic-bezier(0.3, 1.35, 0.5, 1); }
.scene.s-lose .mold-wrap { transform: translate(-62px, -46px) rotate(86deg); }
.scene.s-lose .opp-wrap { transform: scale(1.08); }
.scene.s-warn .mold-wrap { transform: translate(-34px, -20px) rotate(52deg); }
.scene.s-warn .opp-wrap { transform: scale(1.02); }
.scene.s-win .opp-wrap { transform: translate(58px, -40px) rotate(-86deg); }
.scene.s-win .mold-wrap { transform: translateX(-30px) scale(calc(1.05 + var(--p) * 0.35)); }

.scene .bob { animation: bob 0.7s ease-in-out infinite alternate; }
.scene .mold-wrap .bob { animation-duration: calc(0.9s - var(--p) * 0.4s); }
.scene.s-lose .mold-wrap .bob, .scene.s-win .opp-wrap .bob { animation: none; }
.scene.s-lose .opp-wrap .bob, .scene.s-win .mold-wrap .bob { animation: cheer 0.45s ease-in-out infinite alternate; }
.scene.s-warn .mold-wrap .bob { animation: shake 0.22s linear infinite; }
.scene.s-warn .opp-wrap .bob { animation: bob 0.5s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-5px); } }
@keyframes cheer { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-16px) rotate(2deg); } }
@keyframes shake { from { transform: translateX(-3px); } to { transform: translateX(3px); } }

.scene .glove-f { animation: punch 1.2s ease-in infinite; }
.scene .opp-wrap .glove-f { --dir: 1; animation-duration: 0.9s; animation-delay: 0.35s; }
.scene .mold-wrap .glove-f { --dir: -1; animation-duration: calc(1.5s - var(--p) * 0.8s); }
@keyframes punch { 0%, 55%, 100% { transform: translateX(0); } 68% { transform: translateX(calc(var(--dir) * 20px)); } 78% { transform: translateX(0); } }
.scene.s-warn .mold-wrap .glove-f, .scene.s-lose .mold-wrap .glove-f, .scene.s-win .opp-wrap .glove-f { animation: none; }
.scene.s-lose .opp-wrap .glove-f, .scene.s-win .mold-wrap .glove-f { animation-duration: 0.5s; animation-delay: 0s; }

.scene .fan { animation: spin 0.35s linear infinite; transform-origin: 0 0; }
.scene.s-warn .fan { animation: spin 1.4s steps(7) infinite; }
.scene.s-win .fan { animation-duration: 7s; animation-timing-function: ease-out; }
.scene.s-idle .fan { animation: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* effects, each shown in its own state */
.scene .on-warn, .scene .on-lose, .scene .on-win { opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.scene.s-warn .on-warn, .scene.s-lose .on-lose, .scene.s-win .on-win { opacity: 1; }
.scene .spore { fill: var(--mold); opacity: 0; animation: rise 3s linear infinite; }
.scene.s-warn .spore { opacity: 0.25; }
.scene.s-win .spore { opacity: calc(0.3 + var(--p) * 0.7); }
.scene .spore:nth-child(2) { animation-delay: -0.6s; }
.scene .spore:nth-child(3) { animation-delay: -1.2s; }
.scene .spore:nth-child(4) { animation-delay: -1.8s; }
.scene .spore:nth-child(5) { animation-delay: -2.4s; }
@keyframes rise { from { transform: translateY(0) scale(1); } to { transform: translateY(-46px) scale(0.3); } }
.scene .sweat { fill: #7fd3ff; opacity: 0.9; animation: drip 0.9s ease-in infinite; }
.scene:not(.s-warn) .sweat { display: none; }
@keyframes drip { from { transform: translateY(-6px); } to { transform: translateY(10px); } }
.scene .stars g { animation: spin 1.4s linear infinite; transform-origin: 0 0; }
.scene .burst { animation: pop 1.6s ease-out infinite; transform-origin: 0 0; }
.scene .burst.b2 { animation-delay: 0.8s; }
.scene .burst.keep { animation: wob 1s ease-in-out infinite alternate; }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 12% { transform: scale(1.1); opacity: 1; } 40% { transform: scale(1); opacity: 1; } 60%, 100% { transform: scale(0.9); opacity: 0; } }
@keyframes wob { from { transform: scale(1) rotate(-4deg); } to { transform: scale(1.09) rotate(4deg); } }
.scene .crowd { animation: bob 1s ease-in-out infinite alternate; }

/* no current data: the fighters stand still and the picture dims */
.scene.s-idle { opacity: 0.6; }
.scene.s-idle .glove-f, .scene.s-idle .bob, .scene.s-idle .crowd { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .scene *, .scene { animation: none !important; transition: none !important; }
}
