:root {
  --bg: #ffffff;
  --fg: #111;
  --muted: #666;
  --card: #f6f6f6;
  --link: #0645ad;
  --accent: #2151d1;
  --radius: 14px;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
  --max: 900px;
  --cultural-accent: #7c3aed;
  --city-accent: #ea580c;
  --badge-bg: rgba(124, 58, 237, 0.1);
  --badge-city-bg: rgba(234, 88, 12, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #eaeaea;
    --muted: #9aa0a6;
    --card: #1a1d24;
    --link: #8ab4f8;
    --accent: #8ab4f8;
    --cultural-accent: #a78bfa;
    --city-accent: #fb923c;
    --badge-bg: rgba(167, 139, 250, 0.15);
    --badge-city-bg: rgba(251, 146, 60, 0.15);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial;
}

header, main, footer {
  max-width: var(--max);
  margin: auto;
  padding: 1rem;
}

.stamp {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0;
}

main {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.event-section {
  display: grid;
  gap: 1.5rem;
}

/* Responsive grid for event cards */
/* Tablet: 2 columns */
@media (min-width: 768px) {
  .event-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem 1.5rem; /* row gap, column gap */
  }

  /* Section header spans full width */
  .event-section .section-header {
    grid-column: 1 / -1;
  }
}

/* Desktop: 3 columns */
@media (min-width: 1200px) {
  .event-section {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem 1.5rem;
  }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  font-size: 1.5rem;
  border-bottom: 2px solid var(--muted);
  padding-bottom: 0.5rem;
}

.time-group .section-header {
  font-size: 1.3rem;
  border-bottom: 1px solid var(--muted);
}

.section-icon {
  font-size: 1.26rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.section-icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

.distance svg {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: text-bottom;
  margin-right: 0.2em;
}

.event-count {
  margin-left: auto;
  font-size: 0.9rem;
  font-weight: normal;
  color: var(--muted);
  background: var(--card);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
}

.cultural-section .section-header {
  color: var(--cultural-accent);
  border-color: var(--cultural-accent);
}

.city-section .section-header {
  color: var(--city-accent);
  border-color: var(--city-accent);
}

.event-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  position: relative;
}

.event-card.cultural {
  border-left: 4px solid var(--cultural-accent);
}

.event-card.city {
  border-left: 4px solid var(--city-accent);
}

.event-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.cultural-badge {
  background: var(--badge-bg);
  color: var(--cultural-accent);
}

.city-badge {
  background: var(--badge-city-bg);
  color: var(--city-accent);
}

.event-card h3 {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.25rem;
}

.no-events {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

.when, .where {
  margin: 0.4rem 0;
}

.description {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.5rem 0 0.25rem;
  line-height: 1.6;
}

a {
  color: var(--link);
}

a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

footer {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2rem;
  padding: 1.5rem 0 1rem;
  border-top: 1px solid var(--muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 0.75rem;
  text-align: center;
}

.footer-sep {
  opacity: 0.5;
}

.footer-date {
  margin-right: 0.25rem;
}

.footer-commit {
  font-family: monospace;
  font-size: 0.8rem;
  opacity: 0.7;
}

/* Mobile: smaller spacing */
@media (max-width: 600px) {
  footer {
    font-size: 0.8rem;
    gap: 0.4rem 0.6rem;
  }

  .footer-commit {
    font-size: 0.75rem;
  }
}

/* Toggle cultural events visibility */
#toggle-cultural:not(:checked) ~ main .event-card.cultural {
  display: none;
}

/* Toggle count display based on checkbox state */
/* When unchecked: show city-only count */
#toggle-cultural:not(:checked) ~ main .count-all {
  display: none;
}

/* When checked: show all count, hide city-only */
#toggle-cultural:checked ~ main .count-city-only {
  display: none;
}

/* Cultural filter section */
.cultural-filter {
  display: flex;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid var(--muted);
}

.toggle-label {
  display: inline-block;
  cursor: pointer;
  padding: 0.5rem 1rem;
  background: var(--bg);
  border: 2px solid var(--muted);
  border-radius: 8px;
  user-select: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.toggle-label:hover {
  border-color: var(--cultural-accent);
  background: var(--card);
}

/* When checkbox is checked, update label appearance */
#toggle-cultural:checked ~ header .filters-container .toggle-label {
  background: var(--cultural-accent);
  border-color: var(--cultural-accent);
  color: white;
  font-weight: 600;
}

/* Change checkbox symbol when checked */
.toggle-label::before {
  content: "☐ ";
}

#toggle-cultural:checked ~ header .filters-container .toggle-label::before {
  content: "☑ ";
}

#toggle-cultural {
  display: none;
}

/* Filters container - groups distance and cultural filters */
.filters-container {
  margin: 1rem 0;
  padding: 1.25rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Distance filter */
input[name="distance-filter"] {
  display: none;
}

.distance-filter {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.filter-title {
  display: block;
  font-weight: 600;
  color: var(--fg);
  font-size: 0.95rem;
}

.distance-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.distance-label {
  cursor: pointer;
  padding: 0.5rem 1rem;
  background: var(--bg);
  border: 2px solid var(--muted);
  border-radius: 8px;
  font-size: 0.9rem;
  user-select: none;
  transition: all 0.2s;
}

.distance-label:hover {
  border-color: var(--accent);
  background: var(--card);
}

/* Filter button counts - show/hide based on cultural toggle */
.distance-label .filter-count-city {
  display: inline; /* Show city counts by default (cultural hidden) */
}
.distance-label .filter-count-all {
  display: none; /* Hide all counts by default */
}

/* When cultural events are shown, switch to showing all counts */
#toggle-cultural:checked ~ header .filters-container .distance-label .filter-count-city {
  display: none;
}
#toggle-cultural:checked ~ header .filters-container .distance-label .filter-count-all {
  display: inline;
}

/* Active state for selected distance filter */
#distance-plaza:checked ~ header .filters-container .distance-filter label[for="distance-plaza"],
#distance-nearby:checked ~ header .filters-container .distance-filter label[for="distance-nearby"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* Distance filtering rules */
/* When "En Plaza" is selected: show only events at Plaza de España */
#distance-plaza:checked ~ main .event-card:not([data-at-plaza="true"]) {
  display: none;
}

/* When "Nearby" (default): show all events (no hiding needed) */

/* Dynamic event counts based on distance + cultural toggle */
/* Hide all count variants by default */
.event-count span {
  display: none;
}

/* Show nearby counts when "Nearby" (Cerca) filter is active */
#distance-nearby:checked ~ main .count-nearby-city {
  display: inline; /* Show by default (city-only) */
}
#distance-nearby:checked ~ main .count-nearby-all {
  display: none; /* Hidden by default */
}
/* When cultural events are shown, switch to showing all count */
#toggle-cultural:checked ~ #distance-nearby:checked ~ main .count-nearby-city {
  display: none;
}
#toggle-cultural:checked ~ #distance-nearby:checked ~ main .count-nearby-all {
  display: inline;
}

/* Show plaza counts when "En Plaza" filter is active */
#distance-plaza:checked ~ main .count-plaza-city {
  display: inline; /* Show by default (city-only) */
}
#distance-plaza:checked ~ main .count-plaza-all {
  display: none; /* Hidden by default */
}
/* When cultural events are shown, switch to showing all count */
#toggle-cultural:checked ~ #distance-plaza:checked ~ main .count-plaza-city {
  display: none;
}
#toggle-cultural:checked ~ #distance-plaza:checked ~ main .count-plaza-all {
  display: inline;
}

/* Section reordering: empty sections sink to bottom based on filter state
   Uses data attributes computed at build time (no JavaScript needed) */

/* Filter state 1: En Plaza + Cultural shown
   Sink sections with no plaza events (all types) */
#toggle-cultural:checked ~ #distance-plaza:checked ~ main .event-section[data-count-plaza="0"] {
  order: 999;
}

/* Filter state 2: En Plaza + Cultural hidden
   Sink sections with no city plaza events */
#toggle-cultural:not(:checked) ~ #distance-plaza:checked ~ main .event-section[data-count-plaza-city="0"] {
  order: 999;
}

/* Filter state 3: Cerca (nearby) + Cultural shown
   Sink sections with no nearby events (all types) */
#toggle-cultural:checked ~ #distance-nearby:checked ~ main .event-section[data-count-nearby="0"] {
  order: 999;
}

/* Filter state 4: Cerca (nearby) + Cultural hidden
   Sink sections with no city nearby events */
#toggle-cultural:not(:checked) ~ #distance-nearby:checked ~ main .event-section[data-count-nearby-city="0"] {
  order: 999;
}

/* ===================================================================
   WEATHER INFO - AEMET forecast display on event cards
   =================================================================== */

/* Weather info container */
.weather-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 8px;
}

@media (prefers-color-scheme: dark) {
  .weather-info {
    background: rgba(255, 255, 255, 0.03);
  }
}

/* Weather icon from AEMET */
.weather-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* Temperature display */
.weather-temp {
  font-weight: 600;
  color: var(--city-accent);
  font-size: 1rem;
}

/* Precipitation probability (only shown if >30%) */
.weather-precip {
  color: #3b82f6;
  font-size: 0.85rem;
}

@media (prefers-color-scheme: dark) {
  .weather-precip {
    color: #60a5fa;
  }
}
