/* Run Clean — shared styles (app + explainer). Mobile first. */
:root {
  --green: #1b7f5a; --green-dark: #145f43; --green-soft: #e6f3ed;
  --ink: #18231f; --muted: #56645f; --line: #d9e1dd; --bg: #f4f6f5; --surface: #fff;
  --amber: #8a5300; --amber-soft: #fff4e0; --red: #b3261e; --focus: #0b57d0;
  --radius: 14px; --shadow: 0 6px 24px rgba(16, 32, 26, .18);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--green-dark); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ---------- app shell ---------- */
#map { position: fixed; inset: 0; }
.topbar {
  position: fixed; z-index: 20; top: calc(8px + var(--safe-t)); left: 8px; right: 8px;
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow);
}
.brand { font-weight: 750; font-size: 16px; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--green); display: inline-block; }
.pill { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; border-radius: 999px; background: transparent; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; font-weight: 600; text-decoration: none; color: var(--ink); }
.iconbtn:hover { background: var(--bg); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn span { white-space: nowrap; }
@media (max-width: 420px) { #howlink span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } .brand { font-size: 15px; } }

.sheet {
  position: fixed; z-index: 15; left: 0; right: 0; bottom: 0; max-height: 58vh; max-height: 58dvh;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding-bottom: var(--safe-b);
}
.sheet-handle { border: 0; background: transparent; padding: 8px 0 2px; display: flex; justify-content: center; min-height: 28px; }
.sheet-handle span { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.sheet.collapsed .sheet-body > :not(.always) { display: none; }
@media (min-width: 900px) {
  .topbar { left: 16px; right: auto; width: 420px; top: 16px; }
  .sheet { left: 16px; right: auto; top: 80px; bottom: 16px; width: 420px; max-height: none; border-radius: var(--radius); }
  .sheet-handle { display: none; }
  .sheet.collapsed .sheet-body > :not(.always) { display: revert; }
}

/* ---------- controls ---------- */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--bg); border-radius: 12px; margin: 4px 0 12px; }
.modes button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 650; font-size: 15px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
@media (max-width: 360px) { .modes button { font-size: 13.5px; } }
.modes button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.field { margin: 10px 0; }
.field > label, .label { display: block; font-weight: 650; font-size: 14px; margin-bottom: 4px; }
.searchbox { position: relative; }
.searchbox input { width: 100%; min-height: 48px; padding: 10px 44px 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); }
.searchbox input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(27,127,90,.18); }
.searchbox .clear { position: absolute; right: 2px; top: 2px; }
/* the box has its own ✕ button; hide the browser's built-in one for type="search" */
.searchbox input::-webkit-search-cancel-button,
.searchbox input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.suggestions { list-style: none; margin: 4px 0 0; padding: 4px; position: absolute; z-index: 30; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 50vh; overflow-y: auto; }
.suggestions li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--green-soft); }
.suggestions .kind { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.locate { min-height: 44px; border: 0; background: transparent; color: var(--green-dark); font-weight: 650; padding: 0 4px; display: inline-flex; align-items: center; gap: 6px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { min-height: 44px; min-width: 52px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 650; }
.chips button[aria-pressed="true"] { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
.btn { min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; width: 100%; }
.btn.primary:hover { background: var(--green-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions .btn { flex: 1 1 auto; }
.linkbtn { border: 0; background: none; padding: 8px 0; color: var(--green-dark); text-decoration: underline; font-weight: 600; min-height: 44px; }

/* ---------- results ---------- */
.result { margin-top: 12px; }
.card { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.card.option { padding: 0; position: relative; }
.option-head { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 12px 56px 12px 14px; color: inherit; border-radius: var(--radius); }
.option-head:hover { background: var(--bg); }
.option-head .cardtop { display: flex; }
.optline { display: block; margin-top: 4px; }
.optline.good { color: var(--green-dark); font-weight: 750; font-size: 17px; line-height: 1.25; }
.optline.clamp { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.card.option[data-selected="true"] { border-color: var(--green); box-shadow: 0 0 0 2px rgba(27,127,90,.25); }
.card.option[data-selected="true"] .option-head:hover { background: transparent; }
.morebtn { position: absolute; top: 6px; right: 4px; font-size: 22px; font-weight: 800; line-height: 1; color: var(--ink); }
.morebtn:hover { background: var(--bg); }

/* action menu: a bottom sheet on phones, a small dialog on desktop */
.menu { display: flex; flex-direction: column; margin: 4px -18px 4px; }
.menu button { display: grid; grid-template-columns: 28px 1fr; align-items: center; text-align: left; gap: 0 10px; min-height: 56px;
  padding: 8px 18px; border: 0; border-top: 1px solid var(--line); background: none; font-weight: 650; }
.menu button:hover { background: var(--bg); }
.menu button span { font-size: 18px; grid-row: span 2; text-align: center; }
.menu button small { grid-column: 2; color: var(--muted); font-weight: 400; font-size: 13px; }
@media (max-width: 899px) {
  dialog.actionsheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b); }
}
.headline { font-size: 22px; font-weight: 800; line-height: 1.2; margin: 2px 0 4px; }
.headline.good { color: var(--green-dark); }
.headline.same { color: var(--ink); }
.sub { margin: 2px 0; }
.muted { color: var(--muted); font-size: 14px; }
.grade { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 9px; font-weight: 800; color: #fff; flex: none; }
.grade.A { background: #17703f; } .grade.B { background: #3d7a25; } .grade.C { background: #c99a1a; color: #1d1d00; } .grade.D { background: #b0440c; } .grade.E { background: #a3221b; }
.cardtop { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.estimate { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.estimate:hover { color: var(--ink); }
.up { color: var(--amber); font-weight: 650; }
.warn { background: var(--amber-soft); color: #5a3800; border-radius: 10px; padding: 8px 10px; font-size: 14px; margin: 8px 0; }
.error { background: #fdecea; color: #6b1510; border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
details { margin-top: 6px; }
details summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; color: var(--green-dark); }
details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 4px 0 8px; font-size: 14px; }
details dt { color: var(--muted); }
details dd { margin: 0; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--green-soft); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.legend { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.legend i { flex: 1; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #1a9850, #a6d96a, #fee08b, #f46d43, #a50026); max-width: 160px; }
.datafoot { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.intro { background: var(--green-soft); border-radius: 12px; padding: 10px 12px; margin: 0 0 10px; font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.intro p { margin: 0; flex: 1; }

/* map controls */
.mapctl { position: fixed; z-index: 12; right: 8px; top: calc(68px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
.mapctl button { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--surface); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; }
.mapctl button[aria-pressed="true"] { background: var(--green-soft); }
@media (min-width: 900px) { .mapctl { top: 16px; right: 56px; flex-direction: row; } }
.maplibregl-ctrl-bottom-right { margin-bottom: calc(110px + var(--safe-b)); }
@media (min-width: 900px) { .maplibregl-ctrl-bottom-right { margin-bottom: 0; } }

/* dialogs */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 20, 16, .45); }
.dlg { padding: 18px; }
.dlg h2 { margin: 0 0 8px; font-size: 20px; }
.dlg .close { position: absolute; right: 8px; top: 8px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-of-type { border-bottom: 0; }
.setting input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--green); flex: none; }
.setting input[type="range"] { width: 100%; accent-color: var(--green); }
.setting.stack { display: block; }
textarea, select, .dlg input[type="text"] { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; }
textarea { min-height: 96px; }

/* ---------- explainer page ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 84px 18px 60px; background: var(--surface); min-height: 100vh; }
.page h1 { font-size: 30px; line-height: 1.15; margin: 8px 0 12px; }
.page h2 { font-size: 22px; margin: 34px 0 8px; padding-top: 8px; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.page h3 { font-size: 17px; margin: 18px 0 6px; scroll-margin-top: 80px; }
.page p, .page li { font-size: 16.5px; }
.page .lead { font-size: 18px; color: var(--muted); }
.toc { background: var(--bg); border-radius: 12px; padding: 12px 16px; }
.toc ol { margin: 6px 0; padding-left: 20px; }
.toc li { margin: 4px 0; }
.callout { background: var(--green-soft); border-radius: 12px; padding: 12px 14px; }
.callout.amber { background: var(--amber-soft); }
table.simple { border-collapse: collapse; width: 100%; font-size: 15px; }
table.simple th, table.simple td { text-align: left; border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: top; }
.topbar.pagebar { position: fixed; top: 0; left: 0; right: 0; width: auto; margin: 0; border-radius: 0; z-index: 50;
  background: var(--surface); box-shadow: 0 1px 0 var(--line); padding: calc(8px + var(--safe-t)) 16px 8px; }
body:has(.pagebar) { height: auto; }
body:has(.pagebar) .page { padding-top: calc(84px + var(--safe-t)); }
body:has(.pagebar) h2, body:has(.pagebar) h3 { scroll-margin-top: 90px; }
.back { margin-top: 30px; }
.marker { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
.marker::after { content: ""; width: 22px; height: 22px; border-radius: 50%; background: var(--marker-color, #1b7f5a); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); box-sizing: border-box; }
.marker:active { cursor: grabbing; }
