:root {
  --navy: #0f1f3d;
  --navy-2: #1b2f55;
  --orange: #ff7a1a;
  --orange-soft: #fff1e6;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --muted: #7a8396;
  --line: #e6e9ef;
  --bg: #f5f6f9;
  --card: #ffffff;
  --red: #d93b3b;
  --red-soft: #fdecec;
  --amber: #e08a00;
  --amber-soft: #fff5e0;
  --green: #1f9d60;
  --green-soft: #e7f6ee;
  --blue: #2563c9;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(15, 31, 61, .12);
  --font-head: 'Kanit', 'Leelawadee UI', Tahoma, sans-serif;
  --font-body: 'Sarabun', 'Leelawadee UI', Tahoma, sans-serif;
  --top: 56px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font-body); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.55; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; }
a { color: var(--blue); }

.topbar { height: var(--top); background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; position: relative; z-index: 1001; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 30px; height: 30px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-head); font-weight: 600; font-size: 20px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: #b9c3d8; }
.beta { font-size: 12px; background: rgba(255, 122, 26, .18); color: #ffc79e; border: 1px solid rgba(255, 122, 26, .45); padding: 3px 9px; border-radius: 99px; }

.layout { position: relative; height: calc(100% - var(--top)); }
.map-wrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #e9edf2; }

.search { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 1000; display: flex; gap: 6px; }
.search input { flex: 1; min-width: 0; height: 46px; border: 0; border-radius: 12px; padding: 0 14px; box-shadow: var(--shadow); font-size: 16px; outline: none; }
.search input:focus { box-shadow: 0 0 0 3px rgba(255, 122, 26, .35), var(--shadow); }
.btn-search { height: 46px; border: 0; border-radius: 12px; padding: 0 16px; background: var(--orange); color: #fff; font-family: var(--font-head); font-weight: 500; box-shadow: var(--shadow); cursor: pointer; }
.btn-locate { width: 46px; height: 46px; border: 0; border-radius: 12px; background: #fff; color: var(--navy); box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center; }
.btn-locate svg { width: 22px; height: 22px; }
.results { position: absolute; top: 52px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; background: #fff; border-radius: 12px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
.results li { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.results li:hover, .results li:focus { background: var(--orange-soft); outline: none; }
.results li small { display: block; color: var(--muted); font-size: 12.5px; }

.layers { position: absolute; top: 66px; left: 12px; right: 12px; z-index: 999; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.layers::-webkit-scrollbar { display: none; }
.layers button { flex: 0 0 auto; border: 1px solid var(--line); background: rgba(255, 255, 255, .96); color: var(--ink-2); border-radius: 99px; padding: 6px 12px; font-size: 13.5px; cursor: pointer; box-shadow: 0 2px 8px rgba(15, 31, 61, .08); }
.layers button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.legend { position: absolute; left: 12px; bottom: 150px; z-index: 999; background: rgba(255, 255, 255, .97); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 12.5px; max-width: 240px; }
.legend .lg-title { font-family: var(--font-head); font-weight: 500; font-size: 13px; margin-bottom: 6px; color: var(--navy); }
.legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; color: var(--ink-2); }
.legend .sw { width: 16px; height: 12px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0, 0, 0, .08); }
.legend .dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }

.hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: 170px; z-index: 998; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
.hint strong { color: #ffb27a; font-weight: 600; }
.loading { position: absolute; inset: 0; z-index: 1002; display: grid; place-items: center; background: rgba(245, 246, 249, .85); font-family: var(--font-head); color: var(--navy); font-size: 16px; }
.loading[hidden] { display: none; }

/* bottom sheet on phones */
.panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(15, 31, 61, .18); max-height: 64%; display: flex; flex-direction: column; transition: transform .28s ease; }
.panel.collapsed { transform: translateY(calc(100% - 132px)); }
.panel-handle { border: 0; background: transparent; padding: 10px 0 4px; cursor: pointer; flex: 0 0 auto; }
.panel-handle span { display: block; width: 44px; height: 5px; border-radius: 9px; background: #c9cfdb; margin: 0 auto; }
.panel-body { overflow-y: auto; padding: 4px 16px 28px; -webkit-overflow-scrolling: touch; }

.intro h1 { font-family: var(--font-head); font-weight: 600; font-size: 21px; line-height: 1.35; color: var(--navy); margin: 6px 0 8px; }
.intro p { margin: 6px 0; color: var(--ink-2); }
.intro-list { margin: 8px 0 10px; padding-left: 18px; color: var(--ink-2); }
.intro-list li { margin: 6px 0; }
.intro-list b { color: var(--ink); }
.muted { color: var(--muted); font-size: 13px; }

.place { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 2px 0 10px; }
.place h2 { font-family: var(--font-head); font-weight: 600; font-size: 20px; color: var(--navy); margin: 0; line-height: 1.3; }
.place .coord { color: var(--muted); font-size: 12.5px; }
.btn-share { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 12px; cursor: pointer; color: var(--navy); font-size: 13.5px; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); cursor: pointer; }
.tile .t-label { font-size: 12.5px; color: var(--muted); }
.tile .t-value { font-family: var(--font-head); font-weight: 500; font-size: 15.5px; line-height: 1.35; margin-top: 2px; }
.tile.red { background: var(--red-soft); border-color: #f6caca; }
.tile.red .t-value { color: var(--red); }
.tile.amber { background: var(--amber-soft); border-color: #f5ddb0; }
.tile.amber .t-value { color: #a86300; }
.tile.green { background: var(--green-soft); border-color: #bfe6cf; }
.tile.green .t-value { color: var(--green); }

/* location score */
.score { --c: var(--green); --cs: var(--green-soft); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.score.s-b { --c: #2f9e8f; --cs: #e4f5f2; }
.score.s-c { --c: var(--amber); --cs: var(--amber-soft); }
.score.s-d { --c: var(--red); --cs: var(--red-soft); }
.score-head { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; flex: 0 0 auto; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; align-content: center;
  background: radial-gradient(closest-side, var(--card) 76%, transparent 77% 100%), conic-gradient(var(--c) calc(var(--p) * 1%), #e8ebf1 0); }
.ring b { font-family: var(--font-head); font-weight: 600; font-size: 30px; line-height: 1; color: var(--c); }
.ring small { font-size: 12px; color: var(--muted); margin-top: 2px; }
.score-title { font-family: var(--font-head); font-weight: 600; font-size: 19px; color: var(--navy); line-height: 1.3; }
.score-sub { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; }
.bars { margin-top: 12px; display: grid; gap: 8px; }
.bar { --c: var(--green); display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: #fbfcfd; border-radius: 10px; padding: 8px 10px; cursor: pointer; font: inherit; color: inherit; }
.bar.s-b { --c: #2f9e8f; }
.bar.s-c { --c: var(--amber); }
.bar.s-d { --c: var(--red); }
.bar:hover { border-color: #cfd5df; }
.b-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.b-label { font-weight: 600; font-size: 14.5px; }
.b-label small { color: var(--muted); font-weight: 400; font-size: 12px; }
.b-val { font-family: var(--font-head); font-weight: 600; font-size: 16px; color: var(--c); }
.b-track { display: block; height: 7px; border-radius: 9px; background: #e8ebf1; margin: 5px 0 4px; overflow: hidden; }
.b-fill { display: block; height: 100%; border-radius: 9px; background: var(--c); }
.b-why { display: block; font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.how { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.how summary { cursor: pointer; color: var(--blue); font-weight: 500; }
.how ul { padding-left: 18px; margin: 8px 0; }
.how li { margin: 5px 0; }
.how p { margin: 6px 0 0; color: var(--muted); }
.search-tip { position: absolute; top: 52px; left: 0; right: 0; background: #fff; border-radius: 10px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 13px; color: var(--ink-2); }

.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 14px 14px 12px; margin-bottom: 12px; }
.card h3 { font-family: var(--font-head); font-weight: 600; font-size: 17px; margin: 0 0 8px; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.card h3 .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--orange-soft); color: var(--orange); font-size: 15px; }
.verdict { border-radius: 10px; padding: 10px 12px; margin: 4px 0 10px; font-family: var(--font-head); font-weight: 500; font-size: 15.5px; }
.verdict small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 13px; margin-top: 2px; }
.verdict.red { background: var(--red-soft); color: var(--red); }
.verdict.amber { background: var(--amber-soft); color: #a86300; }
.verdict.green { background: var(--green-soft); color: var(--green); }
.item { padding: 9px 0; border-top: 1px dashed var(--line); }
.item:first-of-type { border-top: 0; }
.item .i-head { font-weight: 600; color: var(--ink); display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.item .i-head .flag { margin-top: 2px; }
.item .i-body { color: var(--ink-2); margin-top: 2px; }
.flag { display: inline-block; font-size: 12px; border-radius: 99px; padding: 1px 8px; font-weight: 500; font-family: var(--font-body); white-space: nowrap; }
.flag.red { background: var(--red-soft); color: var(--red); }
.flag.amber { background: var(--amber-soft); color: #a86300; }
.flag.green { background: var(--green-soft); color: var(--green); }
.flag.grey { background: #eef0f4; color: var(--ink-2); }
.zone { display: flex; gap: 10px; align-items: flex-start; }
.zone .chip { flex: 0 0 auto; min-width: 46px; text-align: center; font-family: var(--font-head); font-weight: 600; border-radius: 8px; padding: 4px 6px; color: #222; border: 1px solid rgba(0, 0, 0, .1); }
.zone .z-text { flex: 1; }
.zone .z-name { font-weight: 600; }
.zone .z-plain { color: var(--ink-2); font-size: 14px; }
.zone .z-far { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.alert { background: var(--amber-soft); color: #8a5200; border-radius: 10px; padding: 9px 11px; margin-top: 10px; font-size: 14px; }
.list { list-style: none; margin: 4px 0 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--line); }
.list li:first-child { border-top: 0; }
.list .l-name { font-weight: 500; }
.list .l-sub { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.list .l-dist { flex: 0 0 auto; color: var(--navy); font-family: var(--font-head); font-weight: 500; font-size: 14px; text-align: right; }
.sources { font-size: 12.5px; color: var(--muted); }
.sources h4 { font-family: var(--font-head); font-weight: 500; font-size: 14px; color: var(--ink-2); margin: 6px 0; }
.sources ul { padding-left: 18px; margin: 4px 0 10px; }
.sources li { margin: 3px 0; word-break: break-word; }
.outside { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; }
.outside h2 { font-family: var(--font-head); font-size: 18px; color: var(--navy); margin: 0 0 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 2000; box-shadow: var(--shadow); font-size: 14px; }

.pin { width: 34px; height: 44px; }
.leaflet-container { font-family: var(--font-body); }
.leaflet-control-attribution { font-size: 10.5px; }

/* ?clean=1 : map only (for share images and clip footage) */
body.clean .topbar, body.clean .search, body.clean .layers, body.clean .legend, body.clean .hint, body.clean .panel,
body.clean .leaflet-control-zoom { display: none !important; }
body.clean .layout { height: 100%; }
body.clean .map-wrap { right: 0 !important; }

/* desktop: map left, panel right */
@media (min-width: 900px) {
  .panel { top: 0; bottom: 0; left: auto; right: 0; width: 440px; max-height: none; border-radius: 0; box-shadow: -6px 0 24px rgba(15, 31, 61, .1); }
  .panel.collapsed { transform: none; }
  .panel-handle { display: none; }
  .panel-body { padding: 16px 20px 32px; }
  .map-wrap { right: 440px; }
  .search { right: auto; width: min(560px, calc(100% - 24px)); }
  .layers { right: auto; max-width: calc(100% - 24px); flex-wrap: wrap; }
  .legend { bottom: 24px; }
  .hint { bottom: 28px; }
  .intro h1 { font-size: 24px; }
}
