:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --text: #1f2a1f;
  --muted: #5d6a5b;
  --line: #ddd6c8;
  --brand: #2f5d3a;
  --brand-2: #3f7a4c;
  --brand-ink: #ffffff;
  --soil: #8a5a33;
  --good: #2e7d32;
  --moderate: #b7791f;
  --low: #c0392b;
  --nodata: #6b7280;
  --est: #6d4ab1;
  --water: #1f6fb2;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --nav-h: 64px;
  --font: 'Inter', 'Hind Siliguri', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121612; --surface: #1b211b; --surface-2: #232b23; --text: #e8ede6; --muted: #a3b0a0; --line: #334033;
    --brand: #6fb47d; --brand-2: #8ccb98; --brand-ink: #0e140e; --soil: #d2a06f; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --good: #66bb6a; --moderate: #f0b44c; --low: #ef6f61; --nodata: #9ca3af; --est: #b39ddb; --water: #64b5f6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121612; --surface: #1b211b; --surface-2: #232b23; --text: #e8ede6; --muted: #a3b0a0; --line: #334033;
  --brand: #6fb47d; --brand-2: #8ccb98; --brand-ink: #0e140e; --soil: #d2a06f; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --good: #66bb6a; --moderate: #f0b44c; --low: #ef6f61; --nodata: #9ca3af; --est: #b39ddb; --water: #64b5f6;
  color-scheme: dark;
}
:lang(bn) { --font: 'Hind Siliguri', 'Inter', system-ui, sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.mono { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { min-height: 100%; }
.screen { max-width: 640px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 24px); min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 12px 0; background: var(--bg); }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; font-size: 1.25rem; }
.icon-btn:hover { background: var(--surface-2); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.card h2 { display: flex; align-items: center; gap: 8px; }
.hero { text-align: center; padding: 24px 16px; background: linear-gradient(160deg, var(--brand), var(--brand-2)); color: var(--brand-ink); border: 0; }
.hero .muted { color: inherit; opacity: .85; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 12px 18px; border-radius: 12px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); min-height: 46px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1 1 140px; }

.field { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.field:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.error { color: var(--low); margin: 8px 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list button, .list a.row { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: space-between; text-align: left; padding: 12px 4px; border: 0; background: none; cursor: pointer; text-decoration: none; color: var(--text); }
.list .sub { display: block; font-size: .8rem; color: var(--muted); }

.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.prop { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.prop:last-child { border-bottom: 0; }
.prop .name { font-weight: 500; }
.prop .val { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.prop .meta { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.prop a.src { font-size: .78rem; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge.good { color: var(--good); } .badge.moderate { color: var(--moderate); } .badge.low { color: var(--low); }
.badge.nodata { color: var(--nodata); } .badge.est { color: var(--est); } .badge.water { color: var(--water); } .badge.info { color: var(--muted); }
.chip { display: inline-block; font-size: .78rem; padding: 2px 8px; background: var(--surface-2); border-radius: 999px; }

.warn { border-left: 4px solid var(--moderate); background: color-mix(in srgb, var(--moderate) 10%, var(--surface)); padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: .88rem; }
.note { border-left: 4px solid var(--line); padding: 8px 12px; font-size: .85rem; color: var(--muted); margin: 10px 0; }

.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); }
.scale { position: relative; height: 26px; margin: 6px 0 2px; }
.scale .track { position: absolute; top: 11px; left: 0; right: 0; height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--line)); }
.scale .range { position: absolute; top: 9px; height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--brand) 45%, transparent); }
.scale .dot { position: absolute; top: 5px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--brand); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--brand); }
.scale-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

.stars { color: var(--moderate); letter-spacing: 2px; font-size: 1.2rem; }
.depth-block { border-left: 6px solid var(--soil); padding: 8px 12px; margin: 10px 0; background: var(--surface); border-radius: 0 10px 10px 0; }
.depth-block.empty { border-left-color: var(--line); opacity: .8; }
.depth-block h3 { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
/* Two badges (source + status) crowd the header at phone width; wrap the badges together, never the label. */
.depth-block h3 > span:first-child { white-space: nowrap; }
.depth-block h3 .badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; margin-left: auto; }

/* Map */
.map-screen { position: fixed; inset: 0 0 var(--nav-h) 0; }
#map { position: absolute; inset: 0; background: #dfe9e1; }
.map-top { position: absolute; top: 0; left: 0; right: 0; z-index: 500; padding: 12px 16px 0; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.map-top > * { pointer-events: auto; }
.brandbar { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .04em; }
.brandbar .pill { background: var(--surface); padding: 6px 12px; border-radius: 999px; box-shadow: var(--shadow); display: inline-flex; gap: 6px; align-items: center; }
.searchbox { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); border: 1px solid var(--line); cursor: text; color: var(--muted); }
.map-fabs { position: absolute; right: 12px; bottom: 96px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.fab { width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; font-size: 1.3rem; display: grid; place-items: center; }
.map-hint { position: absolute; left: 16px; bottom: 20px; z-index: 500; background: var(--surface); padding: 8px 12px; border-radius: 10px; box-shadow: var(--shadow); font-size: .82rem; max-width: 60%; }
.legend { position: absolute; left: 16px; bottom: 70px; z-index: 500; background: var(--surface); padding: 8px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: .75rem; min-width: 150px; }
.legend .bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, #440154, #3b528b, #21918c, #5ec962, #fde725); margin: 4px 0; }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 600; background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18); padding: 10px 16px 16px; max-height: 70%; overflow: auto; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 10px; }

.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; }
.mini-map { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }

/* Bottom nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 1000; background: var(--surface); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600; gap: 2px; }
.nav a .ico { font-size: 1.3rem; }
.nav a.active { color: var(--brand); }

/* Onboarding */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 16px; max-width: 520px; margin: 0 auto; }
.splash { background: linear-gradient(160deg, #2f5d3a, #1f3d27); color: #fff; max-width: none; }
.splash .logo { width: 96px; height: 96px; margin-bottom: 16px; }
.splash h1 { font-size: 2rem; letter-spacing: .12em; margin: 0; }
.splash .sub { letter-spacing: .3em; opacity: .85; font-weight: 600; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(127,127,127,.3); border-top-color: currentColor; border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { text-align: left; margin: 20px 0; display: grid; gap: 12px; }
.step { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.step .n { flex: 0 0 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }

/* Charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend-inline { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.legend-inline i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: 90px 1fr 60px; gap: 8px; align-items: center; font-size: .82rem; margin: 4px 0; }
.hbar .b { height: 12px; border-radius: 6px; background: var(--brand); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.check { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.check.disabled { opacity: .55; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 2000; font-size: .9rem; max-width: calc(100% - 32px); }

table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th, table.data td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.scroll-x { overflow-x: auto; }

@media print {
  .nav, .topbar .icon-btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
  .screen { max-width: none; padding: 0; }
}
