:root {
  --bg: var(--tg-theme-bg-color, #fff7ee);
  --bg2: var(--tg-theme-secondary-bg-color, #f6ead9);
  --text: var(--tg-theme-text-color, #0f2f38);
  --muted: var(--tg-theme-hint-color, #7a8a8f);
  --accent: var(--tg-theme-button-color, #e36414);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --stroke: var(--tg-theme-bg-color, #fff7ee);
  --high: #e4572e;
  --mid: #f2b134;
  --low: #4caf7a;
  --none: #ddd3c4;
}
html.dark { --none: #4a4f55; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html.web body { max-width: 720px; margin: 0 auto; }
html.web .sheet { max-width: 720px; margin: 0 auto; }
/* Desktop browsers: the map scales to the screen height, centred (viewBox keeps its aspect). */
@media (min-width: 600px) { html.web #map { height: min(52vh, 420px); } }
body {
  margin: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); }
.top p { margin: 2px 0 12px; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.total { background: var(--bg2); border-radius: 14px; padding: 10px; }
.total b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.total span { font-size: 12px; color: var(--muted); }

.crumbs { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.link { background: none; border: 0; color: var(--accent); font-size: 26px; line-height: 1; padding: 0 6px 0 0; cursor: pointer; }

.map-wrap { position: relative; }
#map { width: 100%; height: auto; display: block; touch-action: manipulation; }
#map path { stroke: var(--stroke); stroke-linejoin: round; cursor: pointer; transition: opacity .15s; }
#map path.sel { stroke: var(--text); }
#map path.mine { stroke-dasharray: 4 3; stroke: var(--text); }
#map .marker { fill: none; stroke: var(--accent); stroke-width: 3; cursor: pointer; }
#map .marker-hit { fill: transparent; cursor: pointer; }
#map text { font-size: 22px; font-weight: 700; fill: var(--text); pointer-events: none; }
#map path.pulse { animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0% { opacity: 1; } 40% { opacity: .35; } 100% { opacity: 1; } }

.hint { text-align: center; font-size: 13px; margin: 6px 0 10px; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: 0 0 14px; font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.lvl-high { background: var(--high); } .lvl-mid { background: var(--mid); } .lvl-low { background: var(--low); } .lvl-none { background: var(--none); }

.list { list-style: none; padding: 0; margin: 0; border-radius: 14px; overflow: hidden; background: var(--bg2); }
.list li { display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-bottom: 1px solid var(--bg); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list .name { flex: 1; }
.list .num { font-variant-numeric: tabular-nums; color: var(--muted); }
.list .num b { color: var(--text); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.foot { font-size: 12px; text-align: center; margin-top: 14px; }
.share-view { width: 100%; margin: 0 0 14px; }
.btn:disabled { opacity: .6; }

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--muted); opacity: .4; margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--bg2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.needs { padding-left: 18px; margin: 6px 0 14px; }
.note { background: var(--bg2); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.btns { display: grid; gap: 8px; margin-top: 12px; }
.btn { border: 0; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--bg2); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.error { margin-top: 16px; padding: 14px; border-radius: 12px; background: var(--bg2); text-align: center; }
