// data.jsx — TRAIL data for Apple 50 (Origin Trail).
// Eight stops tracing Apple's arc from a Los Altos garage to Apple Park.
// Each stop drives Home, Map, Detail, Radar, Claim and Passport.
//
// Shape per stop:
//   id, n (1-based order), name, year, place, lat, lng,
//   mark   -> Patch glyph key (see patch.jsx)
//   lede   -> one-line summary (bold in Detail)
//   history-> array of paragraphs
//   quote  -> { t: text, c: citation }
//   sources-> array of strings
//   visit  -> optional { tone:'warn'|undefined, label, lines:[] }
//   video  -> optional { id, title, channel, year, source }   (YouTube id)
//   photo  -> optional image URL
//   secret -> optional { name, place, lat, lng, fact, source, video? }
//             A hidden Steve-Jobs/Apple-related location revealed ONLY after the
//             site's patch is claimed. It gets its OWN screen (SecretScreen) with
//             an optional `video` (same shape as a site video). The parent site's
//             detail only shows a small teaser — not the full secret info.
//             Every `fact` must be real and carry a `source` (see CLAUDE.md).
//
// History credited to the Computer History Museum (CHM) "Apple at 50".
// Coordinates are well-known public values.

window.SOURCE_NOTE =
  "History courtesy of the Computer History Museum (Apple at 50). " +
  "Several stops are private residences or active workplaces — please view from public areas and respect the people who live and work there. " +
  "This is an unofficial fan-made side quest — not affiliated with, endorsed by, or sponsored by Apple Inc. or WWDC.";


// All WWDC patches share one special gold accent (distinct from the blue trail
// patches) and carry a `wwdcYear` so the Passport can group them by year. Add a
// new entry per year (wwdc-2027, …) with its own `event` window to collect it.
const WWDC_ACCENT = "#ffd23f";

// Full set of stops (including the special WWDC event patch).
const TRAIL_ALL = [
  {
    id: "los-altos-garage",
    n: 1,
    name: "Los Altos Garage",
    year: "1976",
    place: "2066 Crist Dr, Los Altos, CA",
    lat: 37.3496, lng: -122.0927,
    mark: "garage",
    lede: "On April 1, 1976, Steve Jobs, Steve Wozniak and Ron Wayne founded Apple Computer.",
    history: [
      "To fund the first batch of Apple I boards, Wozniak sold his HP-65 calculator and Jobs sold his VW van. The earliest machines were assembled by hand in and around the Jobs family garage.",
      "Apple I was sold as a bare board — buyers added their own case, keyboard and power supply. It was the start of a company built on the idea that powerful computing should be personal."
    ],
    quote: {
      t: "Two Steves, a garage, and a hand-built circuit board — the seed of the personal-computer era.",
      c: "Computer History Museum — Apple at 50"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "CHM walking tour: Historic Apple Buildings with Early Employees"
    ],
    visit: {
      tone: "warn",
      label: "Private residence",
      lines: [
        "The Jobs family home is a private residence.",
        "Please view only from the public street and keep the neighborhood quiet."
      ]
    },
    // Date-aware secret: on Halloween (Oct 31) it reveals Steve Jobs' Palo Alto
    // house; every other day it's Atari (his pre-Apple job). `secret` is a getter
    // so every reader (Detail, Home, Map, SecretScreen) picks up the right one.
    _secretDefault: {
      name: "Atari",
      place: "Los Gatos, CA",
      lat: 37.2520, lng: -121.9530,
      fact: "Before Apple, a 19-year-old Steve Jobs was Atari employee #40 — a $5/hr technician here in 1974. Boss Nolan Bushnell stuck him on the night shift, and his job to trim chips from the game Breakout pulled in Woz to do the engineering — a preview of the partnership to come.",
      source: "Game Developer — 'Steve Jobs, Atari Employee Number 40'; Nolan Bushnell interviews"
    },
    _secretHalloween: {
      name: "Steve Jobs' House",
      place: "Palo Alto, CA",
      lat: 37.4419, lng: -122.1419,
      fact: "Halloween only: every Oct 31, Steve Jobs' family turned the garden of his Old Palo Alto home into a fog-and-thunder 'haunted garden,' handing trick-or-treaters candy (and once, boxes of his favorite carrot juice). It still draws thousands. It's a private home — please view respectfully.",
      source: "AppleInsider (2011); Washington Post (2019)"
    },
    get secret() {
      return (window.__isHalloween && window.__isHalloween()) ? this._secretHalloween : this._secretDefault;
    }
  },
  {
    id: "homebrew-slac",
    n: 2,
    name: "Homebrew Computer Club",
    year: "1975",
    place: "SLAC Auditorium, 2575 Sand Hill Rd, Menlo Park, CA",
    lat: 37.4178, lng: -122.2014,
    mark: "club",
    video: {
      id: "3Fo3K0BXPh0",
      title: "Homebrew Computer Club",
      channel: "Computer History Museum",
      year: "2024",
      source: "YouTube"
    },
    lede: "The hobbyist club where Wozniak first showed his Apple I design.",
    history: [
      "From March 5, 1975, Bay Area hobbyists gathered in the auditorium of the Stanford Linear Accelerator Center (SLAC) to swap parts, schematics and ideas.",
      "Wozniak credited the club's open, share-everything culture as a direct inspiration for the Apple I — he handed out copies of his design and demoed it to the room."
    ],
    quote: {
      t: "The spirit of Homebrew was simple: bring what you know, take what you need, and build.",
      c: "Computer History Museum — Apple at 50"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "Homebrew Computer Club newsletters (1975–1977)"
    ],
    secret: {
      name: "Gordon French's garage",
      place: "Menlo Park, CA",
      lat: 37.4530, lng: -122.1817,
      fact: "Before SLAC, Homebrew's very first meeting was held on March 5, 1975 in Gordon French's Menlo Park garage. Steve Wozniak was in the room that rainy night — he credits it as the spark for the Apple I.",
      source: "Homebrew Computer Club, Wikipedia; Computer History Museum"
    }
  },
  {
    id: "byte-shop",
    n: 3,
    name: "The Byte Shop",
    year: "1975",
    place: "1063 W El Camino Real, Mountain View, CA",
    lat: 37.3889, lng: -122.0838,
    mark: "shop",
    video: {
      id: "TbWTgFUbre0",
      title: "Importance of Byte Shop to Computer History by Steve Wozniak,part of full Byte Shop 50th Interviews",
      channel: "Floppy Days Podcast",
      year: "2026",
      source: "YouTube"
    },
    lede: "The first order of 50 Apple I computers turned a hobby into a company.",
    history: [
      "Opened December 8, 1975, Paul Terrell's Byte Shop was one of the Bay Area's first personal-computer stores.",
      "Terrell ordered 50 fully assembled Apple I units — roughly $50,000 of business — on the condition that they arrive built, not as kits. That single purchase order pushed Apple from workbench project to real company."
    ],
    quote: {
      t: "Fifty assembled machines, cash on delivery — the order that made Apple a business.",
      c: "Computer History Museum — Apple at 50"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "Paul Terrell, founder, The Byte Shop"
    ],
    secret: {
      name: "Buck's of Woodside",
      place: "Woodside, CA",
      lat: 37.4298, lng: -122.2564,
      fact: "This eccentric Silicon Valley diner keeps a 1976 Apple-1 locked in a stainless-steel safe and a rare photo of Steve Jobs goofing in Groucho gag glasses. Deals for Netscape, PayPal and Tesla were struck in its booths.",
      source: "Buck's of Woodside (Wikipedia); Palo Alto Online (2021)"
    }
  },
  {
    id: "bandley-drive",
    n: 4,
    name: "Bandley Drive",
    year: "1978",
    place: "10260 Bandley Dr, Cupertino, CA",
    lat: 37.3244, lng: -122.0312,
    mark: "factory",
    video: {
      id: "sbCVETsmtoM",
      title: "Historic Apple Buildings Walking Tour with Early Employees",
      channel: "Computer History Museum",
      year: "2026",
      source: "YouTube"
    },
    lede: "Apple's first custom-built headquarters — and the birthplace of the Macintosh team.",
    history: [
      "On January 28, 1978, Apple moved into Bandley 1, its first purpose-built office. The complex grew to six buildings as the company expanded.",
      "Bandley 3, opened in 1983, housed Steve Jobs's original Macintosh team — the small, fiercely independent group that shipped the Mac in 1984."
    ],
    quote: {
      t: "Real artists ship.",
      c: "Steve Jobs, to the Macintosh team"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "CHM walking tour: Historic Apple Buildings with Early Employees"
    ],
    visit: {
      label: "Then & now",
      lines: [
        "The original Bandley buildings are gone, redeveloped over the decades.",
        "You're standing on the ground where the first Macintosh was built."
      ]
    },
    secret: {
      name: "Texaco Towers",
      place: "Cupertino, CA",
      lat: 37.3229, lng: -122.0322,
      fact: "To keep the Lisa and early Mac groups apart from HQ, Apple rented a small two-story office above a Texaco gas station at Stevens Creek & De Anza. Employees dubbed it 'Texaco Towers.'",
      source: "folklore.org (Andy Hertzfeld) — Texaco Towers"
    }
  },
  {
    id: "infinite-loop",
    n: 5,
    name: "Infinite Loop",
    year: "1993",
    place: "1 Infinite Loop, Cupertino, CA",
    lat: 37.3318, lng: -122.0312,
    mark: "loop",
    video: {
      id: "Mc_FiHTITHE",
      title: "Apple - Steve Jobs introduces the iPod - 2001",
      channel: "Tech Knowology",
      year: "2011",
      source: "YouTube"
    },
    lede: "Apple's headquarters from 1993 to 2017 — home of the iMac, iPod and the first iPhone.",
    history: [
      "The six-building Infinite Loop campus opened in 1993 and became Apple's center of gravity through its turnaround and its biggest launches.",
      "It was here, on October 23, 2001, that Steve Jobs unveiled the iPod — '1,000 songs in your pocket' — the device that reinvented how the world carried music and powered Apple's comeback decade."
    ],
    quote: {
      t: "1,000 songs in your pocket.",
      c: "Steve Jobs, iPod introduction, October 2001"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "Apple Newsroom archives"
    ],
    secret: {
      name: "Gourmet Haus Staudt",
      place: "Redwood City, CA",
      lat: 37.4860, lng: -122.2297,
      fact: "On March 18, 2010, an Apple engineer celebrating his birthday left a disguised iPhone 4 prototype on a barstool at this German beer hall. A patron found it and sold it to Gizmodo — the most famous leak in Apple history.",
      source: "Gizmodo, 'How Apple Lost the iPhone 4' (2010)",
      video: {
        id: "7KihemSZkNs",
        title: "History of the Leaked iPhone 4 Prototype",
        channel: "Apple Explained",
        year: "2018",
        source: "YouTube"
      }
    }
  },
  {
    id: "apple-park",
    n: 6,
    name: "Apple Park",
    year: "2017",
    place: "One Apple Park Way, Cupertino, CA",
    lat: 37.3349, lng: -122.0090,
    mark: "ring",
    video: {
      id: "gtuz5OmOh_M",
      title: "Steve Jobs Presents to the Cupertino City Council (6/7/11)",
      channel: "City of Cupertino",
      year: "2011",
      start: 249,
      source: "YouTube"
    },
    lede: "The ring-shaped campus that opened in 2017 — Steve Jobs's final design vision.",
    history: [
      "Apple Park's mile-around main building is wrapped in the largest panels of curved glass ever made, set in a restored orchard landscape.",
      "Jobs pitched the 'spaceship' campus to the Cupertino City Council in 2011; he did not live to see it completed, but it stands as the bookend to the trail that began in a garage a few miles away."
    ],
    quote: {
      t: "From a garage to a glass ring in the orchard, all within a few miles of Cupertino.",
      c: "Computer History Museum — Apple at 50"
    },
    sources: [
      "Computer History Museum — Apple at 50",
      "Apple Newsroom — Apple Park"
    ],
    visit: {
      label: "Open to visitors",
      lines: [
        "The Apple Park Visitor Center is open to the public.",
        "The campus itself is private — enjoy the view from the visitor center."
      ]
    },
    secret: {
      name: "The Steve Jobs Building, Pixar",
      place: "Emeryville, CA",
      lat: 37.8326, lng: -122.2820,
      fact: "Long before the ring, Jobs obsessed over collisions at Pixar: he put the campus's only restrooms in a central atrium so people would bump into each other. The main building was renamed 'The Steve Jobs Building' after his death.",
      source: "Walter Isaacson, Steve Jobs; Office Snapshots",
      video: {
        id: "R0XmBKsRJF8",
        title: "Pixar's Early Days - A Never-Before-Seen Interview With Steve Jobs, 1996",
        channel: "Steve Jobs Archive",
        year: "2025",
        source: "YouTube"
      }
    }
  },
  {
    id: "wwdc-2026",
    n: 7,
    name: "WWDC 2026",
    year: "2026",
    place: "Apple Park, Cupertino, CA",
    lat: 37.3349, lng: -122.0090,
    mark: "dev",
    wwdcYear: 2026,        // yearly collectible — grouped by year in the Passport
    accent: WWDC_ACCENT,   // unique gold patch color (vs the blue trail patches)
    // Special, time-boxed patch: only appears in the trail during this window
    // (inclusive, through end-of-day on `end`). Hidden by default.
    event: { start: "2026-06-08", end: "2026-06-12" },
    lede: "The capstone: Apple welcomes developers back to Apple Park for its 50th year.",
    history: [
      "Each June, Apple's Worldwide Developers Conference gathers more than a thousand developers at Apple Park for the keynote and a week of sessions.",
      "Collecting this stop closes the loop — fifty years from the founding to a developer conference on the ring's front lawn."
    ],
    quote: {
      t: "Fifty years on, the work that started in a garage continues on the orchard lawn.",
      c: "Apple 50 — Origin Trail"
    },
    sources: [
      "Apple Newsroom — WWDC 2026",
      "Computer History Museum — Apple at 50"
    ],
    visit: {
      tone: "warn",
      label: "Limited window",
      lines: [
        "WWDC 2026 runs June 8–12 at Apple Park.",
        "This stop is a special, time-boxed patch — collect it on-site during the event."
      ]
    },
    secret: {
      name: "Flint Center, De Anza College",
      place: "Cupertino, CA",
      lat: 37.3194, lng: -122.0455,
      fact: "Before keynotes moved to Apple Park, the original Macintosh debuted here on January 24, 1984 — Jobs pulling the Mac from a bag. The hall also launched the iMac and Apple Watch before it was demolished in 2024.",
      source: "9to5Mac; AppleInsider — Flint Center"
    }
  }
];

// A stop with an `event` window is only included when "now" falls inside it
// (inclusive through end-of-day on `end`). Stops without `event` always show.
function _inEventWindow(ev) {
  if (!ev || !ev.event) return true;
  // DebugPanel (localhost) can spoof "WWDC week" to preview the time-boxed patch.
  if (window.__DEBUG_FORCE_EVENTS) return true;
  const now = new Date();
  const [sy, sm, sd] = ev.event.start.split("-").map(Number);
  const [ey, em, ed] = ev.event.end.split("-").map(Number);
  const start = new Date(sy, sm - 1, sd, 0, 0, 0);
  const endExclusive = new Date(ey, em - 1, ed + 1, 0, 0, 0);
  return now >= start && now < endExclusive;
}

window.TRAIL_ALL = TRAIL_ALL;
window.TRAIL = TRAIL_ALL.filter(_inEventWindow);
// Re-derive the visible trail after a debug toggle (e.g. spoofing WWDC week).
window.__recomputeTrail = () => { window.TRAIL = TRAIL_ALL.filter(_inEventWindow); };

// ============================================================ WWDC 2026 BINGO
// A fun, time-boxed mini-game that only surfaces during the keynote: tap each
// prediction as Apple announces it; complete a line for BINGO. Every square is a
// real community rumor from public pre-WWDC reporting, attributed to a primary
// outlet (the `src`) so the leaderboard can tally "who called it." These are
// fan speculation, NOT official — see `note`. Sources were verified against the
// outlets' own pre-WWDC coverage (see CLAUDE.md "always credit sources").
window.WWDC_BINGO = {
  // Keynote window — Mon June 8, 2026, 10:00 AM–1:00 PM PT. Offset-aware
  // instants so the gate is correct in any timezone.
  keynote: { start: "2026-06-08T10:00:00-07:00", end: "2026-06-08T13:00:00-07:00" },
  // 16 squares (4×4), balanced 4-per-outlet across 4 publications. `src` = the
  // outlet credited as a prominent reporter of that rumor; full credits in `note`.
  // Audited against pre-WWDC 2026 reporting (June 2026).
  squares: [
    // Bloomberg (Mark Gurman scoops)
    { id: "siri-gemini",  text: "Siri rebuilt on Google Gemini",      src: "Bloomberg" },
    { id: "siri-island",  text: "Siri lives in the Dynamic Island",   src: "Bloomberg" },
    { id: "glass-tuneup", text: "macOS 27 Liquid Glass tune-up",      src: "Bloomberg" },
    { id: "watch-hr",     text: "watchOS 27 better heart-rate",       src: "Bloomberg" },
    // MacRumors
    { id: "siri-app",     text: "Standalone Siri app (saves chats)",  src: "MacRumors" },
    { id: "watch-face",   text: "New “Modular Ultra” watch face",     src: "MacRumors" },
    { id: "macos-intel",  text: "macOS 27 drops Intel Macs",          src: "MacRumors" },
    { id: "mac-island",   text: "Dynamic Island in the Mac menu bar", src: "MacRumors" },
    // 9to5Mac
    { id: "watch-three",  text: "watchOS 27 adds 3 new features",     src: "9to5Mac" },
    { id: "shortcuts-nl", text: "Plain-English “Natural” Shortcuts",  src: "9to5Mac" },
    { id: "ai-models",    text: "Pick ChatGPT / Gemini / Claude",     src: "9to5Mac" },
    { id: "writing",      text: "Slide-up AI writing assistant",      src: "9to5Mac" },
    // AppleInsider
    { id: "siri-cards",   text: "Siri answers with rich cards",       src: "AppleInsider" },
    { id: "notif-left",   text: "Notifications slide in from the left", src: "AppleInsider" },
    { id: "touch-mac",    text: "First touchscreen MacBook teased",   src: "AppleInsider" },
    { id: "mac-m5",       text: "Mac mini & Studio jump to M5",       src: "AppleInsider" }
  ],
  note: "Predictions are community rumors compiled from public pre-WWDC 2026 reporting by " +
    "Bloomberg (Mark Gurman), MacRumors, 9to5Mac, and AppleInsider — four squares each. " +
    "“Primary reporter” is best-effort. This is fan speculation — not official, and not " +
    "affiliated with, endorsed by, or sponsored by Apple Inc. or WWDC."
};

// The bingo is live only during the keynote window. The DebugPanel (localhost)
// can preview it via its dedicated "WWDC Bingo" toggle (__DEBUG_FORCE_BINGO), and
// the existing "WWDC week" toggle (__DEBUG_FORCE_EVENTS) reveals it too. In
// production both flags are always falsy, so the real time gate applies.
window.bingoLive = () => {
  if (window.__DEBUG_FORCE_BINGO || window.__DEBUG_FORCE_EVENTS) return true;
  const { start, end } = window.WWDC_BINGO.keynote;
  const now = Date.now();
  return now >= Date.parse(start) && now < Date.parse(end);
};

// True on Halloween (Oct 31). The DebugPanel can force it on for preview.
window.__isHalloween = function () {
  if (window.__DEBUG_HALLOWEEN) return true;
  const d = new Date();
  return d.getMonth() === 9 && d.getDate() === 31;
};
