/* ===== DESIGN TOKENS ===== */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);
  --text-3xl:  clamp(2.5rem,   1rem    + 4vw,    5rem);

  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  --font-display: 'Clash Display', 'Helvetica Neue', sans-serif;
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* DARK MODE (default) */
:root, [data-theme="dark"] {
  --color-bg:             #0f1114;
  --color-surface:        #161a1e;
  --color-surface-2:      #1c2128;
  --color-surface-offset: #1a1e24;
  --color-divider:        #262d36;
  --color-border:         #2e3640;
  --color-text:           #e2e4e8;
  --color-text-muted:     #8b919a;
  --color-text-faint:     #555c66;
  --color-text-inverse:   #0f1114;

  --color-primary:        #e85d3a;
  --color-primary-hover:  #d44a28;
  --color-primary-active: #b83e22;
  --color-primary-light:  rgba(232, 93, 58, 0.12);

  --color-scotland:       #4f98a3;
  --color-wales:          #d4614a;
  --color-england:        #7aa856;

  --color-thrilling:      #e85d3a;
  --color-challenging:    #d4a04a;
  --color-scenic:         #4f98a3;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.5);
}

/* LIGHT MODE */
[data-theme="light"] {
  --color-bg:             #f5f5f0;
  --color-surface:        #ffffff;
  --color-surface-2:      #fafaf8;
  --color-surface-offset: #eeece8;
  --color-divider:        #ddd9d4;
  --color-border:         #ccc8c2;
  --color-text:           #1a1a1a;
  --color-text-muted:     #6b6b6b;
  --color-text-faint:     #a0a0a0;
  --color-text-inverse:   #ffffff;

  --color-primary:        #c94a2a;
  --color-primary-hover:  #a83d22;
  --color-primary-active: #8e321b;
  --color-primary-light:  rgba(201, 74, 42, 0.08);

  --color-scotland:       #1a7a85;
  --color-wales:          #b84a35;
  --color-england:        #5a8a3a;

  --color-thrilling:      #c94a2a;
  --color-challenging:    #b8891a;
  --color-scenic:         #1a7a85;

  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg:             #f5f5f0;
    --color-surface:        #ffffff;
    --color-surface-2:      #fafaf8;
    --color-surface-offset: #eeece8;
    --color-divider:        #ddd9d4;
    --color-border:         #ccc8c2;
    --color-text:           #1a1a1a;
    --color-text-muted:     #6b6b6b;
    --color-text-faint:     #a0a0a0;
    --color-text-inverse:   #ffffff;
    --color-primary:        #c94a2a;
    --color-primary-hover:  #a83d22;
    --color-primary-active: #8e321b;
    --color-primary-light:  rgba(201, 74, 42, 0.08);
    --color-scotland:       #1a7a85;
    --color-wales:          #b84a35;
    --color-england:        #5a8a3a;
    --color-thrilling:      #c94a2a;
    --color-challenging:    #b8891a;
    --color-scenic:         #1a7a85;
    --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
    --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
    --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
  }
}

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: oklch(from var(--color-bg) l c h / 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-divider);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-icon { color: var(--color-primary); flex-shrink: 0; }

.logo-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  display: block;
  line-height: 1.2;
}

.logo-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: block;
  line-height: 1.2;
}

.header-nav {
  display: flex;
  gap: var(--space-1);
}

.nav-btn {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}

.nav-btn:hover { color: var(--color-text); }

.nav-btn.active {
  color: var(--color-text);
  background: var(--color-surface-2);
  border-color: var(--color-border);
}

.nav-btn[data-filter="scotland"].active { color: var(--color-scotland); }
.nav-btn[data-filter="wales"].active { color: var(--color-wales); }
.nav-btn[data-filter="england"].active { color: var(--color-england); }

.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}

.theme-toggle:hover { color: var(--color-text); background: var(--color-surface-2); }

/* ===== HERO ===== */
.hero {
  position: relative;
  min-height: 50vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-16) var(--space-6) var(--space-12);
  background:
    radial-gradient(ellipse at 30% 20%, var(--color-primary-light), transparent 60%),
    radial-gradient(ellipse at 70% 80%, oklch(from var(--color-scotland) l c h / 0.06), transparent 50%),
    var(--color-bg);
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 60px,
    var(--color-divider) 60px,
    var(--color-divider) 61px
  );
  opacity: 0.15;
  pointer-events: none;
}

.hero-content { position: relative; z-index: 1; }

.hero-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
}

.hero-accent {
  color: var(--color-primary);
}

.hero-desc {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  max-width: 540px;
  margin: 0 auto var(--space-8);
  line-height: 1.6;
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: var(--radius-full);
  letter-spacing: 0.01em;
}

.hero-cta:hover { background: var(--color-primary-hover); }
.hero-cta:active { background: var(--color-primary-active); transform: scale(0.98); }

.hero-stats {
  position: relative;
  z-index: 1;
  display: flex;
  gap: var(--space-10);
  margin-top: var(--space-10);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-divider);
}

.stat { text-align: center; }

.stat-num {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  display: block;
  line-height: 1;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: var(--space-1);
  display: block;
}

/* ===== MAP SECTION ===== */
.map-section {
  padding: 0 var(--space-6) var(--space-12);
  max-width: 1400px;
  margin: 0 auto;
}

.map-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  flex: 0 1 280px;
}

.search-box i { color: var(--color-text-faint); flex-shrink: 0; }

.search-box input {
  background: none;
  border: none;
  outline: none;
  width: 100%;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.search-box input::placeholder { color: var(--color-text-faint); }

.difficulty-filters {
  display: flex;
  gap: var(--space-1);
}

.diff-btn {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}

.diff-btn:hover { color: var(--color-text); }

.diff-btn.active {
  background: var(--color-surface-2);
  border-color: var(--color-border);
  color: var(--color-text);
}

.diff-btn[data-difficulty="thrilling"].active { color: var(--color-thrilling); }
.diff-btn[data-difficulty="challenging"].active { color: var(--color-challenging); }
.diff-btn[data-difficulty="scenic"].active { color: var(--color-scenic); }

.map-wrapper {
  position: relative;
  display: flex;
  gap: 0;
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
}

#map {
  flex: 1;
  height: 600px;
  z-index: 1;
}

/* ===== ROAD PANEL ===== */
.road-panel {
  width: 360px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  z-index: 2;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.road-panel.collapsed {
  width: 0;
  overflow: hidden;
  border-left: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.panel-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
}

.panel-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}

.panel-close:hover { background: var(--color-surface-2); color: var(--color-text); }

.panel-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

.panel-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
}

.panel-road-name {
  font-size: var(--text-xs);
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.panel-region {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

.panel-desc {
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.65;
  margin-bottom: var(--space-5);
}

.panel-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.meta-item {
  background: var(--color-surface-offset);
  padding: var(--space-3);
  border-radius: var(--radius-md);
}

.meta-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: var(--space-1);
}

.meta-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
}

.panel-highlights {
  margin-bottom: var(--space-5);
}

.panel-highlights h3 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  font-weight: 600;
}

.highlight-list {
  list-style: none;
  padding: 0;
}

.highlight-list li {
  font-size: var(--text-sm);
  color: var(--color-text);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.highlight-list li:last-child { border-bottom: none; }

.highlight-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  margin-top: 7px;
  flex-shrink: 0;
}

.diff-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.diff-badge.thrilling {
  background: oklch(from var(--color-thrilling) l c h / 0.15);
  color: var(--color-thrilling);
}

.diff-badge.challenging {
  background: oklch(from var(--color-challenging) l c h / 0.15);
  color: var(--color-challenging);
}

.diff-badge.scenic {
  background: oklch(from var(--color-scenic) l c h / 0.15);
  color: var(--color-scenic);
}

/* ===== ROAD LIST GRID ===== */
.road-list-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-12) var(--space-6) var(--space-16);
}

.section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-8);
  text-align: center;
}

.road-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-4);
}

.road-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: transform var(--transition-interactive),
              box-shadow var(--transition-interactive),
              border-color var(--transition-interactive);
}

.road-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.road-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.road-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  line-height: 1.3;
}

.road-card-region {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.road-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.road-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.road-card-stat {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ===== FOOTER ===== */
.site-footer {
  text-align: center;
  padding: var(--space-8) var(--space-6);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.site-footer p {
  max-width: 100%;
  margin: 0 auto var(--space-3);
}

.footer-attr {
  color: var(--color-text-faint);
  text-decoration: none;
}

.footer-attr:hover { color: var(--color-text-muted); text-decoration: underline; }

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container {
  background: var(--color-bg) !important;
  font-family: var(--font-body) !important;
}

.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.custom-marker:hover { transform: scale(1.2); }

.custom-marker.scotland { background: var(--color-scotland); }
.custom-marker.wales { background: var(--color-wales); }
.custom-marker.england { background: var(--color-england); }

.leaflet-popup-content-wrapper {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--color-border) !important;
}

.leaflet-popup-content {
  margin: var(--space-3) var(--space-4) !important;
  font-family: var(--font-body) !important;
  font-size: var(--text-sm) !important;
  line-height: 1.5 !important;
}

.leaflet-popup-tip {
  background: var(--color-surface) !important;
  box-shadow: none !important;
}

.popup-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  margin-bottom: var(--space-1);
}

.popup-region {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.popup-link {
  font-size: var(--text-xs);
  color: var(--color-primary);
  font-weight: 500;
  cursor: pointer;
  display: inline-block;
  margin-top: var(--space-1);
}

.popup-link:hover { text-decoration: underline; }

/* Zoom controls */
.leaflet-control-zoom a {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--color-surface-2) !important;
}

.leaflet-control-attribution {
  background: oklch(from var(--color-bg) l c h / 0.8) !important;
  color: var(--color-text-faint) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--color-text-muted) !important;
}

/* ===== MOBILE ===== */
@media (max-width: 900px) {
  .header-nav { display: none; }
  
  .hero { min-height: 40vh; padding: var(--space-12) var(--space-4) var(--space-8); }
  .hero-title { font-size: var(--text-2xl); }
  .hero-stats { gap: var(--space-6); }

  .map-section { padding: 0 var(--space-3) var(--space-8); }
  
  .map-wrapper { flex-direction: column; }
  
  #map { height: 450px; min-height: 450px; }

  .road-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-divider);
    max-height: 300px;
  }

  .road-panel.collapsed {
    max-height: 0;
    height: 0;
  }

  .map-controls { flex-direction: column; align-items: stretch; }
  .search-box { flex: 1; }

  .road-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .hero-stats { flex-direction: row; gap: var(--space-4); }
  .difficulty-filters { overflow-x: auto; }
}
