/*
 * main.css — Trail Running Event Sites
 *
 * Design system: DESIGN.md (see repo root)
 * Typography: Prompt (headings) + Bai Jamjuree (body) — loaded from fonts.css
 *
 * Tokens live in theme-base.css + themes/{site}.css. This file must ONLY
 * reference var(--token); never hardcode a brand color or font family.
 * See DESIGN.md §6 for architecture.
 *
 * Sections:
 *  1. Reset
 *  2. Base
 *  3. Typography
 *  4. Header & Navigation
 *  5. Hero
 *  6. Buttons
 *  7. Section wrappers
 *  8. Distance cards (+ division chips)
 *  9. Prose
 * 10. FAQ accordion
 * 11. Sponsors
 * 12. Contact
 * 13. Footer
 * 14. Utilities & mobile overrides
 */


/* ─────────────────────────────────────────────────────────────
   1. Reset
   ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

img, video {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
}

ul, ol {
  list-style: none;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}


/* ─────────────────────────────────────────────────────────────
   2. Base
   ───────────────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--nav-height);
}

body {
  font-family: var(--font-body);
  font-weight: var(--weight-body);
  font-size: 1rem;       /* minimum 16px — Thai script harder to read smaller */
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}


/* ─────────────────────────────────────────────────────────────
   3. Typography
   ───────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  line-height: 1.2;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: var(--weight-heading);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.5rem;
  font-weight: var(--weight-subhead);
}

h3 {
  font-size: 1.125rem;
  font-weight: var(--weight-subhead);
}

/* Label / eyebrow caps — used across all components */
.label-caps {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  display: block;
}


/* ─────────────────────────────────────────────────────────────
   5. Header & Navigation
   ───────────────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  height: var(--nav-height);
  /* Transparent over hero — toggled by JS via .is-scrolled */
  background: transparent;
  color: #fff;
  transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.site-header.is-scrolled {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 1px 0 var(--color-border);
}

.nav-inner {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  max-width: var(--max-layout);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 100%;
}

.nav-logo {
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-left: auto;
}

.nav-links a {
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.15s;
  /* Minimum touch target */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-links a:hover {
  opacity: 1;
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

.lang-toggle a {
  text-decoration: none;
  opacity: 0.5;
  transition: opacity 0.15s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.lang-toggle a.active {
  opacity: 1;
  color: var(--color-accent);
}

.site-header.is-scrolled .lang-toggle a.active {
  color: var(--color-accent);
}

.lang-toggle a:hover {
  opacity: 0.8;
}

.lang-toggle .sep {
  opacity: 0.3;
  user-select: none;
}


/* ─────────────────────────────────────────────────────────────
   6. Hero
   ───────────────────────────────────────────────────────────── */
.hero {
  position: relative;
  width: 100%;
  min-height: 70vh;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  background: var(--color-accent); /* solid fallback if no image uploaded */
}

/* No hero image — show accent color background, text content centered */
.hero--no-image {
  min-height: 50vh;
  align-items: center;
}

.hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  /* Ensure image never overlaps nav on scroll */
  top: 0;
}

.hero-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--max-layout);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  padding-top: calc(var(--nav-height) + var(--space-xl));
}

/* Gradient overlay — improves text legibility on any photo */
.hero:not(.hero--no-image) .hero-content::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.65) 0%,
    rgba(0, 0, 0, 0.25) 50%,
    rgba(0, 0, 0, 0) 100%
  );
  z-index: -1;
  /* Extend gradient further up to cover full hero */
  top: -100vh;
}

.hero-title {
  color: #fff;
  margin-bottom: var(--space-sm);
}

.hero-date {
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: var(--space-lg);
  font-size: 0.875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
}

.cta-note {
  color: rgba(255, 255, 255, 0.75);
}

.race-day-contact {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
}


/* ─────────────────────────────────────────────────────────────
   7. Buttons
   ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  min-height: 44px;           /* accessibility touch target */
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: var(--weight-bold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
  transition: opacity 0.15s, transform 0.1s, background 0.15s;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

/* Focus ring — don't remove, required for keyboard nav */
.btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.btn-secondary {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.6);
}

.btn-secondary:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

/* Ghost — non-interactive states (registration not yet open, closed) */
.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.65);
  border-color: rgba(255, 255, 255, 0.25);
  cursor: default;
}

.btn-ghost:hover {
  opacity: 1;
  transform: none;
}

.btn-outline {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.btn-outline:hover {
  background: var(--color-accent);
  color: #fff;
  opacity: 1;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
  min-height: 36px;
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.125rem;
  min-height: 56px;
}


/* ─────────────────────────────────────────────────────────────
   8. Section wrappers
   ───────────────────────────────────────────────────────────── */
.section-inner {
  max-width: var(--max-layout);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

.section-inner--prose {
  max-width: var(--max-prose);
}

.section-heading {
  margin-bottom: var(--space-lg);
}

.section-heading--minor {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-lg);
}

/* Alternating section backgrounds */
.section-distances  { background: var(--color-bg); }
.section-prose      { background: var(--color-surface); }
.section-faq        { background: var(--color-bg); }
.section-sponsors   { background: var(--color-surface); }
.section-contact    { background: var(--color-bg); }


/* ─────────────────────────────────────────────────────────────
   9. Distance cards
   ───────────────────────────────────────────────────────────── */
.distances-grid {
  display: grid;
  grid-template-columns: 1fr;      /* 1 col mobile */
  gap: var(--space-lg);
}

@media (min-width: 640px) {
  .distances-grid {
    grid-template-columns: repeat(2, 1fr);   /* 2 col tablet */
  }
}

@media (min-width: 1024px) {
  .distances-grid {
    grid-template-columns: repeat(3, 1fr);   /* 3 col desktop */
  }
}

/* Fewer than 3 distances: don't stretch cards to full grid width */
.distances-grid:has(> :only-child) {
  max-width: 400px;
}
.distances-grid:has(> :nth-child(2):last-child) {
  max-width: 800px;
}

.distance-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

.distance-card-header {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  position: relative;
}

/* Big display number — "21K", "50K" */
.distance-number {
  font-family: var(--font-heading);
  font-size: 3.5rem;
  font-weight: var(--weight-heading);
  line-height: 1;
  letter-spacing: -0.02em;
}

.distance-name {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: var(--weight-subhead);
  opacity: 0.85;
}

/* ─── Division color chip ──────────────────────────────────────
   Small marker derived from the brand guide's division color system
   (D1 Green → D7 Black). Used ONLY here — a 10px square in the card
   header corner. See DESIGN.md §4.6 for rules of use. */
.distance-division {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 10px;
  height: 10px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}
.distance-division--d1 { background: var(--color-d1); }
.distance-division--d2 { background: var(--color-d2); }
.distance-division--d3 { background: var(--color-d3); }
.distance-division--d4 { background: var(--color-d4); }
.distance-division--d5 { background: var(--color-d5); }
.distance-division--d6 { background: var(--color-d6); }
.distance-division--d7 { background: var(--color-d7); }

.distance-stats {
  padding: var(--space-md) var(--space-lg);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.distance-stats dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.distance-stats dd {
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0;
}

.distance-aid,
.distance-notes {
  padding: var(--space-sm) var(--space-lg);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.distance-actions {
  margin-top: auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.elevation-profile {
  padding: 0 var(--space-lg) var(--space-md);
}

.elevation-profile img {
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}


/* ─────────────────────────────────────────────────────────────
   10. Prose (Rules & Regulations rich text)
   ───────────────────────────────────────────────────────────── */
.prose h2 {
  margin: var(--space-lg) 0 var(--space-md);
}

.prose h3 {
  margin: var(--space-md) 0 var(--space-sm);
}

.prose p {
  margin-bottom: var(--space-md);
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose ul,
.prose ol {
  margin: 0 0 var(--space-md) var(--space-lg);
}

.prose li {
  margin-bottom: var(--space-xs);
}

.prose a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.prose a:hover {
  opacity: 0.8;
}

.prose strong {
  font-weight: 700;
}


/* ─────────────────────────────────────────────────────────────
   11. FAQ accordion (native <details> / <summary>)
   ───────────────────────────────────────────────────────────── */
.faq-list {
  display: flex;
  flex-direction: column;
}

.faq-item {
  border: 1px solid var(--color-border);
  border-top: none;
}

.faq-item:first-child {
  border-top: 1px solid var(--color-border);
  border-radius: 4px 4px 0 0;
}

.faq-item:last-child {
  border-radius: 0 0 4px 4px;
}

.faq-item:only-child {
  border-radius: 4px;
  border-top: 1px solid var(--color-border);
}

/* Remove default triangle marker */
.faq-question {
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  list-style: none;
  min-height: 44px;          /* touch target */
  user-select: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

/* +/× indicator */
.faq-question::after {
  content: '+';
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1;
  color: var(--color-accent);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.faq-item[open] > .faq-question {
  border-bottom: 1px solid var(--color-border);
}

.faq-item[open] > .faq-question::after {
  transform: rotate(45deg);
}

.faq-question:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

.faq-answer {
  padding: var(--space-md) var(--space-lg);
  color: var(--color-text);
  line-height: 1.7;
}

.faq-answer p + p {
  margin-top: var(--space-sm);
}


/* ─────────────────────────────────────────────────────────────
   12. Sponsors
   ───────────────────────────────────────────────────────────── */
.sponsors-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-xl);
}

.sponsor-item {
  text-decoration: none;
  display: block;
  min-height: 44px;          /* touch target */
  display: flex;
  align-items: center;
}

.sponsor-logo {
  height: 48px;
  width: auto;
  max-width: 180px;
  filter: grayscale(100%);
  opacity: 0.5;
  transition: filter 0.2s ease, opacity 0.2s ease;
}

.sponsor-item:hover .sponsor-logo,
.sponsor-item:focus .sponsor-logo {
  filter: grayscale(0%);
  opacity: 1;
}


/* ─────────────────────────────────────────────────────────────
   13. Contact
   ───────────────────────────────────────────────────────────── */
.hero-venue {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  margin-bottom: var(--space-md);
}

.section-contact .venue-info {
  margin-bottom: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-surface);
  border-radius: 4px;
  border-left: 3px solid var(--color-accent);
}

.section-contact .venue-info p + p {
  margin-top: var(--space-xs);
  color: var(--color-text-muted);
}

.contact-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.contact-item {
  display: flex;
  gap: var(--space-md);
  align-items: baseline;
}

.contact-item .label-caps {
  min-width: 72px;
  flex-shrink: 0;
}

.contact-item a {
  color: var(--color-accent);
  text-decoration: none;
}

.contact-item a:hover {
  text-decoration: underline;
}


/* ─────────────────────────────────────────────────────────────
   14. Footer
   ───────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: var(--space-lg) 0;
  background: var(--color-bg);
}

.footer-inner {
  max-width: var(--max-layout);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.footer-brand {
  font-weight: 700;
  font-size: 0.9rem;
}

.footer-lang {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.footer-lang a {
  text-decoration: none;
  opacity: 0.5;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.15s;
}

.footer-lang a.active {
  opacity: 1;
  color: var(--color-accent);
}

.footer-lang a:hover {
  opacity: 0.8;
}

.footer-lang .sep {
  opacity: 0.3;
  user-select: none;
}

.footer-copy {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}


/* ─────────────────────────────────────────────────────────────
   15. Utilities & mobile overrides
   ───────────────────────────────────────────────────────────── */

/* Prevent horizontal scroll at 375px viewport */
@media (max-width: 640px) {
  body {
    overflow-x: hidden;
  }

  .nav-inner {
    padding: 0 var(--space-md);
    gap: var(--space-sm);
  }

  .nav-links {
    gap: var(--space-md);
  }

  .nav-links a {
    font-size: 0.8rem;
  }

  .lang-toggle {
    font-size: 0.7rem;
  }

  .section-inner {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .hero-content {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .distance-card-header {
    padding: var(--space-md);
  }

  .distance-stats {
    padding: var(--space-md);
  }

  .distance-actions {
    padding: var(--space-md);
  }

  .footer-inner {
    padding: 0 var(--space-md);
    gap: var(--space-md);
  }

  .footer-copy {
    width: 100%;
    margin-left: 0;
  }
}

/* ─────────────────────────────────────────────────────────────
   Umbrella mode — event cards, breadcrumb, hero tagline
   ───────────────────────────────────────────────────────────── */

/* Tagline in umbrella hero */
.hero-tagline {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.1rem;
  max-width: 56ch;
  margin-top: var(--space-md);
}
.hero-tagline p { margin: 0 0 var(--space-sm) 0; }
.hero-tagline p:last-child { margin-bottom: 0; }

/* Breadcrumb on event sub-pages (back to umbrella) */
.breadcrumb--event {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-sm) 0;
  font-size: 0.875rem;
}
.breadcrumb--event a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.breadcrumb--event a:hover { color: var(--color-accent); }

/* Events grid — similar grid as distances but visually richer cards */
.section-events { background: var(--color-bg); }

.events-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}
@media (min-width: 640px) {
  .events-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .events-grid { grid-template-columns: repeat(2, 1fr); }
}

.event-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.event-card::before {
  /* Accent bar — uses the event's own accent color */
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--event-accent, var(--color-accent));
}
.event-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.event-card-image-link {
  display: block;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--color-surface);
}
.event-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.event-card:hover .event-card-image { transform: scale(1.03); }

.event-card-image-link--placeholder {
  background-color: var(--event-accent, var(--color-accent));
}

.event-card-body {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex: 1;
}

.event-card-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}
.event-card-title a {
  color: var(--color-text);
  text-decoration: none;
}
.event-card-title a:hover { color: var(--event-accent, var(--color-accent)); }

.event-card-date {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0;
}

.event-card-status {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  padding: 4px 10px;
  border-radius: 4px;
  align-self: flex-start;
}
.event-card-status--open {
  background: #d4edda;
  color: #155724;
}
.event-card-status--upcoming {
  background: #fff3cd;
  color: #856404;
}
.event-card-status--closed {
  background: #f8d7da;
  color: #721c24;
}
.event-card-status--race-day {
  background: var(--event-accent, var(--color-accent));
  color: #fff;
}
.event-card-status--past {
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.event-card-link {
  margin-top: auto;
  align-self: flex-start;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
