:root {
  --red: #C8102E;
  --red-dark: #9E0B23;
  --green: #1B7F3B;
  --amber: #8A5A00;
  --amber-bg: #FFF4D6;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --text: #16181D;
  --muted: #5B6270;
  --line: #E1E4EA;
  --radius: 14px;
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1C1F25;
    --text: #F1F2F4;
    --muted: #A3A9B5;
    --line: #2E323A;
    --amber: #F2C14E;
    --amber-bg: #3A2F12;
    --green: #4CC27A;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 17px; line-height: 1.45; }
button, a { font: inherit; }

/* ── Sticky emergency header ── */
.top {
  position: sticky; top: 0; z-index: 1000;
  background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  display: grid; gap: 8px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.lang {
  margin-left: auto; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 4px 14px; font-size: 15px; cursor: pointer;
}
.call {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--red); color: #fff; text-decoration: none; border-radius: var(--radius);
  padding: 12px; min-height: 68px; box-shadow: 0 2px 0 var(--red-dark);
}
.call:active { transform: translateY(1px); }
.call-big { font-size: 28px; font-weight: 800; letter-spacing: .5px; }
.call-sub { font-size: 14px; opacity: .9; }
.cpr-btn {
  border: 2px solid var(--red); color: var(--red); background: var(--card);
  border-radius: var(--radius); padding: 10px; font-weight: 700; font-size: 18px; cursor: pointer;
}

main { padding: 12px 16px 8px; max-width: 680px; margin: 0 auto; }
.top > * { max-width: 648px; width: 100%; justify-self: center; }

.banner { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 8px 12px; font-size: 15px; margin-bottom: 8px; }
.gps { margin: 4px 0 10px; color: var(--muted); font-size: 15px; }
.gps.warn { color: var(--amber); font-weight: 600; }

/* ── Area chips ── */
.areas { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 15px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── Tabs ── */
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; color: var(--text); padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ── List ── */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.first { border: 2px solid var(--red); }
.card.closed { opacity: .72; }
.row1 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dist { font-size: 24px; font-weight: 800; }
.walk { color: var(--muted); font-size: 15px; }
.dir { color: var(--muted); font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }
.arrow { display: inline-block; font-weight: 800; color: var(--red); }
.card h3 { margin: 4px 0 2px; font-size: 19px; }
.loc { margin: 0 0 8px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.badge { font-size: 14px; border-radius: 6px; padding: 2px 8px; background: var(--bg); }
.badge.ok { color: var(--green); }
.badge.bad { color: var(--red); font-weight: 700; }
.badge.key { color: var(--amber); background: var(--amber-bg); font-weight: 700; }
.actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.actions .btn:not(.nav) { padding: 10px 16px; white-space: nowrap; }
.btn {
  display: flex; align-items: center; justify-content: center; text-align: center;
  border-radius: 10px; padding: 10px; font-weight: 700; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text); min-height: 46px;
}
.btn.nav { background: #1565C0; border-color: #1565C0; color: #fff; }
.more { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 15px; }
.more img { width: 100%; max-height: 320px; object-fit: cover; border-radius: 10px; background: var(--bg); }
.more dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; }
.more dt { color: var(--muted); }
.more dd { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* ── Map ── */
.map-wrap { position: relative; }
#map { height: 60vh; min-height: 320px; border-radius: var(--radius); border: 1px solid var(--line); }
.map-msg { margin: 8px 0 0; color: var(--amber); font-size: 15px; }
.leaflet-popup-content { font-size: 15px; }
.leaflet-popup-content a.btn { margin-top: 6px; color: #fff; }

/* ── Footer ── */
.foot { max-width: 680px; margin: 8px auto 0; padding: 12px 16px max(24px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 14px; }
.foot p { margin: 4px 0; }
.report { color: #1565C0; font-weight: 600; }
.about summary { cursor: pointer; }

/* ── CPR dialog ── */
.cpr { width: min(640px, 100vw); max-width: 100vw; max-height: 100dvh; margin: auto; border: 0; padding: 16px; border-radius: var(--radius); background: var(--card); color: var(--text); }
.cpr::backdrop { background: rgba(0,0,0,.55); }
.cpr-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cpr-head h2 { margin: 0; font-size: 21px; }
.x { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.draft { background: var(--amber-bg); color: var(--amber); padding: 6px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.steps { padding-left: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; margin: 12px 0; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; }
.steps li::before {
  content: counter(s); width: 40px; height: 40px; border-radius: 50%; background: var(--red); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.steps h3 { margin: 4px 0 2px; font-size: 18px; }
.steps p { margin: 0; font-size: 15px; }
.metro { text-align: center; border-top: 1px solid var(--line); padding-top: 12px; }
.beat { font-size: 44px; font-weight: 800; color: var(--muted); transition: transform .06s; }
.beat.on { color: var(--red); transform: scale(1.15); }
.elapsed { font-size: 15px; color: var(--muted); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.switch { background: var(--amber-bg); color: var(--amber); border: 2px solid currentColor; border-radius: 10px; padding: 10px; font-weight: 800; font-size: 18px; margin: 0 0 10px; }
.metro-btn { width: 100%; border: 0; border-radius: var(--radius); background: var(--text); color: var(--bg); font-weight: 800; font-size: 20px; padding: 14px; cursor: pointer; }
.metro-btn.running { background: var(--red); color: #fff; }
.metro-note { font-size: 14px; color: var(--muted); }
.call-inline { margin-top: 8px; min-height: 56px; font-size: 22px; font-weight: 800; }
