:root {
  --bg: #fafaf9;
  --text: #1c1917;
  --text-muted: #57534e;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --border: #e7e5e4;
  --card-bg: #f5f5f4;
  --card-hover: #ece9e7;
  --max-width: 56rem;
  --modal-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #1c1917;
  --text: #fafaf9;
  --text-muted: #a8a29e;
  --accent: #ea580c;
  --accent-hover: #f97316;
  --border: #44403c;
  --card-bg: #292524;
  --card-hover: #3a3533;
  --modal-bg: #292524;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* Top bar */
.top-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.2s;
}
.back-link:hover { color: var(--accent); }

.top-actions { display: flex; gap: 0.5rem; }

.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
}
.toggle-btn:hover { color: var(--accent); border-color: var(--accent); }
.toggle-btn.active { color: var(--accent); border-color: var(--accent); background: var(--card-bg); }

/* Header */
header {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
  text-align: center;
}

header h1 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.tagline { font-size: 1.0625rem; color: var(--text-muted); font-weight: 500; }
.tagline-sub { font-size: 0.9375rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.tagline-sub a { color: var(--accent); text-decoration: none; }
.tagline-sub a:hover { text-decoration: underline; }

.header-divider {
  width: 100%; height: 2px; background: var(--accent);
  border: none; margin-top: 0.75rem;
}

/* Stats */
.stats-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.stat { text-align: center; }
.stat-num { font-size: 1.5rem; font-weight: 700; color: var(--accent); display: block; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* Search */
.search-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem 1rem;
}
.search-bar input {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text-muted); }

/* View containers */
.view-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Map */
#map {
  width: 100%;
  height: 500px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

/* List — Continent */
.continent-group {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.continent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: var(--card-bg);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}
.continent-header:hover { background: var(--card-hover); }

.continent-name {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.25rem;
  color: var(--text);
}

.continent-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.15rem 0.6rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.continent-chevron {
  color: var(--accent);
  font-size: 1.25rem;
  transition: transform 0.3s;
}
.continent-group.open .continent-chevron { transform: rotate(90deg); }

.continent-body {
  display: none;
  padding: 0.5rem 0;
}
.continent-group.open .continent-body { display: block; }

/* Country */
.country-group {
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}

.country-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  border-radius: 8px;
  background: var(--card-bg);
  border-left: 3px solid var(--accent);
  transition: background 0.2s;
}
.country-header:hover { background: var(--card-hover); }

.country-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.country-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.country-body {
  display: none;
  padding: 0.25rem 0 0.5rem 0.75rem;
  margin-left: 3px;
  border-left: 1px solid var(--border);
}
.country-group.open .country-body { display: block; }

/* State group (USA) */
.state-group {
  padding: 0.25rem 0 0.25rem 0;
  margin-bottom: 0.35rem;
  margin-left: 0.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--accent);
}
.state-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
  padding: 0.35rem 0 0.15rem;
}

/* Post card */
.post-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 0.35rem;
  text-decoration: none;
  color: inherit;
  border-left: 2px solid transparent;
}
.post-card:hover {
  background: var(--card-bg);
  border-left-color: var(--accent);
}

.post-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.6;
}
.post-card:hover .post-dot { opacity: 1; }

.post-info { flex: 1; min-width: 0; }

.post-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.post-type-badge {
  font-size: 0.6875rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  overflow-y: auto;
  padding: 2rem 1rem;
  backdrop-filter: blur(4px);
}

.modal-content {
  max-width: 48rem;
  margin: 0 auto;
  background: var(--modal-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  overflow: hidden;
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 2px solid var(--accent);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem; right: 1.25rem;
  background: none;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-close:hover { color: var(--accent); }

.modal-breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-header h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 400;
  color: var(--text);
}

.modal-date {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.modal-body {
  padding: 1.5rem 2rem 2.5rem;
  line-height: 1.8;
  color: var(--text);
}

.modal-body h2 {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 2rem 0 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.modal-body h2:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.modal-body p { margin-bottom: 1rem; }
.modal-body ul, .modal-body ol { margin-bottom: 1rem; padding-left: 1.25rem; }
.modal-body li { margin-bottom: 0.4rem; }
.modal-body strong { font-weight: 600; }

/* Footer */
footer {
  max-width: var(--max-width);
  margin: 3rem auto 0;
  padding: 1.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 640px) {
  header h1 { font-size: 1.875rem; }
  .stats-bar { gap: 1rem; }
  .modal-header { padding: 1.25rem 1.25rem 0.75rem; }
  .modal-body { padding: 1.25rem 1.25rem 2rem; }
  .modal-header h2 { font-size: 1.375rem; }
  #map { height: 350px; }
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
}
.leaflet-popup-content {
  margin: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  max-height: 220px;
  overflow-y: auto;
}
.popup-title {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.25rem;
}
.popup-meta { color: #57534e; font-size: 0.8125rem; }
.popup-link {
  display: inline-block;
  margin-top: 0.35rem;
  color: #c2410c;
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  text-decoration: none;
}
.popup-link:hover { text-decoration: underline; }

/* ─── TIMELINE VIEW ─── */
.timeline-trip {
  max-width: var(--max-width);
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
}
.timeline-trip-header {
  margin-bottom: 1rem;
}
.timeline-trip-header h3 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.375rem;
  font-weight: 400;
  color: var(--text);
  margin: 0 0 0.25rem;
}
.timeline-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.timeline-route {
  padding-left: 1rem;
}
.timeline-stop {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}
.timeline-stop:hover {
  background: var(--card-bg);
}
.timeline-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--accent);
}
.timeline-stop-info { display: flex; flex-direction: column; }
.timeline-stop-title { font-weight: 500; font-size: 0.9375rem; }
.timeline-stop-date { font-size: 0.75rem; color: var(--text-muted); }
.timeline-connector {
  width: 2px;
  height: 20px;
  background: var(--accent);
  margin-left: calc(0.75rem + 5px);
  opacity: 0.4;
}

/* ─── BADGES ─── */
.wine-badge {
  font-size: 0.8125rem;
  margin-left: 0.25rem;
  vertical-align: middle;
}
.rating-badge {
  font-size: 0.6875rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  margin-left: 0.35rem;
  vertical-align: middle;
}

/* ─── VIEW BUTTONS ─── */
.view-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--card-bg);
}

/* Country page link in list */
.country-page-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}
.country-page-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Ensure link buttons look identical to button buttons */
a.toggle-btn {
  text-decoration: none;
  display: inline-block;
  line-height: 1;
}
a.toggle-btn:hover {
  text-decoration: none;
}
