:root {
  /* theme: deep brown base, green highlight, burgundy for selected states */
  --bg: #1f100a;
  --panel: rgba(38, 21, 14, 0.94);
  --panel-solid: #26150e;
  --line: rgba(255, 235, 220, 0.10);
  --line-strong: rgba(255, 235, 220, 0.20);
  --text: #f5ede3;
  --muted: #b5a393;
  --faint: #806b5c;
  --accent: #a0c65e;
  --on-accent: #1f100a;
  --burgundy: #6e1f30;
  --burgundy-soft: rgba(110, 31, 48, 0.92);
  --burgundy-light: #d98a9a;
  --chip: rgba(255, 240, 225, 0.07);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);

  --red: #c23a52;
  --white: #e6cf6a;
  --sparkling: #f3ecc4;
  --rose: #f095aa;
  --orange: #e8913a;
  --sweet: #c47f22;
  --fortified: #8c4a5c;
  --amaro: #86a36a;

  --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- map ---------- */
#map {
  position: fixed;
  inset: 0;
  height: 100dvh;
  background:
    radial-gradient(ellipse at 50% 45%, #2e1a10 0%, var(--bg) 55%, #150a06 100%);
}
#map::before {
  /* faint starfield behind the globe */
  content: "";
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(1px 1px at 72% 12%, rgba(255,255,255,.4), transparent 60%),
    radial-gradient(1px 1px at 86% 64%, rgba(255,255,255,.45), transparent 60%),
    radial-gradient(1px 1px at 22% 78%, rgba(255,255,255,.35), transparent 60%),
    radial-gradient(1.5px 1.5px at 50% 90%, rgba(255,255,255,.35), transparent 60%),
    radial-gradient(1px 1px at 92% 28%, rgba(255,255,255,.3), transparent 60%),
    radial-gradient(1px 1px at 6% 52%, rgba(255,255,255,.4), transparent 60%),
    radial-gradient(1px 1px at 38% 6%, rgba(255,255,255,.35), transparent 60%);
}
.maplibregl-canvas:focus { outline: none; }
.maplibregl-ctrl-attrib {
  background: rgba(31, 16, 10, 0.6) !important;
  color: var(--muted);
  font-size: 10px;
}
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: var(--safe-bottom); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: var(--gutter);
  right: var(--gutter);
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "brand search" "chips chips";
  gap: 10px 14px;
  align-items: center;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { grid-area: brand; display: flex; flex-direction: column; line-height: 1; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.brand-mark { font-family: var(--serif); font-size: 28px; font-weight: 600; letter-spacing: .02em; }
.brand-sub { font-size: 10px; letter-spacing: .28em; text-transform: uppercase; color: var(--accent); margin-top: 3px; }

.search {
  grid-area: search;
  justify-self: end;
  width: min(420px, 100%);
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 6px 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.search > svg { color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: transparent;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { display: none; }

.chips {
  grid-area: chips;
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 13px;
  border-radius: 17px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  font-size: 13px; color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--burgundy-light); background: var(--burgundy-soft); }
.chip .n { color: var(--faint); font-size: 12px; }

/* ---------- map buttons ---------- */
.map-actions {
  position: fixed; z-index: 10;
  right: var(--gutter);
  bottom: calc(var(--safe-bottom) + 28px);
  display: flex; gap: 8px;
}
.pill-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 16px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  font-size: 14px; font-weight: 500;
}
.pill-btn.round { width: 44px; padding: 0; justify-content: center; }
.pill-btn:active { transform: scale(.97); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 600; display: inline-grid; place-items: center;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 20px;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted);
}
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn:hover { color: var(--text); }

.count-line {
  position: fixed; z-index: 9;
  left: var(--gutter);
  bottom: calc(var(--safe-bottom) + 40px);
  font-size: 12px; color: var(--muted);
  text-shadow: 0 1px 8px rgba(0,0,0,.8);
  pointer-events: none;
}

/* ---------- panel: bottom sheet on phones, side panel on desktop ---------- */
.panel {
  position: fixed; z-index: 20;
  left: 0; right: 0; bottom: 0;
  height: calc(100dvh - var(--safe-top) - 24px);
  background: var(--panel-solid);
  border-top: 1px solid var(--line-strong);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
}
.panel[data-state="half"] { transform: translateY(48%); }
.panel[data-state="full"] { transform: translateY(0); }
.panel.dragging { transition: none; }
.panel-grip {
  flex: none; height: 26px; display: grid; place-items: center;
  cursor: grab; touch-action: none;
}
.panel-grip span { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.panel-close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.panel-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 20px calc(var(--safe-bottom) + 24px);
  -webkit-overflow-scrolling: touch;
}
/* in half state the lower part of the panel is off-screen, so leave room to scroll to it */
.panel[data-state="half"] .panel-body { padding-bottom: calc(48vh + 24px); }

@media (min-width: 900px) {
  .panel {
    left: auto; top: 0; right: 0; bottom: 0;
    width: 420px; height: 100dvh;
    border-radius: 0; border-top: 0;
    border-left: 1px solid var(--line-strong);
    transform: translateX(100%);
  }
  .panel[data-state="half"], .panel[data-state="full"] { transform: translateX(0); }
  .panel[data-state="half"] .panel-body { padding-bottom: 32px; }
  .panel-grip { display: none; }
  .panel-body { padding: 56px 28px 32px; }
  body.panel-open .map-actions, body.panel-open .count-line { right: calc(420px + var(--gutter)); }
  body.panel-open .topbar { right: calc(420px + var(--gutter)); }
  .chips { margin: 0; padding: 2px 0; -webkit-mask-image: none; flex-wrap: wrap; overflow: visible; }
}

/* ---------- panel content ---------- */
.eyebrow { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); margin: 4px 0 6px; }
.wine-title { font-family: var(--serif); font-size: 30px; font-weight: 600; line-height: 1.08; margin: 0 40px 4px 0; }
.wine-sub { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--text); opacity: .85; margin: 0 0 12px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 4px 10px; border-radius: 12px;
  background: var(--chip); color: var(--muted);
}
.tag .dot { width: 8px; height: 8px; border-radius: 50%; }
.place {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px;
  background: var(--chip); margin: 6px 0 18px;
}
.place svg { flex: none; color: var(--accent); margin-top: 2px; }
.place strong { display: block; font-weight: 500; }
.place small { color: var(--muted); font-size: 12px; }
.grapes { color: var(--muted); font-size: 14px; margin: 0 0 4px; }
.grapes em { color: var(--faint); font-style: normal; font-size: 12px; }

.bottles { width: 100%; border-collapse: collapse; margin: 8px 0 6px; font-variant-numeric: tabular-nums; }
.bottles th { text-align: left; font-weight: 500; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); padding: 6px 0; border-bottom: 1px solid var(--line); }
.bottles td { padding: 11px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.bottles th:last-child, .bottles td:last-child { text-align: right; }
.bottles .vintage { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.bottles .fmt { color: var(--muted); font-size: 13px; }
.bottles .price { font-weight: 600; }
.half { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.half.no { color: var(--burgundy-light); }
.section-list { color: var(--muted); font-size: 12px; margin-top: 14px; }

/* list views */
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 40px 8px 0; }
.list-head h2 { font-family: var(--serif); font-size: 28px; font-weight: 600; margin: 0; }
.list-head span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.list-section { margin-top: 18px; }
.list-section h3 { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); margin: 0 0 2px; font-weight: 600; }
.list-section p.tagline { margin: 0 0 6px; font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 15px; }
.wine-row {
  width: 100%; display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: start;
  text-align: left; padding: 11px 2px; border: 0; border-bottom: 1px solid var(--line); background: none;
}
.wine-row:hover { background: rgba(255,255,255,.025); }
.wine-row .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.wine-row .name { font-weight: 500; }
.wine-row .sub { color: var(--muted); font-size: 13px; }
.wine-row .px { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 24px 0; }
.empty button { margin-top: 12px; }

/* filter view */
.field { margin: 18px 0; }
.field label, .field .label { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; }
.field select {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px;
  background: var(--chip); border: 1px solid var(--line); font-size: 16px;
}
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--chip); color: var(--muted); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--burgundy-soft); color: var(--text); border-color: var(--burgundy-light); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.text-btn { background: none; border: 0; color: var(--accent); font-weight: 500; padding: 8px 0; }

/* hint + fallback */
.hint {
  position: fixed; z-index: 15; left: 50%; bottom: calc(var(--safe-bottom) + 96px);
  transform: translateX(-50%);
  padding: 10px 16px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; color: var(--muted); white-space: nowrap;
  transition: opacity .6s;
}
.hint.gone { opacity: 0; }
.hint-mouse { display: none; }
@media (hover: hover) and (pointer: fine) { .hint-touch { display: none; } .hint-mouse { display: inline; } }
.fallback { position: fixed; top: calc(var(--safe-top) + 140px); left: var(--gutter); right: var(--gutter); color: var(--muted); text-align: center; }

/* map popup label on hover (desktop) */
.maplibregl-popup.hover-tip .maplibregl-popup-content {
  background: var(--panel-solid); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.maplibregl-popup.hover-tip .maplibregl-popup-tip { display: none; }

@media (max-width: 520px) {
  .brand-mark { font-size: 24px; }
  .brand-sub { letter-spacing: .2em; }
  .pill-btn span:not(.badge) { display: none; }
  .pill-btn { width: 44px; padding: 0; justify-content: center; position: relative; }
  .pill-btn .badge { position: absolute; top: -4px; right: -4px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .chip, .hint { transition: none; }
}
