:root {
  color-scheme: light;
  --ink: #252a28;
  --muted: #68716d;
  --paper: #fffefa;
  --line: rgba(40, 47, 44, 0.12);
  --wine: #9d3f3b;
  --green: #4f7659;
  --shadow: 0 8px 28px rgba(23, 34, 29, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body, #map { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; color: var(--ink); background: #e8e7df; }
#map { position: fixed; inset: 0; }

.topline {
  position: fixed;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 14px;
  font-weight: 720;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark { color: var(--wine); font-size: 20px; line-height: 1; transform: rotate(-35deg); }

.panel {
  position: fixed;
  z-index: 4;
  top: 64px;
  left: 14px;
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100vh - 100px);
  overflow: visible;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 254, 250, 0.97);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.field-label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search-wrap { position: relative; }
#search-input, #kind-filter, #colour-by {
  width: 100%;
  min-height: 43px;
  border: 1px solid rgba(42, 49, 45, 0.18);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
#search-input { padding: 0 40px 0 12px; outline: none; }
#search-input:focus, #kind-filter:focus { border-color: #718c78; box-shadow: 0 0 0 3px rgba(79, 118, 89, 0.13); }
#search-input::placeholder { color: #959c98; }
#kind-filter, #colour-by { padding: 0 10px; }

.clear-search, .icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #69716d;
  cursor: pointer;
  font: inherit;
  font-size: 22px;
  line-height: 1;
}
.clear-search { position: absolute; top: 5px; right: 5px; }
.clear-search:hover, .icon-button:hover { background: #eef0eb; color: var(--ink); }

.suggestions {
  position: absolute;
  z-index: 9;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: min(48vh, 350px);
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 10px 24px rgba(23, 34, 29, 0.18);
}
.suggestion {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.suggestion:hover, .suggestion:focus-visible { background: #f0f1eb; outline: 0; }
.suggestion-title { display: block; overflow: hidden; font-size: 13px; font-weight: 670; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.suggestion-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.panel-section { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--line); }
.panel-section h2 {
  margin: 0 0 10px;
  color: #454d49;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.check-row {
  display: flex;
  align-items: center;
  min-height: 31px;
  gap: 9px;
  color: #373e3b;
  font-size: 13px;
  cursor: pointer;
}
.check-row input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.check-row small { margin-left: auto; color: var(--muted); font-size: 10px; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.winery-swatch { background: var(--wine); box-shadow: 0 0 0 3px rgba(157, 63, 59, 0.13); }
.region-swatch { background: #89759a; }
.vineyard-swatch { background: var(--green); border-radius: 2px; }
.filter-section .check-row { margin-bottom: 8px; }
.panel-foot { margin: 13px 0 0; color: #858d89; font-size: 11px; }

.feature-card {
  position: fixed;
  z-index: 4;
  right: 14px;
  bottom: max(50px, calc(env(safe-area-inset-bottom) + 42px));
  width: min(360px, calc(100vw - 28px));
  max-height: 37vh;
  overflow-y: auto;
  padding: 17px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 254, 250, 0.98);
  box-shadow: var(--shadow);
}
.feature-card h2 { max-width: calc(100% - 28px); margin: 0 0 6px; font-size: 17px; line-height: 1.22; letter-spacing: -0.025em; }
.feature-card .meta { color: var(--muted); font-size: 12px; }
.feature-card .detail-line { margin-top: 10px; font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.feature-card .detail-label { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }
.feature-card a { color: #385e45; font-weight: 650; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 5px; }
.pill { display: inline-block; padding: 4px 7px; border-radius: 9px; background: #eef1eb; color: #4b5d50; font-size: 11px; }
.hint { color: #815d26; }
.card-close { position: absolute; top: 7px; right: 7px; }

.attribution-note, .status-note {
  position: fixed;
  z-index: 3;
  bottom: max(9px, env(safe-area-inset-bottom));
  color: #4c5551;
  font-size: 10px;
  text-shadow: 0 1px 2px rgba(255, 255, 255, .9);
}
.attribution-note { left: 12px; max-width: calc(100vw - 155px); line-height: 1.35; }
.attribution-note a { color: #42534a; }
.status-note { right: 10px; bottom: 38px; padding: 5px 8px; border-radius: 9px; background: rgba(255, 254, 250, .9); }
.maplibregl-ctrl-bottom-right { bottom: 4px; right: 8px; }
.maplibregl-ctrl-top-right { top: 62px; right: 12px; }
.maplibregl-ctrl-group { border-radius: 11px !important; overflow: hidden; box-shadow: var(--shadow) !important; }

.mobile-only { display: none; }

@media (max-width: 640px) {
  .topline { top: max(9px, env(safe-area-inset-top)); left: 10px; right: 10px; justify-content: space-between; pointer-events: none; }
  .brand, .panel-toggle, #panel-toggle, .round-button { pointer-events: auto; }
  .brand { height: 38px; padding: 0 11px; font-size: 13px; }
  .mobile-only { display: grid; flex: 0 0 auto; width: 38px; height: 38px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); pointer-events: auto; }
  .panel { top: 55px; left: 10px; right: 10px; width: auto; max-height: min(47vh, 375px); overflow-y: auto; padding: 13px; border-radius: 15px; }
  .panel.compact { display: none; }
  .panel-section { display: inline-block; vertical-align: top; width: 50%; margin-top: 12px; padding-top: 11px; }
  .panel-section h2 { margin-bottom: 6px; font-size: 10px; }
  .check-row { min-height: 27px; gap: 6px; font-size: 11px; }
  .check-row input { width: 15px; height: 15px; }
  .check-row small { display: none; }
  .filter-section { padding-left: 10px; }
  .filter-section .field-label { margin: 7px 0 4px; font-size: 9px; }
  #kind-filter { min-height: 34px; font-size: 12px; }
  .panel-foot { display: none; }
  .feature-card { right: 10px; bottom: max(46px, calc(env(safe-area-inset-bottom) + 38px)); left: 10px; width: auto; max-height: 31vh; padding: 14px 15px; }
  .feature-card h2 { font-size: 16px; }
  .attribution-note { left: 8px; bottom: max(6px, env(safe-area-inset-bottom)); max-width: calc(100vw - 120px); font-size: 9px; }
  .maplibregl-ctrl-bottom-right { bottom: 2px; right: 6px; }
  .maplibregl-ctrl-top-right { top: auto; bottom: 48px; right: 8px; }
  .maplibregl-ctrl-group button { width: 30px; height: 30px; }
}

.legend { display: grid; gap: 2px; margin-top: 8px; }
.legend-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 8px; width: 100%; padding: 4px 6px; border: 0; border-radius: 6px; background: transparent; font: inherit; font-size: 13px; text-align: left; cursor: pointer; color: inherit; }
.legend-row:hover { background: rgba(0, 0, 0, 0.05); }
.legend-row.off { opacity: 0.35; }
.legend-row .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15); }
.legend-count { font-variant-numeric: tabular-nums; color: #6b625c; font-size: 12px; }
.in-view { margin: 6px 0 0; font-size: 12px; color: #6b625c; }
#colour-by { width: 100%; }

.search-open { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid #d8d1c7; border-radius: 999px; background: #fffefa; font: inherit; font-size: 13px; color: #4a423d; cursor: pointer; }
.search-open:hover { border-color: #718c78; }
#search-form[hidden], .search-open[hidden] { display: none; }

.pill-button { cursor: pointer; border: 1px solid #d8c9a8; font: inherit; }
.pill-button:hover { background: #f6e3b2; border-color: #b8923f; }
.focus-chip { margin-top: 8px; padding: 5px 10px; border: 1px solid #b8923f; border-radius: 999px; background: #f6e3b2; font: inherit; font-size: 12px; cursor: pointer; }
.focus-chip[hidden] { display: none; }

.stat { font-size: 20px; font-weight: 700; margin-right: 6px; }

.round-button { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; line-height: 0; border: 1px solid var(--line); border-radius: 50%; background: rgba(255, 254, 250, 0.97); box-shadow: var(--shadow); font-size: 20px; cursor: pointer; color: var(--ink); }
.round-button[hidden] { display: none; }
.search-popup { position: absolute; top: 0; left: 0; width: min(340px, calc(100vw - 28px)); padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 254, 250, 0.98); box-shadow: var(--shadow); }
.search-popup[hidden] { display: none; }
#search-input::-webkit-search-cancel-button { display: none; }

.panel[hidden] { display: none; }
.panel { top: 70px; }
#search-form { margin-bottom: 4px; }
.clear-search[hidden] { display: none; }
.status-note[hidden], .status-note:empty { display: none; }

.maplibregl-ctrl-attrib-inner { font-size: 10px; color: #8a8580; }
.maplibregl-ctrl-attrib-inner a { color: #8a8580; }
.attrib-stats { display: grid; grid-template-columns: repeat(3, auto); gap: 6px 14px; margin-bottom: 8px; color: #2b2622; }
.stat-block { display: flex; flex-direction: column; font-size: 10.5px; line-height: 1.2; color: #6b625b; }
.stat-block b { font-size: 15px; font-weight: 650; color: #2b2622; letter-spacing: -0.01em; }

.pill-coloured { border-color: color-mix(in srgb, var(--chip) 55%, white); background: color-mix(in srgb, var(--chip) 12%, white); color: color-mix(in srgb, var(--chip) 80%, black); }
.pill-coloured:hover { background: color-mix(in srgb, var(--chip) 22%, white); border-color: var(--chip); }
.feature-card .region-path { margin-top: 2px; color: var(--muted); font-size: 12px; font-style: italic; }
.web-button { display: inline-block; padding: 6px 11px; border-radius: 10px; background: #7a1531; color: #fff !important; font-weight: 600; text-decoration: none; }
.web-button:hover { background: #5e0f25; }

.wordmark { display: inline-flex; align-items: center; gap: 6px; height: 34px; margin-left: 8px; padding: 0 12px 0 9px; border-radius: 17px; background: rgba(255, 254, 250, 0.94); box-shadow: var(--shadow); color: #7a1531; font-size: 14px; font-weight: 700; letter-spacing: -0.01em; pointer-events: none; align-self: center; margin-right: auto; }
.topline:has(+ #map-panel:not([hidden])) .wordmark { display: none; }
