:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --ink: #22271f;
  --muted: #6b7466;
  --line: #e2e6dd;
  --accent: #c0492f;
  --shadow: 0 2px 14px rgba(30, 40, 25, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.hero {
  background: linear-gradient(135deg, #7a2417 0%, #b8432b 55%, #d98a3f 100%);
  color: #fff;
  padding: 34px 20px 30px;
}
.hero-inner { max-width: 960px; margin: 0 auto; }
.hero h1 { margin: 0 0 6px; font-size: 2rem; letter-spacing: -0.5px; }
.tagline { margin: 0; opacity: 0.92; max-width: 620px; font-size: 1.02rem; }

main { max-width: 960px; margin: 0 auto; padding: 20px; }

/* controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 4px 0 16px;
}
.search-wrap { position: relative; flex: 1 1 260px; }
#search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 1rem;
  background: #fff;
}
#search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1000;
  overflow: hidden;
}
.suggestion {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.suggestion:hover { background: #fbeeea; }
.suggestion span { font-size: 0.82rem; color: var(--muted); }

.btn {
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #fbeeea; border-color: var(--accent); }
.coords { flex: 1 1 100%; font-size: 0.88rem; color: var(--muted); }

/* map */
.map-section { position: relative; }
#map {
  height: 340px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1;
}
.loader {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.72);
  display: flex; align-items: center; justify-content: center;
  gap: 12px; border-radius: var(--radius); z-index: 1200;
  font-weight: 600; color: var(--ink);
}
.spinner {
  width: 26px; height: 26px;
  border: 3px solid #cfe0ce; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* heat mapa */
.heat-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 12px 0 4px; font-size: 0.9rem;
}
.heat-controls label { font-weight: 600; }
#heat-target {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 0.92rem; cursor: pointer; max-width: 240px;
}
#heat-target:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.heat-status { color: var(--muted); font-size: 0.85rem; }
.heat-legend {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto; color: var(--muted); font-size: 0.8rem;
}
.heat-legend i {
  width: 90px; height: 10px; border-radius: 5px; display: inline-block;
  background: linear-gradient(90deg, #e5533c, #e8913c, #e8c53c, #3ca55c);
}

/* ranking + grupy buttonów */
.rank-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.btn-group button {
  padding: 9px 14px; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; font-size: 0.9rem; cursor: pointer; color: var(--ink);
  min-height: 40px; transition: background 0.15s, border-color 0.15s;
}
.btn-group button:hover { background: #fbeeea; }
.btn-group button.active {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}

.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; background: #f7f9f5; border: 1px solid var(--line); border-radius: 12px;
}
.rank-pos { flex: 0 0 28px; text-align: center; font-weight: 700; font-size: 1rem; color: var(--muted); }
.rank-place { flex: 1 1 auto; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.rank-place b { font-size: 0.98rem; }
.rank-voi { font-size: 0.78rem; color: var(--muted); }
.rank-score {
  flex: 0 0 auto; min-width: 40px; text-align: center; padding: 5px 10px;
  border-radius: 9px; color: #fff; font-weight: 700; font-variant-numeric: tabular-nums;
}
.rank-item { list-style: none; }
.rank-item .rank-row { cursor: pointer; transition: background 0.12s; }
.rank-item .rank-row:hover { background: #fbeeea; }
.rank-chev { flex: 0 0 auto; color: var(--muted); font-size: 0.8rem; }
.rank-sub {
  padding: 8px 12px 10px 48px; margin-top: 2px;
  background: #fff; border: 1px solid var(--line); border-radius: 0 0 12px 12px;
}
.rank-sub-load { color: var(--muted); font-size: 0.85rem; padding: 4px 0; }
.rank-sub-forest {
  font-size: 0.78rem; color: var(--muted); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600;
}
.rank-sp {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 4px 0; border-bottom: 1px solid #f0f2ed;
}
.rank-sp:last-child { border-bottom: none; }
.rank-sp-name { font-size: 0.88rem; }
.rank-sp-name i { font-style: italic; color: var(--muted); font-size: 0.78rem; }
.rank-sp-score { font-weight: 700; font-variant-numeric: tabular-nums; }

.hint {
  text-align: center; color: var(--muted);
  background: #fff; border: 1px dashed var(--line);
  border-radius: 12px; padding: 16px; margin: 16px 0;
}

/* results */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-top { text-align: center; border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.card-title { font-size: 1.15rem; font-weight: 700; }
.card-level { font-weight: 700; text-transform: capitalize; margin-top: 4px; }

.gauge { display: flex; justify-content: center; margin: 6px 0; }
.gauge svg { width: 130px; height: 130px; }
.ring-bg { fill: none; stroke: #ecefe8; stroke-width: 11; }
.ring-fg { fill: none; stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.ring-num { font-size: 34px; font-weight: 700; text-anchor: middle; fill: var(--ink); }
.ring-unit { font-size: 13px; text-anchor: middle; fill: var(--muted); }

.factors { display: flex; flex-direction: column; gap: 12px; }
.factor-head { display: flex; justify-content: space-between; font-size: 0.9rem; font-weight: 600; }
.factor-w { color: var(--muted); font-weight: 500; }
.bar { height: 7px; background: #ecefe8; border-radius: 6px; overflow: hidden; margin: 4px 0; }
.bar-fill { height: 100%; border-radius: 6px; transition: width 0.6s ease; }
.factor-note { font-size: 0.8rem; color: var(--muted); }

/* gatunki */
.species { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.species-title { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin-bottom: 10px; }
.sp { margin-bottom: 11px; }
.sp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sp-name { font-size: 0.9rem; font-weight: 600; }
.sp-latin { font-style: italic; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.sp-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.sp .bar { margin: 4px 0; }
.sp-note { font-size: 0.78rem; color: var(--muted); }

/* panels */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 16px 0;
}
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }

.forecast { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.fc {
  text-align: center; padding: 10px 4px;
  background: #f7f9f5; border-radius: 12px; border: 1px solid var(--line);
}
.fc-day { font-weight: 700; font-size: 0.82rem; text-transform: capitalize; }
.fc-date { font-size: 0.72rem; color: var(--muted); margin-bottom: 6px; }
.fc-line { font-size: 0.88rem; display: flex; align-items: center; justify-content: center; gap: 4px; }
.fc-line b { font-variant-numeric: tabular-nums; }

.chart svg { width: 100%; height: auto; }
.chart-lbl { font-size: 10px; fill: var(--muted); }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px;
  font-size: 0.8rem; color: var(--muted);
}
.chart-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }

.how summary { cursor: pointer; font-weight: 700; }
.how p { font-size: 0.92rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

.disclaimer {
  margin: 20px 0 40px;
  font-size: 0.85rem;
  color: var(--muted);
  background: #fdf6e3;
  border: 1px solid #eadfb8;
  border-radius: 12px;
  padding: 14px 18px;
}
.disclaimer b { color: #8a6d1a; }

.hidden { display: none !important; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .hero { padding: 24px 16px 22px; }
  .hero h1 { font-size: 1.6rem; }
  .tagline { font-size: 0.95rem; }

  .controls { gap: 8px; }
  .search-wrap { flex: 1 1 100%; }
  #geo-btn { flex: 1 1 100%; }

  #map { height: 260px; }

  .heat-controls { flex-direction: column; align-items: stretch; }
  #heat-target { max-width: none; width: 100%; }
  .heat-legend { margin-left: 0; }

  /* rankingowe grupy buttonów: pełna szerokość, równy podział */
  .rank-controls { flex-direction: column; }
  .btn-group { display: grid; width: 100%; }
  #rank-metric { grid-template-columns: 1fr 1fr; }
  #rank-offset { grid-template-columns: repeat(4, 1fr); }
  .btn-group button { padding: 10px 4px; font-size: 0.82rem; }

  .cards { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .forecast { grid-template-columns: repeat(4, 1fr); }

  .panel { padding: 16px; }
  .disclaimer { padding: 13px 15px; }
}

@media (max-width: 380px) {
  .forecast { grid-template-columns: repeat(3, 1fr); }
  #rank-offset .btn-group button, #rank-offset button { font-size: 0.76rem; padding: 9px 2px; }
  .rank-voi { font-size: 0.72rem; }
}

/* uwaganakleszcze: pojedyncza karta */
.cards-single { grid-template-columns: 1fr; max-width: 520px; margin-left: auto; margin-right: auto; }
