:root {
  --bg: #f3f6fa;
  --card: #ffffff;
  --text: #0f1b2d;
  --muted: #5b6b80;
  --line: #e2e8f0;
  --brand: #0b5cab;
  --brand-soft: #e6f0fb;
  --l1: #16a34a; --l1s: #e8f7ee;
  --l2: #d4a106; --l2s: #fdf6dc;
  --l3: #ea6c0a; --l3s: #fdefe3;
  --l4: #dc2626; --l4s: #fde8e8;
  --water: #2563eb;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #121b2d; --text: #e6edf7; --muted: #93a3b8; --line: #22304a;
    --brand: #5aa2ee; --brand-soft: #16263f;
    --l1: #34d17a; --l1s: #10291c; --l2: #f2c233; --l2s: #2b2510;
    --l3: #fb8a3c; --l3s: #2e1c0f; --l4: #f75a5a; --l4s: #321416;
    --water: #60a5fa; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #121b2d; --text: #e6edf7; --muted: #93a3b8; --line: #22304a;
  --brand: #5aa2ee; --brand-soft: #16263f;
  --l1: #34d17a; --l1s: #10291c; --l2: #f2c233; --l2s: #2b2510;
  --l3: #fb8a3c; --l3s: #2e1c0f; --l4: #f75a5a; --l4s: #321416;
  --water: #60a5fa; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 "IBM Plex Sans Thai", system-ui, sans-serif;
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: .95rem; margin: 18px 0 8px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); } .small { font-size: .82rem; }

.topbar { position: sticky; top: 0; z-index: 1000; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text); }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: var(--muted); font-size: .75rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.updated { color: var(--muted); font-size: .8rem; }
.btn { font: inherit; font-size: .88rem; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 10px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.icon { width: 36px; padding: 6px 0; font-size: 1.1rem; }
.btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding-top: 16px; padding-bottom: 8px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin-right: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.note { color: var(--muted); font-size: .8rem; margin: 12px 0 0; }

.banner { border-radius: 14px; padding: 12px 16px; background: var(--l4s); color: var(--l4); border: 1px solid color-mix(in srgb, var(--l4) 35%, transparent); font-weight: 500; }

/* Risk hero */
.risk { display: flex; gap: 24px; align-items: center; border-width: 2px; --lc: var(--muted); --ls: var(--card); background: linear-gradient(135deg, var(--ls), var(--card) 70%); border-color: color-mix(in srgb, var(--lc) 40%, var(--line)); }
.risk[data-level="1"] { --lc: var(--l1); --ls: var(--l1s); }
.risk[data-level="2"] { --lc: var(--l2); --ls: var(--l2s); }
.risk[data-level="3"] { --lc: var(--l3); --ls: var(--l3s); }
.risk[data-level="4"] { --lc: var(--l4); --ls: var(--l4s); }
.risk-gauge { position: relative; width: 190px; flex: none; }
.risk-gauge svg { width: 100%; display: block; }
.g-track, .g-fill { fill: none; stroke-width: 11; stroke-linecap: round; }
.g-track { stroke: var(--line); }
.g-fill { stroke: var(--lc); stroke-dasharray: 0 100; transition: stroke-dasharray .8s ease; }
.risk-score { position: absolute; left: 0; right: 0; bottom: 2px; text-align: center; font-weight: 700; font-size: 2.3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.risk-score small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.eyebrow { color: var(--muted); font-size: .85rem; }
.risk h1 { font-size: 2rem; color: var(--lc); margin: 2px 0 6px; }
.advice { margin: 0 0 10px; max-width: 62ch; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.lv { font-size: .72rem; padding: 2px 8px; border-radius: 99px; }
.lv1 { background: var(--l1s); color: var(--l1); } .lv2 { background: var(--l2s); color: var(--l2); }
.lv3 { background: var(--l3s); color: var(--l3); } .lv4 { background: var(--l4s); color: var(--l4); }
@media (max-width: 620px) { .risk { flex-direction: column; text-align: center; gap: 8px; } .legend { justify-content: center; } .risk h1 { font-size: 1.7rem; } }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 860px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .v small { font-size: .8rem; font-weight: 500; color: var(--muted); }
.stat .s { font-size: .78rem; color: var(--muted); }

/* Factors */
.factors { display: flex; flex-direction: column; gap: 12px; }
.factor .row { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.factor .row b { font-variant-numeric: tabular-nums; }
.factor .bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 4px 0 2px; }
.factor .bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.factor .d { color: var(--muted); font-size: .78rem; }

.warnings { display: flex; flex-direction: column; gap: 10px; }
.warn { border-left: 3px solid var(--l3); padding: 4px 0 4px 12px; }
.warn b { display: block; font-weight: 600; font-size: .92rem; }
.warn p { margin: 4px 0 0; font-size: .85rem; color: var(--muted); }
.warn.old { border-color: var(--line); opacity: .75; }
details summary { cursor: pointer; color: var(--brand); font-size: .85rem; }

/* Segmented */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 2px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: .82rem; border: 0; background: none; color: var(--muted); padding: 4px 10px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* Map */
#map { height: 460px; border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
@media (max-width: 620px) { #map { height: 360px; } }
.map-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.leaflet-popup-content { font-family: "IBM Plex Sans Thai", sans-serif; font-size: 13px; line-height: 1.5; }
.nearby { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--brand-soft); font-size: .88rem; }

/* Lists */
.list { display: flex; flex-direction: column; max-height: 440px; overflow: auto; }
.st { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.st:last-child { border: 0; }
.st .n { font-weight: 500; font-size: .92rem; }
.st .m { color: var(--muted); font-size: .76rem; grid-column: 1; }
.st .p { grid-row: 1 / span 2; grid-column: 2; text-align: right; align-self: center; }
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.pill.lvl5 { background: var(--l4s); color: var(--l4); } .pill.lvl4 { background: var(--brand-soft); color: var(--water); }
.pill.lvl3 { background: var(--l1s); color: var(--l1); } .pill.lvl2, .pill.lvl1 { background: var(--l2s); color: var(--l2); }
.st .pct { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.up { color: var(--l4); } .down { color: var(--l1); }

.bars { display: flex; flex-direction: column; gap: 7px; max-height: 440px; overflow: auto; }
.brow { display: grid; grid-template-columns: 110px 1fr 64px; gap: 8px; align-items: center; font-size: .85rem; }
.brow .t { height: 14px; background: var(--line); border-radius: 4px; overflow: hidden; }
.brow .t i { display: block; height: 100%; background: var(--water); border-radius: 4px; }
.brow .t i.h { background: var(--l3); } .brow .t i.vh { background: var(--l4); }
.brow b { text-align: right; font-variant-numeric: tabular-nums; }

/* Forecast */
.fc-chart { display: flex; align-items: flex-end; gap: 2px; height: 150px; padding-top: 8px; border-bottom: 1px solid var(--line); position: relative; }
.fc-chart .b { flex: 1; min-width: 3px; background: var(--water); border-radius: 3px 3px 0 0; position: relative; }
.fc-chart .b.day { outline: 0; }
.fc-chart .b:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--card); font-size: .72rem; padding: 3px 6px; border-radius: 6px; white-space: nowrap; margin-bottom: 4px; z-index: 5; }
.fc-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: 4px; }
.fc-daily { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-top: 14px; }
@media (max-width: 620px) { .fc-daily { grid-template-columns: repeat(4, 1fr); } }
.fd { text-align: center; border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; font-size: .8rem; }
.fd b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.fd.h { border-color: var(--l3); background: var(--l3s); } .fd.vh { border-color: var(--l4); background: var(--l4s); }

/* News */
.news { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 860px) { .news { grid-template-columns: 1fr; } }
.ni { display: block; text-decoration: none; color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.ni:hover { border-color: var(--brand); }
.ni .t { font-weight: 500; font-size: .92rem; }
.ni .m { color: var(--muted); font-size: .76rem; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.tagc { background: var(--brand-soft); color: var(--brand); padding: 0 6px; border-radius: 6px; }
.more { grid-column: 1 / -1; justify-self: center; }

/* Checklist */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.progress div { height: 100%; width: 0; background: var(--l1); transition: width .3s; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); cursor: pointer; font-size: .9rem; }
.checklist input { margin-top: 5px; accent-color: var(--l1); width: 16px; height: 16px; flex: none; }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }

.phones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 420px) { .phones { grid-template-columns: repeat(2, 1fr); } }
.phones a { text-decoration: none; color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.phones a:hover { border-color: var(--l4); }
.phones b { display: block; font-size: 1.3rem; color: var(--l4); }
.phones span { font-size: .75rem; color: var(--muted); }
.links { padding-left: 18px; margin: 0; font-size: .9rem; }
.links li { margin: 3px 0; }

.footer { padding-top: 8px; padding-bottom: 40px; font-size: .8rem; color: var(--muted); }
.skeleton { height: 56px; border-radius: 10px; background: linear-gradient(90deg, var(--line), var(--bg), var(--line)); background-size: 200% 100%; animation: sh 1.4s infinite; }
@keyframes sh { to { background-position: -200% 0; } }
.empty { color: var(--muted); font-size: .88rem; padding: 12px 0; }
