/* ============================================================
   yourtrail.run · interactive layer
   Styled with the "I'll Go for a Run" design system tokens
   (colors_and_type.css + brand_effects.css must load first).
   One accent: --orange. Support colors used sparingly:
   --forest = safe/positive, --summit-gold = caution.
   --risk-red is a local semantic addition for "injury zone"
   (the system ships no error red; derived to sit with the scree/
   autumn family, flag if it should join the system).
   ============================================================ */
:root {
  --risk-red: #C9564A;
}

/* ---- widget card ---- */
.iw {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 14px);
  padding: clamp(24px, 4vw, 44px);
  box-shadow: var(--shadow-md, 0 10px 30px rgba(0, 0, 0, .35));
  margin-top: 44px;
}
.iw-note {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--fg-subtle);
  max-width: 62ch;
  margin: 18px 0 0;
}

/* ---- sliders ---- */
.iw input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--ink-700);
  outline: none;
  margin: 26px 0 8px;
}
.iw input[type="range"].zones {
  background: linear-gradient(90deg,
    var(--forest) 0 55%,
    var(--summit-gold) 55% 78%,
    var(--risk-red) 78% 100%);
}
.iw input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--orange);
  border: 3px solid var(--ink-950);
  box-shadow: 0 0 0 1px var(--ink-600), var(--glow-orange, 0 0 18px rgba(255, 140, 0, .35));
  cursor: grab;
}
.iw input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--orange);
  border: 3px solid var(--ink-950);
  cursor: grab;
}
.iw .scale-labels {
  display: flex; justify-content: space-between;
  font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--fg-subtle);
}

/* ---- talk test ---- */
.talk-zone {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-display);
  font-size: clamp(22px, 2.6vw, 32px);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg);
}
.talk-breath {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--forest);
  animation: iw-breathe 3.4s ease-in-out infinite;
}
@keyframes iw-breathe {
  0%, 100% { transform: scale(.72); opacity: .55; }
  50%      { transform: scale(1.25); opacity: 1; }
}
.talk-sentence {
  font-size: clamp(20px, 2.6vw, 30px);
  line-height: 1.45;
  font-style: italic;
  color: var(--snow);
  min-height: 3.1em;
  margin: 20px 0 6px;
  text-wrap: pretty;
}
.talk-sentence .gasp { color: var(--fg-subtle); font-size: .78em; }
.talk-verdict { font-weight: 700; font-size: 16.5px; transition: color .3s; }

/* ---- 10% rule ---- */
.ten-bars {
  display: flex; align-items: flex-end; gap: 6px;
  height: 200px; margin-top: 28px;
}
.ten-bars .bar {
  flex: 1; min-height: 6px;
  background: var(--forest);
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: height .6s var(--ease-out, ease-out), background .4s;
}
.ten-bars .bar span {
  position: absolute; bottom: -24px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--fg-subtle); white-space: nowrap;
}
.ten-verdict { margin-top: 40px; font-weight: 700; font-size: 16.5px; transition: color .3s; }
.ten-detail { color: var(--fg-muted); font-size: 14.5px; margin-top: 6px; }
.ten-detail strong { color: var(--fg); }

/* ---- myth flip cards ---- */
.myths-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 44px;
}
/* Both faces sit in the same grid cell, so the card is always as tall as its
   tallest face and content can never overflow, at any viewport width. */
.flip { perspective: 1200px; cursor: pointer; }
.flip-inner {
  display: grid; height: 100%; min-height: 280px;
  transition: transform .7s var(--ease-out, cubic-bezier(.2, .8, .2, 1));
  transform-style: preserve-3d;
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip .face {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--r-lg, 14px);
  padding: 26px;
  display: flex; flex-direction: column;
}
.flip .face p { margin: 0; }
.flip .face.front {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
}
.flip .face .tag {
  font-family: var(--font-display);
  font-size: 18px; letter-spacing: .1em; text-transform: uppercase;
  margin-bottom: 14px;
}
.flip .face.front .tag { color: var(--fg-muted); }
.flip .face.front .q {
  font-size: 19px; font-style: italic; line-height: 1.45; font-weight: 600;
}
.flip .face .hint {
  margin-top: auto; padding-top: 22px;
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--fg-subtle);
}
.flip .face.back {
  background: var(--snow);
  color: var(--ink-900);
  transform: rotateY(180deg);
  font-size: 15px; line-height: 1.55;
}
.flip .face.back .tag { color: var(--trail-blue-deep); }
.flip .face.back .src {
  margin-top: auto; padding-top: 18px;
  font-size: 12px; color: var(--ink-500);
}

/* ---- firsts strip (built from races.json) ---- */
.firsts-strip {
  display: flex; gap: 16px;
  overflow-x: auto;
  padding: 40px 0 18px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: var(--ink-600) transparent;
}
.firsts-strip::-webkit-scrollbar { height: 8px; }
.firsts-strip::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 4px; }
.first-card {
  flex: 0 0 264px;
  scroll-snap-align: start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 14px);
  overflow: hidden;
  transition: transform .3s var(--ease-out, ease-out), border-color .3s;
}
.first-card:hover { transform: translateY(-6px); border-color: var(--border-strong); }
.first-card img {
  width: 100%; height: 296px; object-fit: cover; display: block;
}
.first-card .meta { padding: 14px 16px 18px; }
.first-card .dist {
  display: inline-flex; align-items: baseline; gap: 8px;
  font-family: var(--font-display);
  font-size: 22px; letter-spacing: .03em; text-transform: uppercase;
  color: var(--trail-blue);
}
.first-card .dist small {
  font-family: var(--font-ui);
  font-size: 11.5px; font-weight: 700; letter-spacing: .08em;
  color: var(--fg-subtle);
}
.first-card .title {
  font-size: 14.5px; font-weight: 600; color: var(--fg);
  margin: 6px 0 2px; line-height: 1.35;
}
.first-card .date { font-size: 12.5px; color: var(--fg-subtle); }
.first-card.is-upcoming {
  border: 1px dashed var(--orange);
  display: flex; flex-direction: column; justify-content: center;
  padding: 24px; min-height: 296px;
  background: color-mix(in srgb, var(--orange) 6%, var(--surface-2));
}
.first-card.is-upcoming .dist { font-size: 30px; color: var(--orange); }
.strip-hint {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--fg-subtle); margin-top: 6px;
}

/* ---- data chart (story page) ---- */
.iw-chart { width: 100%; height: auto; margin-top: 10px; }
.iw-chart .axis  { font-family: var(--font-ui); font-size: 10.5px; fill: var(--fg-subtle); }
.iw-chart .anno  { font-family: var(--font-ui); font-size: 11px; font-weight: 700; fill: var(--fg-muted); }
.iw-chart .anno.orange { fill: var(--orange); }
.iw-legend { display: flex; gap: 26px; font-size: 13px; color: var(--fg-muted); margin-top: 12px; flex-wrap: wrap; }
.iw-legend i { display: inline-block; width: 22px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 8px; }

/* ---- elevation progress bar (index) ----
   The profile lines live in a stretched SVG (preserveAspectRatio: none);
   checkpoints, labels and the moving dot are HTML overlays so text and dots
   keep their shape at every viewport width. */
#elev {
  position: fixed; left: 0; right: 0; bottom: 0; height: 62px; z-index: 60;
  background: linear-gradient(180deg, rgba(7, 24, 43, 0) 0%, rgba(7, 24, 43, .92) 46%);
  pointer-events: none;
  opacity: 0; transform: translateY(100%);
  transition: opacity .6s ease, transform .6s var(--ease-out, ease-out);
}
#elev.on { opacity: 1; transform: none; }
#elev svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#elev svg path { vector-effect: non-scaling-stroke; }
#elev .cp {
  position: absolute; width: 7px; height: 7px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--ink-900);
  border: 1.5px solid var(--ink-500);
  pointer-events: auto; cursor: pointer;
  transition: background .3s, border-color .3s;
}
#elev .cp.done { background: var(--orange); border-color: var(--orange); }
#elev .cp .lbl {
  position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-ui); font-size: 9px; font-weight: 600;
  letter-spacing: .05em; color: var(--fg-subtle); white-space: nowrap;
}
#elev .cp.done .lbl { color: var(--fg-muted); }
#elev-dot {
  position: absolute; width: 11px; height: 11px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--orange);
  border: 2px solid var(--ink-950);
  box-shadow: var(--glow-orange, 0 0 14px rgba(255, 140, 0, .45));
}
@media (max-width: 760px) { #elev .cp .lbl { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .talk-breath { animation: none; }
  .flip-inner, .ten-bars .bar, .first-card { transition: none; }
  #elev { transition: none; }
}
