:root {
  --green: #1a9850;
  --amber: #fdae61;
  --grey: #9e9e9e;
  --dark: #12291c;
  --panel-bg: #ffffff;
  --panel-border: #e0e5e1;
  --accent: #0d7a3f;
  --text: #1c2b22;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
#app { display: flex; flex-direction: column; }
body { color: var(--text); }

#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 14px; background: var(--dark); color: #fff; gap: 10px;
  min-height: 54px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 600; }
.brand .sub { margin: 0; font-size: 11px; opacity: .75; }
.topbar-controls { display: flex; gap: 8px; align-items: center; }
.topbar-controls button {
  background: #234534; color: #fff; border: 1px solid #3a6a50;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.topbar-controls button:hover { background: #2f5a44; }

#searchbox { position: relative; }
#search-input {
  width: 240px; padding: 6px 10px; border-radius: 6px; border: 1px solid #3a6a50;
  background: #234534; color: #fff; font-size: 13px;
}
#search-input::placeholder { color: #9ec0ab; }
#search-results {
  position: absolute; top: 34px; left: 0; right: 0; background: #fff; color: var(--text);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 1200;
  max-height: 260px; overflow-y: auto;
}
#search-results div { padding: 7px 10px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid #eee; }
#search-results div:hover { background: #eef5f0; }

/* flex (not a fixed calc) so a taller wrapped topbar on small screens can't
 * push the year slider off the bottom of the viewport */
#main { display: flex; flex: 1; min-height: 0; }

#panel {
  width: 300px; min-width: 300px; overflow-y: auto; background: var(--panel-bg);
  border-right: 1px solid var(--panel-border); padding: 10px;
}
.panel-block { border-bottom: 1px solid var(--panel-border); padding: 10px 2px; }
.panel-block h2 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.panel-block h3 { font-size: 11.5px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; color: #57685d; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 11px; margin-right: 4px; vertical-align: -3px;
}
.step-lead { margin-top: -2px; }
.panel-block.substep { margin-left: 10px; border-left: 2px solid #e4ebe5; padding-left: 8px; }
.panel-block label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; margin: 6px 0; }
.panel-block label:has(input[type=range]) { display: block; }
.panel-block label.row { justify-content: flex-start; gap: 6px; }
.panel-block input[type=number] {
  width: 80px; flex: 0 0 auto; padding: 3px 6px; border: 1px solid #ccc; border-radius: 4px;
}
.panel-block input[type=range] { width: 100%; }
.hint { font-size: 11px; color: #6b7a70; margin: 4px 0; }
.derived { font-size: 12px; background: #eef5f0; border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row button, button.wide {
  padding: 6px 10px; font-size: 12.5px; border: 1px solid var(--panel-border);
  background: #f6f9f7; border-radius: 6px; cursor: pointer;
}
.btn-row button:hover, button.wide:hover { background: #e8f1eb; }
button.wide { width: 100%; margin-top: 6px; }
details summary { font-size: 12.5px; cursor: pointer; margin: 6px 0; color: var(--accent); }
#drawn-list { font-size: 12px; }
#drawn-list .drawn-item { display: flex; justify-content: space-between; padding: 3px 0; }
#drawn-list button { border: none; background: none; color: #b33; cursor: pointer; }

#map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

#results-bar {
  position: absolute; left: 12px; right: 12px; bottom: 64px; z-index: 1000;
  display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap;
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 8px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18); backdrop-filter: blur(3px);
}
.counter { display: flex; flex-direction: column; min-width: 92px; padding: 2px 10px; border-right: 1px solid #e2e8e4; }
.counter:last-of-type { border-right: none; }
.counter .val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.counter .lab { font-size: 10.5px; color: #5c6b61; text-transform: uppercase; letter-spacing: .03em; }
.counter.accent .val { color: var(--accent); }
#btn-chart-toggle { margin-left: auto; border: none; background: #eef5f0; border-radius: 8px; font-size: 18px; cursor: pointer; padding: 4px 10px; }

#year-control {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 1000;
  display: flex; gap: 10px; align-items: center;
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 8px 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
#year-label { font-weight: 700; font-size: 14px; min-width: 60px; }
#year-slider { flex: 1; accent-color: var(--accent); }
#btn-play { border: none; background: var(--accent); color: #fff; border-radius: 6px; padding: 5px 12px; cursor: pointer; }

#chart-panel {
  position: absolute; right: 12px; top: 12px; z-index: 1000; width: 380px;
  background: rgba(255,255,255,.96); border-radius: 10px; padding: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
#chart-canvas { width: 100%; height: 220px; }
#species-breakdown { font-size: 12px; margin-top: 8px; }
#species-breakdown table { width: 100%; border-collapse: collapse; }
#species-breakdown td, #species-breakdown th { padding: 3px 6px; text-align: right; border-bottom: 1px solid #eee; }
#species-breakdown td:first-child, #species-breakdown th:first-child { text-align: left; }
.prov { color: #a66; font-size: 10px; }

#present-title {
  display: none;
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1000;
  text-align: center; background: rgba(18,41,28,.85); color: #fff; border-radius: 12px;
  padding: 10px 28px; box-shadow: 0 2px 14px rgba(0,0,0,.3);
}
#present-title h1 { margin: 0; font-size: 24px; }
#present-title p { margin: 2px 0 0; font-size: 14px; opacity: .85; }

/* Presentation mode */
body.presenting #panel { display: none; }
body.presenting #topbar { display: none; }
body.presenting #main { height: 100%; }
body.presenting #present-title { display: block; }
body.presenting .counter .val { font-size: 30px; }
body.presenting .counter .lab { font-size: 12px; }
/* presentation stat order: km bank -> net tCO2e -> revenue/NPV -> effective area */
body.presenting #c-bank { order: 1; }
body.presenting #c-net { order: 2; }
body.presenting #c-revenue { order: 3; }
body.presenting #c-npv { order: 4; }
body.presenting #c-area { order: 5; }
body.presenting #c-tbkm { order: 6; }
body.presenting #c-seedlings { order: 7; }
body.presenting #btn-chart-toggle { order: 8; margin-left: auto; }
.counter .sub { display: none; }
body.presenting .counter .sub {
  display: block; font-size: 9.5px; color: #7d8c83; max-width: 150px; line-height: 1.25; margin-top: 2px;
}
body.presenting #year-control { padding: 14px 18px; }
body.presenting #year-label { font-size: 20px; }
#btn-present-exit {
  position: absolute; top: 18px; right: 18px; z-index: 1100; display: none;
  background: rgba(255,255,255,.85); border: none; border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
body.presenting #btn-present-exit { display: block; }

#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
#assumptions-modal {
  background: #fff; border-radius: 12px; width: min(860px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--panel-border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-head button { border: none; background: none; font-size: 18px; cursor: pointer; }
#assumptions-body { padding: 10px 18px 18px; overflow-y: auto; font-size: 13px; }
#assumptions-body table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
#assumptions-body th, #assumptions-body td { text-align: left; padding: 5px 8px; border-bottom: 1px solid #eee; vertical-align: top; }
#assumptions-body th { background: #f2f6f3; }
.disclaimer { background: #fff6e8; border: 1px solid #eeddbb; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }
.modal-links { font-size: 12px; color: #6b7a70; margin: 4px 0 0; }
.modal-links a { color: var(--accent); }

#loading {
  position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.9); font-size: 16px; color: var(--accent);
}

.hidden { display: none !important; }

.leaflet-popup-content { font-size: 12.5px; }
.popup-table td { padding: 1px 6px 1px 0; }
.popup-mix { margin-top: 4px; font-weight: 600; }
.popup-coord { margin: 1px 0 3px; }
.copy-coord {
  font: 11px ui-monospace, Menlo, monospace; color: #336950;
  background: #eef5f0; border-radius: 4px; padding: 1px 6px; cursor: pointer;
}
.copy-coord:hover { background: #dcebe1; }
.popup-badge {
  display: inline-block; background: #e3f4e9; color: #0d7a3f; border: 1px solid #b3dfc4;
  border-radius: 10px; padding: 1px 8px; font-size: 10.5px; font-weight: 700; vertical-align: 2px;
}
#present-benchmark { margin-top: 6px; font-size: 13px; color: #9fd8b4; }
#present-cyclone { margin: 2px 0 0; font-size: 13px; color: #f0c987; }
.popup-sect { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #0d7a3f; margin-top: 7px; border-top: 1px solid #e4e9e5; padding-top: 5px; }
.popup-flags { margin-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.popup-flag { font-size: 11px; border-radius: 6px; padding: 2px 7px; }
.popup-flag.cold { background: #ece7f5; color: #4a3a80; }
.popup-flag.fire { background: #fbeae2; color: #90422a; }
.popup-flag.cyc { background: #fdf3e0; color: #8a6116; }
.popup-flag.sal { background: #e4f0f4; color: #2a5f74; }
.row-group { display: flex; gap: 10px; flex-wrap: wrap; }
.preset-box { background: #f2f7f3; border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.preset-box button { display: block; width: 100%; margin: 2px 0; padding: 6px 10px; font-size: 12.5px; border: 1px solid #bcd4c4; background: #fff; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--accent); }
.preset-box button:hover { background: #e8f1eb; }
.preset-box button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.preset-box #preset-clear { color: #666; font-weight: 400; }
.preset-desc { font-size: 10.5px; color: #6b7a70; margin: 1px 2px 2px; }
.preset-stat { display: block; font-size: 11px; color: #5c6b61; margin: 0 0 6px 2px; font-variant-numeric: tabular-nums; }
.group-label { font-size: 12.5px; display: flex; align-items: center; gap: 4px; width: 100%; }
.display-note { font-style: italic; }
.criterion { border-left: 3px solid #e4ebe5; padding: 3px 0 3px 8px; margin: 7px 0; }
.criterion:has(.f-en:checked) { border-left-color: var(--accent); background: #f4f9f5; }
.criterion .f-dir, .criterion input[type=range].indent { width: calc(100% - 14px); margin-left: 14px; margin-top: 3px; }
.criterion .f-dir { padding: 3px 6px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px; }
.criterion .row-group.indent { margin-left: 14px; }
.saved-preset-row { display: flex; gap: 4px; align-items: stretch; margin: 2px 0; }
.saved-preset-row .saved-preset-btn { flex: 1; }
.saved-preset-del { flex: 0 0 26px; border: 1px solid #d8c4c4 !important; color: #a33 !important; font-weight: 400 !important; }

button.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border: 1.2px solid var(--accent); border-radius: 50%;
  background: none; color: var(--accent); cursor: pointer; flex: 0 0 auto;
  font: italic 700 10px/1 Georgia, serif; padding: 0; vertical-align: 1px;
}
button.info:hover { background: var(--accent); color: #fff; }
button.paint {
  border: 1px solid #cdd8cf; background: #fff; border-radius: 4px; cursor: pointer;
  font-size: 10px; padding: 1px 4px; line-height: 1.2; flex: 0 0 auto; margin-left: 2px;
}
button.paint:hover { background: #e8f1eb; }
button.paint.active { background: var(--accent); border-color: var(--accent); }
#tooltip {
  position: fixed; z-index: 5000; max-width: 250px; background: #16281d; color: #eef5f0;
  font-size: 12px; line-height: 1.45; padding: 8px 10px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.3); display: none; pointer-events: none;
}
#tooltip.show { display: block; }

#filter-summary {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1000;
  display: flex; gap: 10px; align-items: center;
  background: rgba(22,40,29,.92); color: #fff; border-radius: 20px; padding: 6px 16px;
  font-size: 13px; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
#filter-summary button {
  border: none; background: rgba(255,255,255,.15); color: #fff; border-radius: 12px;
  padding: 3px 10px; font-size: 12px; cursor: pointer;
}
#filter-summary button:hover { background: rgba(255,255,255,.3); }
body.presenting #filter-summary { top: 84px; }
#map-legend {
  position: absolute; left: 12px; bottom: 150px; z-index: 1000;
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 8px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18); font-size: 11.5px; max-width: 215px;
  backdrop-filter: blur(3px);
}
#map-legend-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: #33443a;
}
#map-legend-toggle { border: none; background: none; cursor: pointer; font-size: 12px; padding: 0 2px; color: #33443a; }
.legend-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; line-height: 1.25; }
.legend-swatch { width: 20px; height: 4px; border-radius: 2px; flex: 0 0 auto; }
.legend-swatch.thin { height: 2px; opacity: .55; }
.legend-swatch.sel { height: 5px; }
body.presenting #map-legend { font-size: 14px; max-width: 280px; padding: 12px 16px; }
body.presenting #map-legend-head { font-size: 13px; }
body.presenting .legend-swatch { width: 28px; height: 6px; }
body.presenting .legend-swatch.thin { height: 3px; }

#consistency-error {
  flex-basis: 100%; background: #fdecea; border: 1px solid #f0b4ae; color: #8a1c13;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; margin-bottom: 4px;
}
button.subtle { color: #6b7a70; font-weight: 400; }
#block-colour .btn-row .paint { font-size: 12px; padding: 5px 9px; }
#block-colour .btn-row .paint.active { color: #fff; }

#btn-panel-toggle { display: none; }
@media (max-width: 800px) {
  #panel { position: absolute; z-index: 1500; height: 100%; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 18px rgba(0,0,0,.25); }
  #panel.open { transform: none; }
  #btn-panel-toggle {
    display: block; position: absolute; top: 10px; left: 54px; z-index: 1600;
    background: var(--dark); color: #fff; border: none; border-radius: 8px;
    padding: 8px 12px; font-size: 13px; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.3);
  }
  body:has(#panel.open) #btn-panel-toggle { left: auto; right: 10px; }
  body.presenting #btn-panel-toggle { display: none; }
  .brand .sub { display: none; }
  .brand h1 { font-size: 15px; }
  .brand .logo { font-size: 20px; }
  #search-input { width: 130px; }
  #topbar { flex-wrap: wrap; padding: 6px 10px; }
  .topbar-controls { flex-wrap: wrap; justify-content: flex-end; }
  .topbar-controls button { padding: 5px 8px; font-size: 12px; }
  #chart-panel { width: 94vw; }
  .counter { min-width: 70px; }
  .counter .val { font-size: 15px; }
}
