:root {
  --bg: #f6f4ee;
  --panel: #ffffff;
  --ink: #23301f;
  --muted: #6b7566;
  --line: #dcd8cc;
  --accent: #2f7d32;
  --accent-soft: #e4f0e1;
  --shade: rgba(120, 112, 92, 0.16);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; min-height: 100vh; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---- header ---- */
.top { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; justify-content: space-between; padding: 14px 20px 10px; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filters-label { font-size: 0.8rem; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 0.8rem; line-height: 1.3; }
.chip small { color: var(--muted); margin-left: 4px; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[aria-pressed="true"] small { color: rgba(255,255,255,.8); }

/* ---- layout ---- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; padding: 0 20px 20px; }
.stage { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.grid-wrap { position: relative; flex: 1; min-height: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#grid { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#grid:active { cursor: grabbing; }
.note { margin: 8px 2px 0; font-size: 0.78rem; color: var(--muted); }
.status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.status[hidden] { display: none; }

.zoom-ctl { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoom-ctl button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.92); font-size: 1.1rem; line-height: 1; }
.zoom-ctl button:hover { border-color: var(--accent); }

/* ---- grid drawing ---- */
.gridline { stroke: #b9b4a3; stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.55; vector-effect: non-scaling-stroke; fill: none; }
.gridline.quad { stroke: #8f8a78; opacity: 0.8; stroke-dasharray: 7 4; }
.shade { fill: var(--shade); }
.axis { font-size: 13px; fill: #7b7a6c; text-anchor: middle; dominant-baseline: central; user-select: none; }
.qlabel { font-size: 34px; font-weight: 600; fill: #000; opacity: 0.05; user-select: none; pointer-events: none; }

.plant { cursor: pointer; }
.plant .hit { fill: transparent; }
.plant .mark { stroke: rgba(0,0,0,.35); stroke-width: .6; transition: opacity .12s; }
.plant .mark.hollow { stroke: #6d6d6d; stroke-width: 1.1; }
.plant.hover .mark, .plant.on .mark { stroke: #000; stroke-width: 1; }

/* dimming: while a species is focused, everything else recedes */
#world.focusing .plant:not(.on) .mark { opacity: 0.1; }
/* planting-group filter: plants outside the chosen groups nearly vanish and can't be hovered */
#world .plant.out { pointer-events: none; }
#world .plant.out .mark { opacity: 0.06; }

/* ---- tooltip ---- */
.tip { position: fixed; z-index: 10; max-width: 270px; pointer-events: none; background: #1f2a1c; color: #fff; padding: 9px 11px; border-radius: 8px; font-size: 0.82rem; line-height: 1.4; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.tip[hidden] { display: none; }
.tip b { font-size: 0.92rem; }
.tip .row { display: flex; gap: 6px; }
.tip .k { color: #a9bda4; flex: none; }
.tip .codes { font-variant-numeric: tabular-nums; }

/* ---- sidebar ---- */
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 3px 9px; font-size: 0.75rem; }
.seg button.on { background: var(--accent); color: #fff; }
.list { overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.group-head { position: sticky; top: 0; z-index: 1; background: #f0eee5; border-bottom: 1px solid var(--line); padding: 5px 12px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.group-head.out, .item.out { opacity: .4; }
.item { border-bottom: 1px solid #efede4; }
.item-btn { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 12px; }
.item-btn:hover, .item.on .item-btn { background: var(--accent-soft); }
.item .nm { font-size: 0.88rem; }
.item .ct { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.item .cd { display: block; font-size: 0.7rem; color: var(--muted); }
.detail { display: none; padding: 2px 12px 10px 42px; font-size: 0.8rem; line-height: 1.45; background: var(--accent-soft); }
.item.pinned .detail { display: block; }
.detail dt { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.detail dd { margin: 0; }
.detail .sub-codes { color: var(--muted); }

/* ---- small screens ---- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .grid-wrap { aspect-ratio: 1; flex: none; min-height: 0; }
  .side { max-height: 55vh; }
}

/* ---- indoor-start toggle, badge, calendar ---- */
.chip-indoor { border-style: dashed; }
.chip-indoor[aria-pressed="true"] { background: #1d5fa8; border-color: #1d5fa8; border-style: solid; color: #fff; }
.chip-indoor[aria-pressed="true"] small { color: rgba(255,255,255,.8); }
.pill { display: inline-block; font-size: 0.64rem; line-height: 1; padding: 2px 5px; margin-left: 6px; border-radius: 999px; background: #dcebfa; color: #1d5fa8; vertical-align: 1px; text-transform: uppercase; letter-spacing: .03em; }
.cal-ctl { padding: 8px 12px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 0.75rem; color: var(--muted); }
.cal-ctl label { display: flex; flex-direction: column; gap: 2px; }
.cal-ctl input { font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; }
.cal-ctl p { grid-column: 1 / -1; margin: 2px 0 0; font-size: 0.7rem; }
.cal-ctl[hidden] { display: none; }
.cal-row { display: grid; grid-template-columns: 88px 22px 1fr; gap: 8px; align-items: center; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #efede4; background: transparent; padding: 6px 12px; }
.cal-row:hover, .cal-row.on { background: var(--accent-soft); }
.cal-row .dt { font-size: 0.74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-row .nm { font-size: 0.86rem; }
.cal-row .act { display: block; font-size: 0.72rem; color: var(--muted); }
.cal-row.indoor .act { color: #1d5fa8; }
.cal-empty { padding: 20px 14px; color: var(--muted); font-size: 0.85rem; }

/* ---- live soil temperature ---- */
.soil { margin: 3px 0 0; font-size: 0.82rem; color: var(--ink); }
.soil .link { border: 0; background: none; padding: 0 2px; color: #1d5fa8; text-decoration: underline; font-size: 0.78rem; }
.soil form { display: inline; }
.soil input { font: inherit; font-size: 0.8rem; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; width: 190px; }
.soil .err { color: #b3261e; }
.chip.ready:not([aria-pressed="true"]) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip.ready::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.chip.ready[aria-pressed="true"]::before { color: #fff; }
