:root {
  --bg: #eef2f6;
  --card: #ffffff;
  --soft: #f6f8fb;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0e7490;
  --appbar: #0b1220;
  --appbar-ink: #e2e8f0;
  --cloud: #cbd5e1;
  --land: #e2e8f0;
  --land-edge: #ffffff;
  --sun: #f5b82e;
  --rain: #2f6fe4;
  /* behavior colors match the workflow's boxes and key: standing green, sitting red, eating (and drinking) yellow */
  --standing: #22c55e;
  --lying: #ef4444;
  --eating: #facc15;
  --drinking: #facc15;
  --grass: #eab308;
  --bunch: #8b5cf6;
  --restless: #14b8a6;
  --live: #16a34a;
  --replay: #d97706;
  --good: #16a34a;
  --bad: #dc2626;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070b14;
    --card: #0f1623;
    --soft: #0b111c;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #1e293b;
    --accent: #22d3ee;
    --appbar: #04070d;
    --cloud: #475569;
    --land: #1e293b;
    --land-edge: #0f1623;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #070b14;
  --card: #0f1623;
  --soft: #0b111c;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #1e293b;
  --accent: #22d3ee;
  --appbar: #04070d;
  --cloud: #475569;
  --land: #1e293b;
  --land-edge: #0f1623;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3 { margin: 0; }
a { color: var(--accent); }

/* app bar */
.appbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--appbar); color: var(--appbar-ink);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand .name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.tagline-strip { margin: 0; text-align: center; padding: 7px 16px; font-size: 13.5px; color: var(--muted); background: var(--soft); border-bottom: 1px solid var(--line); }
.powered {
  display: inline-flex; align-items: center; gap: 5px; color: #94a3b8; font-size: 11px; line-height: 1;
  text-decoration: none; white-space: nowrap; transition: color .2s;
}
/* the white logo crossfades to the purple brand logo on hover, along with the "Powered by" text */
.rf-logo { position: relative; display: inline-block; height: 22px; margin: -5px 0 -5px -2px; }
.rf-logo img { height: 22px; width: auto; display: block; transition: opacity .2s; }
.rf-logo .color { position: absolute; inset: 0; opacity: 0; }
.powered:hover, .powered:focus-visible { color: var(--appbar-ink); }
.powered:hover .color, .powered:focus-visible .color { opacity: 1; }
.powered:hover .white, .powered:focus-visible .white { opacity: 0; }
.site { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-right: auto; }
.site-line { color: #94a3b8; font-size: 13px; }
.farm-select {
  color-scheme: dark; font: inherit; font-size: 13px; font-weight: 600; color: var(--appbar-ink);
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px;
  padding: 4px 8px; max-width: 100%; cursor: pointer;
}
.farm-select:focus-visible { outline: 2px solid #60a5fa; outline-offset: 1px; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #1e293b; color: #e2e8f0;
}
.pill.live { background: rgba(22, 163, 74, .18); color: #4ade80; }
.pill.replay { background: rgba(217, 119, 6, .2); color: #fbbf24; }
.pill.offline { background: rgba(148, 163, 184, .18); color: #cbd5e1; }
.pill.live::before, .pill.replay::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.live::before { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.note {
  margin: 12px 24px 0; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--replay) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--replay) 30%, transparent);
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { font-size: 12px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }

/* first screen: farms | detection | clock */
.glance {
  display: grid; gap: 14px; padding: 14px 24px 0;
  grid-template-columns: 290px minmax(0, 1fr) 330px;
  grid-template-areas: "farms cam clock" "tiles tiles tiles";
  align-items: start;
}
.farms-card { grid-area: farms; }
.cam-card { grid-area: cam; }
.clock-card { grid-area: clock; }
.tiles { grid-area: tiles; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile .bar { margin: 6px 0 4px; }

/* map */
#map { width: 100%; height: auto; display: block; }
#map .state { fill: var(--land); stroke: var(--land-edge); stroke-width: 1.2; }
#map .pin { cursor: pointer; }
#map .pin circle.dot { stroke-width: 4; }
#map .pin:hover circle.dot, #map .pin:focus circle.dot { stroke-width: 6; }
#map .pin text { font: 600 24px Inter, sans-serif; fill: var(--ink); paint-order: stroke; stroke: var(--card); stroke-width: 6px; }
.farm-list { display: grid; gap: 6px; margin-top: 8px; }
.farm {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 8px; text-align: left;
  border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.farm[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.farm .name { font-weight: 600; }
.farm .state {
  display: inline-block; margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px;
  font-size: 11px; font-weight: 600; font-style: normal; color: var(--muted); vertical-align: 1px;
}
.farm .place, .farm .call { grid-column: 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.farm .swatch-dot { grid-row: span 3; width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--replay); }
.farm .swatch-dot.live { border-color: var(--live); }
.farm .swatch-dot.offline { border-color: var(--muted); }

/* clock */
.clock-card { display: flex; flex-direction: column; }
#clock { width: 100%; max-width: 300px; align-self: center; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; color: var(--muted); font-size: 12px; margin-top: 6px; }
.legend.small { justify-content: flex-end; }
.swatch { display: inline-block; width: 18px; height: 8px; border-radius: 4px; vertical-align: middle; }
/* same stops as RAIN_STOPS in app.js, which colors both clock rings */
.swatch.scale { width: 44px; margin: 0 6px; background: linear-gradient(90deg, rgb(247,197,72) 0%, rgb(215,222,231) 30%, rgb(156,193,255) 50%, rgb(47,111,228) 75%, rgb(30,79,184) 100%); }
.line { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.line.rain { background: var(--rain); }
.line.lying { background: var(--lying); opacity: .45; height: 8px; }
.line.grazing { background: var(--grass); }
.line.wet { background: var(--rain); opacity: .18; height: 10px; }

/* detection view */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 7px;
  padding: 3px 9px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--card); border-color: var(--ink); }
.viewer { border-radius: 10px; overflow: hidden; background: #05080e; }
.stage { position: relative; aspect-ratio: 16 / 9; width: 100%; margin: 0 auto; }
.stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; }
.frame-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; font-size: 14px; padding: 0 20px; text-align: center; }
.boxes, .groups, .group-labels { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.box { position: absolute; border: 1.5px solid; border-radius: 2px; }
.groups polygon { fill: rgba(139, 92, 246, .14); stroke: var(--bunch); stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.group-label {
  position: absolute; transform: translateY(-115%); padding: 2px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 600; color: #fff; background: var(--bunch); white-space: nowrap;
}
.group-label.below { transform: translateY(15%); }
.frame-key { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 4px; pointer-events: none; }
.frame-key span { font: 600 11px/1 Inter, sans-serif; padding: 4px 6px; border-radius: 4px; color: #111; }
.frame-key .sitting { color: #fff; }
.frame-key .group { background: var(--bunch); color: #fff; }
.frame-live {
  position: absolute; top: 10px; left: 10px; padding: 3px 8px 3px 20px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: rgba(5, 8, 14, .72); color: #fff;
}
.frame-live::before { content: ""; position: absolute; left: 8px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; }
.frame-stale {
  position: absolute; bottom: 10px; left: 10px; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: rgba(5, 8, 14, .72); color: #e2e8f0;
}
.frame-live.on::before { background: #4ade80; animation: pulse 1.6s infinite; }
.frame-live.off::before { background: #fbbf24; }
.frame-live.gone::before { background: #94a3b8; }
.expand {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: rgba(5, 8, 14, .72); color: #fff; cursor: pointer;
}
.expand:hover { background: rgba(5, 8, 14, .9); }
/* previous / next cam, on the picture so they work in full screen and on phones */
.cam-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 36px; height: 52px;
  display: grid; place-items: center; border: 0; border-radius: 8px; background: rgba(5, 8, 14, .55);
  color: #fff; cursor: pointer;
}
.cam-nav:hover { background: rgba(5, 8, 14, .85); }
.cam-nav svg { width: 22px; height: 22px; }
.cam-nav.prev { left: 8px; }
.cam-nav.next { right: 8px; }
.cam-nav[hidden] { display: none; }
.frame-name {
  display: none; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 4px 10px; border-radius: 999px; background: rgba(5, 8, 14, .72); color: #fff; font-size: 14px;
  white-space: nowrap;
}
body.expanded .frame-name, .viewer:fullscreen .frame-name { display: block; }
.expand svg { width: 18px; height: 18px; }
.viewer:fullscreen { display: flex; align-items: center; justify-content: center; border-radius: 0; background: #000; }
.viewer:-webkit-full-screen { display: flex; align-items: center; justify-content: center; border-radius: 0; background: #000; }
.viewer:fullscreen .stage { width: min(100vw, calc(100vh * 16 / 9)); }
.viewer:-webkit-full-screen .stage { width: min(100vw, calc(100vh * 16 / 9)); }
.viewer:fullscreen .frame-key span, .viewer:fullscreen .frame-live, .viewer:fullscreen .group-label { font-size: 14px; }
body.expanded { overflow: hidden; }
body.expanded .viewer { position: fixed; inset: 0; z-index: 50; border-radius: 0; background: #000; display: flex; align-items: center; justify-content: center; }
body.expanded .stage { width: min(100vw, calc(100vh * 16 / 9)); }
body.expanded .frame-key span, body.expanded .frame-live, body.expanded .group-label { font-size: 14px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--live); }
.dot.off { background: var(--replay); opacity: .8; }
.dot.gone { background: var(--muted); opacity: .6; }
.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.count { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.count b { display: block; font-size: 20px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.count span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.count i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.cam-call { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.cam-call b { color: var(--ink); }

.more {
  display: flex; justify-content: center; align-items: center; gap: 6px; margin: 16px auto 2px; width: fit-content;
  color: var(--muted); font-size: 13px; text-decoration: none; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
}
.more:hover { color: var(--ink); border-color: var(--muted); }
.more svg { width: 16px; height: 16px; }

/* details */
.details { display: grid; gap: 14px; padding: 12px 24px 8px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); scroll-margin-top: 12px; }
.card.wide { grid-column: 1 / -1; }
.signals { display: grid; gap: 12px; }
.signal-top { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 600; }
.signal-top span:last-child { font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 5px 0 3px; }
.bar > div { height: 100%; border-radius: 3px; transition: width .6s ease; }
.signal small { color: var(--muted); font-size: 12px; }
.reasons { margin: 14px 0 0; font-size: 13.5px; }

.versus-row { display: flex; gap: 14px; align-items: center; }
.score {
  font-size: 30px; font-weight: 700; min-width: 72px; text-align: center; letter-spacing: -.02em;
  padding: 6px 8px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.agree-text { margin: 0; font-size: 13.5px; }
.conditions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.conditions b { color: var(--ink); font-weight: 600; }

/* forecast vs. real weather */
.actual-summary { margin: 0 0 12px; font-size: 13.5px; }
.actual-grid { display: grid; grid-template-columns: repeat(12, minmax(78px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.ahour { border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; text-align: center; font-size: 12px; background: var(--soft); }
.ahour.wet { border-color: color-mix(in srgb, var(--rain) 55%, var(--line)); background: color-mix(in srgb, var(--rain) 8%, var(--card)); }
.ahour .t { font-weight: 600; color: var(--muted); }
.ahour svg { width: 30px; height: 30px; display: block; margin: 2px auto 0; }
.ahour .obs { min-height: 32px; line-height: 1.3; }
.ahour .row { display: flex; justify-content: space-between; gap: 4px; margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.ahour .row span:first-child { color: var(--muted); }
.mark-right { color: var(--good); font-weight: 700; }
.mark-wrong { color: var(--bad); font-weight: 700; }

.chart-wrap { position: relative; }
#chart { width: 100%; height: 220px; display: block; }
.mark {
  position: absolute; top: 0; margin-left: 6px; font-size: 12px; color: var(--muted); white-space: nowrap;
  background: var(--card); padding: 0 4px; border-radius: 4px;
}
.mark.flip { transform: translateX(-100%); margin-left: -6px; }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }

.strip { display: grid; grid-template-columns: repeat(12, minmax(70px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.hour { border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; text-align: center; background: var(--soft); }
.hour.now { border-color: var(--accent); }
.hour .t { font-size: 12px; font-weight: 600; color: var(--muted); }
.hour svg { width: 32px; height: 32px; display: block; margin: 4px auto 0; }
.hour .p { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hour .n { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--muted); }

.all-cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cam-tile { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: transparent; color: var(--ink); padding: 0; text-align: left; font: inherit; cursor: pointer; }
.cam-tile[aria-pressed="true"] { border-color: var(--accent); }
.cam-tile .thumb { position: relative; aspect-ratio: 16 / 9; background: #05080e; }
.cam-tile img { width: 100%; height: 100%; object-fit: fill; display: block; }
.cam-tile .meta { padding: 8px 10px; font-size: 13px; }
.cam-tile .meta b { display: block; font-size: 13px; }
.cam-tile .meta span { color: var(--muted); }

.appendix code { font-size: 12px; background: var(--soft); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; }

/* appendix */
.appendix { margin: 6px 24px 0; padding: 0; }
.appendix summary { cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 13.5px; }
.appendix[open] summary { border-bottom: 1px solid var(--line); }
.appendix-body { padding: 4px 16px 16px; max-width: 900px; }
.appendix h3 { font-size: 13.5px; margin: 14px 0 4px; }
.appendix p { margin: 0 0 8px; font-size: 13.5px; }
.appendix table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 6px 0 8px; }
.appendix th, .appendix td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.appendix th { color: var(--muted); font-weight: 600; font-size: 12px; }
.appendix .formula {
  font: 600 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; overflow-x: auto;
}

.foot { padding: 14px 24px 26px; color: var(--muted); font-size: 12px; }
.foot p { margin: 3px 0; }

@media (max-width: 1280px) {
  .glance { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "cam cam" "farms clock" "tiles tiles"; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .appbar { padding: 10px 16px; }
  .tagline-strip { font-size: 12px; }
  .site { order: 3; width: 100%; }
  .glance { grid-template-columns: 1fr; grid-template-areas: "cam" "clock" "tiles" "farms"; padding: 12px 16px 0; }
  .details { grid-template-columns: 1fr; padding-left: 16px; padding-right: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .note { margin: 12px 16px 0; }
  .counts { grid-template-columns: repeat(2, 1fr); }
  .cam-card .tabs { flex-wrap: wrap; width: 100%; }
  .cam-card .tab { white-space: nowrap; }
  /* thumb-sized targets; 16px on the menu stops iPhone Safari zooming in when it opens */
  .tab { padding: 7px 12px; font-size: 13px; }
  .farm-select { padding: 7px 10px; font-size: 16px; }
  .powered { padding: 6px 0; margin: -6px 0; }
  .frame-key span { font-size: 9px; padding: 3px 4px; }
  .frame-live { font-size: 11px; }
  .legend.small { justify-content: flex-start; }
  .appendix { margin: 6px 16px 0; }
  .foot { padding: 12px 16px 22px; }
}

/* about modal */
.about-link { border: 0; background: none; color: var(--appbar-ink); opacity: .75; font: inherit; font-size: 13px; cursor: pointer; margin-right: 10px; text-decoration: underline; text-underline-offset: 3px; }
.about-link:hover { opacity: 1; }
.about-scrim { position: fixed; inset: 0; z-index: 60; background: rgba(8, 12, 19, .55); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px 16px; }
.about-modal { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; max-width: 430px; width: 100%; padding: 22px 22px 18px; box-shadow: 0 18px 60px rgba(0, 0, 0, .45); position: relative; }
.about-x { position: absolute; top: 8px; right: 12px; border: 0; background: none; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.about-modal h2 { font-size: 19px; margin: 0 0 4px; }
.about-tag { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.about-step { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); color: var(--muted); }
.about-step img, .about-step svg { flex: 0 0 34px; }
.about-step p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ink); }
.about-cta { margin-top: 14px; width: 100%; padding: 11px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
