/* =========================================================================
   RunRoute design system
   Shared by every page: colors, type, layout, header/footer, buttons,
   form controls, chips, badges, cards, modals, and toasts.
   Page-specific styles live in their own files (home.css, explore.css, ...).
   ========================================================================= */

/* ---------- 1. Design tokens ------------------------------------------- */
:root {
  /* Warm, earthy palette */
  --cream: #F7F1E5;        /* page background */
  --cream-deep: #EFE5D2;   /* alternate sections */
  --paper: #FFFCF6;        /* cards and inputs */
  --forest: #2F4F3A;       /* primary color */
  --forest-deep: #1F3528;  /* headings, hover states */
  --sage: #A3B18A;         /* secondary color */
  --sage-deep: #7F9468;
  --sage-soft: #DCE3CF;
  --clay: #8B7355;         /* earthy neutral */
  --sand: #D9CBB3;         /* borders */
  --line: #E6DAC5;         /* hairlines */
  --ink: #2A2722;          /* body text */
  --ink-soft: #5E574D;     /* secondary text */
  --ember: #C8662B;        /* burnt-orange accent (decoration) */
  --ember-deep: #A44F1C;   /* burnt-orange for text and buttons (meets contrast rules) */
  --ember-soft: #F4DCC8;
  --danger: #A33A2B;
  --danger-soft: #F6DCD6;

  /* Typography */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Shape and depth */
  --radius-sm: 10px;
  --radius: 18px;
  --radius-lg: 28px;
  --shadow-sm: 0 1px 2px rgba(42, 39, 34, 0.06), 0 2px 10px rgba(42, 39, 34, 0.05);
  --shadow: 0 18px 40px -18px rgba(42, 39, 34, 0.35);

  /* Layout */
  --max-width: 1180px;
  --header-height: 4.25rem;
}

/* ---------- 2. Base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

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

/* The `hidden` attribute must always win, even over components that set `display`. */
[hidden] { display: none !important; }

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.015em;
  color: var(--forest-deep);
}
h1 { font-size: clamp(2.4rem, 5.5vw, 4.1rem); }
h2 { font-size: clamp(1.8rem, 3.6vw, 2.6rem); }
h3 { font-size: 1.3rem; }

p { margin: 0 0 1em; }

a { color: var(--ember-deep); text-underline-offset: 0.18em; }
a:hover { color: var(--forest); }

:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 3px;
  border-radius: 6px;
}

::selection { background: var(--sage-soft); }

/* Hide visually but keep for screen readers */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 1rem; top: -3rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--forest);
  color: #fff;
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 1rem; color: #fff; }

/* ---------- 3. Layout helpers ------------------------------------------- */
.container {
  width: min(100% - 2.5rem, var(--max-width));
  margin-inline: auto;
}

.section { padding-block: clamp(3.5rem, 8vw, 6.5rem); }
.section--tinted { background: var(--cream-deep); }

.section-heading { max-width: 40rem; margin-bottom: 2.5rem; }
.section-heading p { color: var(--ink-soft); font-size: 1.08rem; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ember-deep);
}
.eyebrow::before {
  content: "";
  width: 1.6rem;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.muted { color: var(--ink-soft); }
.small { font-size: 0.875rem; }

/* ---------- 4. Header and navigation ------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(247, 241, 229, 0.9);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-height);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--forest-deep);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.brand:hover { color: var(--forest-deep); }
.brand img { width: 34px; height: 34px; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.site-nav__link {
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}
.site-nav__link:hover { background: var(--sage-soft); color: var(--forest-deep); }
.site-nav__link[aria-current="page"] { background: var(--sage-soft); color: var(--forest-deep); font-weight: 600; }

.auth-area { display: flex; align-items: center; gap: 0.5rem; margin-left: 0.5rem; }
.auth-area__greeting { font-size: 0.92rem; color: var(--ink-soft); }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.75rem; height: 2.75rem;
  border: 1px solid var(--sand);
  border-radius: 999px;
  background: var(--paper);
  color: var(--forest-deep);
  cursor: pointer;
}
.nav-toggle svg { width: 1.3rem; height: 1.3rem; }

@media (max-width: 820px) {
  .nav-toggle { display: inline-flex; }
  .site-nav {
    position: absolute;
    top: var(--header-height);
    left: 0; right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 0.75rem 1.25rem 1.25rem;
    background: var(--cream);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  .site-nav[data-open="true"] { display: flex; }
  .site-nav__link { padding: 0.75rem 1rem; }
  .auth-area { margin: 0.5rem 0 0; flex-wrap: wrap; }
}

/* ---------- 5. Buttons -------------------------------------------------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.9rem;
  padding: 0.7rem 1.35rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button svg { width: 1.1em; height: 1.1em; flex-shrink: 0; }

.button--primary { background: var(--forest); color: #fff; box-shadow: 0 10px 22px -12px rgba(31, 53, 40, 0.8); }
.button--primary:hover { background: var(--forest-deep); color: #fff; }

.button--accent { background: var(--ember-deep); color: #fff; box-shadow: 0 10px 22px -12px rgba(164, 79, 28, 0.8); }
.button--accent:hover { background: #8C4316; color: #fff; }

.button--ghost { background: transparent; border-color: var(--sand); color: var(--forest-deep); }
.button--ghost:hover { background: var(--paper); border-color: var(--sage); color: var(--forest-deep); }

.button--danger { background: var(--danger); color: #fff; }
.button--danger:hover { background: #87291C; color: #fff; }

.button--light { background: var(--paper); color: var(--forest-deep); }
.button--light:hover { background: #fff; color: var(--forest-deep); }

.button--small { min-height: 2.25rem; padding: 0.4rem 0.95rem; font-size: 0.9rem; }
.button--block { width: 100%; }

.button:disabled, .button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* A plain-looking button (for icon buttons and links that act like buttons) */
.text-button {
  padding: 0.25rem 0.4rem;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--ember-deep);
  cursor: pointer;
  border-radius: 6px;
}
.text-button:hover { color: var(--forest); text-decoration: underline; }

/* ---------- 6. Form controls -------------------------------------------- */
.field { display: grid; gap: 0.4rem; }
.field + .field { margin-top: 1rem; }

.label {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--forest-deep);
}
.hint { font-size: 0.84rem; color: var(--ink-soft); }

.input, .select, .textarea {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid var(--sand);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input::placeholder, .textarea::placeholder { color: #9A9184; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(47, 79, 58, 0.18);
}
.input[aria-invalid="true"] { border-color: var(--danger); }

.form-error {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 500;
}

/* ---------- 7. Chips (toggle buttons) and badges ------------------------ */
.chip-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--sand);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.chip:hover { border-color: var(--sage); }
.chip[aria-pressed="true"], .chip[aria-checked="true"] {
  background: var(--forest);
  border-color: var(--forest);
  color: #fff;
}
.chip__note { font-size: 0.75rem; opacity: 0.8; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge--verified { background: var(--sage-soft); color: var(--forest-deep); }
.badge--inferred { background: #F1E6D2; color: #6B5639; }
.badge--unknown { background: transparent; color: var(--ink-soft); border: 1px dashed var(--sand); }
.badge--mismatch { background: var(--danger-soft); color: var(--danger); }
.badge--accent { background: var(--ember-soft); color: var(--ember-deep); }

/* ---------- 8. Cards ---------------------------------------------------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ---------- 9. Modal dialog (uses the native <dialog> element) ----------- */
.modal {
  width: min(100% - 2rem, 30rem);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(31, 53, 40, 0.45); backdrop-filter: blur(2px); }
.modal__body { display: grid; gap: 1rem; padding: 1.75rem; }
.modal__body h2 { margin: 0; font-size: 1.6rem; }
.modal__body p { margin: 0; }
.modal__body .field + .field { margin-top: 0; }
.modal__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem; }
.modal[open] { animation: modal-in 0.2s ease-out; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* A highlighted note (also used on the Explore page) */
.notice {
  padding: 0.8rem 1rem;
  border-left: 4px solid var(--ember);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--ember-soft);
  color: #5A3418;
  font-size: 0.93rem;
}
.notice--error { border-left-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

/* ---------- 10. Toast notifications ------------------------------------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 200;
  display: grid;
  gap: 0.5rem;
  transform: translateX(-50%);
  width: min(100% - 2rem, 26rem);
}
.toast {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--forest-deep);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 500;
  animation: toast-in 0.25s ease-out;
}
.toast--error { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 11. Footer --------------------------------------------------- */
.site-footer {
  padding-block: 3rem 2rem;
  background: var(--forest-deep);
  color: #E7E2D6;
}
.site-footer a { color: #F3D9C2; }
.site-footer a:hover { color: #fff; }

.site-footer__grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 2rem;
}
.site-footer .brand { color: #fff; }
.site-footer__tagline { margin-top: 0.75rem; max-width: 22rem; color: #CFC9BC; }
.site-footer__heading {
  margin-bottom: 0.75rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #A9B795;
}
.site-footer__list { display: grid; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.site-footer__fineprint {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
  color: #B9B3A6;
}

@media (max-width: 720px) {
  .site-footer__grid { grid-template-columns: 1fr; }
}

/* ---------- 12. Loading helpers ----------------------------------------- */
.spinner {
  width: 1.1em;
  height: 1.1em;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #EDE4D3 0%, #F6F0E4 50%, #EDE4D3 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Gentle entrance animation used across pages */
.reveal { animation: reveal 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Respect people who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
