:root {
  --bg: #0f1c14;
  --card: #16241b;
  --card2: #1d3124;
  --accent: #57c95a;
  --accent2: #8fd98a;
  --text: #e8f2ea;
  --muted: #9fb3a4;
  --border: #2a4030;
  --warn: #e6b34d;
  --good: #57c95a;
  --bad: #e07a5f;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header.appbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(90deg, #16301d, #1d4030);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 500;
}
.appbar .logo { font-size: 22px; }
.appbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.appbar .sub { font-size: 12px; color: var(--muted); margin-left: auto; }
.demo-banner {
  background: repeating-linear-gradient(45deg, #3a2f12, #3a2f12 10px, #44380f 10px, #44380f 20px);
  color: #ffd970; border-bottom: 1px solid #5a4a18;
  font-size: 12px; font-weight: 700; text-align: center; padding: 6px 12px; letter-spacing: .3px;
}
.demotag { background: #5a4a18; color: #ffd970; padding: 1px 7px; border-radius: 999px; font-size: 11px; margin-left: 4px; }
.coinbadge { margin-left: auto; background: #14301d; color: var(--accent2); border: 1px solid var(--border); padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.coin-world { background: #14241a; border: 1px solid var(--accent); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 13.5px; line-height: 1.5; }
.coin-world b { color: var(--accent2); }

nav.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); }
nav.tabs button {
  flex: 1; padding: 12px 6px; background: transparent; border: none; color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
.view.hidden { display: none; }

#map { flex: 1; width: 100%; background: #0b1410; }

/* Sivupaneeli kartan päällä */
#sidepanel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 62%; overflow-y: auto;
  background: var(--card); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; padding: 14px 16px 18px; box-shadow: var(--shadow);
  transform: translateY(0); transition: transform .25s ease;
}
#sidepanel.collapsed { transform: translateY(calc(100% - 46px)); }
.panel-handle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; margin-bottom: 8px; }
.panel-handle h2 { font-size: 16px; margin: 0; }
.panel-handle .chev { color: var(--muted); }

.trail-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.trail-card {
  background: var(--card2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; cursor: pointer; transition: border-color .15s, transform .1s;
}
.trail-card:hover { border-color: var(--accent); }
.trail-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.trail-card .tname { font-weight: 700; font-size: 15px; }
.trail-card .tmeta { color: var(--muted); font-size: 12.5px; margin-top: 3px; display: flex; gap: 12px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.easy { background: #1f3d28; color: var(--accent2); }
.badge.med { background: #3d371f; color: var(--warn); }
.badge.hard { background: #3d2420; color: var(--bad); }
.badge.sponsored { background: #1d3340; color: #8fc7e6; }

.trail-detail { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }
.trail-detail p.desc { font-size: 13.5px; color: var(--muted); margin: 6px 0 10px; line-height: 1.45; }
.detail-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.detail-row .k { color: var(--muted); }
.sponsor-box { background: #142433; border: 1px solid #244a63; border-radius: 10px; padding: 10px; margin-top: 10px; font-size: 13px; }
.sponsor-box b { color: #8fc7e6; }

.mode-row { display: flex; gap: 8px; margin: 12px 0 8px; }
.mode-row label {
  flex: 1; display: flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--card2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.mode-row input { accent-color: var(--accent); }
.weight-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; color: var(--muted); }
.weight-row input { width: 70px; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

.btn {
  display: block; width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: var(--accent); color: #08140c; font-size: 15px; font-weight: 800; cursor: pointer;
  margin-top: 8px;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: #3a2320; color: var(--bad); border: 1px solid #5a352f; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* HUD seurannan aikana */
#hud {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 400;
  background: rgba(13,26,18,.92); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px; box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
#hud.hidden { display: none; }
.hud-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.hud-cell .v { font-size: 18px; font-weight: 800; }
.hud-cell .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#hud .cpbar { height: 6px; background: var(--card2); border-radius: 999px; margin: 10px 0 8px; overflow: hidden; }
#hud .cpfill { height: 100%; background: var(--accent); width: 0%; transition: width .3s; }
#hud .stopwrap { display: flex; gap: 8px; }
#hud .stopwrap .btn { margin-top: 0; }

/* Saavutukset & sponsorit */
.scroll { overflow-y: auto; padding: 16px; }
.section-title { font-size: 17px; font-weight: 700; margin: 0 0 12px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.ach {
  background: var(--card2); border: 1px solid var(--border); border-radius: 14px; padding: 14px;
  text-align: center;
}
.ach .emoji { font-size: 30px; }
.ach .at { font-weight: 700; font-size: 14px; margin-top: 6px; }
.ach .am { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.ach.locked { opacity: .45; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 10px; }

.sponsor-card { background: var(--card2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.sponsor-card h3 { margin: 0 0 2px; font-size: 16px; }
.sponsor-card .who { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
.stat-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.stat-row .v { font-weight: 700; }
.pot { color: var(--accent2); }
.ad-line { margin-top: 12px; background: #142433; border: 1px solid #244a63; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.ad-line b { color: #8fc7e6; }

/* Toast */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 900; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--card2); border: 1px solid var(--accent); color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); animation: pop .25s ease; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.hidden { display: none; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 22px; max-width: 380px; width: 100%; box-shadow: var(--shadow); text-align: center; }
.modal h2 { margin: 0 0 6px; font-size: 22px; }
.modal .big { font-size: 40px; margin: 8px 0; }
.modal p { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.modal .reward { background: #142433; border: 1px solid #244a63; border-radius: 12px; padding: 12px; margin: 12px 0; font-size: 14px; }
.modal .reward b { color: #8fc7e6; }

/* Leaflet popup tumma */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--text); }
.leaflet-container { background: #0b1410; font-family: inherit; }
