*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #3d2c1e;
  background: #f5efe6;
}

#map {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 360px;
  z-index: 0;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 360px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #faf6f0;
  border-right: 1px solid #e0d4c4;
  z-index: 1000;
  overflow: hidden;
  --scrollbar-track: #ede4d6;
  --scrollbar-thumb: #c9b89a;
  --scrollbar-thumb-hover: #b45309;
}

.sidebar-header {
  padding: 1.75rem 2rem 1.35rem;
  border-bottom: 1px solid #e8dfd3;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #5c3d1e;
}

.search-box {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #e8dfd3;
}

.search-box input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid #d4c4b0;
  border-radius: 6px;
  background: #fff;
  font-size: 0.9rem;
}

.search-box input:focus {
  outline: 2px solid #d4a056;
  border-color: #d4a056;
}

.sidebar-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.detail-hero {
  flex-shrink: 0;
  background: #fff8ee;
  box-shadow: 0 4px 14px rgba(60, 40, 20, 0.14);
  position: relative;
  z-index: 1;
}

.detail-hero.hidden {
  display: none;
}

.detail-hero-media {
  height: 10.5rem;
  overflow: hidden;
}

.detail-hero-media.hidden {
  display: none;
}

.detail-hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-hero-body {
  padding: 1.25rem 2rem 1.5rem;
}

.detail-hero-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #5c3d1e;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

.detail-hero-close:hover {
  background: #fff;
}

.detail-hero-back {
  display: none;
}

.detail-hero-name {
  margin: 0 0 0.35rem;
  padding-right: 1.75rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #5c3d1e;
  line-height: 1.25;
}

.detail-region {
  margin: 0 0 0.55rem;
  font-size: 0.8rem;
  color: #8a7358;
}

.detail-region.hidden {
  display: none;
}

.detail-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.detail-meta-chips.hidden {
  display: none;
}

.detail-chip {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #f0e8dc;
  color: #8a7358;
}

.detail-hero-summary {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #4a3a2a;
  white-space: pre-wrap;
}

.detail-hero-wiki {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #b45309;
  text-decoration: none;
}

.detail-hero-wiki:hover {
  text-decoration: underline;
}

.detail-hero-wiki.hidden {
  display: none;
}

.detail-similar-wrap {
  margin-top: 0.85rem;
}

.detail-similar-wrap.hidden {
  display: none;
}

.detail-similar-label {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #a68b6a;
}

.similar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.similar-list li {
  padding: 0.45rem 0;
  font-size: 0.86rem;
  border-bottom: 1px solid #f0e6d8;
  cursor: pointer;
}

.similar-list li:hover {
  color: #b45309;
}

.sidebar-main.has-detail .detail-hero {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-main.has-detail .cheese-list-section {
  flex: 1 1 0;
  margin-top: 0;
  padding-top: 0;
  border-top: 3px solid #d4c4b0;
  background: #f5efe6;
  box-shadow: inset 0 3px 8px rgba(60, 40, 20, 0.07);
}

.sidebar-main.has-detail .detail-hero-body {
  padding-bottom: 0.85rem;
}

.sidebar-main.has-detail .cheese-list-label {
  padding-top: 0.35rem;
}

.cheese-list-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 0.75rem;
}

.cheese-list-label {
  margin: 0;
  padding: 0.5rem 2rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8a7358;
  flex-shrink: 0;
}

.cheese-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 1rem;
}

.cheese-list,
.sidebar-main.has-detail .detail-hero {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.cheese-list::-webkit-scrollbar,
.sidebar-main.has-detail .detail-hero::-webkit-scrollbar {
  width: 8px;
}

.cheese-list::-webkit-scrollbar-track,
.sidebar-main.has-detail .detail-hero::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.cheese-list::-webkit-scrollbar-thumb,
.sidebar-main.has-detail .detail-hero::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
  border: 2px solid var(--scrollbar-track);
}

.cheese-list::-webkit-scrollbar-thumb:hover,
.sidebar-main.has-detail .detail-hero::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.cheese-group {
  margin-bottom: 0.75rem;
}

.cheese-group-letter {
  padding: 0.5rem 2rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #a68b6a;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #f0e8dc;
  position: sticky;
  top: 0;
}

.cheese-item {
  display: block;
  width: 100%;
  padding: 0.75rem 2rem;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.9rem;
  color: #3d2c1e;
  cursor: pointer;
}

.cheese-item:hover,
.cheese-item.active {
  background: #fff3e0;
  color: #b45309;
}

.cheese-item.dimmed {
  opacity: 0.35;
}

.cheese-item .region-tag {
  display: block;
  font-size: 0.72rem;
  color: #a68b6a;
}

.sidebar-footer {
  padding: 1.25rem 2rem;
  border-top: 1px solid #e8dfd3;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-footer a {
  color: #8a7358;
}

.build-notice {
  padding: 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

.build-notice pre {
  background: #f0e8dc;
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  overflow-x: auto;
}

.legend-panel {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1000;
  background: rgba(250, 246, 240, 0.95);
  border: 1px solid #e0d4c4;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  font-size: 0.78rem;
  color: #5c3d1e;
  box-shadow: 0 2px 8px rgba(60, 40, 20, 0.1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  max-width: 280px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.2rem;
  vertical-align: middle;
}

.legend-dot.regional {
  background: #d97706;
}

.legend-dot.general {
  background: #78716c;
}

.loading {
  position: fixed;
  top: 1rem;
  left: 50%;
  margin-left: 180px;
  transform: translateX(-50%);
  z-index: 2000;
  background: rgba(250, 246, 240, 0.95);
  border: 1px solid #e0d4c4;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(60, 40, 20, 0.12);
}

.loading.hidden {
  display: none;
}

.cheese-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, opacity 0.2s;
}

.cheese-marker.regional {
  background: #d97706;
}

.cheese-marker.general {
  background: #78716c;
}

.cheese-marker.selected {
  transform: scale(1.4);
  border-color: #fcd34d;
  z-index: 1000 !important;
}

.cheese-marker.dimmed {
  opacity: 0.75;
}

.cheese-marker.highlighted {
  transform: scale(1.2);
  border-color: #fbbf24;
}

/* Map popups (Leaflet permanent tooltips) */
.leaflet-tooltip.cheese-map-popup-wrap {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.leaflet-tooltip.cheese-map-popup-wrap::before {
  display: none;
}

.cheese-map-popup {
  min-width: 9rem;
  max-width: 13.5rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #e0d4c4;
  background: #fff8ee;
  box-shadow: 0 4px 16px rgba(60, 40, 20, 0.18);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #3d2c1e;
  pointer-events: auto;
  position: relative;
}

.cheese-map-popup::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
}

.cheese-map-popup-main {
  border-color: #d97706;
  border-left-width: 3px;
  background: #fff3e0;
  box-shadow: 0 6px 20px rgba(180, 83, 9, 0.25);
}

.cheese-map-popup-main h3 {
  color: #b45309;
}

.cheese-map-popup-similar {
  border-color: #d4c4b0;
  background: #faf6f0;
  opacity: 0.97;
  cursor: pointer;
}

.cheese-map-popup-similar:hover {
  border-color: #d4a056;
  box-shadow: 0 4px 14px rgba(60, 40, 20, 0.16);
}

.cheese-map-popup h3 {
  margin: 0 0 0.2rem;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.25;
  color: #5c3d1e;
}

.cheese-map-popup-region {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  color: #8a7358;
}

.cheese-map-popup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.15rem;
}

.cheese-map-popup-chip {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #f0e8dc;
  color: #8a7358;
}

.cheese-map-popup-score {
  margin: 0.35rem 0 0;
  font-size: 0.68rem;
  font-weight: 600;
}

.leaflet-tooltip-top.is-main .cheese-map-popup::after {
  left: var(--arrow-x, 50%);
  bottom: -6px;
  margin-left: -5px;
  background: #fff3e0;
  border-right: 1px solid #d97706;
  border-bottom: 1px solid #d97706;
}

.leaflet-tooltip-bottom.is-main .cheese-map-popup::after {
  left: var(--arrow-x, 50%);
  top: -6px;
  margin-left: -5px;
  background: #fff3e0;
  border-left: 1px solid #d97706;
  border-top: 1px solid #d97706;
}

.leaflet-tooltip-right.is-main .cheese-map-popup::after {
  left: -6px;
  top: var(--arrow-y, 50%);
  margin-top: -5px;
  background: #fff3e0;
  border-left: 1px solid #d97706;
  border-bottom: 1px solid #d97706;
}

.leaflet-tooltip-left.is-main .cheese-map-popup::after {
  right: -6px;
  top: var(--arrow-y, 50%);
  margin-top: -5px;
  background: #fff3e0;
  border-right: 1px solid #d97706;
  border-top: 1px solid #d97706;
}

.leaflet-tooltip-top.is-similar .cheese-map-popup::after {
  width: 8px;
  height: 8px;
  left: var(--arrow-x, 50%);
  bottom: -5px;
  margin-left: -4px;
  background: #faf6f0;
  border-right: 1px solid #d4c4b0;
  border-bottom: 1px solid #d4c4b0;
}

.leaflet-tooltip-bottom.is-similar .cheese-map-popup::after {
  width: 8px;
  height: 8px;
  left: var(--arrow-x, 50%);
  top: -5px;
  margin-left: -4px;
  background: #faf6f0;
  border-left: 1px solid #d4c4b0;
  border-top: 1px solid #d4c4b0;
}

.leaflet-tooltip-right.is-similar .cheese-map-popup::after {
  width: 8px;
  height: 8px;
  left: -5px;
  top: var(--arrow-y, 50%);
  margin-top: -4px;
  background: #faf6f0;
  border-left: 1px solid #d4c4b0;
  border-bottom: 1px solid #d4c4b0;
}

.leaflet-tooltip-left.is-similar .cheese-map-popup::after {
  width: 8px;
  height: 8px;
  right: -5px;
  top: var(--arrow-y, 50%);
  margin-top: -4px;
  background: #faf6f0;
  border-right: 1px solid #d4c4b0;
  border-top: 1px solid #d4c4b0;
}

@media (max-width: 768px) {
  :root {
    --mobile-sheet-height: min(52dvh, 420px);
  }

  body.is-mobile-map #map {
    left: 0;
    right: 0;
    top: 0;
    bottom: var(--mobile-sheet-height);
  }

  body.is-mobile-map .sidebar {
    width: 100%;
    height: var(--mobile-sheet-height);
    max-height: var(--mobile-sheet-height);
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-right: none;
    border-top: 1px solid #e0d4c4;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(60, 40, 20, 0.12);
  }

  body.is-mobile-map .sidebar::before {
    content: "";
    display: block;
    width: 2.5rem;
    height: 0.25rem;
    margin: 0.5rem auto 0;
    border-radius: 999px;
    background: #d4c4b0;
    flex-shrink: 0;
  }

  body.is-mobile-map .sidebar-header {
    padding: 0.35rem 1.25rem 0.5rem;
    border-bottom: none;
  }

  body.is-mobile-map .sidebar-header h1 {
    font-size: 1rem;
  }

  body.is-mobile-map .search-box {
    padding: 0 1.25rem 0.65rem;
    border-bottom: none;
  }

  body.is-mobile-map .search-box input {
    padding: 0.55rem 0.75rem;
    font-size: 16px;
  }

  body.is-mobile-map .sidebar-main {
    flex: 1;
    min-height: 0;
  }

  body.is-mobile-map .sidebar-footer {
    display: none;
  }

  /* Browse mode: list fills the sheet */
  body.is-mobile-map .cheese-list-section {
    padding-top: 0;
  }

  body.is-mobile-map .cheese-list-label {
    padding: 0.15rem 1.25rem 0.45rem;
    font-size: 0.68rem;
  }

  body.is-mobile-map .cheese-group-letter {
    padding: 0.35rem 1.25rem;
  }

  body.is-mobile-map .cheese-item {
    padding: 0.6rem 1.25rem;
    font-size: 0.88rem;
  }

  /* Detail mode: hide list, use full sheet for detail */
  body.is-mobile-map .sidebar-main.has-detail .cheese-list-section {
    display: none;
  }

  body.is-mobile-map .sidebar-main.has-detail .detail-hero {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: none;
    background: transparent;
  }

  body.is-mobile-map .sidebar:has(.sidebar-main.has-detail) .sidebar-header,
  body.is-mobile-map .sidebar:has(.sidebar-main.has-detail) .search-box,
  body.is-mobile-map .sidebar:has(.sidebar-main.has-detail)::before {
    display: none;
  }

  body.is-mobile-map .detail-hero-media {
    height: 7rem;
    flex-shrink: 0;
  }

  body.is-mobile-map .detail-hero-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 1.25rem 1rem;
  }

  body.is-mobile-map .detail-hero-name {
    font-size: 1rem;
    padding-right: 0;
  }

  body.is-mobile-map .detail-hero-summary {
    font-size: 0.82rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  body.is-mobile-map .sidebar-main.has-detail .detail-hero-summary {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
  }

  body.is-mobile-map .detail-hero-close {
    display: none;
  }

  body.is-mobile-map .detail-hero-back {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    margin: 0 0 0.5rem;
    padding: 0.45rem 0;
    border: none;
    background: transparent;
    font-size: 0.82rem;
    font-weight: 600;
    color: #b45309;
    cursor: pointer;
    flex-shrink: 0;
  }

  body.is-mobile-map .detail-hero-back::before {
    content: "←";
  }

  /* Map chrome */
  body.is-mobile-map .legend-panel {
    top: 0.5rem;
    bottom: auto;
    left: 0.5rem;
    right: auto;
    max-width: calc(100% - 3.5rem);
    padding: 0.45rem 0.65rem;
    font-size: 0.7rem;
    gap: 0.35rem 0.5rem;
  }

  body.is-mobile-map .loading {
    top: 0.75rem;
    left: 50%;
    margin-left: 0;
    transform: translateX(-50%);
  }

  body.is-mobile-map .leaflet-control-zoom {
    margin-top: 3.25rem !important;
  }

  body.is-mobile-map .cheese-map-popup,
  body.is-mobile-map .cheese-map-popup-compact {
    min-width: 0;
    max-width: 6.75rem;
    padding: 0.35rem 0.45rem;
    border-radius: 7px;
    box-shadow: 0 2px 10px rgba(60, 40, 20, 0.16);
  }

  body.is-mobile-map .cheese-map-popup-main {
    max-width: 7.75rem;
    box-shadow: 0 3px 12px rgba(180, 83, 9, 0.2);
  }

  body.is-mobile-map .cheese-map-popup h3 {
    margin: 0;
    font-size: 0.68rem;
    line-height: 1.2;
  }

  body.is-mobile-map .cheese-map-popup-region {
    margin: 0.12rem 0 0;
    font-size: 0.58rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.is-mobile-map .cheese-map-popup-score {
    margin: 0.12rem 0 0;
    font-size: 0.56rem;
    line-height: 1.2;
  }

  body.is-mobile-map .cheese-map-popup::after {
    width: 7px;
    height: 7px;
  }
}
