/* ============================================================
   SKI NEW ENGLAND — Resort detail
   ============================================================ */
const HERO_IMG = { "jay-peak": "./jay-header-mwbefzms-jgt6.png" };
const CAM_IMG = { "jay-peak": "./jay-cam-mwbef3uh-o6al.png" };

/* ---------- hero carousel ---------- */
const HERO_SHOTS = 4;
function HeroCarousel({ r, heroImg }) {
  const [i, setI] = useState(0);
  const [paused, setPaused] = useState(false);
  useEffect(() => {
    if (paused) return;
    const id = setInterval(() => setI((v) => (v + 1) % HERO_SHOTS), 6000);
    return () => clearInterval(id);
  }, [paused, r.id]);
  useEffect(() => { setI(0); }, [r.id]);
  const labels = ["hero photo (wide)", "second view", "third view", "fourth view"];
  const arrow = (dir) => (
    <button onClick={() => setI((v) => (v + dir + HERO_SHOTS) % HERO_SHOTS)} aria-label={dir > 0 ? "Next photo" : "Previous photo"}
      style={{ position: "absolute", top: "42%", [dir > 0 ? "right" : "left"]: 20, zIndex: 4, width: 42, height: 42, borderRadius: "50%", display: "grid", placeItems: "center", border: "1px solid rgba(255,255,255,0.35)", background: "rgba(6,19,33,0.42)", backdropFilter: "blur(4px)", color: "#fff" }}>
      <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
        <path d={dir > 0 ? "M9 5l7 7-7 7" : "M15 5l-7 7 7 7"} />
      </svg>
    </button>
  );
  return (
    <div onMouseEnter={() => setPaused(true)} onMouseLeave={() => setPaused(false)} style={{ position: "absolute", inset: 0 }}>
      {Array.from({ length: HERO_SHOTS }, (_, n) => (
        <div key={n} style={{ position: "absolute", inset: 0, opacity: i === n ? 1 : 0, transition: "opacity .55s ease", pointerEvents: i === n ? "auto" : "none" }}>
          <image-slot id={n === 0 ? `resort-hero-${r.id}` : `resort-hero-${r.id}-${n + 1}`} shape="rect" placeholder={`${r.name} ${labels[n]}`}
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", ...(n === 0 && heroImg ? { background: `url("${heroImg}") center / cover no-repeat` } : null) }}></image-slot>
        </div>
      ))}
      {arrow(-1)}
      {arrow(1)}
      <div style={{ position: "absolute", inset: "20px 0px 0px -9px", background: "linear-gradient(180deg, rgba(6,19,33,0.5) 0%, rgba(6,19,33,0.2) 40%, rgba(6,19,33,0.9) 100%)" }}>
        <div style={{ position: "absolute", right: 41, bottom: 215, display: "flex", gap: 7, zIndex: 4 }}>
          {Array.from({ length: HERO_SHOTS }, (_, n) => (
            <button key={n} onClick={() => setI(n)} aria-label={`Photo ${n + 1}`}
              style={{ width: i === n ? 26 : 9, height: 9, borderRadius: 99, border: "none", padding: 0, background: i === n ? "#fff" : "rgba(255,255,255,0.45)", transition: "width .25s ease, background .25s ease" }}></button>
          ))}
        </div>
      </div>
    </div>
  );
}
function BigStat({ value, unit, label, accent, light }) {
  return (
    <div>
      <div className="mono tnum" style={{ fontWeight: 600, lineHeight: 1, fontSize: 34, display: "flex", alignItems: "baseline", gap: 3, color: accent ? "var(--blue-300)" : (light ? "#fff" : "var(--ink-900)") }}>
        {value}{unit && <span style={{ fontSize: 14, opacity: 0.6 }}>{unit}</span>}
      </div>
      <div className="eyebrow" style={{ marginTop: 8, fontSize: 9.5, color: light ? "rgba(255,255,255,0.6)" : "var(--muted)" }}>{label}</div>
    </div>
  );
}

/* centered figure for the dark rail card */
function DialStat({ value, unit, label, accent }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 9 }}>
      <div className="mono tnum" style={{ fontWeight: 600, lineHeight: 1, fontSize: 32, display: "flex", alignItems: "baseline", gap: 2, color: accent ? "var(--blue-300)" : "#fff" }}>
        {value}{unit && <span style={{ fontSize: 14, opacity: 0.6 }} dangerouslySetInnerHTML={{ __html: unit }} />}
      </div>
      <div className="eyebrow" style={{ fontSize: 9, letterSpacing: "0.18em", color: "rgba(255,255,255,0.5)" }}>{label}</div>
    </div>
  );
}

/* dark-card ring gauge: percentage in the middle, open/total beneath, dot at the arc head */
function DialGauge({ pct, open, total, label, size = 104, stroke = 6 }) {
  const r = (size - stroke) / 2, c = 2 * Math.PI * r, mid = size / 2;
  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 14 }}>
      <div className="eyebrow" style={{ fontSize: 9, letterSpacing: "0.18em", color: "rgba(255,255,255,0.5)" }}>{label}</div>
      <div style={{ position: "relative", width: size, height: size }}>
        <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} style={{ display: "block" }}>
          <circle cx={mid} cy={mid} r={r} fill="none" stroke="rgba(255,255,255,0.16)" strokeWidth={stroke} />
          <circle cx={mid} cy={mid} r={r} fill="none" stroke="var(--blue-300)" strokeWidth={stroke} strokeLinecap="round"
            strokeDasharray={`${c * pct} ${c}`} transform={`rotate(-90 ${mid} ${mid})`} />
        </svg>
        <div style={{ position: "absolute", inset: 0, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 2 }}>
          <span className="mono tnum" style={{ fontSize: 24, fontWeight: 700, lineHeight: 1, color: "#fff" }}>{Math.round(pct * 100)}%</span>
          <span className="mono tnum" style={{ fontSize: 11, color: "rgba(255,255,255,0.55)", whiteSpace: "nowrap" }}>{open} / {total}</span>
        </div>
      </div>
    </div>
  );
}

/* 0–5 stars, remembered per resort */
function StarRating({ resortId }) {
  const key = "sne_rating_" + resortId;
  const [val, setVal] = useState(0);
  const [hover, setHover] = useState(0);
  useEffect(() => {
    const saved = Number(localStorage.getItem(key) || 0);
    setVal(saved);
    setHover(0);
  }, [key]);
  const set = (n) => { const next = val === n ? 0 : n; setVal(next); localStorage.setItem(key, String(next)); };
  const shown = hover || val;
  return (
    <div>
      <div style={{ display: "flex", gap: 6 }} onMouseLeave={() => setHover(0)}>
        {[1, 2, 3, 4, 5].map((n) => (
          <button key={n} onClick={() => set(n)} onMouseEnter={() => setHover(n)}
            aria-label={`Rate ${n} out of 5`}
            style={{ background: "none", border: "none", padding: 0, cursor: "pointer", lineHeight: 0 }}>
            <svg width="30" height="30" viewBox="0 0 24 24"
              fill={n <= shown ? "var(--blue-400)" : "none"}
              stroke={n <= shown ? "var(--blue-400)" : "var(--line)"} strokeWidth="1.8" strokeLinejoin="round"
              style={{ transition: "fill .12s ease, stroke .12s ease" }}>
              <path d="M12 2.6l2.9 5.9 6.5.9-4.7 4.6 1.1 6.5-5.8-3.1-5.8 3.1 1.1-6.5L2.6 9.4l6.5-.9z" />
            </svg>
          </button>
        ))}
      </div>
      <div className="mono" style={{ fontSize: 11.5, color: "var(--muted)", marginTop: 10 }}>
        {val ? `You rated this ${val} of 5` : "Tap a star to rate"}
      </div>
    </div>
  );
}

/* lodging / tickets / rentals */
function PlanButton({ icon, label, note, onClick }) {
  const paths = {
    bed: "M3 18v-6h18v6M3 12V7M21 12v6M7 12V9.5A1.5 1.5 0 018.5 8h3A1.5 1.5 0 0113 9.5V12",
    ticket: "M4 9V7a1 1 0 011-1h14a1 1 0 011 1v2a2 2 0 000 4v2a1 1 0 01-1 1H5a1 1 0 01-1-1v-2a2 2 0 000-4zM13 7v10",
    ski: "M4 20h16M6 20L9 4M14 4l2 11M16.5 17.5l2.5 1.5M5 16l6 2",
  };
  return (
    <button onClick={onClick} style={{ display: "flex", alignItems: "center", gap: 12, width: "100%", textAlign: "left", background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 7, padding: "13px 14px", cursor: "pointer", transition: "border-color .15s ease, background .15s ease" }}
      onMouseEnter={(e) => { e.currentTarget.style.borderColor = "var(--blue-400)"; e.currentTarget.style.background = "var(--frost-50)"; }}
      onMouseLeave={(e) => { e.currentTarget.style.borderColor = "var(--line)"; e.currentTarget.style.background = "var(--paper)"; }}>
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--blue-500)" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}>
        <path d={paths[icon]} />
      </svg>
      <span style={{ flex: 1 }}>
        <span style={{ display: "block", fontWeight: 700, fontSize: 14 }}>{label}</span>
        <span className="mono" style={{ fontSize: 10.5, color: "var(--muted)" }}>{note}</span>
      </span>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--muted-2)" strokeWidth="2.4" strokeLinecap="round"><path d="M9 6l6 6-6 6" /></svg>
    </button>
  );
}

function ResortPage({ go, data, resortId }) {
  const r = data.RESORTS.find((x) => x.id === resortId) || data.RESORTS[0];
  const nearby = data.RESORTS.filter((x) => x.state === r.state && x.id !== r.id).slice(0, 3);
  const dd = r.difficulty;
  const trailTotal = dd.green + dd.blue + dd.black + dd.dd || 1;
  const pct = (v) => Math.round((v / trailTotal) * 100);
  const days = ["Today", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"];
  const stateName = data.STATES.find((s) => s.code === r.state)?.name || r.state;
  const place = `${r.name} Ski Resort, ${stateName}`;
  const mapEmbed = `https://maps.google.com/maps?q=${encodeURIComponent(place)}&z=11&output=embed`;
  const mapLink = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}`;
  const dirLink = `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(place)}`;
  const fc = r.forecast.slice(0, 4);
  const snowRank = [...data.RESORTS].sort((a, b) => b.newSnow - a.newSnow).findIndex((x) => x.id === r.id) + 1;
  const heroImg = HERO_IMG[r.id];
  const camImg = CAM_IMG[r.id];
  const shortName = r.name.split(" ")[0];

  return (
    <div style={{ background: "var(--frost-50)" }}>
      {/* hero */}
      <section style={{ position: "relative", background: "var(--ink-900)", color: "#fff", minHeight: 460, height: 696, display: "flex", flexDirection: "column", justifyContent: "flex-end" }}>
        {r.surfaceOnly ? (
          <React.Fragment>
            <image-slot id={`resort-hero-${r.id}`} shape="rect" placeholder={`${r.name} hero photo (wide)`} style={{ position: "absolute", inset: 0, width: "100%", height: "100%", ...(heroImg ? { background: `url("${heroImg}") center / cover no-repeat` } : null) }}></image-slot>
            <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(6,19,33,0.5) 0%, rgba(6,19,33,0.2) 40%, rgba(6,19,33,0.9) 100%)" }} />
          </React.Fragment>
        ) : (
          <HeroCarousel r={r} heroImg={heroImg} />
        )}
        <div className="wrap" style={{ position: "relative", paddingTop: 40, paddingBottom: 30 }}>
          <button onClick={() => go("conditions")} className="eyebrow" style={{ background: "none", border: "none", color: "rgba(255,255,255,0.7)", display: "flex", alignItems: "center", gap: 7, marginBottom: 20, padding: 0 }}>
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"><path d="M19 12H5M11 6l-6 6 6 6" /></svg>
            Back to conditions
          </button>
          <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 14 }}>
            <Tag label={r.tag} kind={r.tag} />
            <span className="eyebrow" style={{ color: "rgba(255,255,255,0.7)" }}>{r.surfaceOnly ? STATE_NAMES[r.state] || r.state : `${r.state} · ${r.region}`}</span>
            {r.pass !== "None" && <span style={{ fontFamily: "var(--f-mono)", fontSize: 10.5, fontWeight: 600, letterSpacing: "0.1em", textTransform: "uppercase", border: "1px solid rgba(255,255,255,0.3)", padding: "3px 9px", borderRadius: 3 }}>{r.pass} Pass</span>}
          </div>
          <h1 className="display" style={{ margin: 0, fontSize: "clamp(44px,7vw,92px)" }}>{r.name}</h1>
          <p className="serif" style={{ fontSize: "clamp(16px,1.8vw,20px)", lineHeight: 1.45, maxWidth: 560, marginTop: 16, color: "rgba(255,255,255,0.85)" }}>{r.blurb}</p>
        </div>
        {/* hero stat bar */}
        <div style={{ position: "relative", background: "var(--retro-950)", backdropFilter: "blur(8px)", height: 138 }}>
          <svg viewBox="0 0 1440 84" preserveAspectRatio="none" aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: "100%", width: "100%", height: 84, display: "block", marginBottom: -1 }}>
            <g fill="var(--retro-950)">
              <path d="M0,84 L0,26 Q 150,8 330,20 Q 500,31 690,14 Q 870,-2 1050,16 Q 1230,33 1440,12 L1440,84 Z" fillOpacity="0.22" />
              <path d="M0,84 L0,42 Q 170,24 342,37 Q 520,50 700,33 Q 880,16 1064,34 Q 1248,52 1440,30 L1440,84 Z" fillOpacity="0.34" />
              <path d="M0,84 L0,58 Q 140,42 312,54 Q 486,66 668,50 Q 852,34 1038,51 Q 1224,68 1440,47 L1440,84 Z" fillOpacity="0.5" />
              <path d="M0,84 L0,60 Q 110,46 268,55 Q 420,63 604,51 Q 764,41 942,54 Q 1118,66 1282,53 Q 1372,46 1440,57 L1440,84 Z" />
            </g>
          </svg>
          <div className="wrap" style={{ position: "relative", display: "flex", gap: 0, padding: "20px 28px", flexWrap: "wrap" }}>
            {[
              ["newSnow", `${r.newSnow}`, "&Prime;", "New (24h)", true],
              ["base", `${r.base}`, "&Prime;", "Base depth"],
              ["lifts", `${r.lifts[0]}/${r.lifts[1]}`, "", "Lifts spinning"],
              ["trails", `${r.trailsOpen}/${r.trailsTotal}`, "", "Trails open"],
              ["temp", `${r.tempF}`, "°F", "Summit temp"],
              ["wind", r.wind, "", "Wind"],
            ].map((s, i) => (
              <div key={i} style={{ flex: 1, minWidth: 120, paddingLeft: i === 0 ? 0 : 24, borderLeft: i === 0 ? "none" : "1px solid rgba(255,255,255,0.12)" }}>
                <BigStat value={<span dangerouslySetInnerHTML={{ __html: s[1] + (s[2] ? `<span style="font-size:14px;opacity:.6">${s[2]}</span>` : "") }} />} label={<span dangerouslySetInnerHTML={{ __html: s[3] }} />} accent={s[4]} light />
              </div>
            ))}
          </div>
          <svg viewBox="0 0 1440 26" preserveAspectRatio="none" aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: -1, width: "100%", height: 26, display: "block" }}>
            <path d="M0,26 L1440,26 L1440,9 Q 1290,0 1104,10 Q 902,21 706,9 Q 524,-1 328,11 Q 168,20 0,7 Z" fill="var(--frost-50)" />
            <g fill="none" stroke="var(--frost-50)" strokeLinecap="round" vectorEffect="non-scaling-stroke">
              <path d="M1440,4 Q 1290,-5 1104,5 Q 902,16 706,4 Q 524,-6 328,6 Q 168,15 0,2" strokeWidth="3" strokeOpacity="0.5" strokeDasharray="210 60 150 90 300 48" />
              <path d="M1440,-1 Q 1296,-10 1110,0 Q 908,11 712,-1 Q 530,-11 334,1 Q 174,10 0,-3" strokeWidth="2" strokeOpacity="0.28" strokeDasharray="120 140 240 70 170 110" />
            </g>
          </svg>
        </div>
      </section>

      {/* body */}
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1fr 340px", gap: 40, padding: "50px 28px 70px", alignItems: "start" }}>
        <div style={{ display: "flex", flexDirection: "column", gap: 40 }}>
          {/* write-up */}
          <div>
            <SectionHead eyebrow="MORE INFORMATION" title={`ABOUT ${r.name.toUpperCase()}`} />
            <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, padding: "28px 32px", boxShadow: "var(--shadow-card)" }}>
              <p className="serif" style={{ fontSize: 19, lineHeight: 1.5, margin: 0, color: "var(--ink-900)" }}>{r.blurb}</p>
              {r.wiki
                ? r.wiki.map((para, i) => (
                    <p key={i} className="serif" style={{ fontSize: 15.5, lineHeight: 1.65, marginTop: 18, marginBottom: 0, color: "var(--muted)" }}>{para}</p>
                  ))
                : (
                  <p className="serif" style={{ fontSize: 15.5, lineHeight: 1.65, marginTop: 18, marginBottom: 0, color: "var(--muted-2)" }}>
                    The encyclopedia write-up for {r.name} goes here — two or three paragraphs on its founding, its terrain, and what it is known for.
                  </p>
                )}
              <div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 22, paddingTop: 16, borderTop: "1px solid var(--line-soft)" }}>
                <span className="eyebrow" style={{ fontSize: 9.5, color: "var(--muted-2)" }}>Source</span>
                <a href="#" onClick={(e) => e.preventDefault()} className="mono" style={{ fontSize: 11.5 }}>Wikipedia · {r.name}</a>
              </div>
            </div>
          </div>

          {/* terrain breakdown */}
          <div>
            <SectionHead eyebrow="The Mountain" title="TERRAIN &amp; STATS" />
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
              <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, padding: "24px 26px", boxShadow: "var(--shadow-card)" }}>
                <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 18 }}>Trail difficulty</div>
                <div style={{ marginBottom: 18 }}><TrailBar d={dd} height={12} /></div>
                {[
                  ["green", "Beginner", "var(--trail-green)", "circle"],
                  ["blue", "Intermediate", "var(--trail-blue)", "square"],
                  ["black", "Advanced", "var(--trail-black)", "diamond"],
                  ...(dd.dd ? [["dd", "Expert only", "#000", "diamond"]] : []),
                ].map(([k, label, color, shape]) => (
                  <div key={k} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "9px 0", borderBottom: "1px solid var(--line-soft)" }}>
                    <span style={{ display: "flex", alignItems: "center", gap: 10 }}>
                      <span style={{ width: 12, height: 12, background: color, borderRadius: shape === "circle" ? "50%" : shape === "diamond" ? 2 : 2, transform: shape === "diamond" ? "rotate(45deg)" : "none", display: "inline-block" }} />
                      <span style={{ fontSize: 13.5, fontWeight: 600 }}>{label}</span>
                    </span>
                    <span className="mono tnum" style={{ fontSize: 13, color: "var(--muted)" }}>{pct(dd[k])}%</span>
                  </div>
                ))}
              </div>
              <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, padding: "24px 26px", boxShadow: "var(--shadow-card)" }}>
                <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 18 }}>By the numbers</div>
                {[
                  ["Vertical drop", `${r.vertical.toLocaleString()} ft`],
                  ["Summit elevation", `${r.summit.toLocaleString()} ft`],
                  ["Skiable acres", `${r.acres.toLocaleString()}`],
                  ["Total trails", `${r.trailsTotal}`],
                  ["Total lifts", `${r.lifts[1]}`],
                  ["Season pass", r.pass === "None" ? "Independent" : r.pass],
                ].map(([k, v]) => (
                  <div key={k} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "9px 0", borderBottom: "1px solid var(--line-soft)" }}>
                    <span style={{ fontSize: 13.5, color: "var(--muted)" }}>{k}</span>
                    <span className="mono tnum" style={{ fontSize: 13.5, fontWeight: 600 }}>{v}</span>
                  </div>
                ))}
              </div>
            </div>
          </div>

          {/* trail map */}
          <div>
            <SectionHead eyebrow="EXPLORE THE RESORT" title={`${shortName.toUpperCase()}'S TRAIL MAP`} />
            <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, overflow: "hidden", boxShadow: "var(--shadow-card)" }}>
              <div style={{ position: "relative", aspectRatio: "4/3", background: "var(--frost-100)" }}>
                <image-slot id={`trailmap-${r.id}`} shape="rect" placeholder={`Drop the ${r.name} trail map`} style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}></image-slot>
              </div>
            </div>
          </div>

          {/* map + directions */}
          <div>
            <SectionHead eyebrow="Getting There" title="Find the mountain" />
            <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 8, overflow: "hidden", boxShadow: "var(--shadow-card)" }}>
              <div style={{ position: "relative", aspectRatio: "16/9", background: "var(--frost-100)" }}>
                <iframe title={`Map of ${r.name}`} src={mapEmbed} loading="lazy" referrerPolicy="no-referrer-when-downgrade"
                  style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: "none" }}></iframe>
              </div>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16, padding: "16px 20px", borderTop: "1px solid var(--line)", flexWrap: "wrap" }}>
                <div>
                  <div style={{ fontWeight: 700, fontSize: 14 }}>{r.name}</div>
                  <div className="mono" style={{ fontSize: 11, color: "var(--muted)" }}>{r.surfaceOnly ? stateName : `${r.region} · ${stateName}`}</div>
                </div>
                <div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
                  <a className="btn btn--blue" href={dirLink} target="_blank" rel="noopener noreferrer" style={{ textDecoration: "none" }}>
                    Get directions
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
                  </a>
                  <a className="btn btn--light" href={mapLink} target="_blank" rel="noopener noreferrer" style={{ textDecoration: "none", color: "var(--ink-900)" }}>Open in Google Maps</a>
                </div>
              </div>
            </div>
          </div>
        </div>

        {/* sticky rail */}
        <aside style={{ position: "sticky", top: 110, display: "flex", flexDirection: "column", gap: 18 }}>
          {/* webcam */}
          <div style={{ position: "relative", aspectRatio: "16/9", borderRadius: 10, overflow: "hidden", background: "var(--ink-850)", border: "1px solid var(--line)" }}>
            <image-slot id={`webcam-${r.id}`} shape="rect" placeholder="Webcam still" src={camImg} style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}></image-slot>
            <div style={{ position: "absolute", top: 12, left: 12, display: "flex", alignItems: "center", gap: 8, background: "rgba(6,19,33,0.6)", backdropFilter: "blur(4px)", padding: "6px 11px", borderRadius: 4 }}>
              <span className="pow-badge" style={{ width: 7, height: 7, borderRadius: "50%", background: "var(--pow)" }} />
              <span className="eyebrow" style={{ color: "#fff", fontSize: 10 }}>Live · Summit Cam</span>
            </div>
          </div>

          <div style={{ background: "var(--retro-900)", color: "#fff", borderRadius: 10, padding: "24px 24px 26px", width: 334 }}>
            <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 16 }}>
              <SkyIcon sky={r.sky} size={22} color="var(--blue-300)" />
              <div>
                <div style={{ fontWeight: 700, fontSize: 16 }}>{r.sky}</div>
                <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.6)" }}>Wind {r.wind} mph</div>
              </div>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1px 1fr", gap: 18, alignItems: "center", paddingTop: 20, borderTop: "1px solid rgba(255,255,255,0.12)" }}>
              <DialStat value={r.newSnow} unit="&Prime;" label="New (24h)" accent />
              <span style={{ display: "block", width: 1, height: 54, background: "rgba(255,255,255,0.12)" }} />
              <DialStat value={r.base} unit="&Prime;" label="Base depth" />
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1px 1fr", gap: 18, alignItems: "center", marginTop: 20, paddingTop: 22, borderTop: "1px solid rgba(255,255,255,0.12)" }}>
              <DialGauge pct={r.trailsOpen / r.trailsTotal} open={r.trailsOpen} total={r.trailsTotal} label="Open Trails" />
              <span style={{ display: "block", width: 1, height: 132, background: "rgba(255,255,255,0.12)" }} />
              <DialGauge pct={r.lifts[0] / r.lifts[1]} open={r.lifts[0]} total={r.lifts[1]} label="Lifts Open" />
            </div>
            <button className="btn btn--pow" style={{ width: "100%", justifyContent: "center", marginTop: 22 }} onClick={() => go("conditions")}>Add to my powder alerts</button>
          </div>

          {/* 7-day forecast */}
          <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 10, padding: "20px 22px", boxShadow: "var(--shadow-card)" }}>
            <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 16 }}>Snow forecast · 4 days</div>
            <div style={{ display: "grid", gridTemplateColumns: `repeat(${fc.length},1fr)`, gap: 8, alignItems: "end", height: 112 }}>
              {fc.map((v, i) => {
                const max = Math.max(...fc, 1);
                const hot = v >= 6;
                return (
                  <div key={i} style={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "flex-end", height: "100%", gap: 6 }}>
                    <span className="mono tnum" style={{ fontSize: 11.5, fontWeight: 600, color: hot ? "var(--pow)" : v > 0 ? "var(--ink-900)" : "var(--muted-2)" }}>{v}&Prime;</span>
                    <div style={{ width: "100%", maxWidth: 34, height: `${Math.max((v / max) * 100, 4)}%`, background: hot ? "var(--pow)" : v > 0 ? "var(--blue-400)" : "var(--line)", borderRadius: "3px 3px 0 0", transition: "height .4s ease" }} />
                  </div>
                );
              })}
            </div>
            <div style={{ display: "grid", gridTemplateColumns: `repeat(${fc.length},1fr)`, gap: 8, marginTop: 10, borderTop: "1px solid var(--line)", paddingTop: 10 }}>
              {days.slice(0, fc.length).map((d, i) => (
                <div key={i} className="eyebrow" style={{ textAlign: "center", fontSize: 9.5, letterSpacing: "0.08em", color: i === 0 ? "var(--blue-500)" : "var(--muted)" }}>{d}</div>
              ))}
            </div>
          </div>

          <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 10, padding: "20px 22px", boxShadow: "var(--shadow-card)" }}>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1px auto", gap: 18, alignItems: "start" }}>
              <div>
                <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>Rate this mountain</div>
                <StarRating resortId={r.id} />
              </div>
              <span style={{ display: "block", width: 1, height: 74, background: "var(--line)" }} />
              <div>
                <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>Ranks</div>
                <div className="mono tnum" style={{ fontSize: 32, fontWeight: 700, lineHeight: 1, color: "var(--blue-500)" }}>#{snowRank}</div>
                <div className="mono" style={{ fontSize: 11.5, color: "var(--muted)", marginTop: 10 }}>of {data.RESORTS.length} for new snow</div>
              </div>
            </div>
          </div>

          <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 10, padding: "20px 22px", boxShadow: "var(--shadow-card)" }}>
            <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>Plan your day</div>
            <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
              <PlanButton icon="bed" label="Lodging" note="Slopeside and in town" onClick={() => go("resort", r.id)} />
              <PlanButton icon="ticket" label="Lift tickets" note={r.pass === "None" ? "Day tickets" : `${r.pass} Pass + day tickets`} onClick={() => go("resort", r.id)} />
              <PlanButton icon="ski" label="Ski & board rental" note="On-mountain shops" onClick={() => go("resort", r.id)} />
            </div>
          </div>

          <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 10, padding: "20px 22px", boxShadow: "var(--shadow-card)" }}>
            <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>More in {data.STATES.find((s) => s.code === r.state)?.name}</div>
            <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
              {nearby.map((n) => (
                <button key={n.id} onClick={() => go("resort", n.id)} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", background: "none", border: "none", padding: "10px 0", borderBottom: "1px solid var(--line-soft)", textAlign: "left" }}>
                  <div>
                    <div style={{ fontWeight: 700, fontSize: 14 }}>{n.name}</div>
                    <div className="mono" style={{ fontSize: 10.5, color: "var(--muted)" }}>{n.region}</div>
                  </div>
                  <span className="mono tnum" style={{ fontSize: 15, fontWeight: 600, color: n.newSnow >= 6 ? "var(--pow)" : "var(--blue-500)" }}>{n.newSnow}&Prime;</span>
                </button>
              ))}
            </div>
          </div>
        </aside>
      </div>
    </div>
  );
}

Object.assign(window, { ResortPage, HeroCarousel });
