:root {
  --bg: #f8f9fa;
  --panel: #ffffff;
  --text: #212529;
  --muted: #6c757d;
  --line: #e9ecef;
  --accent: #e8590c;
  --accent-soft: #fff4e6;
  --chip: #f1f3f5;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .04);
  --topbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --panel: #1a1b1e;
    --text: #e9ecef;
    --muted: #909296;
    --line: #2c2e33;
    --accent: #ff922b;
    --accent-soft: #2b1d10;
    --chip: #25262b;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
  .base-tiles { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); flex-shrink: 0; }
.brand-mark { font-size: 26px; }
.brand-text { font-weight: 700; font-size: 20px; line-height: 1.1; display: flex; flex-direction: column; }
.brand-text small { font-weight: 400; font-size: 12px; color: var(--muted); }
.search { flex: 1; max-width: 520px; }
.search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--panel); }
.btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; }

/* ---------- Filters ---------- */
.filters {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chips { display: flex; gap: 6px; min-width: 0; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip.holiday.active { background: #c2410c; border-color: #c2410c; }
.row-label { align-self: center; font-size: 12px; color: var(--muted); white-space: nowrap; padding-right: 2px; }
.chip.cat.active { background: var(--c); border-color: var(--c); }
.date-row { justify-content: space-between; }
.custom-range { display: flex; align-items: center; gap: 4px; flex-shrink: 0; color: var(--muted); }
.custom-range input, .selects select, .list-head select {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 8px;
  padding: 4px 8px;
}
.selects { flex-wrap: wrap; font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; }

/* ---------- Layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.list-panel {
  width: 420px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--bg);
}
.map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; background: var(--chip); }

.list-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.list { list-style: none; margin: 0; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; gap: 12px;
  padding: 12px;
  background: var(--panel);
  border-radius: 12px;
  border-left: 4px solid var(--c);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s ease;
}
.card:hover, .card:focus-visible { transform: translateY(-1px); outline: 2px solid var(--c); outline-offset: 0; }
.card-icon {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 10px;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  font-size: 20px;
}
.card-body { min-width: 0; flex: 1; }
.card-date { font-size: 13px; color: var(--c); font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.card-title { margin: 2px 0; font-size: 16px; font-weight: 600; line-height: 1.3; }
.card-venue { font-size: 13px; color: var(--muted); }
.card-price { font-size: 13px; margin-top: 2px; }
.dist { color: var(--accent); font-weight: 600; margin-left: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.tag.hot { background: var(--accent); color: #fff; }
.tag.repeat { background: var(--chip); color: var(--text); border: 1px solid var(--line); }
.tag.warn { background: #fff3bf; color: #8a6d00; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.sentinel { height: 1px; }
.list-foot { padding: 16px; font-size: 12px; color: var(--muted); }

/* ---------- Map pins & popups ---------- */
.pin span {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  background: var(--c);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.pin i { transform: rotate(45deg); font-style: normal; font-size: 16px; }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-container { font-family: inherit; }
.pop h3 { margin: 4px 0 2px; font-size: 16px; line-height: 1.3; }
.pop-cat { color: var(--c); font-weight: 600; font-size: 12px; }
.pop-en { color: #868e96; font-size: 12px; margin-bottom: 4px; }
.pop-meta { font-size: 13px; margin: 3px 0; }
.pop p { margin: 6px 0; font-size: 13px; }
.pop-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-weight: 600; font-size: 13px; }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background-color: rgba(232, 89, 12, .25); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  background-color: rgba(232, 89, 12, .85); color: #fff; font-weight: 700;
}

.mobile-switch { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .brand-text small { display: none; }
  #nearMe { padding: 8px 10px; }
  .filters { padding: 8px 12px; }
  .date-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .custom-range input { flex: 1; min-width: 0; }
  .selects select { flex: 1; min-width: 40%; }
  .list-panel { width: 100%; border-right: 0; }
  .map-wrap { display: none; }
  body[data-view="map"] .list-panel { display: none; }
  body[data-view="map"] .map-wrap { display: block; }
  .mobile-switch {
    display: flex;
    position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    z-index: 1000;
    background: var(--text);
    border-radius: 999px;
    padding: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  }
  .mobile-switch button {
    border: 0; background: transparent; color: var(--bg);
    padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; white-space: nowrap;
  }
  .mobile-switch button.active { background: var(--accent); color: #fff; }
  .list { padding-bottom: 80px; }
}

/* ---------- Cover images (hotlinked, credited) ---------- */
.card-thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: var(--chip); }
.pop-img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 8px; margin-bottom: 6px; background: #f1f3f5; }
.pop-credit { margin-top: 6px; font-size: 11px; color: #868e96; }
