:root {
  --bg: #f6f1e7; --card: #fffdf8; --ink: #23201b; --quiet: #6a6257; --line: #e0d6c3;
  --forest: #2d5a3d; --bark: #6b4a2f;
  --accent: #2d5a3d; --accent-ink: #ffffff; --accent-2: #6b4a2f; --star: #d99a1e; --danger: #a33a2b;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16140f; --card: #211d17; --ink: #efe9dd; --quiet: #b0a693; --line: #3b342a;
    --accent: #8cc49b; --accent-ink: #0f1a12; --accent-2: #c9a27a; --star: #f0b84a; --danger: #ef8a7a; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: 8px 0 4px; }
h2 { font-size: 1.2rem; margin: 24px 0 8px; }
.quiet { color: var(--quiet); }
.error { color: var(--danger); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px;
  background: var(--card); border-bottom: 3px solid var(--forest); flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem;
  text-decoration: none; color: var(--ink); }
.brand img { width: 36px; height: 36px; }
.brand b { color: var(--accent-2); }
.topbar nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.top-link { display: block; text-align: center; padding: 16px 24px; border-radius: 10px; background: var(--accent);
  color: var(--accent-ink); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.top-link small { display: block; font-weight: 400; font-size: .85rem; }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } }

form.search { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
input[type=search] { flex: 1 1 220px; }
textarea { width: 100%; min-height: 110px; }
button, .button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); cursor: pointer; font-weight: 600; text-decoration: none; display: inline-block; }
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .6; cursor: default; }

.split { display: grid; grid-template-columns: 1fr 380px; gap: 16px; margin-top: 16px; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
#map { height: 520px; border-radius: 10px; border: 1px solid var(--line); }
.results { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; }
.results li { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.results li a { font-weight: 600; text-decoration: none; }

.stars { color: var(--star); letter-spacing: 1px; white-space: nowrap; }
.rate { display: inline-flex; gap: 2px; align-items: center; }
.rate button { background: none; border: none; color: var(--line); font-size: 1.7rem; line-height: 1; padding: 0 2px; }
.rate button.on { color: var(--star); }
.rate button:hover, .rate button:focus-visible { color: var(--star); }

ol.top { padding-left: 0; list-style: none; counter-reset: top; }
ol.top li { counter-increment: top; display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border-bottom: 1px solid var(--line); }
ol.top li::before { content: counter(top); font-size: 1.5rem; font-weight: 700; color: var(--quiet); text-align: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--quiet); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.fav .thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.fav .thumbs img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.fav .note { white-space: pre-wrap; }
.site-map img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }

form.stack { display: grid; gap: 12px; max-width: 420px; }
form.stack label { display: grid; gap: 4px; font-weight: 600; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog.viewer { width: auto; max-width: calc(100vw - 32px); padding: 8px; }
dialog.viewer img { max-width: calc(100vw - 56px); max-height: calc(100vh - 96px); display: block; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- phones ------------------------------------------------------------- */

.tabbar { display: none; }
.offline { background: #8a5a14; color: #fff; text-align: center; padding: 6px 12px; font-size: .9rem; }
.install-hint { margin-top: 16px; }

/* stars stay easy to hit with a thumb at every size */
.rate button { min-width: 44px; min-height: 44px; }

@media (max-width: 640px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  main { padding: 12px 16px; }
  h1 { font-size: 1.35rem; }
  .topbar { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 1000; }
  .desktop-nav { display: none !important; }

  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; min-height: 56px;
    text-decoration: none; color: var(--quiet); font-size: .75rem; font-weight: 600; }
  .tabbar a .ico { font-size: 1.3rem; line-height: 1; }
  .tabbar a.on { color: var(--accent); }

  button, .button, input, select { min-height: 44px; }
  .hero p.quiet { display: none; }
  .top-link { padding: 12px; }
  form.search input[type=search] { flex-basis: 100%; }
  form.search select { flex: 1; }

  /* results first, then a shorter map */
  .split { display: flex; flex-direction: column; }
  .results { max-height: none; order: -1; }
  #map { height: 50vh; min-height: 260px; }

  /* the sites table becomes one card per site */
  table.sites, table.sites tbody, table.sites tr, table.sites td { display: block; }
  table.sites thead { display: none; }
  table.sites tr { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  table.sites td { border: none; padding: 0; }
  table.sites td[data-label]::before { content: attr(data-label) ": "; color: var(--quiet); font-size: .85rem; }
  table.sites td.site-name { grid-column: 1 / -1; font-weight: 700; font-size: 1.05rem; }
  table.sites td.site-name::before { content: none; }
  table.sites td.actions { grid-column: 1 / -1; margin-top: 6px; }
  table.sites td.actions button { width: 100%; }
  table.sites td.empty { display: none; }

  ol.top li { grid-template-columns: 32px 1fr; }
  ol.top li > div:last-child { grid-column: 2; }

  .gallery { grid-template-columns: 1fr; }
  .fav .thumbs img { width: calc(50% - 3px); height: 120px; }

  /* dialogs become a bottom sheet */
  dialog:not(.viewer) { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
  form.stack { max-width: none; }
}

/* the photo picker: on phones this opens the camera or the photo library */
input[type=file] { padding: 6px; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; padding: 8px 14px; margin-right: 10px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; }

/* ---- generated site map ---------------------------------------------------- */
.sitemap { height: 460px; border-radius: 10px; border: 1px solid var(--line); }
@media (max-width: 640px) { .sitemap { height: 60vh; } }
.small { font-size: .85rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .9rem; margin: 4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 2px solid #fff;
  box-shadow: 0 0 0 1px #0003; background: var(--c); }
/* one color per site kind, on the map dots (SVG) and in the legend */
.kind-full { --c: #1f7a3f; }
.kind-power { --c: #2563b8; }
.kind-rv { --c: #c27a12; }
.kind-tent { --c: #8a5a9e; }
.kind-other { --c: #6b6b6b; }
.leaflet-interactive.site-dot { fill: var(--c); fill-opacity: .9; stroke: #fff; }
.site-label { background: transparent; border: none; box-shadow: none; color: #fff; font-weight: 700; font-size: 10px;
  padding: 0; text-shadow: 0 0 3px #000, 0 0 2px #000; display: none; }
.site-label::before { display: none; }
.show-labels .site-label { display: block; }
.site-pop { min-width: 160px; line-height: 1.4; }
.site-pop .row { margin-top: 8px; }
.credit { margin-top: 24px; }
