:root {
  --bg: #f4f1e8;
  --card: #fffdf7;
  --ink: #1d2a1f;
  --muted: #5d665c;
  --line: #ddd6c4;
  --green: #1f4d2b;
  --green-2: #2d6b3c;
  --wheat: #e3c35a;
  --warn-bg: #fff4d6;
  --warn-line: #e6c560;
  --weak: #d6266e;
  --radius: 12px;
  --panel-w: 440px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
a { color: var(--green-2); }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 0 0 .4rem; }
h2 { font-size: 1.2rem; margin: 0; }
h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
ul { padding-left: 1.2rem; margin: .4rem 0; }
li { margin: .2rem 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--green); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 1.1rem; letter-spacing: .01em; }
.brand small { display: block; font-size: .8rem; opacity: .85; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: radial-gradient(circle at 50% 36%, #a8d062 0 6px, transparent 7px), linear-gradient(180deg, #2d6b3c, #173d22);
  box-shadow: inset 0 -9px 0 -6px var(--wheat);
}
.top-nav .link { background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 999px; padding: 6px 14px; font: inherit; cursor: pointer; }
.top-nav .link:hover { background: rgba(255,255,255,.12); }

/* layout */
.layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #dfe3d6; }
#map.drawing, #map.drawing .leaflet-interactive { cursor: crosshair; }
.panel {
  width: var(--panel-w); max-width: 100%; overflow-y: auto; padding: 14px;
  border-left: 1px solid var(--line); background: var(--bg);
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.lead { margin: 0 0 1rem; color: var(--muted); }

/* forms */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.row { display: flex; gap: 8px; }
input[type=text], input[type=search] {
  flex: 1; min-width: 0; font: inherit; padding: 10px 12px; border: 1px solid #c9c1ad; border-radius: 10px; background: #fff;
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--wheat); outline-offset: 1px; }
.hint { font-size: .875rem; color: var(--muted); margin: 6px 0 0; }
.btn {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--green);
  background: var(--green); color: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--green-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; color: var(--green); }
.btn.ghost:hover { background: #eef3ea; }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: .875rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* field */
.field-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.field-head p { margin: 2px 0 0; font-size: .9rem; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 2px solid var(--line); margin: 6px -4px 12px; padding: 0 4px; scrollbar-width: none; }
.tabs button {
  font: inherit; font-size: .92rem; font-weight: 600; background: none; border: 0; padding: 8px 10px; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--green); border-bottom-color: var(--green); }
.tab-nav { display: flex; justify-content: space-between; margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }

.status { color: var(--muted); min-height: 1.5em; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #c9d4c3; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { background: #eef3ea; border: 1px solid #cfdcc8; border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.notice p { margin: .3rem 0; }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.scene-date { margin: 0 0 10px; }

.big-state { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: #f1efe6; margin: 8px 0 10px; }
.big-state strong { display: block; font-size: 1.15rem; }
.big-state small { color: var(--muted); }
.big-state .dot { width: 22px; height: 22px; border-radius: 50%; flex: none; background: #999; box-shadow: inset 0 0 0 2px rgba(0,0,0,.12); }
.c-bare .dot { background: rgb(170,134,83); }
.c-sparse .dot { background: rgb(214,190,103); }
.c-medium .dot { background: rgb(178,211,99); }
.c-dense .dot { background: rgb(73,158,70); }
.c-vdense .dot { background: rgb(25,105,48); }
.c-weak .dot { background: var(--weak); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.kpi small { display: block; color: var(--muted); font-size: .8rem; }
.kpi strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 14px 9.5em 1fr 3.2em; align-items: center; gap: 8px; font-size: .88rem; }
.bar { height: 10px; background: #ebe7da; border-radius: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.bar-row .sw { margin: 0; }
.tag { display: inline-block; padding: 0 6px; border-radius: 6px; font-size: .85em; font-weight: 600; }
.tag.weak { background: var(--weak); color: #fff; }

details.explain { margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; background: #fff; }
details.explain summary { cursor: pointer; font-weight: 600; }

/* weather */
.days { display: grid; gap: 6px; }
.day {
  display: grid; grid-template-columns: 6.2em 2em 5.6em 1fr; grid-template-areas: "name icon temp rain" "name icon wind et";
  align-items: center; column-gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: .9rem;
}
.day.frost { border-color: #9cc3e6; background: #f2f8fe; }
.day-name { grid-area: name; font-weight: 600; text-transform: capitalize; }
.day-name small { font-weight: 400; color: var(--muted); text-transform: none; }
.day-icon { grid-area: icon; font-size: 1.4rem; text-align: center; }
.day-temp { grid-area: temp; font-variant-numeric: tabular-nums; }
.day-temp span { color: var(--muted); }
.day-rain { grid-area: rain; }
.day-wind { grid-area: wind; color: var(--muted); }
.day-et { grid-area: et; color: var(--muted); font-size: .85rem; }
.windows { list-style: none; padding: 0; }
.windows li { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--green-2); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.hours { max-height: 360px; overflow-y: auto; margin-top: 8px; }
.hours table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.hours th, .hours td { padding: 3px 6px; border-bottom: 1px solid #eee7d6; text-align: left; }
.hours tr.hday td { background: #f1efe6; font-weight: 600; text-transform: capitalize; }

/* map extras */
.map-bar {
  position: absolute; z-index: 800; left: 50%; transform: translateX(-50%); top: 10px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  max-width: calc(100% - 20px); font-size: .9rem;
}
.map-hint {
  position: absolute; z-index: 700; left: 50%; transform: translateX(-50%); bottom: 26px;
  background: rgba(29,42,31,.85); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: .88rem; pointer-events: none;
  max-width: calc(100% - 20px); text-align: center;
}
.legend {
  position: absolute; z-index: 750; left: 10px; bottom: 26px; background: rgba(255,253,247,.95); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: .8rem; line-height: 1.6; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.legend strong { display: block; }
.pix-overlay { image-rendering: pixelated; image-rendering: crisp-edges; }
.leaflet-container { font: inherit; }

.toast {
  position: fixed; z-index: 2000; left: 50%; transform: translateX(-50%); bottom: 20px; max-width: min(560px, calc(100% - 24px));
  background: #1d2a1f; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.3); font-size: .95rem;
}
.credits { font-size: .72rem; color: var(--muted); padding: 4px 12px; border-top: 1px solid var(--line); background: var(--bg); }

/* phones and small tablets: map on top, panel below */
@media (max-width: 899px) {
  body { display: block; height: auto; }
  .layout { flex-direction: column; }
  .map-wrap { height: 58vh; min-height: 320px; flex: none; }
  .panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding: 10px; }
  .brand small { display: none; }
  .bar-row { grid-template-columns: 14px 8em 1fr 3em; }
  .legend { bottom: 34px; font-size: .75rem; }
  .map-hint { bottom: 34px; left: auto; right: 10px; transform: none; max-width: 55%; }
}

/* explanation buttons ("?") and their bubble */
.tip {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: 1px;
  width: 18px; height: 18px; padding: 0; margin: 0 2px; border-radius: 50%;
  border: 1.5px solid var(--green-2); background: #fff; color: var(--green-2);
  font: 700 11px/1 system-ui, sans-serif; cursor: pointer; flex: none;
}
.tip:hover, .tip:focus-visible { background: var(--green-2); color: #fff; }
.legend .tip { width: 15px; height: 15px; font-size: 10px; }
.tip-pop {
  position: fixed; z-index: 3000; max-width: min(320px, calc(100vw - 16px));
  background: #1d2a1f; color: #fff; padding: 10px 12px; border-radius: 10px;
  font-size: .88rem; line-height: 1.45; box-shadow: 0 8px 28px rgba(0,0,0,.3);
}
.tip-pop strong { color: var(--wheat); }
.sw.hole { background: #e9e6dc; border: 1.5px dashed #555; box-shadow: none; }

/* v4: one-line answer, findings, season card, saved fields */
.headline { border-radius: 12px; padding: 12px 14px; margin: 8px 0 12px; border: 1px solid var(--line); background: #f1efe6; }
.headline p { margin: .25rem 0; }
.headline strong { font-size: 1.08rem; line-height: 1.35; }
.headline.alert { background: #fff1f5; border-color: #f0b7cb; }
.headline.calm { background: #eef6ea; border-color: #c9dfc0; }
.findings { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.finding { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--weak); border-radius: 10px; padding: 8px 10px; margin: 0; }
.finding.water { border-left-color: #2171d6; }
.finding.drop { border-left-color: #d7302a; }
.finding.more { border-left-color: var(--line); }
.nav-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.btn.tiny { padding: 4px 10px; font-size: .82rem; border-radius: 8px; text-decoration: none; display: inline-block; }
a.btn { color: #fff; }
a.btn.ghost { color: var(--green); }
.season { background: #fbf6e4; border: 1px solid #ecd9a0; border-radius: 10px; padding: 8px 12px; margin: 12px 0; font-size: .92rem; }
.season p { margin: .3rem 0 0; }
.saved { margin: 0 0 14px; }
.saved h2 { font-size: 1.05rem; margin: 0 0 6px; }
.saved-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.saved-list li { display: flex; gap: 6px; margin: 0; }
.saved-open { flex: 1; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font: inherit; cursor: pointer; }
.saved-open:hover { background: #eef3ea; }
.saved-open strong { display: block; }
.saved-open small { color: var(--muted); }
.saved-del { background: #fff; border: 1px solid var(--line); border-radius: 10px; width: 40px; cursor: pointer; color: var(--muted); font: inherit; }
.saved-del:hover { color: #b3261e; border-color: #b3261e; }
.save-row { margin: -4px 0 6px; }
.sw.outline { background: transparent; border: 2.5px solid var(--weak); box-shadow: none; }
.legend-note { margin-top: 4px; color: var(--muted); font-size: .72rem; }
