// ============================================================================
// data.jsx — Mock content + API-ready data layer for Muafakat Games 2026
// All content here is PLACEHOLDER and meant to be swapped with real data later.
// Live Scores are wired through fetchLiveScores() so the real Sportall MY API
// can drop straight in (see the TODO inside fetchLiveScores).
// ============================================================================

const { useState, useEffect, useRef, useCallback } = React;

// --- Event date (countdown target) -----------------------------------------
const GAMES_DATE = new Date('2026-07-06T18:00:00+10:00'); // 6pm, 6 July 2026 (Victoria, AEST)

// --- Navigation -------------------------------------------------------------
const NAV = [
  { id: 'home', label: 'HOME' },
  { id: 'about', label: 'ABOUT' },
  { id: 'schedule', label: 'SCHEDULE' },
  { id: 'committee', label: 'COMMITTEE' },
  { id: 'scores', label: 'LIVE SCORES' },
  { id: 'contact', label: 'CONTACT' },
];

// --- Pillars (About) --------------------------------------------------------
const PILLARS = [
  { title: 'Unity beyond borders', tone: 'red', offset: 0 },
  { title: 'Leadership and development', tone: 'blue', offset: 64 },
  { title: 'Empowering the Malaysian Spirit', tone: 'yellow', offset: 28 },
];

// --- Schedule ---------------------------------------------------------------
// type → drives the colored category accent (see CSS --cat colors)
const SCHEDULE = {
  'Day 1': {
    date: 'Mon · 6 Jul',
    items: [
      { start: '07:00', end: '16:00', title: 'Arrival of Contingents', venue: 'N/A', type: 'logistics' },
      { start: '18:00', end: '19:30', title: 'Opening Ceremony', venue: 'The Couch', type: 'ceremony' },
    ],
  },
  'Day 2': {
    date: 'Tue · 7 Jul',
    items: [
      { start: '08:00', end: '14:15', title: 'Basketball Match', venue: 'Bundha Sports', type: 'sport', sport: 'basketball' },
      { start: '08:30', end: '13:30', title: 'Netball Match', venue: 'Bundha Sports', type: 'sport', sport: 'netball' },
      { start: '15:50', end: '21:30', title: 'Volleyball Match', venue: 'SSC Stadium B', type: 'sport', sport: 'volleyball' },
      { start: '16:00', end: '22:00', title: 'Badminton Singles Match', venue: 'SSC Stadium D', type: 'sport', sport: 'badminton' },
    ],
  },
  'Day 3': {
    date: 'Wed · 8 Jul',
    items: [
      { start: '08:00', end: '12:00', title: 'Flag Rugby Match', venue: 'Walker Ovals', type: 'sport', sport: 'flag-rugby' },
      { start: '14:00', end: '20:40', title: 'E-Sports Match', venue: 'SSC Anne Henderson Room', type: 'sport', sport: 'esports' },
      { start: '16:30', end: '21:30', title: 'Badminton Doubles Match', venue: 'SSC Stadium D', type: 'sport', sport: 'badminton' },
    ],
  },
  'Day 4': {
    date: 'Thu · 9 Jul',
    items: [
      { start: '09:00', end: '11:00', title: 'Track and Field Match', venue: 'MSAC Lakeside', type: 'sport', sport: 'track-field' },
      { start: '11:15', end: '16:35', title: 'Football Match', venue: 'Flemington Road Oval', type: 'sport', sport: 'football' },
      { start: '18:30', end: '23:00', title: 'Closing Ceremony', venue: 'The Edge, Federation Square', type: 'ceremony' },
    ],
  },
};

// --- Committee --------------------------------------------------------------
const COMMITTEE = [
  { dept: 'Directors', color: '#ef3b2f',
    people: [
      { name: "Raja I'rfan Imanullah Bin Raja Azmer Syahren", position: 'Project Director', photo: 'assets/Committee/PD/Raja.jpg', photoPosition: 'center 38%', rank: true },
    ] },
  { dept: 'Secretary General', color: '#2a52e0',
    people: [
      { name: 'Tan Ee Va', position: 'Secretary General', photo: 'assets/Committee/Secretary General/Ee Va Tan.jpeg', rank: true },
      { name: 'Nur Adila Aysha Binti Ahmad Haniff', position: 'Deputy Secretary General', photo: 'assets/Committee/Secretary General/Aysha.jpg', rank: true },
    ] },
  { dept: 'Sports', color: '#16a34a',
    people: [
      { name: 'Andi Nur Qistina Rania Binti Abd Jalil', position: 'Head of Sports', photo: 'assets/Committee/Sports/Andi.JPG', rank: true },
      { name: 'Nur Sharyna Alia Binti Shamsul Bahari', position: 'Secretary of Sports', photo: 'assets/Committee/Sports/Shary.jpg', rank: true },
      { name: 'Che Ku Eshal Aeesha Binti Che Ku Alias', position: 'Badminton Director', photo: 'assets/Committee/Sports/Eshal.jpg', photoPosition: 'center 35%' },
      { name: 'Elaine Low Qing Feng', position: 'Basketball Director', photo: 'assets/Committee/Sports/Elaine Low.jpg' },
      { name: 'Amir Raeza Bin Shaik Razwan', position: 'Football Director', photo: 'assets/Committee/Sports/AMir.jpg' },
      { name: 'Ariyana binti Ibrahim', position: 'Netball Director', photo: 'assets/Committee/Sports/Ariyana.jpg' },
      { name: 'Muhammad Faiq Nazhan Bin Junaidi', position: 'Flag Rugby Director', photo: 'assets/Committee/Sports/Nazhan.jpg' },
      { name: 'Muhammad Iyas Naufal Bin Nazlim', position: 'Track and Field Director', photo: 'assets/Committee/Sports/Iyas.jpg' },
      { name: 'Nur Rusydina Aqilah Binti Rosli', position: 'E-sports Director', photo: 'assets/Committee/Sports/Rusydina Aqilah.jpg' },
      { name: 'Ain Nadia Binti Md Nazri', position: 'Officials & Referee Coordinator', photo: 'assets/Committee/Sports/Ain.jpg' },
    ] },
  { dept: 'Finance', color: '#f5a300',
    people: [
      { name: 'Luceouz Vincente Jorge', position: 'Head of Finance', photo: 'assets/Committee/Finance/Luceouz.jpg', rank: true },
      { name: 'Calvin Isaiah Clement', position: 'Deputy Head of Finance', photo: 'assets/Committee/Finance/Calvin.jpg', rank: true },
      { name: 'Nurul Insyirah Binti Ashari', position: 'Secretary of Finance', photo: 'assets/Committee/Finance/Insyirah.jpg', rank: true },
      { name: 'Anson Siaw Thong Qing', position: 'Account Officer', photo: 'assets/Committee/Finance/Anson Siaw Thong Qing.jpg' },
      { name: 'Mohammad Haikal Afiq Bin Mohammad Hussin', position: 'Procurement Officer 1', photo: 'assets/Committee/Finance/Haikal.jpeg' },
      { name: 'Haziq Hakim Bin Zainal Abidin Yeoh', position: 'Procurement Officer 2', photo: 'assets/Committee/Finance/Haziq.jpeg' },
      { name: 'Furkha Binti Rusli', position: 'Monetary & In Kind Officer 1', photo: 'assets/Committee/Finance/Furkha.jpg' },
      { name: 'Adithya Suria', position: 'Monetary & In Kind Officer 2', photo: 'assets/Committee/Finance/Adithya.jpg' },
      { name: 'Asrul Afzal Bin Asrul Kamal', position: 'Monetary & In Kind Officer 3', photo: 'assets/Committee/Finance/Afzal.jpg' },
    ] },
  { dept: 'Operations', color: '#d61f8f',
    people: [
      { name: 'Ariq Anwar Bin Ahmad Lokman', position: 'Head of Operations', photo: 'assets/Committee/Operations/Ariq.png', rank: true },
      { name: 'Muhammad Irfan Bin Muhamad Nasir', position: 'Deputy Head of Operations', photo: 'assets/Committee/Operations/Irfan.jpg', rank: true },
      { name: 'Puteri Nurin Aisya Binti Ainul Hasni', position: 'Secretary of Operations', photo: 'assets/Committee/Operations/Puteri.jpg', rank: true },
      { name: 'Nur Alya Batrisyia Binti Muhamad Shahrul', position: 'Inventory Manager', photo: 'assets/Committee/Operations/Alya.jpg' },
    ] },
  { dept: 'Special Task', color: '#7c3aed',
    people: [
      { name: 'Tengku Safiyya Khadeeja binti Tengku Shahril Norzaimi', position: 'Special Task Officer 1', photo: 'assets/Committee/Special Task/Safiyya.jpg' },
      { name: 'Amirul Aiman Bin Rosli', position: 'Special Task Officer 2', photo: 'assets/Committee/Special Task/Iman.jpg' },
    ] },
  { dept: 'Human Resource', color: '#0ea5b7',
    people: [
      { name: 'Nur Aryssa Binti Marzuki', position: 'HR Manager', photo: 'assets/Committee/HR/Aryssa.jpg', photoPosition: 'center 42%', rank: true },
      { name: 'Nafisah Binti Ahmad Rizal', position: 'HR Executive', photo: 'assets/Committee/HR/Nafisah.jpg', rank: true },
      { name: 'Riham Binti Ahmad Muneer', position: 'Volunteer Coordinator 1', photo: 'assets/Committee/HR/Riham.jpg' },
      { name: 'Nurin Adlina Binti Muazam', position: 'Volunteer Coordinator 2', photo: 'assets/Committee/HR/Adlina.jpeg' },
      { name: 'Nur Nadhrah Binti Mohd Faisal', position: 'Food Coordinator', photo: 'assets/Committee/HR/Nadhrah.jpg' },
      { name: "A'shadieeyah Nabeeha Binti Muhammad Imran", position: 'Sub-Event Coordinator', photo: 'assets/Committee/HR/Asha.jpg' },
      { name: 'Liew Xin Yi', position: 'Sub-Event Assistant', photo: 'assets/Committee/HR/Xin Yi.JPG' },
    ] },
  { dept: 'Media', color: '#ff6a00',
    people: [
      { name: 'Raihanah Husna Binti Shahidan', position: 'Head of Media', photo: 'assets/Committee/Media/Raihanah.jpg', photoPosition: 'center 36%', rank: true },
      { name: 'Murfiqah Binti Musthafa', position: 'Deputy Head of Media', photo: 'assets/Committee/Media/Murfiqah.jpg', rank: true },
      { name: 'Delaila Binti Abdul Razak', position: 'Secretary Head of Media', photo: 'assets/Committee/Media/Delaila.JPG', rank: true },
      { name: 'Nur Diana Binti Mohd Shahuriy', position: 'Graphic Designer 1', photo: 'assets/Committee/Media/Diana.jpg' },
      { name: 'Nur Izzaty Binti Yaacob', position: 'Graphic Designer 2', photo: 'assets/Committee/Media/Izzaty.JPG' },
      { name: 'Nur Ariana Binti Faizalhary', position: 'Senior Content Creator', photo: 'assets/Committee/Media/Ariana.jpg' },
      { name: 'Muhammad Hafiy Bin Eddie', position: 'Junior Content Creator 1', photo: 'assets/Committee/Media/Hafiy.jpeg' },
      { name: 'Tan Ye Jing', position: 'Junior Content Creator 2', photo: 'assets/Committee/Media/Ye Jing.jpg' },
      { name: 'Hannah Binti Jasri', position: 'Social Media Manager 1', photo: 'assets/Committee/Media/Hannah.jpg' },
      { name: 'Raja Nur Sofina binti Raja Muhamad Yusof', position: 'Social Media Manager 2', photo: 'assets/Committee/Media/Sofi.jpg' },
    ] },
];

// --- Sports (Live Scores list) ----------------------------------------------
const SPORTS = [
  { id: 'badminton', name: 'Badminton', venue: 'Venue' },
  { id: 'basketball', name: 'Basketball', venue: 'Venue' },
  { id: 'football', name: 'Football', venue: 'Venue' },
  { id: 'netball', name: 'Netball', venue: 'Venue' },
  { id: 'flag-rugby', name: 'Flag Rugby', venue: 'Venue' },
  { id: 'esports', name: 'E-sports', venue: 'Venue' },
  { id: 'volleyball', name: 'Volleyball', venue: 'Venue' },
  { id: 'track-field', name: 'Track & Field', venue: 'Venue' },
];

// State contingents
const TEAMS = {
  ACT: {
    code: 'ACT', name: 'ACT', color: '#7c3aed', logo: 'assets/Logos/ACT.png',
    participation: '2024–2026',
    description: 'ACT has participated from 2024 to 2026, representing a consistent contingent across Muafakat Games.',
    stateSummary: 'Representing Australia’s capital region, Team ACT consists of students, researchers, and young professionals from Canberra and surrounding areas. Many athletes hail from institutions including Australian National University and University of Canberra. Team ACT is known for its determination, close-knit community, and commitment to excellence. They proudly represent the nation’s capital with confidence and ambition.',
    statePhotos: [
      'assets/State_act/ACT/Basketball-32.jpg',
      'assets/State_act/ACT/IMG_2763.JPEG',
      'assets/State_act/ACT/IMG_2766.JPEG',
      'assets/State_act/ACT/IMG_2768.JPEG',
      'assets/State_act/ACT/IMG_2769.JPEG',
      'assets/State_act/ACT/IMG_2770.JPEG',
    ],
  },
  QLD: {
    code: 'QLD', name: 'Queensland', color: '#d61f8f', logo: 'assets/Logos/QLD.png',
    participation: '2024–2026',
    description: 'Queensland has participated from 2024 to 2026, bringing strong energy across sports and team events.',
    stateSummary: 'Representing the tropical and vibrant state of Queensland, Team Queensland consists of students, graduates, and community members from Brisbane, Gold Coast, Sunshine Coast, and beyond. Many members come from institutions such as The University of Queensland, Queensland University of Technology, and Griffith University. Known for their energy, resilience, and positive spirit, the team brings the warmth of the Sunshine State to Muafakat Games 2026 while striving for excellence in every competition.',
    statePhotos: [
      'assets/State_act/QLD/ARF_0661.JPG',
      'assets/State_act/QLD/DSCF0499.JPG',
      'assets/State_act/QLD/DSCF3542.JPG',
      'assets/State_act/QLD/DSCF3635.JPG',
      'assets/State_act/QLD/DSCF7070.JPG',
      'assets/State_act/QLD/DSCF7350.JPG',
      'assets/State_act/QLD/IMG_7086.JPG',
    ],
  },
  VIC: {
    code: 'VIC', name: 'Victoria', color: '#2a52e0', logo: 'assets/Logos/VIC.png',
    participation: '2024–2026',
    win: '2025',
    description: 'Victoria participated in 2024 and 2026, and was also part of the 2025 Muafakat Games cycle.',
    stateSummary: 'Representing the host state for Muafakat Games Melbourne 2026, Team Victoria brings together students and young professionals from universities and communities across Melbourne and regional Victoria, including institutions such as University of Melbourne, Monash University, RMIT University, and Deakin University. The team consists of athletes, volunteers, and emerging leaders who embody the state’s reputation for sporting excellence, diversity, and innovation. Competing on home soil, they are determined to showcase Victorian pride while fostering friendship and unity among all participants.',
    statePhotos: [
      'assets/State_act/VIC/volleyball tryout (victoria).JPG',
      'assets/State_act/VIC/ARF_0587.JPG',
      'assets/State_act/VIC/DSCF6990.JPG',
      'assets/State_act/VIC/DSCF9225.JPG',
      'assets/State_act/VIC/DSCF9305.JPG',
      'assets/State_act/VIC/IMG_6291.JPG',
    ],
  },
  NSW: {
    code: 'NSW', name: 'New South Wales', color: '#0ea5b7', logo: 'assets/Logos/NSW.png',
    participation: '2024–2026',
    win: '2024',
    description: 'New South Wales carries its 2024 champion legacy into Muafakat Games 2026 with a strong sporting squad.',
    stateSummary: 'Representing Australia’s most populous state, Team New South Wales brings together talented participants from Sydney, Newcastle, Wollongong, and regional communities. The team consists of students and professionals from leading institutions such as University of Sydney, UNSW Sydney, Macquarie University, and University of Technology Sydney. With a strong culture of achievement and diversity, Team NSW is ready to compete with passion, discipline, and sportsmanship.',
    statePhotos: [
      'assets/State_act/NSW/DSCF1702.JPG',
      'assets/State_act/NSW/DSCF4110.JPG',
      'assets/State_act/NSW/DSCF7346.JPG',
      'assets/State_act/NSW/DSCF8160.JPG',
      'assets/State_act/NSW/IMG_0267.JPG',
    ],
  },
  SA: {
    code: 'SA', name: 'South Australia', color: '#16a34a', logo: 'assets/Logos/SA.png',
    participation: '2026',
    description: 'South Australia joins Muafakat Games for the first time in 2026, marking a new milestone for the contingent.',
    stateSummary: 'Representing South Australia’s capital city of Adelaide and its surrounding regions, Team South Australia consists of students, graduates, and community members dedicated to sporting excellence and community engagement. Many participants come from institutions such as University of Adelaide, University of South Australia, and Flinders University. The team is driven by perseverance, teamwork, and a shared commitment to representing South Australia with pride and distinction.',
  },
  WA: {
    code: 'WA', name: 'Western Australia', color: '#f5a300', logo: 'assets/Logos/WA.png',
    participation: '2025–2026',
    description: 'Western Australia has participated in 2025 and 2026, representing the west coast with unity and sportsmanship.',
    stateSummary: 'Representing Australia’s vast western frontier, Team Western Australia brings Perth and regional communities stretching across the country’s largest state. The team consists of students and young professionals from institutions such as The University of Western Australia, Curtin University, and Edith Cowan University. United by resilience and determination, they bring a strong sense of camaraderie and pride as they compete on the national stage.',
    statePhotos: [
      'assets/State_act/WA/DSC01125.JPG',
      'assets/State_act/WA/DSCF6601.JPG',
      'assets/State_act/WA/DSCF7749.JPG',
      'assets/State_act/WA/IMG_6581.JPG',
      'assets/State_act/WA/IMG_7054.JPG',
    ],
  },
};
const TEAM_CODES = ['NSW', 'VIC', 'QLD', 'ACT', 'WA', 'SA'];

// Add confirmed match rows as:
// matches: [{ time: '08:00', home: 'Victoria', away: 'New South Wales' }]
// Timed rows may use { start, end, home, away }.
const FIXTURES = [
  { event: 'Basketball Match', sport: 'basketball', title: 'Basketball Fixtures', date: 'Tue · 7 Jul', start: '08:00', end: '14:15', venue: 'Bundha Sports', format: 'Team fixtures',
    matches: [
      { start: '08:00', end: '08:22', home: 'A1', away: 'A2' },
      { start: '08:27', end: '08:49', home: 'B1', away: 'B2' },
      { start: '08:54', end: '09:16', home: 'A3', away: 'A4' },
      { start: '09:21', end: '09:43', home: 'B2', away: 'B3' },
      { start: '09:48', end: '10:10', home: 'A1', away: 'A3' },
      { start: '10:15', end: '10:37', home: 'B1', away: 'B3' },
      { start: '10:42', end: '11:04', home: 'A2', away: 'A4' },
      { start: '11:14', end: '11:36', home: 'A2', away: 'A3' },
      { start: '11:41', end: '12:03', home: 'A1', away: 'A4' },
      { start: '12:13', end: '12:35', home: '1st A', away: '2nd B' },
      { start: '12:40', end: '13:02', home: '1st B', away: '2nd A' },
      { start: '13:12', end: '13:34', home: 'Loser Semi-final 1', away: 'Loser Semi-final 2' },
      { start: '13:39', end: '14:01', home: 'Winner Semi-final 1', away: 'Winner Semi-final 2' },
    ] },
  { event: 'Netball Match', sport: 'netball', title: 'Netball Fixtures', date: 'Tue · 7 Jul', start: '08:30', end: '13:30', venue: 'Bundha Sports', format: 'Team fixtures',
    matches: [
      { start: '08:30', end: '08:45', home: 'Team 1', away: 'Team 2' },
      { start: '08:47', end: '09:02', home: 'Team 3', away: 'Team 4' },
      { start: '09:04', end: '09:19', home: 'Team 1', away: 'Team 5' },
      { start: '09:21', end: '09:36', home: 'Team 2', away: 'Team 3' },
      { start: '09:38', end: '09:53', home: 'Team 4', away: 'Team 5' },
      { start: '09:55', end: '10:10', home: 'Team 1', away: 'Team 3' },
      { start: '10:12', end: '10:27', home: 'Team 2', away: 'Team 4' },
      { start: '10:29', end: '10:44', home: 'Team 3', away: 'Team 5' },
      { start: '10:46', end: '11:01', home: 'Team 1', away: 'Team 4' },
      { start: '11:03', end: '11:18', home: 'Team 2', away: 'Team 5' },
      { start: '11:28', end: '11:46', home: 'Team A', away: 'Team B' },
      { start: '11:51', end: '12:09', home: 'Team C', away: 'Team D' },
      { start: '12:19', end: '12:44', home: '#2 Semi-final', away: '#2 Semi-final' },
      { start: '12:49', end: '13:14', home: '#1 Semi-final', away: '#1 Semi-final' },
    ] },
  { event: 'Volleyball Match', sport: 'volleyball', title: 'Volleyball Fixtures', date: 'Tue · 7 Jul', start: '15:50', end: '21:30', venue: 'SSC Stadium B', format: 'Team fixtures',
    matches: [
      { start: '15:50', end: '16:50', games: [['A', 'B'], ['E', 'F'], ['C', 'D']] },
      { start: '17:00', end: '18:00', games: [['A', 'C'], ['G', 'H'], ['B', 'D']] },
      { start: '18:10', end: '19:10', games: [['E', 'G'], ['F', 'H'], ['A', 'D']] },
      { start: '19:20', end: '20:20', games: [['B', 'C'], ['E', 'H'], ['F', 'G']] },
      { start: '20:30', end: '21:30', games: [['3rd', '4th'], ['1st', '2nd']] },
    ] },
  { event: 'Badminton Singles Match', sport: 'badminton', title: 'Badminton Singles Fixtures', date: 'Tue · 7 Jul', start: '16:00', end: '22:00', venue: 'SSC Stadium D', format: 'Singles fixtures',
    matches: [
      { start: '16:00', end: '16:45', games: [['Men A', 'Men B'], ['Men C', 'Men D'], ['Women A', 'Women B'], ['Women C', 'Women D']] },
      { start: '16:50', end: '17:35', games: [['Men A', 'Men E'], ['Men B', 'Men C'], ['Women A', 'Women E'], ['Women B', 'Women C']] },
      { start: '17:40', end: '18:25', games: [['Men D', 'Men E'], ['Men A', 'Men C'], ['Women D', 'Women E'], ['Women A', 'Women C']] },
      { start: '18:30', end: '19:15', games: [['Men B', 'Men D'], ['Men C', 'Men E'], ['Women B', 'Women D'], ['Women C', 'Women E']] },
      { start: '19:20', end: '20:05', games: [['Men A', 'Men D'], ['Men B', 'Men E'], ['Women A', 'Women D'], ['Women B', 'Women E']] },
      { start: '20:15', end: '21:00', games: [['Men 3rd', 'Men 4th'], ['Women 3rd', 'Women 4th']] },
      { start: '21:05', end: '21:50', games: [['Men 1st', 'Men 2nd'], ['Women 1st', 'Women 2nd']] },
    ] },
  { event: 'Flag Rugby Match', sport: 'flag-rugby', title: 'Flag Rugby Fixtures', date: 'Wed · 8 Jul', start: '08:00', end: '12:00', venue: 'Walker Ovals', format: 'Team fixtures',
    matches: [
      { start: '08:00', end: '08:21', home: 'A', away: 'B' },
      { start: '08:26', end: '08:47', home: 'C', away: 'D' },
      { start: '09:02', end: '09:23', home: 'A', away: 'C' },
      { start: '09:28', end: '09:49', home: 'B', away: 'D' },
      { start: '10:04', end: '10:25', home: 'A', away: 'D' },
      { start: '10:30', end: '10:51', home: 'B', away: 'C' },
      { start: '11:06', end: '11:27', home: '4th', away: '3rd' },
      { start: '11:32', end: '11:53', home: '1st', away: '2nd' },
    ] },
  { event: 'E-Sports Match', sport: 'esports', title: 'E-sports Fixtures', date: 'Wed · 8 Jul', start: '14:00', end: '20:40', venue: 'SSC Anne Henderson Room', format: 'Bracket fixtures',
    matches: [
      { start: '14:00', end: '14:25', games: [['A1', 'A2'], ['B1', 'B2'], ['A3', 'A4']] },
      { start: '14:40', end: '15:05', games: [['B3', 'B1'], ['A1', 'A3'], ['A4', 'A2']] },
      { start: '15:20', end: '15:45', games: [['A2', 'A3'], ['A4', 'A1'], ['B2', 'B3']] },
      { start: '16:05', end: '16:30', home: '#3A', away: '#3B' },
      { start: '16:05', end: '17:11', home: '#1B', away: '#2A' },
      { start: '16:45', end: '17:51', home: '#2B', away: 'Winner Wildcard' },
      { start: '18:10', end: '19:16', home: 'Winner Playoff 1', away: 'Winner Playoff 2' },
      { start: '19:31', end: '20:37', home: '#1A', away: 'Winner Semi-final' },
    ] },
  { event: 'Badminton Doubles Match', sport: 'badminton', title: 'Badminton Doubles Fixtures', date: 'Wed · 8 Jul', start: '16:30', end: '21:30', venue: 'SSC Stadium D', format: 'Doubles fixtures',
    matches: [
      { start: '16:30', end: '17:00', games: [['D', 'E'], ['A', 'B']] },
      { start: '17:05', end: '17:35', games: [['B', 'D'], ['A', 'E']] },
      { start: '17:40', end: '18:10', games: [['A', 'D'], ['C', 'E']] },
      { start: '18:15', end: '18:45', games: [['A', 'C'], ['B', 'E']] },
      { start: '18:50', end: '19:20', home: 'B', away: 'C' },
      { start: '19:25', end: '19:55', home: 'C', away: 'D' },
      { start: '20:05', end: '20:35', home: '3rd', away: '4th' },
      { start: '20:40', end: '21:10', home: '1st', away: '2nd' },
    ] },
  { event: 'Track and Field Match', sport: 'track-field', title: 'Track & Field Events', date: 'Thu · 9 Jul', start: '09:00', end: '11:00', venue: 'MSAC Lakeside', format: 'Event programme',
    matches: [
      { time: '09:00', event: 'Men 100m Heat 1', participants: 'Men' },
      { time: '09:10', event: 'Men 100m Heat 2', participants: 'Men' },
      { time: '09:20', event: 'Women 100m Heat 1', participants: 'Women' },
      { time: '09:30', event: 'Women 100m Heat 2', participants: 'Women' },
      { time: '09:40', event: 'Men 100m Final', participants: 'Men' },
      { time: '09:50', event: 'Women 100m Final', participants: 'Women' },
      { time: '10:05', event: 'Men 1500m Final', participants: 'Men' },
      { time: '10:20', event: 'Women 1500m Final', participants: 'Women' },
      { time: '10:40', event: 'Mixed 4×100m Final', participants: 'Mixed' },
    ] },
  { event: 'Football Match', sport: 'football', title: 'Football Fixtures', date: 'Thu · 9 Jul', start: '11:15', end: '16:35', venue: 'Flemington Road Oval', format: 'Team fixtures',
    matches: [
      { start: '11:15', end: '11:50', home: 'A', away: 'B' },
      { start: '11:55', end: '12:30', home: 'C', away: 'D' },
      { start: '12:35', end: '13:10', home: 'A', away: 'C' },
      { start: '13:15', end: '13:50', home: 'B', away: 'D' },
      { start: '13:55', end: '14:30', home: 'A', away: 'D' },
      { start: '14:35', end: '15:10', home: 'B', away: 'C' },
      { start: '15:20', end: '15:55', home: '3rd', away: '4th' },
      { start: '16:00', end: '16:35', home: '1st', away: '2nd' },
    ] },
];

const SOCIAL_LINKS = {
  email: 'muafakat.au@gmail.com',
  emailHref: 'mailto:muafakat.au@gmail.com',
  instagram: 'https://www.instagram.com/muafakatgames/',
  facebook: 'https://www.facebook.com/share/1CTrhhkr3H/?mibextid=wwXIfr',
  tiktok: 'https://www.tiktok.com/@muafakatgames',
  linkedin: 'https://www.linkedin.com/in/muafakat-games',
};
const SOCIAL_ORDER = ['instagram', 'facebook', 'tiktok', 'linkedin'];

const VENUE_PHOTOS = {
  'N/A': 'assets/Venues/arrival.jpg',
  'The Couch': 'assets/Venues/thecouch.jpeg',
  'Bundha Sports': 'assets/Venues/bundasports.jpg',
  'SSC Stadium B': 'assets/Venues/ssc.jpg',
  'SSC Stadium D': 'assets/Venues/ssc.jpg',
  'SSC Anne Henderson Room': 'assets/Venues/ssc.jpg',
  'Walker Ovals': 'assets/Venues/smithwalkeroval.jpg',
  'MSAC Lakeside': 'assets/Venues/msaclakeside.jpg',
  'Flemington Road Oval': 'assets/Venues/smithwalkeroval.jpg',
  'The Edge, Federation Square': 'assets/Venues/theedge.jpg',
};

// ----------------------------------------------------------------------------
// fetchLiveScores() — API-ready data fetch.
// Currently returns deterministic mock data shaped like a typical sports feed.
// >>> TO WIRE THE REAL SPORTALL MY API <<<
//   const res = await fetch('https://api.sportall.my/v1/muafakat/2026/scores', {
//     headers: { Authorization: `Bearer ${API_KEY}` },
//   });
//   const json = await res.json();
//   return normalizeSportall(json);   // map their shape -> the shape below
// The UI only depends on the returned shape, so swapping the source is enough.
// ----------------------------------------------------------------------------
function winnerFromScore(home, away, status) {
  if (status === 'upcoming' || home.score === away.score) return null;
  return home.score > away.score ? home : away;
}

function mockSetDetails(seed, home, away) {
  const homeWins = home.score > away.score;
  const setCount = 2 + seed % 2;
  return Array.from({ length: setCount }, (_, i) => {
    const homeSet = 19 + (seed + i * 2) % 4;
    const awaySet = 18 + (seed + i * 3) % 5;
    const homeScore = i === setCount - 1 && homeWins ? Math.max(homeSet, awaySet + 2) : homeSet;
    const awayScore = i === setCount - 1 && !homeWins ? Math.max(awaySet, homeSet + 2) : awaySet;
    return { label: `Set ${i + 1}`, home: homeScore, away: awayScore };
  });
}

function mockScorers(seed, sportId, home, away) {
  const labels = {
    basketball: ['2PT', '3PT', 'Free throw', 'Fast break'],
    netball: ['Goal', 'Goal', 'Penalty goal', 'Goal'],
    football: ['Goal', 'Assist', 'Goal', 'Penalty'],
    'flag-rugby': ['Try', 'Conversion', 'Try', 'Try'],
  };
  const events = labels[sportId] || ['Score'];
  return Array.from({ length: 5 }, (_, i) => {
    const team = i % 2 === 0 ? home : away;
    return {
      team: team.code,
      name: `${team.code} Player ${((seed + i) % 9) + 1}`,
      detail: events[i % events.length],
      time: `${8 + i * 6}'`,
    };
  });
}

function mockTrackTimes(seed) {
  const raceEvents = ['100m Race', '200m Race', '4×100m Relay'];
  const teams = ['QLD', 'VIC', 'SA', 'NSW'];
  const event = raceEvents[seed % raceEvents.length];
  const base = event === '200m Race' ? 24 : event === '4×100m Relay' ? 48 : 12;
  const entrants = teams.map((code, i) => ({
    team: TEAMS[code],
    athlete: event === '4×100m Relay' ? `${code} Relay Team` : `${code} Runner ${i + 1}`,
    offset: i * 13,
  }));
  return entrants.map((entry) => ({
    team: entry.team.code,
    athlete: entry.athlete,
    event,
    time: `${base + ((seed + entry.offset) % 45) / 100}s`,
  })).sort((a, b) => parseFloat(a.time) - parseFloat(b.time)).map((entry, i) => ({ ...entry, rank: i + 1 }));
}

function mockScoreDetails(seed, sportId, home, away, status) {
  if (['badminton', 'volleyball'].includes(sportId)) {
    return { type: 'sets', sets: status === 'upcoming' ? [] : mockSetDetails(seed, home, away) };
  }
  if (['basketball', 'netball', 'football', 'flag-rugby'].includes(sportId)) {
    return { type: 'scorers', scorers: status === 'upcoming' ? [] : mockScorers(seed, sportId, home, away) };
  }
  if (sportId === 'track-field') {
    return { type: 'track', event: `${['100m Race', '200m Race', '4×100m Relay'][seed % 3]}`, times: status === 'upcoming' ? [] : mockTrackTimes(seed) };
  }
  if (sportId === 'esports') {
    const winner = winnerFromScore(home, away, status);
    return {
      type: 'esports',
      finalScore: status === 'upcoming' ? 'TBD' : `${home.score} - ${away.score}`,
      winner: winner ? winner.name : 'TBD',
    };
  }
  return { type: 'score' };
}

function mockMatch(seed, sportId) {
  // deterministic-ish pseudo data based on seed
  const a = TEAM_CODES[seed % TEAM_CODES.length];
  const b = TEAM_CODES[(seed + 2) % TEAM_CODES.length];
  const statuses = ['live', 'live', 'upcoming', 'final'];
  const status = statuses[seed % statuses.length];
  const big = ['football', 'basketball', 'netball', 'volleyball'].includes(sportId);
  const base = big ? 12 : 1;
  const home = { ...TEAMS[a], score: status === 'upcoming' ? null : base + (seed * 3) % 9 };
  const away = { ...TEAMS[b], score: status === 'upcoming' ? null : base + (seed * 5) % 7 };
  const livePeriod = sportId === 'track-field' ? `Heat ${1 + seed % 3}`
    : sportId === 'esports' ? `Game ${1 + seed % 3}`
    : ['badminton', 'volleyball'].includes(sportId) ? `Set ${1 + seed % 3}`
    : `Q${1 + seed % 4}`;
  return {
    id: `${sportId}-${seed}`,
    home,
    away,
    status,
    period: status === 'live' ? livePeriod
      : status === 'final' ? 'Full time'
      : 'Today 14:30',
    court: sportId === 'track-field' ? `Track ${1 + seed % 3}`
      : sportId === 'esports' ? `Station ${1 + seed % 3}`
      : `Court ${1 + seed % 3}`,
    details: mockScoreDetails(seed, sportId, home, away, status),
  };
}

async function fetchLiveScores() {
  // simulate latency
  await new Promise((r) => setTimeout(r, 350));
  return SPORTS.map((s, i) => ({
    ...s,
    matches: [mockMatch(i + 1, s.id), mockMatch(i + 4, s.id)],
  }));
}

// --- Real asset paths -------------------------------------------------------
const ASSETS = {
  logoMuafakat: 'assets/logo-muafakat.png',
  emblem: 'assets/emblem.png',
  faceTiger: 'assets/face-rimau.png',
  faceKoala: 'assets/face-koko.png',
  duo: 'assets/duo.png',
  logoEma: 'assets/logo-ema.png',
  logoConsulate: 'assets/logo-consulate.jpg',
  logoSportall: 'assets/sportall.png',
  logoWa: 'assets/logo-wa.png',
  header: 'assets/header.png',
  footerKoko: 'assets/footer-koko.png',
  footerRimau: 'assets/footer-rimau.png',
  cendawantech: 'assets/cendawantech.png',
  medal: 'assets/photo-medal.jpg',
  committee: 'assets/photo-committee.jpg',
  events: [
    'assets/Events/A.Main-Slideshow-Photo.jpg',
    'assets/Events/Event-Photo-10.JPG',
    'assets/Events/Event-Photo-1.JPG',
    'assets/Events/Event-Photo-2.JPG',
    'assets/Events/Event-Photo-3.jpg',
    'assets/Events/Event-Photo-4.JPG',
    'assets/Events/Event-Photo-5.JPG',
    'assets/Events/Event-Photo-6.JPG',
    'assets/Events/Event-Photo-7.JPG',
    'assets/Events/Event-Photo-8.JPG',
    'assets/Events/Event-Photo-9.JPG',
    'assets/Events/Medal-Photo.JPG',
    'assets/Events/Opening-2.jpg',
    'assets/Events/Sports-Basketball.jpg',
    'assets/Events/Sports-E-Sports-1.jpg',
    'assets/Events/Sports-E-Sports-2.jpg',
    'assets/Events/Sports-Flag-Rugby.JPG',
    'assets/Events/Sports-Football.jpg',
    'assets/Events/Sports-Volleyball.jpg',
    'assets/Events/Team-Pic-1.JPG',
    'assets/Events/Team-Pic-2.jpg',
  ],
  pic: {
    badminton: 'assets/pic/badminton.png', basketball: 'assets/pic/basketball.png',
    football: 'assets/pic/football.png', netball: 'assets/pic/netball.png',
    'flag-rugby': 'assets/pic/flag-rugby.png', esports: 'assets/pic/esports.png',
    volleyball: 'assets/pic/volleyball.png', 'track-field': 'assets/pic/track-field.png',
  },
};

// ----------------------------------------------------------------------------
// Ph — renders a real image when `src` is given, else a striped placeholder
// with a monospace label. `fit` controls object-fit (cover|contain).
// ----------------------------------------------------------------------------
function Ph({ label, src, fit = 'cover', dark = false, className = '', style = {}, children }) {
  if (src) {
    return (
      <div className={`ph ph--img ${className}`} style={style}>
        <img src={src} alt={label} className="ph__img" style={{ objectFit: fit }} />
        {children}
      </div>
    );
  }
  return (
    <div className={`ph ${dark ? 'ph--dark' : ''} ${className}`} style={style}>
      {children}
      <span className="ph__label">{label}</span>
    </div>
  );
}

// ----------------------------------------------------------------------------
// Minimal line icons (mail / instagram / facebook / linkedin / arrow / chevron)
// ----------------------------------------------------------------------------
const Icon = {
  mail: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}>
      <rect x="3" y="5" width="18" height="14" rx="2" /><path d="m3 7 9 6 9-6" />
    </svg>
  ),
  instagram: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}>
      <rect x="3" y="3" width="18" height="18" rx="5" /><circle cx="12" cy="12" r="4" />
      <circle cx="17.5" cy="6.5" r="1.2" fill="currentColor" stroke="none" />
    </svg>
  ),
  facebook: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M14 9h3l.5-3.5H14V3.8c0-1 .3-1.6 1.7-1.6H17V-.9C16.7-1 15.6-1 14.4-1 11.9-1 10-.5 10 2.6V5.5H7V9h3v11h4V9Z" transform="translate(0 1)" />
    </svg>
  ),
  tiktok: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M16.6 2c.4 3 2.1 4.8 5 5v3.4c-1.8.1-3.5-.5-5-1.6v6.2c0 4.2-2.7 6.7-6.4 6.7-3.4 0-6.2-2.5-6.2-5.8 0-3.8 3.5-6.5 7.8-5.7v3.5c-2.2-.7-4.1.4-4.1 2.1 0 1.3 1.1 2.3 2.5 2.3 1.6 0 2.7-.9 2.7-3.1V2h3.7Z" />
    </svg>
  ),
  linkedin: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M4.98 3.5A2.5 2.5 0 1 0 5 8.5a2.5 2.5 0 0 0-.02-5ZM3 9.5h4V21H3V9.5Zm6 0h3.8v1.57h.05c.53-1 1.83-2.07 3.77-2.07 4.03 0 4.78 2.65 4.78 6.1V21h-4v-5.1c0-1.22-.02-2.78-1.7-2.78-1.7 0-1.96 1.33-1.96 2.69V21H9V9.5Z" />
    </svg>
  ),
  arrow: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 12h14M13 6l6 6-6 6" />
    </svg>
  ),
  chevron: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="m6 9 6 6 6-6" />
    </svg>
  ),
  menu: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" {...p}>
      <path d="M4 7h16M4 12h16M4 17h16" />
    </svg>
  ),
  pin: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M12 21s7-6.3 7-11a7 7 0 1 0-14 0c0 4.7 7 11 7 11Z" /><circle cx="12" cy="10" r="2.6" />
    </svg>
  ),
  close: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" {...p}>
      <path d="M6 6l12 12M18 6 6 18" />
    </svg>
  ),
};

Object.assign(window, {
  GAMES_DATE, NAV, PILLARS, SCHEDULE, COMMITTEE, SPORTS, TEAMS, TEAM_CODES, FIXTURES, VENUE_PHOTOS,
  fetchLiveScores, Ph, Icon, ASSETS,
  useState, useEffect, useRef, useCallback,
});
