:root {
  --surface-0: #f3f2ef;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --border: #dddcd7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7b7a75;
  --accent: #2a78d6;
  --good: #008300;
  --warn: #b26b00;
  --bad: #c62828;
  --radius: 8px;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-primary);
  background: var(--surface-0);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #3a3936;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --good: #0ca30c;
    --warn: #e0a030;
    --bad: #e66767;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 6px 14px; background: var(--surface-1); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 6px 12px; border-radius: 6px; color: var(--text-secondary); text-decoration: none; }
.tab.active { background: var(--surface-0); color: var(--text-primary); font-weight: 600; }
.spacer { flex: 1; }
.note { color: var(--text-muted); font-size: 12px; }

main { flex: 1; min-height: 0; position: relative; }
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: flex; }

/* ---------- map tab ---------- */
#map { flex: 1; min-width: 0; }
.panel { width: 300px; flex: none; overflow-y: auto; background: var(--surface-1); border-right: 1px solid var(--border); padding: 12px 14px; }
.panel.detail { width: 360px; border-right: 0; border-left: 1px solid var(--border); position: relative; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input:not([type]) { width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.hint { color: var(--text-muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 2px 9px; font-size: 12px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.species-info { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.species-info canvas { width: 100%; height: 46px; display: block; margin-top: 4px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid currentColor; margin-left: 4px; }
.tag.edible { color: var(--good); } .tag.toxic { color: var(--warn); } .tag.deadly { color: var(--bad); font-weight: 700; }

.factor { display: grid; grid-template-columns: 18px 1fr 70px; align-items: center; gap: 6px; margin: 4px 0; }
.factor .name { font-size: 13px; }
.factor.off .name { color: var(--text-muted); }
.travel-mode { font-size: 12px; color: var(--text-secondary); display: flex; gap: 10px; margin: 2px 0 0 24px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.seg button { border: 0; background: var(--surface-2); padding: 4px 10px; }
.seg button.on { background: var(--accent); color: #fff; }
.row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 3px 0; font-weight: 400 !important; }
.row span { flex: none; }
#overlays label { display: flex; gap: 6px; align-items: center; font-size: 13px; margin: 3px 0; }
.legend { font-size: 12px; color: var(--text-secondary); }
.legend .ramp { display: flex; height: 10px; border-radius: 3px; overflow: hidden; margin: 4px 0 2px; }
.legend .ramp span { flex: 1; }
.legend .ticks { display: flex; justify-content: space-between; }
.disclaimer { font-size: 11px; color: var(--text-muted); margin-top: 16px; }

/* ---------- detail panel ---------- */
.detail h2 { margin: 0 0 2px; font-size: 18px; }
.detail .sub { color: var(--text-secondary); font-size: 12px; margin-bottom: 10px; }
.detail h3 { font-size: 13px; margin: 14px 0 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.detail .close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 20px; color: var(--text-muted); }
.big-score { font-size: 34px; font-weight: 700; line-height: 1; }
.bars .bar { display: grid; grid-template-columns: 120px 1fr 32px; gap: 6px; align-items: center; font-size: 12px; margin: 3px 0; }
.bars .track { height: 8px; background: var(--surface-0); border-radius: 4px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.bars .off { color: var(--text-muted); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 2px 8px; font-size: 13px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; }
.wx { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; align-items: end; height: 80px; margin-top: 4px; }
.wx .d { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 10px; color: var(--text-muted); position: relative; }
.wx .r { width: 70%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.wx .d.fc .r { background: repeating-linear-gradient(45deg, var(--accent) 0 3px, transparent 3px 6px); border: 1px solid var(--accent); }
.wx .d.today { color: var(--text-primary); font-weight: 600; }
.wx-legend { font-size: 11px; color: var(--text-muted); }
ul.recent { padding-left: 16px; margin: 4px 0; font-size: 12px; }
.conn { font-size: 13px; }
.conn .c { padding: 6px 0; border-bottom: 1px solid var(--border); }
.conn .legs { color: var(--text-muted); font-size: 12px; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; }
button.ghost { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; }

.maplibregl-popup-content { background: var(--surface-2); color: var(--text-primary); font-size: 12px; }

/* ---------- trees tab ---------- */
#tab-trees { flex-direction: column; overflow-y: auto; padding: 14px 18px; }
.trees-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.trees-toolbar .seg { margin: 0; }
.tree-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.tree-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tree-card .photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; background: var(--border); }
.tree-card .photos figure { margin: 0; position: relative; aspect-ratio: 1; background: var(--surface-0); }
.tree-card .photos img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.tree-card .photos figcaption { position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px; background: rgb(0 0 0 / .55); color: #fff; padding: 1px 4px; }
.tree-card .body { padding: 10px 12px 12px; }
.tree-card h3 { margin: 0; font-size: 16px; }
.tree-card .latin { font-style: italic; color: var(--text-secondary); font-size: 12px; }
.tree-card .names, .detail .names { color: var(--text-secondary); font-size: 12.5px; margin-top: 2px; }
.tree-card .names [lang=he], .detail .names [lang=he] { unicode-bidi: isolate; }
.tree-card .key { background: var(--surface-0); border-radius: 6px; padding: 6px 8px; margin: 8px 0; font-size: 13px; }
.tree-card dl { display: grid; grid-template-columns: 82px 1fr; gap: 3px 8px; font-size: 12.5px; margin: 0; }
.tree-card dt { color: var(--text-secondary); font-weight: 600; }
.tree-card dd { margin: 0; }
.tree-card .credits { font-size: 10px; color: var(--text-muted); padding: 0 12px 8px; }
.lightbox { position: fixed; inset: 0; background: rgb(0 0 0 / .85); display: flex; align-items: center; justify-content: center; z-index: 50; flex-direction: column; gap: 8px; color: #ddd; font-size: 12px; }
.lightbox img { max-width: 92vw; max-height: 85vh; }
#quiz { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; max-width: 760px; }
#quiz .q-img { width: 100%; max-height: 420px; object-fit: contain; background: var(--surface-0); border-radius: 6px; }
#quiz .opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
#quiz .opts button { padding: 8px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; text-align: left; }
#quiz .opts button.right { border-color: var(--good); color: var(--good); font-weight: 600; }
#quiz .opts button.wrong { border-color: var(--bad); color: var(--bad); }

@media (max-width: 900px) {
  .tab-panel.active { flex-direction: column; }
  .panel, .panel.detail { width: 100%; max-height: 40vh; border: 0; }
  #map { min-height: 50vh; }
}
