#4991 ATC Simulation Training Data

#4991 ATC Simulation Training Data

What We Heard in the Moments Before the FAA’s Nationwide Ground Stop

https://www.youtube.com/shorts/NaJtUQgQKv4?feature=share

  1. Create data for a air traffic control simulation involving 10 airports with 10 planes each.
  2. Add flight schedules
  3. Provide an application specification for an air traffic control application with selectable dashboards for each airport
  4. Build a single-file interactive React and HTML5 Canvas prototype of this 10-airport ATC dashboard preloaded with the 10-airport and 100-plane dataset.

#4991 Create data for a air traffic control simulation involving 10 airports with 10 planes each.

Below is a deterministic, relational dataset for an air traffic control (ATC) simulation comprising 10 major US hub airports and 100 active flights (10 per airport) operating across various flight phases (ground taxi, departure climb, en-route cruise, terminal arrival, and holding patterns).

The data uses realistic ICAO codes, coordinates, runways, aircraft performance envelopes, and initial state vectors ready for ingestion into a discrete-event or continuous-time simulation engine.

1. Airport Nodes (airports.json)

Each airport defines spatial coordinates, field elevation, primary active runways (with true headings), and terminal airspace control radii.

[
  {
    "icao": "KATL",
    "iata": "ATL",
    "name": "Hartsfield-Jackson Atlanta International",
    "lat": 33.6407,
    "lon": -84.4277,
    "elevation_ft": 1026,
    "tracon_radius_nm": 40,
    "runways": [
      { "id": "08L/26R", "heading_deg": 90, "length_ft": 9000, "status": "ACTIVE_ARR" },
      { "id": "08R/26L", "heading_deg": 90, "length_ft": 10000, "status": "ACTIVE_DEP" },
      { "id": "09L/27R", "heading_deg": 90, "length_ft": 12390, "status": "ACTIVE_DEP" },
      { "id": "09R/27L", "heading_deg": 90, "length_ft": 9000, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KDFW",
    "iata": "DFW",
    "name": "Dallas/Fort Worth International",
    "lat": 32.8998,
    "lon": -97.0403,
    "elevation_ft": 607,
    "tracon_radius_nm": 45,
    "runways": [
      { "id": "17C/35C", "heading_deg": 175, "length_ft": 13401, "status": "ACTIVE_DEP" },
      { "id": "17L/35R", "heading_deg": 175, "length_ft": 8500, "status": "ACTIVE_ARR" },
      { "id": "18R/36L", "heading_deg": 175, "length_ft": 13400, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KDEN",
    "iata": "DEN",
    "name": "Denver International",
    "lat": 39.8561,
    "lon": -104.6737,
    "elevation_ft": 5434,
    "tracon_radius_nm": 50,
    "runways": [
      { "id": "16R/34L", "heading_deg": 170, "length_ft": 16000, "status": "ACTIVE_DEP" },
      { "id": "16L/34R", "heading_deg": 170, "length_ft": 12000, "status": "ACTIVE_ARR" },
      { "id": "08/26", "heading_deg": 90, "length_deg": 12000, "status": "ACTIVE_DEP" }
    ]
  },
  {
    "icao": "KORD",
    "iata": "ORD",
    "name": "Chicago O'Hare International",
    "lat": 41.9742,
    "lon": -87.9073,
    "elevation_ft": 680,
    "tracon_radius_nm": 40,
    "runways": [
      { "id": "09C/27C", "heading_deg": 90, "length_ft": 11245, "status": "ACTIVE_ARR" },
      { "id": "10L/28R", "heading_deg": 90, "length_ft": 13000, "status": "ACTIVE_DEP" },
      { "id": "10C/28C", "heading_deg": 90, "length_ft": 10801, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KLAX",
    "iata": "LAX",
    "name": "Los Angeles International",
    "lat": 33.9416,
    "lon": -118.4085,
    "elevation_ft": 128,
    "tracon_radius_nm": 40,
    "runways": [
      { "id": "06L/24R", "heading_deg": 249, "length_ft": 8926, "status": "ACTIVE_ARR" },
      { "id": "06R/24L", "heading_deg": 249, "length_ft": 10885, "status": "ACTIVE_DEP" },
      { "id": "07L/25R", "heading_deg": 249, "length_ft": 12923, "status": "ACTIVE_DEP" },
      { "id": "07R/25L", "heading_deg": 249, "length_ft": 11095, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KJFK",
    "iata": "JFK",
    "name": "John F. Kennedy International",
    "lat": 40.6413,
    "lon": -73.7781,
    "elevation_ft": 13,
    "tracon_radius_nm": 35,
    "runways": [
      { "id": "04L/22R", "heading_deg": 44, "length_ft": 12079, "status": "ACTIVE_DEP" },
      { "id": "04R/22L", "heading_deg": 44, "length_ft": 8400, "status": "ACTIVE_ARR" },
      { "id": "13R/31L", "heading_deg": 134, "length_ft": 14511, "status": "ACTIVE_DEP" }
    ]
  },
  {
    "icao": "KIAH",
    "iata": "IAH",
    "name": "George Bush Intercontinental",
    "lat": 29.9902,
    "lon": -95.3368,
    "elevation_ft": 97,
    "tracon_radius_nm": 40,
    "runways": [
      { "id": "08L/26R", "heading_deg": 90, "length_ft": 9000, "status": "ACTIVE_ARR" },
      { "id": "08R/26L", "heading_deg": 90, "length_ft": 9402, "status": "ACTIVE_DEP" },
      { "id": "09/27", "heading_deg": 90, "length_ft": 10000, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KSFO",
    "iata": "SFO",
    "name": "San Francisco International",
    "lat": 37.6213,
    "lon": -122.3790,
    "elevation_ft": 13,
    "tracon_radius_nm": 35,
    "runways": [
      { "id": "01L/19R", "heading_deg": 12, "length_ft": 7650, "status": "ACTIVE_DEP" },
      { "id": "01R/19L", "heading_deg": 12, "length_ft": 8650, "status": "ACTIVE_DEP" },
      { "id": "10L/28R", "heading_deg": 284, "length_ft": 11870, "status": "ACTIVE_ARR" },
      { "id": "10R/28L", "heading_deg": 284, "length_ft": 11381, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KSEA",
    "iata": "SEA",
    "name": "Seattle-Tacoma International",
    "lat": 47.4502,
    "lon": -122.3088,
    "elevation_ft": 433,
    "tracon_radius_nm": 40,
    "runways": [
      { "id": "16L/34R", "heading_deg": 164, "length_ft": 11901, "status": "ACTIVE_DEP" },
      { "id": "16C/34C", "heading_deg": 164, "length_ft": 9426, "status": "ACTIVE_ARR" },
      { "id": "16R/34L", "heading_deg": 164, "length_ft": 8500, "status": "ACTIVE_ARR" }
    ]
  },
  {
    "icao": "KMIA",
    "iata": "MIA",
    "name": "Miami International",
    "lat": 25.7959,
    "lon": -80.2870,
    "elevation_ft": 9,
    "tracon_radius_nm": 35,
    "runways": [
      { "id": "08L/26R", "heading_deg": 92, "length_ft": 8600, "status": "ACTIVE_ARR" },
      { "id": "08R/26L", "heading_deg": 92, "length_ft": 10506, "status": "ACTIVE_DEP" },
      { "id": "09/27", "heading_deg": 92, "length_ft": 13016, "status": "ACTIVE_DEP" }
    ]
  }
]

2. Aircraft Performance Lookup (aircraft_types.json)

Standard wake turbulence categories (L = Light, M = Medium, H = Heavy, J = Super) and kinematic limits for separation and physics calculations.

{
  "B738": { "wake": "M", "cruise_tas_kts": 450, "climb_fpm": 2200, "descent_fpm": 1800, "approach_kts": 142 },
  "A321": { "wake": "M", "cruise_tas_kts": 455, "climb_fpm": 2100, "descent_fpm": 1800, "approach_kts": 145 },
  "B77W": { "wake": "H", "cruise_tas_kts": 490, "climb_fpm": 2400, "descent_fpm": 2000, "approach_kts": 152 },
  "B789": { "wake": "H", "cruise_tas_kts": 488, "climb_fpm": 2500, "descent_fpm": 2000, "approach_kts": 148 },
  "A359": { "wake": "H", "cruise_tas_kts": 492, "climb_fpm": 2500, "descent_fpm": 2000, "approach_kts": 146 },
  "E75L": { "wake": "M", "cruise_tas_kts": 430, "climb_fpm": 1900, "descent_fpm": 1600, "approach_kts": 132 },
  "CRJ9": { "wake": "M", "cruise_tas_kts": 425, "climb_fpm": 1850, "descent_fpm": 1600, "approach_kts": 135 }
}

3. Active Flight Roster — 100 Aircraft (flights.csv)

Each airport is assigned 10 aircraft (assigned_sector) distributed across realistic operational states:

  • 2 Ground/Taxi (TAXI_OUT, HOLD_SHORT): Ready for departure sequencing.

  • 3 Departures (CLIMB): Climbing out of TRACON toward cruise altitude.

  • 3 Arrivals (DESCENT, APPROACH): Sequenced onto arrival fixes and final approach courses.

  • 2 En-Route/Holding (CRUISE, HOLDING): Transitioning sector boundaries or orbiting at a metering fix.

callsign,ac_type,assigned_sector,origin,destination,phase,lat,lon,altitude_ft,heading_deg,groundspeed_kts,vertical_rate_fpm,squawk,fuel_lbs
DAL101,B738,KATL,KATL,KJFK,TAXI_OUT,33.6380,-84.4320,1026,90,15,0,2101,18500
DAL102,A321,KATL,KATL,KLAX,HOLD_SHORT,33.6355,-84.4410,1026,90,0,0,2102,34200
DAL103,B738,KATL,KATL,KORD,CLIMB,33.7820,-84.4510,8400,355,250,2400,2103,21000
DAL104,E75L,KATL,KATL,KMIA,CLIMB,33.4100,-84.3120,14200,162,285,2100,2104,11400
DAL105,B77W,KATL,KATL,KSFO,CLIMB,33.7150,-84.6800,19500,285,330,2600,2105,78000
DAL106,A321,KATL,KDFW,KATL,DESCENT,33.5900,-84.8900,11000,88,260,-1800,2106,9200
DAL107,B738,KATL,KJFK,KATL,APPROACH,33.6407,-84.6100,3200,90,165,-850,2107,7400
DAL108,CRJ9,KATL,KIAH,KATL,APPROACH,33.6310,-84.5400,2100,90,145,-720,2108,4100
SWA109,B738,KATL,KDEN,KATL,HOLDING,33.8500,-84.7500,15000,180,220,0,2109,11200
AAL110,A321,KATL,KMIA,KORD,CRUISE,33.9200,-84.2100,35000,342,455,0,2110,24500
AAL201,B738,KDFW,KDFW,KDEN,TAXI_OUT,32.8950,-97.0380,607,175,18,0,2201,19200
AAL202,B789,KDFW,KDFW,KLAX,HOLD_SHORT,32.9120,-97.0420,607,175,0,0,2202,62000
AAL203,A321,KDFW,KDFW,KJFK,CLIMB,33.0800,-96.8500,9600,52,265,2300,2203,26800
AAL204,E75L,KDFW,KDFW,KIAH,CLIMB,32.6500,-96.9500,11200,155,270,1950,2204,8900
AAL205,B77W,KDFW,KDFW,KSEA,CLIMB,33.1500,-97.3200,18400,320,325,2500,2205,71500
AAL206,B738,KDFW,KORD,KDFW,DESCENT,33.3100,-96.8800,12500,205,270,-1900,2206,8800
AAL207,A321,KDFW,KATL,KDFW,APPROACH,33.0400,-97.0280,3500,175,170,-820,2207,7900
AAL208,CRJ9,KDFW,KIAH,KDFW,APPROACH,32.9800,-97.0520,2200,175,148,-700,2208,3800
SWA209,B738,KDFW,KLAX,KDFW,HOLDING,32.7800,-97.4500,14000,90,215,0,2209,10400
UAL210,B738,KDFW,KIAH,KDEN,CRUISE,33.1200,-97.5100,36000,325,450,0,2210,21300
UAL301,B738,KDEN,KDEN,KSFO,TAXI_OUT,39.8510,-104.6710,5434,170,16,0,2301,18900
UAL302,A321,KDEN,KDEN,KORD,HOLD_SHORT,39.8720,-104.6780,5434,170,0,0,2302,22400
UAL303,B738,KDEN,KDEN,KSEA,CLIMB,40.0900,-104.9200,13800,315,275,2200,2303,20500
UAL304,E75L,KDEN,KDEN,KDFW,CLIMB,39.5800,-104.4500,15200,145,280,1900,2304,10200
UAL305,B789,KDEN,KDEN,KJFK,CLIMB,39.9500,-104.1200,21000,82,340,2450,2305,58000
SWA306,B738,KDEN,KLAX,KDEN,DESCENT,39.4800,-105.1200,16500,48,280,-1850,2306,9600
UAL307,A321,KDEN,KORD,KDEN,APPROACH,40.0400,-104.6650,8200,170,175,-880,2307,8100
UAL308,CRJ9,KDEN,KSEA,KDEN,APPROACH,39.9600,-104.6820,6900,170,150,-750,2308,4300
FFT309,A321,KDEN,KMIA,KDEN,HOLDING,39.6200,-104.1800,17000,270,225,0,2309,11500
DAL310,B738,KDEN,KSFO,KATL,CRUISE,39.7100,-104.8800,37000,108,465,0,2310,27800
UAL401,A321,KORD,KORD,KJFK,TAXI_OUT,41.9710,-87.9010,680,90,14,0,2401,19800
AAL402,B738,KORD,KORD,KDFW,HOLD_SHORT,41.9680,-87.9250,680,90,0,0,2402,21100
UAL403,B77W,KORD,KORD,KSFO,CLIMB,42.0200,-88.2500,11500,275,285,2550,2403,74000
AAL404,E75L,KORD,KORD,KATL,CLIMB,41.7200,-87.7500,9800,158,260,2000,2404,9500
UAL405,B738,KORD,KORD,KDEN,CLIMB,41.9500,-88.4100,16400,268,310,2250,2405,19400
DAL406,B738,KORD,KATL,KORD,DESCENT,41.5500,-88.1500,12000,350,265,-1800,2406,8700
AAL407,A321,KORD,KLAX,KORD,APPROACH,41.9810,-88.1200,3400,90,168,-800,2407,8400
UAL408,CRJ9,KORD,KDEN,KORD,APPROACH,41.9690,-88.0300,2100,90,145,-710,2408,3900
SWA409,B738,KORD,KDFW,KORD,HOLDING,41.6800,-88.4500,14000,45,215,0,2409,10800
DAL410,A359,KORD,KSEA,KJFK,CRUISE,42.1800,-87.6200,39000,98,495,0,2410,64000
AAL501,A321,KLAX,KLAX,KJFK,TAXI_OUT,33.9440,-118.4020,128,249,17,0,2501,42500
DAL502,B738,KLAX,KLAX,KATL,HOLD_SHORT,33.9470,-118.3910,128,249,0,0,2502,36000
UAL503,B789,KLAX,KLAX,KORD,CLIMB,34.0800,-118.1200,12400,58,290,2500,2503,54000
SWA504,B738,KLAX,KLAX,KSFO,CLIMB,34.1900,-118.5800,10800,322,275,2200,2504,14200
AAL505,B77W,KLAX,KLAX,KMIA,CLIMB,33.8800,-117.9500,17800,96,335,2450,2505,69000
DAL506,A321,KLAX,KATL,KLAX,DESCENT,34.0500,-117.8500,11500,255,260,-1850,2506,9500
UAL507,B738,KLAX,KDEN,KLAX,APPROACH,33.9850,-118.2100,3100,249,165,-810,2507,7800
ASA508,E75L,KLAX,KSEA,KLAX,APPROACH,33.9620,-118.3100,1900,249,142,-690,2508,4600
JBU509,A321,KLAX,KJFK,KLAX,HOLDING,33.8200,-117.7200,15000,270,220,0,2509,12100
SWA510,B738,KLAX,KSFO,KDFW,CRUISE,34.1100,-118.0500,35000,104,455,0,2510,23100
JBU601,A321,KJFK,KJFK,KLAX,TAXI_OUT,40.6380,-73.7820,13,44,15,0,2601,44000
DAL602,B738,KJFK,KJFK,KMIA,HOLD_SHORT,40.6320,-73.7890,13,44,0,0,2602,22800
AAL603,B77W,KJFK,KJFK,KSFO,CLIMB,40.7800,-74.0500,13200,282,295,2450,2603,82000
JBU604,E75L,KJFK,KJFK,KORD,CLIMB,40.8200,-73.9800,10400,295,265,1950,2604,13500
DAL605,A359,KJFK,KJFK,KSEA,CLIMB,40.9100,-74.1200,18900,302,340,2600,2605,79500
AAL606,B738,KJFK,KDFW,KJFK,DESCENT,40.3200,-74.1500,11800,42,265,-1800,2606,9100
DAL607,A321,KJFK,KATL,KJFK,APPROACH,40.5100,-73.9100,2900,44,162,-790,2607,8200
JBU608,A321,KJFK,KMIA,KJFK,APPROACH,40.5700,-73.8500,1800,44,148,-710,2608,7600
UAL609,B738,KJFK,KDEN,KJFK,HOLDING,40.4500,-74.3500,14000,90,215,0,2609,11000
AAL610,B789,KJFK,KMIA,KORD,CRUISE,40.7200,-74.2200,38000,312,485,0,2610,49000
UAL701,B738,KIAH,KIAH,KDEN,TAXI_OUT,29.9880,-95.3410,97,90,16,0,2701,19500
UAL702,A321,KIAH,KIAH,KORD,HOLD_SHORT,29.9850,-95.3520,97,90,0,0,2702,21600
UAL703,B789,KIAH,KIAH,KSFO,CLIMB,30.1500,-95.6200,12800,295,290,2500,2703,56000
UAL704,E75L,KIAH,KIAH,KDFW,CLIMB,30.2800,-95.4800,10200,338,260,1900,2704,8400
UAL705,B738,KIAH,KIAH,KMIA,CLIMB,29.8500,-94.9500,16500,108,315,2250,2705,18800
AAL706,B738,KIAH,KDFW,KIAH,DESCENT,30.3500,-95.6800,11200,148,260,-1800,2706,8500
DAL707,A321,KIAH,KATL,KIAH,APPROACH,29.9902,-95.5200,3100,90,165,-810,2707,7900
UAL708,CRJ9,KIAH,KDEN,KIAH,APPROACH,29.9850,-95.4400,2000,90,145,-700,2708,4000
SWA709,B738,KIAH,KLAX,KIAH,HOLDING,29.8200,-95.7800,15000,90,220,0,2709,10900
AAL710,B738,KIAH,KMIA,KDFW,CRUISE,30.1200,-95.1800,36000,318,450,0,2710,20400
UAL801,B738,KSFO,KSFO,KDEN,TAXI_OUT,37.6180,-122.3750,13,12,15,0,2801,19100
ASA802,A321,KSFO,KSFO,KSEA,HOLD_SHORT,37.6140,-122.3790,13,12,0,0,2802,17500
UAL803,B77W,KSFO,KSFO,KJFK,CLIMB,37.7800,-122.1200,13500,65,295,2450,2803,81000
DAL804,B738,KSFO,KSFO,KLAX,CLIMB,37.3800,-122.2500,10600,145,270,2200,2804,13800
UAL805,A359,KSFO,KSFO,KORD,CLIMB,37.8500,-121.9500,19200,62,335,2550,2805,68000
SWA806,B738,KSFO,KLAX,KSFO,DESCENT,37.3200,-121.8500,11400,310,260,-1800,2806,8900
UAL807,A321,KSFO,KDEN,KSFO,APPROACH,37.5500,-122.1500,3200,284,165,-820,2807,8100
ASA808,E75L,KSFO,KSEA,KSFO,APPROACH,37.5900,-122.2600,2000,284,142,-700,2808,4500
AAL809,B738,KSFO,KDFW,KSFO,HOLDING,37.4200,-121.6500,14000,270,215,0,2809,10600
DAL810,B789,KSFO,KSEA,KLAX,CRUISE,37.7100,-122.0500,37000,152,485,0,2810,46000
ASA901,B738,KSEA,KSEA,KDEN,TAXI_OUT,47.4480,-122.3050,433,164,16,0,2901,19600
DAL902,A321,KSEA,KSEA,KATL,HOLD_SHORT,47.4620,-122.3090,433,164,0,0,2902,38500
ASA903,B738,KSEA,KSEA,KSFO,CLIMB,47.1800,-122.3200,11200,178,275,2250,2903,16400
DAL904,B789,KSEA,KSEA,KJFK,CLIMB,47.3800,-121.9500,14800,98,300,2500,2904,61000
UAL905,B738,KSEA,KSEA,KORD,CLIMB,47.4200,-121.7500,18500,95,325,2300,2905,31200
ASA906,E75L,KSEA,KSFO,KSEA,DESCENT,47.8200,-122.2800,11600,172,255,-1750,2906,7200
DAL907,A321,KSEA,KATL,KSEA,APPROACH,47.6200,-122.3088,3400,164,168,-830,2907,8500
ASA908,B738,KSEA,KLAX,KSEA,APPROACH,47.5400,-122.3088,2100,164,145,-710,2908,7900
SWA909,B738,KSEA,KDEN,KSEA,HOLDING,47.7500,-121.9000,15000,270,220,0,2909,11100
UAL910,B77W,KSEA,KSFO,KORD,CRUISE,47.2500,-122.1000,37000,94,490,0,2910,67500
AAL001,B738,KMIA,KMIA,KDFW,TAXI_OUT,25.7930,-80.2890,9,92,15,0,3001,21400
DAL002,A321,KMIA,KMIA,KATL,HOLD_SHORT,25.7910,-80.3010,9,92,0,0,3002,16800
AAL003,B77W,KMIA,KMIA,KLAX,CLIMB,25.9200,-80.5800,12600,285,290,2450,3003,76500
JBU004,A321,KMIA,KMIA,KJFK,CLIMB,26.1500,-80.2200,14200,12,285,2200,3004,24000
UAL005,B738,KMIA,KMIA,KIAH,CLIMB,25.8800,-80.6500,17500,278,320,2300,3005,20100
DAL006,B738,KMIA,KATL,KMIA,DESCENT,26.1800,-80.6200,11200,135,260,-1800,3006,8400
AAL007,A321,KMIA,KJFK,KMIA,APPROACH,25.7959,-80.4600,3000,92,164,-800,3007,7800
AAL008,E75L,KMIA,KDFW,KMIA,APPROACH,25.7959,-80.3800,1900,92,140,-680,3008,4200
SWA009,B738,KMIA,KORD,KMIA,HOLDING,26.0500,-80.7500,14000,90,215,0,3009,10500
UAL010,B789,KMIA,KIAH,KJFK,CRUISE,25.9500,-80.1500,39000,18,488,0,3010,51000

4. Simulation Logic & Separation Rules

If you are wiring this into a discrete-time step loop ($\Delta t$ in seconds), apply these standard FAA separation minima and state transitions:

RegimeHorizontal SeparationVertical SeparationState Transition Trigger
Terminal (TRACON)3.0 NM1,000 ftAPPROACH --> LANDED when alt <= elevation_ft & distance to threshold < 0.2 NM.
Wake Turbulence (Heavy behind Super/Heavy)4.0 - 6.0 NM1,000 ftEnforced on APPROACH and CLIMB within 10 NM of threshold.
En-Route (ARTCC)5.0 NM1,000 ft (up to FL410)CLIMB --> CRUISE upon reaching filed cruise flight level (FL350–FL390).
Ground / RunwayRunway occupancy = 1 aircraftN/AHOLD_SHORT --> TAKEOFF when active departure runway is clear and wake timer expires (90s–120s).


Add flight schedules

Below is the relational schedule table (flight_schedules.csv) synchronized to a simulation epoch of 16:00Z.

All departure (STD/ETD) and arrival (STA/ETA) timestamps are kinematically consistent with each aircraft's current coordinates, phase, great-circle distance, and cruise true airspeed:

  • TAXI_OUT / HOLD_SHORT: Scheduled to depart between 16:03Z and 16:12Z (with HOLD_SHORT flights carrying a 3-minute wake/runway sequencing delay).

  • CLIMB: Departed between 15:50Z and 15:53Z; projected to arrive ahead of STA due to unimpeded climb profiles.

  • APPROACH / DESCENT: Touchdown (ETA) sequenced between 16:02Z and 16:14Z for clean runway spacing.

  • HOLDING: Carrying a 15-minute metering delay past STA due to terminal arrival congestion.

Flight Schedules (flight_schedules.csv)

callsign,origin,destination,phase,std_utc,etd_utc,sta_utc,eta_utc,ete_min,filed_fl,delay_min
DAL101,KATL,KJFK,TAXI_OUT,16:08Z,16:08Z,18:01Z,18:01Z,113,FL350,0
DAL102,KATL,KLAX,HOLD_SHORT,16:03Z,16:06Z,20:11Z,20:14Z,248,FL370,3
DAL103,KATL,KORD,CLIMB,15:53Z,15:53Z,17:28Z,17:21Z,95,FL370,0
DAL104,KATL,KMIA,CLIMB,15:52Z,15:52Z,17:29Z,17:22Z,97,FL380,0
DAL105,KATL,KSFO,CLIMB,15:53Z,15:53Z,20:05Z,19:57Z,252,FL390,0
DAL106,KDFW,KATL,DESCENT,14:23Z,14:23Z,16:12Z,16:12Z,109,FL110,0
DAL107,KJFK,KATL,APPROACH,14:11Z,14:11Z,16:04Z,16:04Z,113,FL032,0
DAL108,KIAH,KATL,APPROACH,14:13Z,14:13Z,16:02Z,16:02Z,109,FL021,0
SWA109,KDEN,KATL,HOLDING,13:25Z,13:25Z,16:09Z,16:24Z,164,FL150,15
AAL110,KMIA,KORD,CRUISE,14:41Z,14:41Z,17:23Z,17:23Z,162,FL350,0
AAL201,KDFW,KDEN,TAXI_OUT,16:08Z,16:08Z,17:47Z,17:47Z,99,FL350,0
AAL202,KDFW,KLAX,HOLD_SHORT,16:05Z,16:08Z,18:42Z,18:45Z,157,FL390,3
AAL203,KDFW,KJFK,CLIMB,15:52Z,15:52Z,18:56Z,18:49Z,184,FL370,0
AAL204,KDFW,KIAH,CLIMB,15:52Z,15:52Z,16:44Z,16:37Z,52,FL380,0
AAL205,KDFW,KSEA,CLIMB,15:51Z,15:51Z,19:12Z,19:06Z,201,FL390,0
AAL206,KORD,KDFW,DESCENT,14:14Z,14:14Z,16:12Z,16:12Z,118,FL125,0
AAL207,KATL,KDFW,APPROACH,14:14Z,14:14Z,16:03Z,16:03Z,109,FL035,0
AAL208,KIAH,KDFW,APPROACH,15:09Z,15:09Z,16:02Z,16:02Z,53,FL022,0
SWA209,KLAX,KDFW,HOLDING,13:21Z,13:21Z,16:09Z,16:24Z,168,FL140,15
UAL210,KIAH,KDEN,CRUISE,15:21Z,15:21Z,17:26Z,17:26Z,125,FL360,0
UAL301,KDEN,KSFO,TAXI_OUT,16:08Z,16:08Z,18:25Z,18:25Z,137,FL350,0
UAL302,KDEN,KORD,HOLD_SHORT,16:03Z,16:06Z,18:10Z,18:13Z,127,FL370,3
UAL303,KDEN,KSEA,CLIMB,15:52Z,15:52Z,18:15Z,18:08Z,143,FL370,0
UAL304,KDEN,KDFW,CLIMB,15:51Z,15:51Z,17:34Z,17:27Z,103,FL380,0
UAL305,KDEN,KJFK,CLIMB,15:50Z,15:50Z,19:08Z,19:02Z,198,FL390,0
SWA306,KLAX,KDEN,DESCENT,14:09Z,14:09Z,16:14Z,16:14Z,125,FL165,0
UAL307,KORD,KDEN,APPROACH,13:57Z,13:57Z,16:04Z,16:04Z,127,FL082,0
UAL308,KSEA,KDEN,APPROACH,13:32Z,13:32Z,16:02Z,16:02Z,150,FL069,0
FFT309,KMIA,KDEN,HOLDING,12:29Z,12:29Z,16:10Z,16:25Z,221,FL170,15
DAL310,KSFO,KATL,CRUISE,14:03Z,14:03Z,18:35Z,18:35Z,272,FL370,0
UAL401,KORD,KJFK,TAXI_OUT,16:08Z,16:08Z,17:58Z,17:58Z,110,FL350,0
AAL402,KORD,KDFW,HOLD_SHORT,16:05Z,16:08Z,18:03Z,18:06Z,118,FL390,3
UAL403,KORD,KSFO,CLIMB,15:52Z,15:52Z,19:33Z,19:26Z,221,FL370,0
AAL404,KORD,KATL,CLIMB,15:52Z,15:52Z,17:30Z,17:23Z,98,FL380,0
UAL405,KORD,KDEN,CLIMB,15:51Z,15:51Z,17:59Z,17:52Z,128,FL390,0
DAL406,KATL,KORD,DESCENT,14:38Z,14:38Z,16:13Z,16:13Z,95,FL120,0
AAL407,KLAX,KORD,APPROACH,12:19Z,12:19Z,16:04Z,16:04Z,225,FL034,0
UAL408,KDEN,KORD,APPROACH,13:48Z,13:48Z,16:02Z,16:02Z,134,FL021,0
SWA409,KDFW,KORD,HOLDING,14:13Z,14:13Z,16:11Z,16:26Z,118,FL140,15
DAL410,KSEA,KJFK,CRUISE,12:51Z,12:51Z,17:32Z,17:32Z,281,FL390,0
AAL501,KLAX,KJFK,TAXI_OUT,16:08Z,16:08Z,21:16Z,21:16Z,308,FL350,0
DAL502,KLAX,KATL,HOLD_SHORT,16:03Z,16:06Z,20:13Z,20:16Z,250,FL370,3
UAL503,KLAX,KORD,CLIMB,15:52Z,15:52Z,19:23Z,19:16Z,211,FL370,0
SWA504,KLAX,KSFO,CLIMB,15:52Z,15:52Z,16:56Z,16:49Z,64,FL380,0
AAL505,KLAX,KMIA,CLIMB,15:51Z,15:51Z,20:25Z,20:18Z,274,FL390,0
DAL506,KATL,KLAX,DESCENT,12:05Z,12:05Z,16:13Z,16:13Z,248,FL115,0
UAL507,KDEN,KLAX,APPROACH,13:59Z,13:59Z,16:04Z,16:04Z,125,FL031,0
ASA508,KSEA,KLAX,APPROACH,13:41Z,13:41Z,16:02Z,16:02Z,141,FL019,0
JBU509,KJFK,KLAX,HOLDING,11:05Z,11:05Z,16:13Z,16:28Z,308,FL150,15
SWA510,KSFO,KDFW,CRUISE,15:21Z,15:21Z,18:35Z,18:35Z,194,FL350,0
JBU601,KJFK,KLAX,TAXI_OUT,16:08Z,16:08Z,21:16Z,21:16Z,308,FL350,0
DAL602,KJFK,KMIA,HOLD_SHORT,16:05Z,16:08Z,18:36Z,18:39Z,151,FL390,3
AAL603,KJFK,KSFO,CLIMB,15:53Z,15:53Z,20:53Z,20:45Z,300,FL370,0
JBU604,KJFK,KORD,CLIMB,15:53Z,15:53Z,17:48Z,17:40Z,115,FL380,0
DAL605,KJFK,KSEA,CLIMB,15:51Z,15:51Z,20:32Z,20:25Z,281,FL390,0
AAL606,KDFW,KJFK,DESCENT,13:06Z,13:06Z,16:12Z,16:12Z,186,FL118,0
DAL607,KATL,KJFK,APPROACH,14:12Z,14:12Z,16:04Z,16:04Z,112,FL029,0
JBU608,KMIA,KJFK,APPROACH,13:32Z,13:32Z,16:02Z,16:02Z,150,FL018,0
UAL609,KDEN,KJFK,HOLDING,12:38Z,12:38Z,16:11Z,16:26Z,213,FL140,15
AAL610,KMIA,KORD,CRUISE,14:58Z,14:58Z,17:31Z,17:31Z,153,FL380,0
UAL701,KIAH,KDEN,TAXI_OUT,16:08Z,16:08Z,18:13Z,18:13Z,125,FL350,0
UAL702,KIAH,KORD,HOLD_SHORT,16:03Z,16:06Z,18:14Z,18:17Z,131,FL370,3
UAL703,KIAH,KSFO,CLIMB,15:52Z,15:52Z,19:11Z,19:04Z,199,FL370,0
UAL704,KIAH,KDFW,CLIMB,15:51Z,15:51Z,16:43Z,16:37Z,52,FL380,0
UAL705,KIAH,KMIA,CLIMB,15:51Z,15:51Z,18:08Z,18:01Z,137,FL390,0
AAL706,KDFW,KIAH,DESCENT,15:22Z,15:22Z,16:13Z,16:13Z,51,FL112,0
DAL707,KATL,KIAH,APPROACH,14:20Z,14:20Z,16:04Z,16:04Z,104,FL031,0
UAL708,KDEN,KIAH,APPROACH,13:51Z,13:51Z,16:02Z,16:02Z,131,FL020,0
SWA709,KLAX,KIAH,HOLDING,13:06Z,13:06Z,16:10Z,16:25Z,184,FL150,15
AAL710,KMIA,KDFW,CRUISE,14:06Z,14:06Z,16:41Z,16:41Z,155,FL360,0
UAL801,KSFO,KDEN,TAXI_OUT,16:08Z,16:08Z,18:25Z,18:25Z,137,FL350,0
ASA802,KSFO,KSEA,HOLD_SHORT,16:05Z,16:08Z,17:48Z,17:51Z,103,FL390,3
UAL803,KSFO,KJFK,CLIMB,15:52Z,15:52Z,20:52Z,20:45Z,300,FL370,0
DAL804,KSFO,KLAX,CLIMB,15:52Z,15:52Z,16:56Z,16:49Z,64,FL380,0
UAL805,KSFO,KORD,CLIMB,15:51Z,15:51Z,19:31Z,19:24Z,220,FL390,0
SWA806,KLAX,KSFO,DESCENT,15:10Z,15:10Z,16:14Z,16:14Z,64,FL114,0
UAL807,KDEN,KSFO,APPROACH,13:49Z,13:49Z,16:05Z,16:05Z,136,FL032,0
ASA808,KSEA,KSFO,APPROACH,14:15Z,14:15Z,16:02Z,16:02Z,107,FL020,0
AAL809,KDFW,KSFO,HOLDING,12:59Z,12:59Z,16:13Z,16:28Z,194,FL140,15
DAL810,KSEA,KLAX,CRUISE,14:43Z,14:43Z,16:50Z,16:50Z,127,FL370,0
ASA901,KSEA,KDEN,TAXI_OUT,16:08Z,16:08Z,18:31Z,18:31Z,143,FL350,0
DAL902,KSEA,KATL,HOLD_SHORT,16:03Z,16:06Z,20:38Z,20:41Z,275,FL370,3
ASA903,KSEA,KSFO,CLIMB,15:52Z,15:52Z,17:36Z,17:29Z,104,FL370,0
DAL904,KSEA,KJFK,CLIMB,15:53Z,15:53Z,20:36Z,20:28Z,283,FL380,0
UAL905,KSEA,KORD,CLIMB,15:51Z,15:51Z,19:35Z,19:28Z,224,FL390,0
ASA906,KSFO,KSEA,DESCENT,14:25Z,14:25Z,16:12Z,16:12Z,107,FL116,0
DAL907,KATL,KSEA,APPROACH,11:29Z,11:29Z,16:04Z,16:04Z,275,FL034,0
ASA908,KLAX,KSEA,APPROACH,13:46Z,13:46Z,16:02Z,16:02Z,136,FL021,0
SWA909,KDEN,KSEA,HOLDING,13:47Z,13:47Z,16:10Z,16:25Z,143,FL150,15
UAL910,KSFO,KORD,CRUISE,15:36Z,15:36Z,19:17Z,19:17Z,221,FL370,0
AAL001,KMIA,KDFW,TAXI_OUT,16:08Z,16:08Z,18:43Z,18:43Z,155,FL350,0
DAL002,KMIA,KATL,HOLD_SHORT,16:05Z,16:08Z,17:38Z,17:41Z,93,FL390,3
AAL003,KMIA,KLAX,CLIMB,15:52Z,15:52Z,20:26Z,20:19Z,274,FL370,0
JBU004,KMIA,KJFK,CLIMB,15:51Z,15:51Z,18:21Z,18:14Z,150,FL380,0
UAL005,KMIA,KIAH,CLIMB,15:51Z,15:51Z,18:08Z,18:01Z,137,FL390,0
DAL006,KATL,KMIA,DESCENT,14:39Z,14:39Z,16:13Z,16:13Z,94,FL112,0
AAL007,KJFK,KMIA,APPROACH,13:34Z,13:34Z,16:04Z,16:04Z,150,FL030,0
AAL008,KDFW,KMIA,APPROACH,13:21Z,13:21Z,16:02Z,16:02Z,161,FL019,0
SWA009,KORD,KMIA,HOLDING,13:27Z,13:27Z,16:11Z,16:26Z,164,FL140,15
UAL010,KIAH,KJFK,CRUISE,15:14Z,15:14Z,18:10Z,18:10Z,176,FL390,0

Schema Field Definitions

  • std_utc / etd_utc: Scheduled vs. Estimated Time of Departure (HH:MMZ).

  • sta_utc / eta_utc: Scheduled vs. Estimated Time of Arrival (HH:MMZ).

  • ete_min: Estimated Time En-Route (total scheduled block minutes, including 25 minutes of taxi/climb/descent overhead).

  • filed_fl: Filed cruise flight level (or current cleared flight level for descending/holding traffic).

  • delay_min: Schedule variance in minutes (ETD - STD for departures, ETA - STA for arrivals).


Provide an application specification for an air traffic control application with selectable dashboards for each airport

System Overview & Architecture

This specification defines a local-first, deterministic Multi-Airport Air Traffic Control (ATC) Simulation & Tactical Display Application designed to ingest the 10-airport, 100-aircraft dataset (airports.json, aircraft_types.json, flights.csv, flight_schedules.csv).

  • Architectural Pattern: Event-driven Client-Server architecture with a decoupled deterministic kinematic engine (1 Hz tick rate) and a reactive radar client.

  • Local-First Stack: Python (FastAPI + WebSockets + Pydantic + SQLite3) for the simulation kernel and state persistence; React + HTML5 Canvas / WebGL (or D3.js) for high-framerate PPI (Plan Position Indicator) radar rendering.

  • Operational Scope: Supports simultaneous simulation of all 100 flights across the National Airspace System (NAS) while allowing the user to dynamically switch between CONUS Overview and 10 dedicated Airport TRACON/Tower Dashboards (KATL, KDFW, KDEN, KORD, KLAX, KJFK, KIAH, KSFO, KSEA, KMIA).

Core Functional Modules

1. Airport Selector & Global Telemetry Header

A persistent top navigation bar allowing instant context switching without interrupting the underlying simulation clock:

  • Sector Tabs: 11 selectable views (NAS-ALL + 10 ICAO airport tabs). Each tab displays a live badge showing:

    • Active traffic count inside the sector (TRACON radius).

    • Conflict alert counter (0 nominal, amber/red pulse on loss of separation).

  • Simulation Clock & Transport Controls: Displays Zulu time (16:00:00Z epoch), simulation speed multiplier (1x, 2x, 5x, 10x, PAUSE), and snapshot reset/export triggers.

  • Airport METAR / Field Status Strip: Updates dynamically when an airport tab is selected, showing field elevation, active arrival/departure runway assignments (ACTIVE_ARR / ACTIVE_DEP), and surface wind vector.

2. Plan Position Indicator (PPI) Radar Scope

The primary canvas occupying 65% of the viewport, centered on the selected airport's coordinates (lat, lon) and scaled to its tracon_radius_nm (defaulting to a 60 NM display range with 10 NM range rings):

  • Static Vector Overlays:

    • Runway centerlines and extended final approach courses (15 NM feather).

    • TRACON boundary circle and compass rose (000°–359°).

    • Holding pattern racetracks at metering fixes.

  • Dynamic Aircraft Targets & Data Blocks:

    • Position Symbol: Directional chevron oriented to heading_deg, color-coded by operational state (Cyan = Arrival/Approach, Green = Departure/Climb, Yellow = Ground/Taxi, Magenta = Holding, White = En-Route Overflight).

    • Velocity Leader Line: Projected position vector showing 30-second or 60-second lookahead based on groundspeed_kts.

    • 3-Line Limited Data Block (LDB):

      • Line 1: CALLSIGN + Wake Category (H/M)

      • Line 2: ALTITUDE (in hundreds of feet, e.g., 032) + Vertical Trend Arrow (↑, ↓, =) + GROUNDSPEED (in tens of knots, e.g., 16)

      • Line 3: DESTINATION ICAO + SQUAWK

3. Interactive Electronic Flight Progress Strips (EFPS)

A three-column vertical bay occupying 35% of the viewport, filtered automatically to the selected airport's traffic:

  • Bay 1 — Departures (TAXI_OUT, HOLD_SHORT, CLIMB): Displays callsign, ac_type, destination, STD/ETD, delay_min, and assigned departure runway.

  • Bay 2 — Arrivals (DESCENT, APPROACH, HOLDING): Displays callsign, origin, STA/ETA, filed_fl, distance-to-threshold (DME), and approach sequence number.

  • Bay 3 — Sector Overflights (CRUISE): Tracks high-altitude traffic transiting the airport's lateral boundary.

  • Bi-Directional Selection: Clicking a flight strip highlights and centers the target on the radar scope; clicking a radar target highlights its corresponding strip and opens the Clearance Command Palette.

4. Tactical Clearance & Command Interface

Allows the controller to issue deterministic state overrides to any selected aircraft via keyboard shortcuts or UI controls:

  • Vectoring: HDG [001-360] (Turn Left/Right), ALT [010-410] (Climb/Descend and Maintain), SPD [130-500] (Adjust Indicated/Ground Speed).

  • Sequencing & Ground: CLEARED_TO_LAND, LINE_UP_AND_WAIT, CLEARED_FOR_TAKEOFF, HOLD_AT_PRESENT_POSITION, GO_AROUND.

  • Command Validation: Rejects clearances that violate aircraft performance envelopes defined in aircraft_types.json (e.g., commanding 120 kts to a B77W whose minimum approach speed is 152 kts).

5. Automated Conflict Detection & Alerting (CA / MSAW)

Runs continuously on every simulation tick across all 100 aircraft:

  • Short-Term Conflict Alert (STCA): Evaluates pairwise slant/horizontal distance and vertical separation. Triggers an Amber Predictive Alert if projected trajectories breach minima within 90 seconds, and a Red Conflict Alert if active separation drops below:

    • < 3.0 NM horizontal AND < 1,000 ft vertical inside TRACON (<= 40 NM from airport).

    • < 5.0 NM horizontal AND < 1,000 ft vertical in En-Route airspace.

    • Wake turbulence trailing minima (4.0–6.0 NM) on final approach behind Heavy (H) aircraft.

  • Runway Incursion Alert: Triggers if two aircraft occupy the same active runway surface simultaneously or if an APPROACH aircraft is within 1.5 NM of the threshold while a HOLD_SHORT aircraft crosses the hold line.

Data Model & State Schema (Pydantic / SQLite)

Every simulation tick updates and broadcasts a unified JSON state packet to the active dashboard:

EntityPrimary KeyKey AttributesUpdate Frequency
Airporticaoname, lat, lon, elevation_ft, tracon_radius_nm, runways[]Static (Load)
AircraftTypeac_typewake, cruise_tas_kts, climb_fpm, descent_fpm, approach_ktsStatic (Load)
FlightStatecallsignassigned_sector, phase, lat, lon, altitude_ft, heading_deg, groundspeed_kts, vertical_rate_fpm, fuel_lbs1 Hz (Tick)
FlightSchedulecallsignorigin, destination, std_utc, etd_utc, sta_utc, eta_utc, ete_min, delay_minEvent-driven
ClearanceEventevent_idtimestamp_z, callsign, command_type, target_value, statusOn User Input
ConflictAlertalert_idseverity, sector_icao, callsign_a, callsign_b, horiz_nm, vert_ft, cpa_sec1 Hz (Tick)

Kinematic & Simulation Engine Rules

  1. Coordinate Integration: On each step $\Delta t$, update (lat, lon) using spherical dead-reckoning from groundspeed_kts and heading_deg. Update altitude_ft by vertical_rate_fpm * (dt / 60) until reaching target cleared altitude.

  2. Turn Dynamics: Standard rate turn capped at 3°/sec airborne and 15°/sec during TAXI_OUT.

  3. Automatic Phase State Machine:

    • HOLD_SHORT $\rightarrow$ TAKEOFF $\rightarrow$ CLIMB (at elevation_ft + 400 ft) $\rightarrow$ CRUISE (at filed_fl).

    • CRUISE $\rightarrow$ DESCENT (at Top-of-Descent calculated via $3:1$ altitude-to-distance rule) $\rightarrow$ APPROACH (when intercepted within 15 NM and ±15° of active arrival runway heading) $\rightarrow$ LANDED (at threshold elevation_ft).

  4. Dynamic Sector Handoff: When an aircraft crosses out of an airport's tracon_radius_nm or enters another airport's tracon_radius_nm, assigned_sector updates automatically so the target seamlessly migrates between airport dashboards.

Non-Functional & Verification Requirements

  • Determinism: Given identical initial CSV/JSON seeds and identical timestamped clearance logs, replaying the simulation must yield bit-exact (lat, lon, altitude_ft) trajectories.

  • Rendering Performance: Maintain $\ge 60\text{ FPS}$ on the HTML5 Canvas radar scope with 100 active targets, velocity vectors, range rings, and real-time collision rings enabled.

  • Audit Logging: All user clearances, runway state changes, and STCA conflict events must be written to a local append-only SQLite audit table (sim_audit_log) for post-run playback and safety review.



Build a single-file interactive React and HTML5 Canvas prototype of this 10-airport ATC dashboard preloaded with the 10-airport and 100-plane dataset.

I will now generate the single-file interactive React and HTML5 Canvas prototype for the Multi-Airport Air Traffic Control (ATC) Simulation & Tactical Display Dashboard, preloaded with all 10 US hub airports, 100 active flights, synchronized flight schedules, real-time kinematic engine, STCA conflict alerting, and interactive clearance controls.


Summary of Generated Prototype

  • 10-Airport & 100-Aircraft Dataset Preloaded: Includes all 10 US hub airports (KATL, KDFW, KDEN, KORD, KLAX, KJFK, KIAH, KSFO, KSEA, KMIA), aircraft performance envelopes (B738, A321, B77W, B789, A359, E75L, CRJ9), and all 100 active flights merged with their synchronized 16:00:00Z flight schedules (STD, ETD, STA, ETA, ETE, delay_min, filed_fl).

  • Selectable Airport Dashboards & CONUS Overview: Switch seamlessly between NAS-ALL and any of the 10 dedicated airport TRACON scopes with live aircraft counts, STCA conflict badges, dynamic METAR/wind strips, and active arrival/departure runway layouts.

  • HTML5 Canvas PPI Radar Scope: Features 10 NM range rings, TRACON boundary circles, compass rose azimuth ticks, extended 15 NM final approach feathers, zoom/pan controls, 60-second velocity leader lines, 3-line Limited Data Blocks, and pulsing Red/Amber Short-Term Conflict Alert (STCA) rings.

  • Interactive Flight Strips & Clearance Deck: Supports bi-directional target selection, phase filtering (ALL, DEP, ARR, CRZ), heading/altitude/speed vectoring with aircraft envelope validation, procedural commands (CLR T/O, HOLD POS, CLR ILS, GO AROUND), and an append-only audit log.


Regenerate the app with HTML, JavaScript and CSS

I will now generate the standalone single-file HTML, CSS, and vanilla JavaScript Air Traffic Control (ATC) simulation and tactical display web application (atc_dashboard.html) preloaded with all 10 US hub airports, 100 active flights, synchronized 16:00:00Z schedules, real-time kinematic physics, STCA conflict detection, and interactive clearance controls.


Summary of Implementation

  • Self-Contained Single-File Architecture: Built entirely in a single .html file (atc_dashboard.html) using Tailwind CSS via CDN, custom tactical dark-mode CSS, and zero-dependency vanilla JavaScript.

  • Complete 10-Airport & 100-Aircraft Preload: Embeds all 10 US hub airports (KATL, KDFW, KDEN, KORD, KLAX, KJFK, KIAH, KSFO, KSEA, KMIA), aircraft performance lookup envelopes (B738, A321, B77W, B789, A359, E75L, CRJ9), and all 100 active flights merged with their synchronized 16:00:00Z flight schedules (STD, ETD, STA, ETA, ETE, delay_min, filed_fl).

  • Interactive PPI Radar Scope & EFPS Bay: Provides a responsive, zoomable/pannable HTML5 Canvas radar display with 10 NM range rings, TRACON boundaries, compass rose ticks, runway centerlines with 15 NM extended final approach feathers, 60-second velocity vectors, 3-line Limited Data Blocks, pulsing Red/Amber Short-Term Conflict Alert (STCA) rings, bi-directional Electronic Flight Progress Strips, envelope-validated vectoring commands, procedural ATC buttons, and an append-only audit log.


From <https://gemini.google.com/app/ce5456480fd65fce>  Google Gemini (4 Hydrogen)



import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';

import {

  Radar,

  Plane,

  AlertTriangle,

  Play,

  Pause,

  RotateCcw,

  Compass,

  Radio,

  Navigation,

  Clock,

  ShieldAlert,

  Crosshair,

  Wind,

  ArrowUp,

  ArrowDown,

  Minus,

  CheckCircle2,

  XCircle,

  Sliders,

  ZoomIn,

  ZoomOut,

  LocateFixed,

  Terminal,

  Activity

} from 'lucide-react';


// ============================================================================

// 1. STATIC REFERENCE DATASETS (10 AIRPORTS, AIRCRAFT TYPES, 100 FLIGHTS)

// ============================================================================


const AIRPORTS = [

  {

    icao: "KATL",

    iata: "ATL",

    name: "Hartsfield-Jackson Atlanta Intl",

    lat: 33.6407,

    lon: -84.4277,

    elevation_ft: 1026,

    tracon_radius_nm: 40,

    wind: "090/12KT",

    altimeter: "30.12",

    runways: [

      { id: "08L/26R", heading_deg: 90, length_ft: 9000, status: "ACTIVE_ARR" },

      { id: "08R/26L", heading_deg: 90, length_ft: 10000, status: "ACTIVE_DEP" },

      { id: "09L/27R", heading_deg: 90, length_ft: 12390, status: "ACTIVE_DEP" },

      { id: "09R/27L", heading_deg: 90, length_ft: 9000, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KDFW",

    iata: "DFW",

    name: "Dallas/Fort Worth Intl",

    lat: 32.8998,

    lon: -97.0403,

    elevation_ft: 607,

    tracon_radius_nm: 45,

    wind: "180/14G20KT",

    altimeter: "29.98",

    runways: [

      { id: "17C/35C", heading_deg: 175, length_ft: 13401, status: "ACTIVE_DEP" },

      { id: "17L/35R", heading_deg: 175, length_ft: 8500, status: "ACTIVE_ARR" },

      { id: "18R/36L", heading_deg: 175, length_ft: 13400, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KDEN",

    iata: "DEN",

    name: "Denver Intl",

    lat: 39.8561,

    lon: -104.6737,

    elevation_ft: 5434,

    tracon_radius_nm: 50,

    wind: "170/16KT",

    altimeter: "30.04",

    runways: [

      { id: "16R/34L", heading_deg: 170, length_ft: 16000, status: "ACTIVE_DEP" },

      { id: "16L/34R", heading_deg: 170, length_ft: 12000, status: "ACTIVE_ARR" },

      { id: "08/26", heading_deg: 90, length_ft: 12000, status: "ACTIVE_DEP" }

    ]

  },

  {

    icao: "KORD",

    iata: "ORD",

    name: "Chicago O'Hare Intl",

    lat: 41.9742,

    lon: -87.9073,

    elevation_ft: 680,

    tracon_radius_nm: 40,

    wind: "090/15G22KT",

    altimeter: "29.89",

    runways: [

      { id: "09C/27C", heading_deg: 90, length_ft: 11245, status: "ACTIVE_ARR" },

      { id: "10L/28R", heading_deg: 90, length_ft: 13000, status: "ACTIVE_DEP" },

      { id: "10C/28C", heading_deg: 90, length_ft: 10801, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KLAX",

    iata: "LAX",

    name: "Los Angeles Intl",

    lat: 33.9416,

    lon: -118.4085,

    elevation_ft: 128,

    tracon_radius_nm: 40,

    wind: "250/11KT",

    altimeter: "30.01",

    runways: [

      { id: "06L/24R", heading_deg: 249, length_ft: 8926, status: "ACTIVE_ARR" },

      { id: "06R/24L", heading_deg: 249, length_ft: 10885, status: "ACTIVE_DEP" },

      { id: "07L/25R", heading_deg: 249, length_ft: 12923, status: "ACTIVE_DEP" },

      { id: "07R/25L", heading_deg: 249, length_ft: 11095, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KJFK",

    iata: "JFK",

    name: "John F. Kennedy Intl",

    lat: 40.6413,

    lon: -73.7781,

    elevation_ft: 13,

    tracon_radius_nm: 35,

    wind: "040/13KT",

    altimeter: "30.18",

    runways: [

      { id: "04L/22R", heading_deg: 44, length_ft: 12079, status: "ACTIVE_DEP" },

      { id: "04R/22L", heading_deg: 44, length_ft: 8400, status: "ACTIVE_ARR" },

      { id: "13R/31L", heading_deg: 134, length_ft: 14511, status: "ACTIVE_DEP" }

    ]

  },

  {

    icao: "KIAH",

    iata: "IAH",

    name: "George Bush Intercontinental",

    lat: 29.9902,

    lon: -95.3368,

    elevation_ft: 97,

    tracon_radius_nm: 40,

    wind: "090/09KT",

    altimeter: "30.06",

    runways: [

      { id: "08L/26R", heading_deg: 90, length_ft: 9000, status: "ACTIVE_ARR" },

      { id: "08R/26L", heading_deg: 90, length_ft: 9402, status: "ACTIVE_DEP" },

      { id: "09/27", heading_deg: 90, length_ft: 10000, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KSFO",

    iata: "SFO",

    name: "San Francisco Intl",

    lat: 37.6213,

    lon: -122.3790,

    elevation_ft: 13,

    tracon_radius_nm: 35,

    wind: "280/17G24KT",

    altimeter: "30.09",

    runways: [

      { id: "01L/19R", heading_deg: 12, length_ft: 7650, status: "ACTIVE_DEP" },

      { id: "01R/19L", heading_deg: 12, length_ft: 8650, status: "ACTIVE_DEP" },

      { id: "10L/28R", heading_deg: 284, length_ft: 11870, status: "ACTIVE_ARR" },

      { id: "10R/28L", heading_deg: 284, length_ft: 11381, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KSEA",

    iata: "SEA",

    name: "Seattle-Tacoma Intl",

    lat: 47.4502,

    lon: -122.3088,

    elevation_ft: 433,

    tracon_radius_nm: 40,

    wind: "160/10KT",

    altimeter: "29.94",

    runways: [

      { id: "16L/34R", heading_deg: 164, length_ft: 11901, status: "ACTIVE_DEP" },

      { id: "16C/34C", heading_deg: 164, length_ft: 9426, status: "ACTIVE_ARR" },

      { id: "16R/34L", heading_deg: 164, length_ft: 8500, status: "ACTIVE_ARR" }

    ]

  },

  {

    icao: "KMIA",

    iata: "MIA",

    name: "Miami Intl",

    lat: 25.7959,

    lon: -80.2870,

    elevation_ft: 9,

    tracon_radius_nm: 35,

    wind: "090/12KT",

    altimeter: "30.14",

    runways: [

      { id: "08L/26R", heading_deg: 92, length_ft: 8600, status: "ACTIVE_ARR" },

      { id: "08R/26L", heading_deg: 92, length_ft: 10506, status: "ACTIVE_DEP" },

      { id: "09/27", heading_deg: 92, length_ft: 13016, status: "ACTIVE_DEP" }

    ]

  }

];


const AIRPORT_MAP = Object.fromEntries(AIRPORTS.map((a) => [a.icao, a]));


const AIRCRAFT_TYPES = {

  B738: { wake: "M", cruise_tas_kts: 450, climb_fpm: 2200, descent_fpm: 1800, approach_kts: 142, max_alt: 41000 },

  A321: { wake: "M", cruise_tas_kts: 455, climb_fpm: 2100, descent_fpm: 1800, approach_kts: 145, max_alt: 39800 },

  B77W: { wake: "H", cruise_tas_kts: 490, climb_fpm: 2400, descent_fpm: 2000, approach_kts: 152, max_alt: 43100 },

  B789: { wake: "H", cruise_tas_kts: 488, climb_fpm: 2500, descent_fpm: 2000, approach_kts: 148, max_alt: 43100 },

  A359: { wake: "H", cruise_tas_kts: 492, climb_fpm: 2500, descent_fpm: 2000, approach_kts: 146, max_alt: 43100 },

  E75L: { wake: "M", cruise_tas_kts: 430, climb_fpm: 1900, descent_fpm: 1600, approach_kts: 132, max_alt: 41000 },

  CRJ9: { wake: "M", cruise_tas_kts: 425, climb_fpm: 1850, descent_fpm: 1600, approach_kts: 135, max_alt: 41000 }

};


// Schematic CONUS boundary polyline (lat, lon) for NAS-ALL radar background

const CONUS_OUTLINE = [

  [48.4, -124.7], [46.2, -124.0], [42.0, -124.3], [38.9, -123.7], [37.8, -122.5],

  [34.5, -120.6], [32.6, -117.1], [31.3, -111.0], [31.8, -106.5], [29.5, -104.4],

  [28.9, -100.6], [25.9, -97.1], [27.8, -97.1], [29.3, -94.8], [29.7, -93.8],

  [29.1, -89.3], [30.3, -88.1], [29.9, -85.4], [27.8, -82.8], [25.2, -81.1],

  [25.8, -80.1], [28.5, -80.6], [30.7, -81.4], [32.1, -80.8], [33.9, -77.9],

  [35.2, -75.5], [36.9, -76.0], [38.9, -74.9], [40.6, -74.0], [41.3, -71.8],

  [42.3, -71.0], [43.6, -70.2], [44.8, -67.0], [47.3, -68.3], [45.0, -71.5],

  [45.0, -74.8], [43.6, -79.2], [42.3, -83.0], [45.8, -84.7], [46.5, -87.4],

  [46.8, -92.1], [49.0, -95.1], [49.0, -104.0], [49.0, -114.0], [49.0, -122.8],

  [48.4, -124.7]

];


// Raw CSV Strings for the 100 Flights & 100 Synchronized Schedules

const FLIGHTS_CSV = `callsign,ac_type,assigned_sector,origin,destination,phase,lat,lon,altitude_ft,heading_deg,groundspeed_kts,vertical_rate_fpm,squawk,fuel_lbs

DAL101,B738,KATL,KATL,KJFK,TAXI_OUT,33.6380,-84.4320,1026,90,15,0,2101,18500

DAL102,A321,KATL,KATL,KLAX,HOLD_SHORT,33.6355,-84.4410,1026,90,0,0,2102,34200

DAL103,B738,KATL,KATL,KORD,CLIMB,33.7820,-84.4510,8400,355,250,2400,2103,21000

DAL104,E75L,KATL,KATL,KMIA,CLIMB,33.4100,-84.3120,14200,162,285,2100,2104,11400

DAL105,B77W,KATL,KATL,KSFO,CLIMB,33.7150,-84.6800,19500,285,330,2600,2105,78000

DAL106,A321,KATL,KDFW,KATL,DESCENT,33.5900,-84.8900,11000,88,260,-1800,2106,9200

DAL107,B738,KATL,KJFK,KATL,APPROACH,33.6407,-84.6100,3200,90,165,-850,2107,7400

DAL108,CRJ9,KATL,KIAH,KATL,APPROACH,33.6310,-84.5400,2100,90,145,-720,2108,4100

SWA109,B738,KATL,KDEN,KATL,HOLDING,33.8500,-84.7500,15000,180,220,0,2109,11200

AAL110,A321,KATL,KMIA,KORD,CRUISE,33.9200,-84.2100,35000,342,455,0,2110,24500

AAL201,B738,KDFW,KDFW,KDEN,TAXI_OUT,32.8950,-97.0380,607,175,18,0,2201,19200

AAL202,B789,KDFW,KDFW,KLAX,HOLD_SHORT,32.9120,-97.0420,607,175,0,0,2202,62000

AAL203,A321,KDFW,KDFW,KJFK,CLIMB,33.0800,-96.8500,9600,52,265,2300,2203,26800

AAL204,E75L,KDFW,KDFW,KIAH,CLIMB,32.6500,-96.9500,11200,155,270,1950,2204,8900

AAL205,B77W,KDFW,KDFW,KSEA,CLIMB,33.1500,-97.3200,18400,320,325,2500,2205,71500

AAL206,B738,KDFW,KORD,KDFW,DESCENT,33.3100,-96.8800,12500,205,270,-1900,2206,8800

AAL207,A321,KDFW,KATL,KDFW,APPROACH,33.0400,-97.0280,3500,175,170,-820,2207,7900

AAL208,CRJ9,KDFW,KIAH,KDFW,APPROACH,32.9800,-97.0520,2200,175,148,-700,2208,3800

SWA209,B738,KDFW,KLAX,KDFW,HOLDING,32.7800,-97.4500,14000,90,215,0,2209,10400

UAL210,B738,KDFW,KIAH,KDEN,CRUISE,33.1200,-97.5100,36000,325,450,0,2210,21300

UAL301,B738,KDEN,KDEN,KSFO,TAXI_OUT,39.8510,-104.6710,5434,170,16,0,2301,18900

UAL302,A321,KDEN,KDEN,KORD,HOLD_SHORT,39.8720,-104.6780,5434,170,0,0,2302,22400

UAL303,B738,KDEN,KDEN,KSEA,CLIMB,40.0900,-104.9200,13800,315,275,2200,2303,20500

UAL304,E75L,KDEN,KDEN,KDFW,CLIMB,39.5800,-104.4500,15200,145,280,1900,2304,10200

UAL305,B789,KDEN,KDEN,KJFK,CLIMB,39.9500,-104.1200,21000,82,340,2450,2305,58000

SWA306,B738,KDEN,KLAX,KDEN,DESCENT,39.4800,-105.1200,16500,48,280,-1850,2306,9600

UAL307,A321,KDEN,KORD,KDEN,APPROACH,40.0400,-104.6650,8200,170,175,-880,2307,8100

UAL308,CRJ9,KDEN,KSEA,KDEN,APPROACH,39.9600,-104.6820,6900,170,150,-750,2308,4300

FFT309,A321,KDEN,KMIA,KDEN,HOLDING,39.6200,-104.1800,17000,270,225,0,2309,11500

DAL310,B738,KDEN,KSFO,KATL,CRUISE,39.7100,-104.8800,37000,108,465,0,2310,27800

UAL401,A321,KORD,KORD,KJFK,TAXI_OUT,41.9710,-87.9010,680,90,14,0,2401,19800

AAL402,B738,KORD,KORD,KDFW,HOLD_SHORT,41.9680,-87.9250,680,90,0,0,2402,21100

UAL403,B77W,KORD,KORD,KSFO,CLIMB,42.0200,-88.2500,11500,275,285,2550,2403,74000

AAL404,E75L,KORD,KORD,KATL,CLIMB,41.7200,-87.7500,9800,158,260,2000,2404,9500

UAL405,B738,KORD,KORD,KDEN,CLIMB,41.9500,-88.4100,16400,268,310,2250,2405,19400

DAL406,B738,KORD,KATL,KORD,DESCENT,41.5500,-88.1500,12000,350,265,-1800,2406,8700

AAL407,A321,KORD,KLAX,KORD,APPROACH,41.9810,-88.1200,3400,90,168,-800,2407,8400

UAL408,CRJ9,KORD,KDEN,KORD,APPROACH,41.9690,-88.0300,2100,90,145,-710,2408,3900

SWA409,B738,KORD,KDFW,KORD,HOLDING,41.6800,-88.4500,14000,45,215,0,2409,10800

DAL410,A359,KORD,KSEA,KJFK,CRUISE,42.1800,-87.6200,39000,98,495,0,2410,64000

AAL501,A321,KLAX,KLAX,KJFK,TAXI_OUT,33.9440,-118.4020,128,249,17,0,2501,42500

DAL502,B738,KLAX,KLAX,KATL,HOLD_SHORT,33.9470,-118.3910,128,249,0,0,2502,36000

UAL503,B789,KLAX,KLAX,KORD,CLIMB,34.0800,-118.1200,12400,58,290,2500,2503,54000

SWA504,B738,KLAX,KLAX,KSFO,CLIMB,34.1900,-118.5800,10800,322,275,2200,2504,14200

AAL505,B77W,KLAX,KLAX,KMIA,CLIMB,33.8800,-117.9500,17800,96,335,2450,2505,69000

DAL506,A321,KLAX,KATL,KLAX,DESCENT,34.0500,-117.8500,11500,255,260,-1850,2506,9500

UAL507,B738,KLAX,KDEN,KLAX,APPROACH,33.9850,-118.2100,3100,249,165,-810,2507,7800

ASA508,E75L,KLAX,KSEA,KLAX,APPROACH,33.9620,-118.3100,1900,249,142,-690,2508,4600

JBU509,A321,KLAX,KJFK,KLAX,HOLDING,33.8200,-117.7200,15000,270,220,0,2509,12100

SWA510,B738,KLAX,KSFO,KDFW,CRUISE,34.1100,-118.0500,35000,104,455,0,2510,23100

JBU601,A321,KJFK,KJFK,KLAX,TAXI_OUT,40.6380,-73.7820,13,44,15,0,2601,44000

DAL602,B738,KJFK,KJFK,KMIA,HOLD_SHORT,40.6320,-73.7890,13,44,0,0,2602,22800

AAL603,B77W,KJFK,KJFK,KSFO,CLIMB,40.7800,-74.0500,13200,282,295,2450,2603,82000

JBU604,E75L,KJFK,KJFK,KORD,CLIMB,40.8200,-73.9800,10400,295,265,1950,2604,13500

DAL605,A359,KJFK,KJFK,KSEA,CLIMB,40.9100,-74.1200,18900,302,340,2600,2605,79500

AAL606,B738,KJFK,KDFW,KJFK,DESCENT,40.3200,-74.1500,11800,42,265,-1800,2606,9100

DAL607,A321,KJFK,KATL,KJFK,APPROACH,40.5100,-73.9100,2900,44,162,-790,2607,8200

JBU608,A321,KJFK,KMIA,KJFK,APPROACH,40.5700,-73.8500,1800,44,148,-710,2608,7600

UAL609,B738,KJFK,KDEN,KJFK,HOLDING,40.4500,-74.3500,14000,90,215,0,2609,11000

AAL610,B789,KJFK,KMIA,KORD,CRUISE,40.7200,-74.2200,38000,312,485,0,2610,49000

UAL701,B738,KIAH,KIAH,KDEN,TAXI_OUT,29.9880,-95.3410,97,90,16,0,2701,19500

UAL702,A321,KIAH,KIAH,KORD,HOLD_SHORT,29.9850,-95.3520,97,90,0,0,2702,21600

UAL703,B789,KIAH,KIAH,KSFO,CLIMB,30.1500,-95.6200,12800,295,290,2500,2703,56000

UAL704,E75L,KIAH,KIAH,KDFW,CLIMB,30.2800,-95.4800,10200,338,260,1900,2704,8400

UAL705,B738,KIAH,KIAH,KMIA,CLIMB,29.8500,-94.9500,16500,108,315,2250,2705,18800

AAL706,B738,KIAH,KDFW,KIAH,DESCENT,30.3500,-95.6800,11200,148,260,-1800,2706,8500

DAL707,A321,KIAH,KATL,KIAH,APPROACH,29.9902,-95.5200,3100,90,165,-810,2707,7900

UAL708,CRJ9,KIAH,KDEN,KIAH,APPROACH,29.9850,-95.4400,2000,90,145,-700,2708,4000

SWA709,B738,KIAH,KLAX,KIAH,HOLDING,29.8200,-95.7800,15000,90,220,0,2709,10900

AAL710,B738,KIAH,KMIA,KDFW,CRUISE,30.1200,-95.1800,36000,318,450,0,2710,20400

UAL801,B738,KSFO,KSFO,KDEN,TAXI_OUT,37.6180,-122.3750,13,12,15,0,2801,19100

ASA802,A321,KSFO,KSFO,KSEA,HOLD_SHORT,37.6140,-122.3790,13,12,0,0,2802,17500

UAL803,B77W,KSFO,KSFO,KJFK,CLIMB,37.7800,-122.1200,13500,65,295,2450,2803,81000

DAL804,B738,KSFO,KSFO,KLAX,CLIMB,37.3800,-122.2500,10600,145,270,2200,2804,13800

UAL805,A359,KSFO,KSFO,KORD,CLIMB,37.8500,-121.9500,19200,62,335,2550,2805,68000

SWA806,B738,KSFO,KLAX,KSFO,DESCENT,37.3200,-121.8500,11400,310,260,-1800,2806,8900

UAL807,A321,KSFO,KDEN,KSFO,APPROACH,37.5500,-122.1500,3200,284,165,-820,2807,8100

ASA808,E75L,KSFO,KSEA,KSFO,APPROACH,37.5900,-122.2600,2000,284,142,-700,2808,4500

AAL809,B738,KSFO,KDFW,KSFO,HOLDING,37.4200,-121.6500,14000,270,215,0,2809,10600

DAL810,B789,KSFO,KSEA,KLAX,CRUISE,37.7100,-122.0500,37000,152,485,0,2810,46000

ASA901,B738,KSEA,KSEA,KDEN,TAXI_OUT,47.4480,-122.3050,433,164,16,0,2901,19600

DAL902,A321,KSEA,KSEA,KATL,HOLD_SHORT,47.4620,-122.3090,433,164,0,0,2902,38500

ASA903,B738,KSEA,KSEA,KSFO,CLIMB,47.1800,-122.3200,11200,178,275,2250,2903,16400

DAL904,B789,KSEA,KSEA,KJFK,CLIMB,47.3800,-121.9500,14800,98,300,2500,2904,61000

UAL905,B738,KSEA,KSEA,KORD,CLIMB,47.4200,-121.7500,18500,95,325,2300,2905,31200

ASA906,E75L,KSEA,KSFO,KSEA,DESCENT,47.8200,-122.2800,11600,172,255,-1750,2906,7200

DAL907,A321,KSEA,KATL,KSEA,APPROACH,47.6200,-122.3088,3400,164,168,-830,2907,8500

ASA908,B738,KSEA,KLAX,KSEA,APPROACH,47.5400,-122.3088,2100,164,145,-710,2908,7900

SWA909,B738,KSEA,KDEN,KSEA,HOLDING,47.7500,-121.9000,15000,270,220,0,2909,11100

UAL910,B77W,KSEA,KSFO,KORD,CRUISE,47.2500,-122.1000,37000,94,490,0,2910,67500

AAL001,B738,KMIA,KMIA,KDFW,TAXI_OUT,25.7930,-80.2890,9,92,15,0,3001,21400

DAL002,A321,KMIA,KMIA,KATL,HOLD_SHORT,25.7910,-80.3010,9,92,0,0,3002,16800

AAL003,B77W,KMIA,KMIA,KLAX,CLIMB,25.9200,-80.5800,12600,285,290,2450,3003,76500

JBU004,A321,KMIA,KMIA,KJFK,CLIMB,26.1500,-80.2200,14200,12,285,2200,3004,24000

UAL005,B738,KMIA,KMIA,KIAH,CLIMB,25.8800,-80.6500,17500,278,320,2300,3005,20100

DAL006,B738,KMIA,KATL,KMIA,DESCENT,26.1800,-80.6200,11200,135,260,-1800,3006,8400

AAL007,A321,KMIA,KJFK,KMIA,APPROACH,25.7959,-80.4600,3000,92,164,-800,3007,7800

AAL008,E75L,KMIA,KDFW,KMIA,APPROACH,25.7959,-80.3800,1900,92,140,-680,3008,4200

SWA009,B738,KMIA,KORD,KMIA,HOLDING,26.0500,-80.7500,14000,90,215,0,3009,10500

UAL010,B789,KMIA,KIAH,KJFK,CRUISE,25.9500,-80.1500,39000,18,488,0,3010,51000`;


const SCHEDULES_CSV = `callsign,origin,destination,phase,std_utc,etd_utc,sta_utc,eta_utc,ete_min,filed_fl,delay_min

DAL101,KATL,KJFK,TAXI_OUT,16:08Z,16:08Z,18:01Z,18:01Z,113,FL350,0

DAL102,KATL,KLAX,HOLD_SHORT,16:03Z,16:06Z,20:11Z,20:14Z,248,FL370,3

DAL103,KATL,KORD,CLIMB,15:53Z,15:53Z,17:28Z,17:21Z,95,FL370,0

DAL104,KATL,KMIA,CLIMB,15:52Z,15:52Z,17:29Z,17:22Z,97,FL380,0

DAL105,KATL,KSFO,CLIMB,15:53Z,15:53Z,20:05Z,19:57Z,252,FL390,0

DAL106,KDFW,KATL,DESCENT,14:23Z,14:23Z,16:12Z,16:12Z,109,FL110,0

DAL107,KJFK,KATL,APPROACH,14:11Z,14:11Z,16:04Z,16:04Z,113,FL032,0

DAL108,KIAH,KATL,APPROACH,14:13Z,14:13Z,16:02Z,16:02Z,109,FL021,0

SWA109,KDEN,KATL,HOLDING,13:25Z,13:25Z,16:09Z,16:24Z,164,FL150,15

AAL110,KMIA,KORD,CRUISE,14:41Z,14:41Z,17:23Z,17:23Z,162,FL350,0

AAL201,KDFW,KDEN,TAXI_OUT,16:08Z,16:08Z,17:47Z,17:47Z,99,FL350,0

AAL202,KDFW,KLAX,HOLD_SHORT,16:05Z,16:08Z,18:42Z,18:45Z,157,FL390,3

AAL203,KDFW,KJFK,CLIMB,15:52Z,15:52Z,18:56Z,18:49Z,184,FL370,0

AAL204,KDFW,KIAH,CLIMB,15:52Z,15:52Z,16:44Z,16:37Z,52,FL380,0

AAL205,KDFW,KSEA,CLIMB,15:51Z,15:51Z,19:12Z,19:06Z,201,FL390,0

AAL206,KORD,KDFW,DESCENT,14:14Z,14:14Z,16:12Z,16:12Z,118,FL125,0

AAL207,KATL,KDFW,APPROACH,14:14Z,14:14Z,16:03Z,16:03Z,109,FL035,0

AAL208,KIAH,KDFW,APPROACH,15:09Z,15:09Z,16:02Z,16:02Z,53,FL022,0

SWA209,KLAX,KDFW,HOLDING,13:21Z,13:21Z,16:09Z,16:24Z,168,FL140,15

UAL210,KIAH,KDEN,CRUISE,15:21Z,15:21Z,17:26Z,17:26Z,125,FL360,0

UAL301,KDEN,KSFO,TAXI_OUT,16:08Z,16:08Z,18:25Z,18:25Z,137,FL350,0

UAL302,KDEN,KORD,HOLD_SHORT,16:03Z,16:06Z,18:10Z,18:13Z,127,FL370,3

UAL303,KDEN,KSEA,CLIMB,15:52Z,15:52Z,18:15Z,18:08Z,143,FL370,0

UAL304,KDEN,KDFW,CLIMB,15:51Z,15:51Z,17:34Z,17:27Z,103,FL380,0

UAL305,KDEN,KJFK,CLIMB,15:50Z,15:50Z,19:08Z,19:02Z,198,FL390,0

SWA306,KLAX,KDEN,DESCENT,14:09Z,14:09Z,16:14Z,16:14Z,125,FL165,0

UAL307,KORD,KDEN,APPROACH,13:57Z,13:57Z,16:04Z,16:04Z,127,FL082,0

UAL308,KSEA,KDEN,APPROACH,13:32Z,13:32Z,16:02Z,16:02Z,150,FL069,0

FFT309,KMIA,KDEN,HOLDING,12:29Z,12:29Z,16:10Z,16:25Z,221,FL170,15

DAL310,KSFO,KATL,CRUISE,14:03Z,14:03Z,18:35Z,18:35Z,272,FL370,0

UAL401,KORD,KJFK,TAXI_OUT,16:08Z,16:08Z,17:58Z,17:58Z,110,FL350,0

AAL402,KORD,KDFW,HOLD_SHORT,16:05Z,16:08Z,18:03Z,18:06Z,118,FL390,3

UAL403,KORD,KSFO,CLIMB,15:52Z,15:52Z,19:33Z,19:26Z,221,FL370,0

AAL404,KORD,KATL,CLIMB,15:52Z,15:52Z,17:30Z,17:23Z,98,FL380,0

UAL405,KORD,KDEN,CLIMB,15:51Z,15:51Z,17:59Z,17:52Z,128,FL390,0

DAL406,KATL,KORD,DESCENT,14:38Z,14:38Z,16:13Z,16:13Z,95,FL120,0

AAL407,KLAX,KORD,APPROACH,12:19Z,12:19Z,16:04Z,16:04Z,225,FL034,0

UAL408,KDEN,KORD,APPROACH,13:48Z,13:48Z,16:02Z,16:02Z,134,FL021,0

SWA409,KDFW,KORD,HOLDING,14:13Z,14:13Z,16:11Z,16:26Z,118,FL140,15

DAL410,KSEA,KJFK,CRUISE,12:51Z,12:51Z,17:32Z,17:32Z,281,FL390,0

AAL501,KLAX,KJFK,TAXI_OUT,16:08Z,16:08Z,21:16Z,21:16Z,308,FL350,0

DAL502,KLAX,KATL,HOLD_SHORT,16:03Z,16:06Z,20:13Z,20:16Z,250,FL370,3

UAL503,KLAX,KORD,CLIMB,15:52Z,15:52Z,19:23Z,19:16Z,211,FL370,0

SWA504,KLAX,KSFO,CLIMB,15:52Z,15:52Z,16:56Z,16:49Z,64,FL380,0

AAL505,KLAX,KMIA,CLIMB,15:51Z,15:51Z,20:25Z,20:18Z,274,FL390,0

DAL506,KATL,KLAX,DESCENT,12:05Z,12:05Z,16:13Z,16:13Z,248,FL115,0

UAL507,KDEN,KLAX,APPROACH,13:59Z,13:59Z,16:04Z,16:04Z,125,FL031,0

ASA508,KSEA,KLAX,APPROACH,13:41Z,13:41Z,16:02Z,16:02Z,141,FL019,0

JBU509,KJFK,KLAX,HOLDING,11:05Z,11:05Z,16:13Z,16:28Z,308,FL150,15

SWA510,KSFO,KDFW,CRUISE,15:21Z,15:21Z,18:35Z,18:35Z,194,FL350,0

JBU601,KJFK,KLAX,TAXI_OUT,16:08Z,16:08Z,21:16Z,21:16Z,308,FL350,0

DAL602,KJFK,KMIA,HOLD_SHORT,16:05Z,16:08Z,18:36Z,18:39Z,151,FL390,3

AAL603,KJFK,KSFO,CLIMB,15:53Z,15:53Z,20:53Z,20:45Z,300,FL370,0

JBU604,KJFK,KORD,CLIMB,15:53Z,15:53Z,17:48Z,17:40Z,115,FL380,0

DAL605,KJFK,KSEA,CLIMB,15:51Z,15:51Z,20:32Z,20:25Z,281,FL390,0

AAL606,KDFW,KJFK,DESCENT,13:06Z,13:06Z,16:12Z,16:12Z,186,FL118,0

DAL607,KATL,KJFK,APPROACH,14:12Z,14:12Z,16:04Z,16:04Z,112,FL029,0

JBU608,KMIA,KJFK,APPROACH,13:32Z,13:32Z,16:02Z,16:02Z,150,FL018,0

UAL609,KDEN,KJFK,HOLDING,12:38Z,12:38Z,16:11Z,16:26Z,213,FL140,15

AAL610,KMIA,KORD,CRUISE,14:58Z,14:58Z,17:31Z,17:31Z,153,FL380,0

UAL701,KIAH,KDEN,TAXI_OUT,16:08Z,16:08Z,18:13Z,18:13Z,125,FL350,0

UAL702,KIAH,KORD,HOLD_SHORT,16:03Z,16:06Z,18:14Z,18:17Z,131,FL370,3

UAL703,KIAH,KSFO,CLIMB,15:52Z,15:52Z,19:11Z,19:04Z,199,FL370,0

UAL704,KIAH,KDFW,CLIMB,15:51Z,15:51Z,16:43Z,16:37Z,52,FL380,0

UAL705,KIAH,KMIA,CLIMB,15:51Z,15:51Z,18:08Z,18:01Z,137,FL390,0

AAL706,KDFW,KIAH,DESCENT,15:22Z,15:22Z,16:13Z,16:13Z,51,FL112,0

DAL707,KATL,KIAH,APPROACH,14:20Z,14:20Z,16:04Z,16:04Z,104,FL031,0

UAL708,KDEN,KIAH,APPROACH,13:51Z,13:51Z,16:02Z,16:02Z,131,FL020,0

SWA709,KLAX,KIAH,HOLDING,13:06Z,13:06Z,16:10Z,16:25Z,184,FL150,15

AAL710,KMIA,KDFW,CRUISE,14:06Z,14:06Z,16:41Z,16:41Z,155,FL360,0

UAL801,KSFO,KDEN,TAXI_OUT,16:08Z,16:08Z,18:25Z,18:25Z,137,FL350,0

ASA802,KSFO,KSEA,HOLD_SHORT,16:05Z,16:08Z,17:48Z,17:51Z,103,FL390,3

UAL803,KSFO,KJFK,CLIMB,15:52Z,15:52Z,20:52Z,20:45Z,300,FL370,0

DAL804,KSFO,KLAX,CLIMB,15:52Z,15:52Z,16:56Z,16:49Z,64,FL380,0

UAL805,KSFO,KORD,CLIMB,15:51Z,15:51Z,19:31Z,19:24Z,220,FL390,0

SWA806,KLAX,KSFO,DESCENT,15:10Z,15:10Z,16:14Z,16:14Z,64,FL114,0

UAL807,KDEN,KSFO,APPROACH,13:49Z,13:49Z,16:05Z,16:05Z,136,FL032,0

ASA808,KSEA,KSFO,APPROACH,14:15Z,14:15Z,16:02Z,16:02Z,107,FL020,0

AAL809,KDFW,KSFO,HOLDING,12:59Z,12:59Z,16:13Z,16:28Z,194,FL140,15

DAL810,KSEA,KLAX,CRUISE,14:43Z,14:43Z,16:50Z,16:50Z,127,FL370,0

ASA901,KSEA,KDEN,TAXI_OUT,16:08Z,16:08Z,18:31Z,18:31Z,143,FL350,0

DAL902,KSEA,KATL,HOLD_SHORT,16:03Z,16:06Z,20:38Z,20:41Z,275,FL370,3

ASA903,KSEA,KSFO,CLIMB,15:52Z,15:52Z,17:36Z,17:29Z,104,FL370,0

DAL904,KSEA,KJFK,CLIMB,15:53Z,15:53Z,20:36Z,20:28Z,283,FL380,0

UAL905,KSEA,KORD,CLIMB,15:51Z,15:51Z,19:35Z,19:28Z,224,FL390,0

ASA906,KSFO,KSEA,DESCENT,14:25Z,14:25Z,16:12Z,16:12Z,107,FL116,0

DAL907,KATL,KSEA,APPROACH,11:29Z,11:29Z,16:04Z,16:04Z,275,FL034,0

ASA908,KLAX,KSEA,APPROACH,13:46Z,13:46Z,16:02Z,16:02Z,136,FL021,0

SWA909,KDEN,KSEA,HOLDING,13:47Z,13:47Z,16:10Z,16:25Z,143,FL150,15

UAL910,KSFO,KORD,CRUISE,15:36Z,15:36Z,19:17Z,19:17Z,221,FL370,0

AAL001,KMIA,KDFW,TAXI_OUT,16:08Z,16:08Z,18:43Z,18:43Z,155,FL350,0

DAL002,KMIA,KATL,HOLD_SHORT,16:05Z,16:08Z,17:38Z,17:41Z,93,FL390,3

AAL003,KMIA,KLAX,CLIMB,15:52Z,15:52Z,20:26Z,20:19Z,274,FL370,0

JBU004,KMIA,KJFK,CLIMB,15:51Z,15:51Z,18:21Z,18:14Z,150,FL380,0

UAL005,KMIA,KIAH,CLIMB,15:51Z,15:51Z,18:08Z,18:01Z,137,FL390,0

DAL006,KATL,KMIA,DESCENT,14:39Z,14:39Z,16:13Z,16:13Z,94,FL112,0

AAL007,KJFK,KMIA,APPROACH,13:34Z,13:34Z,16:04Z,16:04Z,150,FL030,0

AAL008,KDFW,KMIA,APPROACH,13:21Z,13:21Z,16:02Z,16:02Z,161,FL019,0

SWA009,KORD,KMIA,HOLDING,13:27Z,13:27Z,16:11Z,16:26Z,164,FL140,15

UAL010,KIAH,KJFK,CRUISE,15:14Z,15:14Z,18:10Z,18:10Z,176,FL390,0`;


// ============================================================================

// 2. GEODESIC, KINEMATIC & PARSING UTILITIES

// ============================================================================


const DEG_TO_RAD = Math.PI / 180;

const RAD_TO_DEG = 180 / Math.PI;

const EARTH_RADIUS_NM = 3440.065;


/**

 * Great-circle Haversine distance in Nautical Miles

 */

function distanceNM(lat1, lon1, lat2, lon2) {

  const dLat = (lat2 - lat1) * DEG_TO_RAD;

  const dLon = (lon2 - lon1) * DEG_TO_RAD;

  const a =

    Math.sin(dLat / 2) * Math.sin(dLat / 2) +

    Math.cos(lat1 * DEG_TO_RAD) *

      Math.cos(lat2 * DEG_TO_RAD) *

      Math.sin(dLon / 2) *

      Math.sin(dLon / 2);

  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

  return EARTH_RADIUS_NM * c;

}


/**

 * Initial bearing from (lat1, lon1) to (lat2, lon2) in degrees [0, 360)

 */

function bearingDeg(lat1, lon1, lat2, lon2) {

  const phi1 = lat1 * DEG_TO_RAD;

  const phi2 = lat2 * DEG_TO_RAD;

  const dLambda = (lon2 - lon1) * DEG_TO_RAD;

  const y = Math.sin(dLambda) * Math.cos(phi2);

  const x =

    Math.cos(phi1) * Math.sin(phi2) -

    Math.sin(phi1) * Math.cos(phi2) * Math.cos(dLambda);

  return ((Math.atan2(y, x) * RAD_TO_DEG) + 360) % 360;

}


/**

 * Spherical dead-reckoning step given lat, lon, heading (deg), and distance (NM)

 */

function movePosition(lat, lon, headingDeg, distNM) {

  if (distNM === 0) return { lat, lon };

  const delta = distNM / EARTH_RADIUS_NM;

  const theta = headingDeg * DEG_TO_RAD;

  const phi1 = lat * DEG_TO_RAD;

  const lambda1 = lon * DEG_TO_RAD;


  const phi2 = Math.asin(

    Math.sin(phi1) * Math.cos(delta) +

      Math.cos(phi1) * Math.sin(delta) * Math.cos(theta)

  );

  const lambda2 =

    lambda1 +

    Math.atan2(

      Math.sin(theta) * Math.sin(delta) * Math.cos(phi1),

      Math.cos(delta) - Math.sin(phi1) * Math.sin(phi2)

    );


  return {

    lat: phi2 * RAD_TO_DEG,

    lon: ((lambda2 * RAD_TO_DEG + 540) % 360) - 180

  };

}


/**

 * Shortest angular difference in degrees [-180, 180]

 */

function normalizeAngleDiff(target, current) {

  return ((target - current + 540) % 360) - 180;

}


/**

 * Parses and merges the raw CSV strings into strongly-typed initial flight state objects

 */

function buildInitialFlights() {

  const schedMap = {};

  const schedLines = SCHEDULES_CSV.trim().split('\n');

  for (let i = 1; i < schedLines.length; i++) {

    const [callsign, origin, destination, phase, std_utc, etd_utc, sta_utc, eta_utc, ete_min, filed_fl, delay_min] =

      schedLines[i].split(',');

    schedMap[callsign] = {

      std_utc,

      etd_utc,

      sta_utc,

      eta_utc,

      ete_min: Number(ete_min),

      filed_fl,

      filed_alt_ft: Number(filed_fl.replace('FL', '')) * 100,

      delay_min: Number(delay_min)

    };

  }


  const flightLines = FLIGHTS_CSV.trim().split('\n');

  const flights = [];


  for (let i = 1; i < flightLines.length; i++) {

    const [

      callsign,

      ac_type,

      assigned_sector,

      origin,

      destination,

      phase,

      lat,

      lon,

      altitude_ft,

      heading_deg,

      groundspeed_kts,

      vertical_rate_fpm,

      squawk,

      fuel_lbs

    ] = flightLines[i].split(',');


    const sched = schedMap[callsign] || {

      std_utc: '16:00Z',

      etd_utc: '16:00Z',

      sta_utc: '17:30Z',

      eta_utc: '17:30Z',

      ete_min: 90,

      filed_fl: 'FL350',

      filed_alt_ft: 35000,

      delay_min: 0

    };


    const alt = Number(altitude_ft);

    const hdg = Number(heading_deg);

    const spd = Number(groundspeed_kts);

    const vr = Number(vertical_rate_fpm);

    const perf = AIRCRAFT_TYPES[ac_type];

    const destApt = AIRPORT_MAP[destination];


    // Set sensible initial target values consistent with phase

    let targetAlt = alt;

    if (phase === 'CLIMB') targetAlt = sched.filed_alt_ft;

    else if (phase === 'DESCENT') targetAlt = destApt ? destApt.elevation_ft + 3000 : 4000;

    else if (phase === 'APPROACH') targetAlt = destApt ? destApt.elevation_ft : 500;


    let targetSpd = spd;

    if (phase === 'CLIMB') targetSpd = perf ? perf.cruise_tas_kts : 450;


    flights.push({

      callsign,

      ac_type,

      assigned_sector,

      origin,

      destination,

      phase,

      lat: Number(lat),

      lon: Number(lon),

      altitude_ft: alt,

      heading_deg: hdg,

      groundspeed_kts: spd,

      vertical_rate_fpm: vr,

      squawk,

      fuel_lbs: Number(fuel_lbs),

      // Autopilot / ATC Clearance targets

      target_heading_deg: hdg,

      target_altitude_ft: targetAlt,

      target_speed_kts: targetSpd,

      manual_hdg: false,

      hold_timer_sec: 0,

      takeoff_roll_sec: 0,

      // Schedule metadata

      ...sched

    });

  }


  return flights;

}


/**

 * Formats simulation elapsed seconds from 16:00:00Z epoch into HH:MM:SSZ

 */

function formatZuluClock(elapsedSec) {

  const baseSec = 16 * 3600 + Math.floor(elapsedSec);

  const hrs = Math.floor(baseSec / 3600) % 24;

  const mins = Math.floor((baseSec % 3600) / 60);

  const secs = baseSec % 60;

  return `${String(hrs).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}Z`;

}


// ============================================================================

// 3. STCA CONFLICT DETECTION ENGINE

// ============================================================================


function detectConflicts(flights) {

  const alerts = [];

  const activeFlights = flights.filter(

    (f) => f.phase !== 'TAXI_OUT' && f.phase !== 'HOLD_SHORT' && f.phase !== 'LANDED'

  );


  for (let i = 0; i < activeFlights.length; i++) {

    const a = activeFlights[i];

    const perfA = AIRCRAFT_TYPES[a.ac_type];


    for (let j = i + 1; j < activeFlights.length; j++) {

      const b = activeFlights[j];

      const perfB = AIRCRAFT_TYPES[b.ac_type];


      const horizNM = distanceNM(a.lat, a.lon, b.lat, b.lon);

      // Quick spatial bounding cull (> 25 NM cannot conflict within 90s)

      if (horizNM > 25) continue;


      const vertFt = Math.abs(a.altitude_ft - b.altitude_ft);

      const inTerminal =

        a.phase === 'APPROACH' ||

        b.phase === 'APPROACH' ||

        a.phase === 'CLIMB' ||

        b.phase === 'CLIMB' ||

        a.altitude_ft < 18000 ||

        b.altitude_ft < 18000;


      // Wake turbulence requirement if one is Heavy and both on approach

      const isWakePair =

        (a.phase === 'APPROACH' && b.phase === 'APPROACH') &&

        (perfA?.wake === 'H' || perfB?.wake === 'H');


      const minHoriz = isWakePair ? 5.0 : inTerminal ? 3.0 : 5.0;

      const minVert = 1000;


      // 1. Active Loss of Separation (RED)

      if (horizNM < minHoriz && vertFt < minVert) {

        alerts.push({

          id: `${a.callsign}-${b.callsign}`,

          severity: 'RED',

          type: isWakePair ? 'WAKE SEPARATION' : 'LOSS OF SEPARATION',

          sector: a.assigned_sector,

          callsignA: a.callsign,

          callsignB: b.callsign,

          horizNM: Number(horizNM.toFixed(2)),

          vertFt: Math.round(vertFt),

          cpaSec: 0

        });

        continue;

      }


      // 2. Predictive 90-second CPA Lookahead (AMBER)

      let minFutureHoriz = horizNM;

      let minFutureVert = vertFt;

      let cpaSec = 90;

      let breached = false;


      for (let t = 15; t <= 90; t += 15) {

        const posA = movePosition(a.lat, a.lon, a.heading_deg, (a.groundspeed_kts / 3600) * t);

        const posB = movePosition(b.lat, b.lon, b.heading_deg, (b.groundspeed_kts / 3600) * t);

        const futH = distanceNM(posA.lat, posA.lon, posB.lat, posB.lon);

        const futAltA = a.altitude_ft + a.vertical_rate_fpm * (t / 60);

        const futAltB = b.altitude_ft + b.vertical_rate_fpm * (t / 60);

        const futV = Math.abs(futAltA - futAltB);


        if (futH < minHoriz && futV < minVert) {

          breached = true;

          minFutureHoriz = futH;

          minFutureVert = futV;

          cpaSec = t;

          break;

        }

      }


      if (breached) {

        alerts.push({

          id: `${a.callsign}-${b.callsign}`,

          severity: 'AMBER',

          type: 'PREDICTIVE CPA',

          sector: a.assigned_sector,

          callsignA: a.callsign,

          callsignB: b.callsign,

          horizNM: Number(minFutureHoriz.toFixed(2)),

          vertFt: Math.round(minFutureVert),

          cpaSec

        });

      }

    }

  }


  // Sort RED alerts first

  return alerts.sort((x, y) => (x.severity === y.severity ? 0 : x.severity === 'RED' ? -1 : 1));

}


// ============================================================================

// 4. PHASE COLOR & BADGE HELPERS

// ============================================================================


const PHASE_STYLES = {

  TAXI_OUT: { color: '#facc15', bg: 'bg-yellow-500/15', text: 'text-yellow-300', border: 'border-yellow-500/40', label: 'TAXI OUT' },

  HOLD_SHORT: { color: '#fb923c', bg: 'bg-orange-500/15', text: 'text-orange-300', border: 'border-orange-500/40', label: 'HOLD SHORT' },

  TAKEOFF: { color: '#4ade80', bg: 'bg-emerald-500/15', text: 'text-emerald-300', border: 'border-emerald-500/40', label: 'TAKEOFF' },

  CLIMB: { color: '#34d399', bg: 'bg-emerald-500/15', text: 'text-emerald-300', border: 'border-emerald-500/40', label: 'CLIMB' },

  CRUISE: { color: '#e2e8f0', bg: 'bg-slate-500/15', text: 'text-slate-200', border: 'border-slate-500/40', label: 'CRUISE' },

  DESCENT: { color: '#38bdf8', bg: 'bg-sky-500/15', text: 'text-sky-300', border: 'border-sky-500/40', label: 'DESCENT' },

  APPROACH: { color: '#22d3ee', bg: 'bg-cyan-500/15', text: 'text-cyan-300', border: 'border-cyan-500/40', label: 'APPROACH' },

  HOLDING: { color: '#e879f9', bg: 'bg-fuchsia-500/15', text: 'text-fuchsia-300', border: 'border-fuchsia-500/40', label: 'HOLDING' },

  LANDED: { color: '#94a3b8', bg: 'bg-slate-700/30', text: 'text-slate-400', border: 'border-slate-600/40', label: 'LANDED' }

};


// ============================================================================

// 5. MAIN APPLICATION COMPONENT

// ============================================================================


export default function App() {

  // Navigation & Simulation Controls

  const [selectedSector, setSelectedSector] = useState('KATL'); // 'NAS-ALL' or ICAO

  const [simSpeed, setSimSpeed] = useState(1); // 0 = PAUSE, 1, 2, 5, 10

  const [elapsedSec, setElapsedSec] = useState(0);


  // Core Simulation State

  const [flights, setFlights] = useState(() => buildInitialFlights());

  const [selectedCallsign, setSelectedCallsign] = useState('DAL107');

  const [stripFilter, setStripFilter] = useState('ALL'); // 'ALL', 'DEP', 'ARR', 'OVER'

  const [searchQuery, setSearchQuery] = useState('');


  // Clearance Command Deck Inputs

  const [cmdHdg, setCmdHdg] = useState('');

  const [cmdAlt, setCmdAlt] = useState('');

  const [cmdSpd, setCmdSpd] = useState('');

  const [cmdFeedback, setCmdFeedback] = useState(null);

  const [auditLog, setAuditLog] = useState([

    { time: '16:00:00Z', callsign: 'SYSTEM', msg: 'NAS TRACON/ARTCC KERNEL INITIALIZED — 10 SECTORS / 100 ACTIVE TARGETS', type: 'INFO' }

  ]);


  // Radar Canvas Viewport State (Zoom & Pan offsets in pixels)

  const [radarZoom, setRadarZoom] = useState(1.0);

  const [panOffset, setPanOffset] = useState({ x: 0, y: 0 });

  const [showLeaderLines, setShowLeaderLines] = useState(true);

  const [showRangeRings, setShowRangeRings] = useState(true);


  // Refs for smooth animation & canvas interaction

  const canvasRef = useRef(null);

  const isDraggingRef = useRef(false);

  const dragStartRef = useRef({ x: 0, y: 0 });

  const flightsRef = useRef(flights);

  flightsRef.current = flights;

  const conflictsRef = useRef([]);


  // Compute live STCA conflicts

  const conflicts = useMemo(() => detectConflicts(flights), [flights]);

  conflictsRef.current = conflicts;


  // Currently selected aircraft object

  const selectedFlight = useMemo(

    () => flights.find((f) => f.callsign === selectedCallsign) || null,

    [flights, selectedCallsign]

  );


  // Sync clearance form fields when selected aircraft changes

  useEffect(() => {

    if (selectedFlight) {

      setCmdHdg(String(Math.round(selectedFlight.target_heading_deg)).padStart(3, '0'));

      setCmdAlt(String(Math.round(selectedFlight.target_altitude_ft / 100)).padStart(3, '0'));

      setCmdSpd(String(Math.round(selectedFlight.target_speed_kts)));

      setCmdFeedback(null);

    }

  }, [selectedCallsign]);


  // Reset radar pan/zoom when switching airports

  const handleSelectSector = useCallback((sector) => {

    setSelectedSector(sector);

    setPanOffset({ x: 0, y: 0 });

    setRadarZoom(1.0);

    if (sector !== 'NAS-ALL') {

      const sectorFlights = flightsRef.current.filter((f) => f.assigned_sector === sector);

      if (sectorFlights.length > 0 && (!selectedFlight || selectedFlight.assigned_sector !== sector)) {

        setSelectedCallsign(sectorFlights[0].callsign);

      }

    }

  }, [selectedFlight]);


  // ==========================================================================

  // 6. KINEMATIC PHYSICS TICK ENGINE (10 Hz SUB-STEPPED FOR SMOOTH MOTION)

  // ==========================================================================


  useEffect(() => {

    if (simSpeed === 0) return;


    const tickIntervalMs = 100; // 10 updates per wall-clock second

    const timer = setInterval(() => {

      const dt = (tickIntervalMs / 1000) * simSpeed; // simulated seconds elapsed this tick

      setElapsedSec((prev) => prev + dt);


      setFlights((prevFlights) =>

        prevFlights.map((f) => {

          if (f.phase === 'LANDED') return f;


          const perf = AIRCRAFT_TYPES[f.ac_type] || {

            wake: 'M',

            cruise_tas_kts: 450,

            climb_fpm: 2200,

            descent_fpm: 1800,

            approach_kts: 142,

            max_alt: 41000

          };

          const originApt = AIRPORT_MAP[f.origin];

          const destApt = AIRPORT_MAP[f.destination];


          let {

            lat,

            lon,

            altitude_ft,

            heading_deg,

            groundspeed_kts,

            vertical_rate_fpm,

            phase,

            target_heading_deg,

            target_altitude_ft,

            target_speed_kts,

            manual_hdg,

            hold_timer_sec,

            takeoff_roll_sec,

            assigned_sector,

            fuel_lbs

          } = f;


          // 1. Phase-specific kinematic behavior

          if (phase === 'HOLD_SHORT') {

            groundspeed_kts = 0;

            vertical_rate_fpm = 0;

          } else if (phase === 'TAXI_OUT') {

            // Taxi along runway/taxiway heading at 15 kts, stop at hold short after 45s

            takeoff_roll_sec += dt;

            if (takeoff_roll_sec > 45) {

              phase = 'HOLD_SHORT';

              groundspeed_kts = 0;

            } else {

              const moved = movePosition(lat, lon, heading_deg, (groundspeed_kts / 3600) * dt);

              lat = moved.lat;

              lon = moved.lon;

            }

          } else if (phase === 'TAKEOFF') {

            // Accelerate down runway and rotate at 155 kts

            groundspeed_kts = Math.min(165, groundspeed_kts + 4.5 * dt);

            const moved = movePosition(lat, lon, heading_deg, (groundspeed_kts / 3600) * dt);

            lat = moved.lat;

            lon = moved.lon;

            if (groundspeed_kts >= 150) {

              altitude_ft += (perf.climb_fpm / 60) * dt;

              vertical_rate_fpm = perf.climb_fpm;

              if (originApt && altitude_ft >= originApt.elevation_ft + 400) {

                phase = 'CLIMB';

                target_altitude_ft = f.filed_alt_ft;

                target_speed_kts = perf.cruise_tas_kts;

              }

            }

          } else if (phase === 'HOLDING') {

            // Standard 1-minute right-hand racetrack holding orbit

            hold_timer_sec = (hold_timer_sec + dt) % 120;

            if (hold_timer_sec < 60) {

              // Straight leg (outbound/inbound)

            } else {

              // 180-degree standard rate turn (3 deg/sec over 60s)

              heading_deg = (heading_deg + 3 * dt) % 360;

            }

            target_heading_deg = heading_deg;

            const moved = movePosition(lat, lon, heading_deg, (groundspeed_kts / 3600) * dt);

            lat = moved.lat;

            lon = moved.lon;

          } else {

            // Airborne phases: CLIMB, CRUISE, DESCENT, APPROACH

            // A. Lateral Navigation (Autopilot direct-to-destination unless manual HDG active)

            if (!manual_hdg && destApt) {

              if (phase === 'APPROACH') {

                // Align with destination active arrival runway heading

                const arrRwy = destApt.runways.find((r) => r.status === 'ACTIVE_ARR') || destApt.runways[0];

                const distToDest = distanceNM(lat, lon, destApt.lat, destApt.lon);

                const brgToDest = bearingDeg(lat, lon, destApt.lat, destApt.lon);

                // Blend intercept angle onto final approach centerline

                const rwyHdg = arrRwy ? arrRwy.heading_deg : brgToDest;

                const diff = normalizeAngleDiff(brgToDest, rwyHdg);

                target_heading_deg = distToDest < 5 ? brgToDest : (brgToDest + diff * 0.45 + 360) % 360;

              } else {

                target_heading_deg = bearingDeg(lat, lon, destApt.lat, destApt.lon);

              }

            }


            // Standard rate turn (3 deg/sec)

            const hdgDiff = normalizeAngleDiff(target_heading_deg, heading_deg);

            const maxTurn = 3.0 * dt;

            if (Math.abs(hdgDiff) <= maxTurn) {

              heading_deg = target_heading_deg;

            } else {

              heading_deg = (heading_deg + Math.sign(hdgDiff) * maxTurn + 360) % 360;

            }


            // B. Vertical Profile & Phase Transitions

            const altDiff = target_altitude_ft - altitude_ft;

            if (Math.abs(altDiff) < 25) {

              altitude_ft = target_altitude_ft;

              vertical_rate_fpm = 0;

              if (phase === 'CLIMB' && altitude_ft >= f.filed_alt_ft - 100) {

                phase = 'CRUISE';

              }

            } else if (altDiff > 0) {

              vertical_rate_fpm = perf.climb_fpm;

              altitude_ft = Math.min(target_altitude_ft, altitude_ft + (vertical_rate_fpm / 60) * dt);

            } else {

              const descRate = phase === 'APPROACH' ? 800 : perf.descent_fpm;

              vertical_rate_fpm = -descRate;

              altitude_ft = Math.max(target_altitude_ft, altitude_ft - (descRate / 60) * dt);

            }


            // C. Speed Envelope & Automatic Approach/Landing Transitions

            if (destApt) {

              const distToDest = distanceNM(lat, lon, destApt.lat, destApt.lon);

              // Top-of-Descent (3:1 rule) for CRUISE aircraft

              if (phase === 'CRUISE' && distToDest < (altitude_ft - destApt.elevation_ft) / 310) {

                phase = 'DESCENT';

                target_altitude_ft = destApt.elevation_ft + 3000;

                target_speed_kts = 250;

              }

              // Transition DESCENT -> APPROACH within 16 NM of destination

              if (phase === 'DESCENT' && distToDest <= 16) {

                phase = 'APPROACH';

                target_altitude_ft = destApt.elevation_ft;

                target_speed_kts = perf.approach_kts;

              }

              // Touchdown check on APPROACH

              if (phase === 'APPROACH') {

                // Smooth glideslope altitude proportional to distance (300 ft/NM)

                const glideslopeAlt = destApt.elevation_ft + distToDest * 310;

                if (altitude_ft > glideslopeAlt + 200) {

                  altitude_ft -= (900 / 60) * dt;

                  vertical_rate_fpm = -900;

                }

                if (distToDest < 0.35 || altitude_ft <= destApt.elevation_ft + 15) {

                  phase = 'LANDED';

                  altitude_ft = destApt.elevation_ft;

                  groundspeed_kts = 0;

                  vertical_rate_fpm = 0;

                }

              }

            }


            // Smooth groundspeed acceleration/deceleration (2 kts/sec)

            if (phase !== 'LANDED') {

              const spdDiff = target_speed_kts - groundspeed_kts;

              const maxAccel = 2.0 * dt;

              if (Math.abs(spdDiff) <= maxAccel) {

                groundspeed_kts = target_speed_kts;

              } else {

                groundspeed_kts += Math.sign(spdDiff) * maxAccel;

              }


              const moved = movePosition(lat, lon, heading_deg, (groundspeed_kts / 3600) * dt);

              lat = moved.lat;

              lon = moved.lon;


              // Fuel burn (~1.8 lbs/sec for heavy, ~0.9 lbs/sec for medium)

              const burnRate = perf.wake === 'H' ? 1.8 : 0.95;

              fuel_lbs = Math.max(0, fuel_lbs - burnRate * dt);

            }

          }


          // 2. Dynamic TRACON Sector Handoff Check

          let closestSector = assigned_sector;

          let minDist = Infinity;

          for (const apt of AIRPORTS) {

            const d = distanceNM(lat, lon, apt.lat, apt.lon);

            if (d <= apt.tracon_radius_nm && d < minDist) {

              minDist = d;

              closestSector = apt.icao;

            }

          }

          if (minDist < Infinity) {

            assigned_sector = closestSector;

          }


          return {

            ...f,

            lat,

            lon,

            altitude_ft,

            heading_deg,

            groundspeed_kts,

            vertical_rate_fpm,

            phase,

            target_heading_deg,

            target_altitude_ft,

            target_speed_kts,

            manual_hdg,

            hold_timer_sec,

            takeoff_roll_sec,

            assigned_sector,

            fuel_lbs

          };

        })

      );

    }, tickIntervalMs);


    return () => clearInterval(timer);

  }, [simSpeed]);


  // ==========================================================================

  // 7. CLEARANCE COMMAND HANDLERS & ENVELOPE VALIDATION

  // ==========================================================================


  const pushAudit = useCallback((callsign, msg, type = 'CLEARANCE') => {

    setAuditLog((prev) => [

      { time: formatZuluClock(elapsedSec), callsign, msg, type },

      ...prev.slice(0, 39)

    ]);

  }, [elapsedSec]);


  const handleApplyVectorClearance = (e) => {

    e.preventDefault();

    if (!selectedFlight) return;

    const perf = AIRCRAFT_TYPES[selectedFlight.ac_type];

    const hdgVal = parseInt(cmdHdg, 10);

    const flVal = parseInt(cmdAlt, 10);

    const spdVal = parseInt(cmdSpd, 10);


    if (isNaN(hdgVal) || hdgVal < 1 || hdgVal > 360) {

      setCmdFeedback({ ok: false, msg: 'INVALID HDG: Enter 001–360°' });

      return;

    }

    const altFt = flVal * 100;

    if (isNaN(altFt) || altFt < 0 || altFt > (perf?.max_alt || 41000)) {

      setCmdFeedback({ ok: false, msg: `ALT EXCEEDS ${selectedFlight.ac_type} CEILING (FL${Math.floor((perf?.max_alt || 41000) / 100)})` });

      return;

    }

    const minSpd = perf?.approach_kts || 130;

    const maxSpd = (perf?.cruise_tas_kts || 460) + 35;

    if (selectedFlight.phase !== 'TAXI_OUT' && selectedFlight.phase !== 'HOLD_SHORT') {

      if (isNaN(spdVal) || spdVal < minSpd || spdVal > maxSpd) {

        setCmdFeedback({

          ok: false,

          msg: `SPD ENVELOPE REJECTED: ${selectedFlight.ac_type} (${perf?.wake}) requires ${minSpd}–${maxSpd} KTS`

        });

        return;

      }

    }


    setFlights((prev) =>

      prev.map((f) => {

        if (f.callsign !== selectedFlight.callsign) return f;

        let newPhase = f.phase;

        if (newPhase === 'HOLDING') newPhase = 'DESCENT';

        if (altFt > f.altitude_ft + 300 && (newPhase === 'CRUISE' || newPhase === 'DESCENT')) newPhase = 'CLIMB';

        if (altFt < f.altitude_ft - 300 && (newPhase === 'CRUISE' || newPhase === 'CLIMB')) newPhase = 'DESCENT';


        return {

          ...f,

          target_heading_deg: hdgVal === 360 ? 0 : hdgVal,

          manual_hdg: true,

          target_altitude_ft: altFt,

          target_speed_kts: spdVal,

          phase: newPhase

        };

      })

    );


    const summary = `HDG ${String(hdgVal).padStart(3, '0')}° | FL${String(flVal).padStart(3, '0')} | ${spdVal} KTS`;

    setCmdFeedback({ ok: true, msg: `TRANSMITTED: ${summary}` });

    pushAudit(selectedFlight.callsign, summary, 'VECTOR');

  };


  const handleQuickAction = (actionType) => {

    if (!selectedFlight) return;

    const perf = AIRCRAFT_TYPES[selectedFlight.ac_type];

    const originApt = AIRPORT_MAP[selectedFlight.origin];

    const destApt = AIRPORT_MAP[selectedFlight.destination];


    setFlights((prev) =>

      prev.map((f) => {

        if (f.callsign !== selectedFlight.callsign) return f;


        if (actionType === 'TAKEOFF') {

          const depRwy = originApt?.runways.find((r) => r.status === 'ACTIVE_DEP') || originApt?.runways[0];

          const rwyHdg = depRwy ? depRwy.heading_deg : f.heading_deg;

          return {

            ...f,

            phase: 'TAKEOFF',

            heading_deg: rwyHdg,

            target_heading_deg: rwyHdg,

            groundspeed_kts: 35,

            target_altitude_ft: f.filed_alt_ft,

            target_speed_kts: perf?.cruise_tas_kts || 450,

            manual_hdg: false

          };

        }


        if (actionType === 'HOLD') {

          return {

            ...f,

            phase: 'HOLDING',

            target_speed_kts: 215,

            vertical_rate_fpm: 0,

            target_altitude_ft: f.altitude_ft,

            hold_timer_sec: 0

          };

        }


        if (actionType === 'APPROACH') {

          return {

            ...f,

            phase: 'APPROACH',

            manual_hdg: false,

            target_altitude_ft: destApt ? destApt.elevation_ft : 500,

            target_speed_kts: perf?.approach_kts || 145

          };

        }


        if (actionType === 'GO_AROUND') {

          const goAlt = (destApt ? destApt.elevation_ft : 500) + 4000;

          return {

            ...f,

            phase: 'CLIMB',

            manual_hdg: true,

            target_heading_deg: f.heading_deg,

            target_altitude_ft: goAlt,

            target_speed_kts: 210

          };

        }


        return f;

      })

    );


    const labels = {

      TAKEOFF: 'CLEARED FOR TAKEOFF — RWY HEADING, CLIMB & MAINTAIN FILED FL',

      HOLD: 'HOLD AT PRESENT POSITION — RIGHT TURNS, 1 MIN LEGS',

      APPROACH: 'CLEARED ILS APPROACH — INTERCEPT FINAL',

      GO_AROUND: 'GO AROUND — CLIMB & MAINTAIN +4,000 FT AGL'

    };

    setCmdFeedback({ ok: true, msg: labels[actionType] });

    pushAudit(selectedFlight.callsign, labels[actionType], 'PROCEDURE');

  };


  const handleResetSimulation = () => {

    setSimSpeed(1);

    setElapsedSec(0);

    setFlights(buildInitialFlights());

    setPanOffset({ x: 0, y: 0 });

    setRadarZoom(1.0);

    setCmdFeedback(null);

    setAuditLog([

      { time: '16:00:00Z', callsign: 'SYSTEM', msg: 'SIMULATION RESET TO 16:00:00Z EPOCH — ALL 100 FLIGHTS RESTORED', type: 'INFO' }

    ]);

  };


  // ==========================================================================

  // 8. HTML5 CANVAS RADAR SCOPE RENDERER & INTERACTION

  // ==========================================================================


  // Coordinate projection helper shared by renderer and click hit-testing

  const projectToScreen = useCallback(

    (lat, lon, width, height) => {

      const cx = width / 2 + panOffset.x;

      const cy = height / 2 + panOffset.y;


      if (selectedSector === 'NAS-ALL') {

        // Equirectangular projection centered on CONUS (-98.5 W, 38.5 N)

        const centerLat = 38.2;

        const centerLon = -98.5;

        const baseScale = Math.min(width / 62, height / 34) * radarZoom;

        const x = cx + (lon - centerLon) * Math.cos(centerLat * DEG_TO_RAD) * baseScale * 1.15;

        const y = cy - (lat - centerLat) * baseScale * 1.15;

        return { x, y, pxPerNM: baseScale / 60 };

      } else {

        const apt = AIRPORT_MAP[selectedSector] || AIRPORTS[0];

        // Default radar scope covers ~110 NM diameter (55 NM radius)

        const basePxPerNM = (Math.min(width, height) / 115) * radarZoom;

        const dLatNM = (lat - apt.lat) * 60;

        const dLonNM = (lon - apt.lon) * 60 * Math.cos(apt.lat * DEG_TO_RAD);

        return {

          x: cx + dLonNM * basePxPerNM,

          y: cy - dLatNM * basePxPerNM,

          pxPerNM: basePxPerNM

        };

      }

    },

    [selectedSector, radarZoom, panOffset]

  );


  // Main Radar Render Loop

  useEffect(() => {

    const canvas = canvasRef.current;

    if (!canvas) return;

    const ctx = canvas.getContext('2d');


    let animId;

    const render = () => {

      const rect = canvas.parentElement.getBoundingClientRect();

      const dpr = window.devicePixelRatio || 1;

      if (canvas.width !== Math.floor(rect.width * dpr) || canvas.height !== Math.floor(rect.height * dpr)) {

        canvas.width = Math.floor(rect.width * dpr);

        canvas.height = Math.floor(rect.height * dpr);

      }


      ctx.save();

      ctx.scale(dpr, dpr);

      const W = rect.width;

      const H = rect.height;


      // 1. Deep Tactical TRACON Obsidian Background

      ctx.fillStyle = '#05090e';

      ctx.fillRect(0, 0, W, H);


      // Subtle radial phosphor glow in center

      const grad = ctx.createRadialGradient(W / 2, H / 2, 10, W / 2, H / 2, Math.max(W, H) * 0.65);

      grad.addColorStop(0, 'rgba(14, 42, 56, 0.28)');

      grad.addColorStop(1, 'rgba(5, 9, 14, 0)');

      ctx.fillStyle = grad;

      ctx.fillRect(0, 0, W, H);


      const activeConflicts = conflictsRef.current;

      const conflictCallsigns = new Map();

      activeConflicts.forEach((c) => {

        if (c.severity === 'RED' || !conflictCallsigns.has(c.callsignA)) {

          conflictCallsigns.set(c.callsignA, c.severity);

        }

        if (c.severity === 'RED' || !conflictCallsigns.has(c.callsignB)) {

          conflictCallsigns.set(c.callsignB, c.severity);

        }

      });


      if (selectedSector === 'NAS-ALL') {

        // ====================================================================

        // MODE A: CONUS NATIONAL AIRSPACE OVERVIEW

        // ====================================================================

        // Draw schematic CONUS coastline

        ctx.beginPath();

        CONUS_OUTLINE.forEach(([clat, clon], idx) => {

          const pt = projectToScreen(clat, clon, W, H);

          if (idx === 0) ctx.moveTo(pt.x, pt.y);

          else ctx.lineTo(pt.x, pt.y);

        });

        ctx.strokeStyle = 'rgba(56, 189, 248, 0.22)';

        ctx.lineWidth = 1.5;

        ctx.stroke();

        ctx.fillStyle = 'rgba(15, 30, 46, 0.25)';

        ctx.fill();


        // Draw all 10 Hub Airports & TRACON rings

        AIRPORTS.forEach((apt) => {

          const pt = projectToScreen(apt.lat, apt.lon, W, H);

          const ringR = Math.max(12, apt.tracon_radius_nm * pt.pxPerNM);


          ctx.beginPath();

          ctx.arc(pt.x, pt.y, ringR, 0, Math.PI * 2);

          ctx.strokeStyle = 'rgba(34, 211, 238, 0.35)';

          ctx.setLineDash([4, 4]);

          ctx.lineWidth = 1;

          ctx.stroke();

          ctx.setLineDash([]);


          // Airport beacon square

          ctx.fillStyle = '#22d3ee';

          ctx.fillRect(pt.x - 3, pt.y - 3, 6, 6);


          ctx.font = '600 10px ui-monospace, SFMono-Regular, Menlo, monospace';

          ctx.fillStyle = '#67e8f9';

          ctx.fillText(apt.icao, pt.x + 7, pt.y - 5);

        });

      } else {

        // ====================================================================

        // MODE B: SINGLE-AIRPORT TRACON / TOWER PPI RADAR SCOPE

        // ====================================================================

        const apt = AIRPORT_MAP[selectedSector] || AIRPORTS[0];

        const centerPt = projectToScreen(apt.lat, apt.lon, W, H);

        const pxPerNM = centerPt.pxPerNM;


        // Range Rings (10, 20, 30, 40, 50, 60 NM)

        if (showRangeRings) {

          for (let nm = 10; nm <= 70; nm += 10) {

            const r = nm * pxPerNM;

            const isTracon = nm === apt.tracon_radius_nm;

            ctx.beginPath();

            ctx.arc(centerPt.x, centerPt.y, r, 0, Math.PI * 2);

            ctx.strokeStyle = isTracon ? 'rgba(34, 211, 238, 0.42)' : 'rgba(51, 78, 104, 0.35)';

            ctx.lineWidth = isTracon ? 1.5 : 1;

            if (isTracon) ctx.setLineDash([6, 4]);

            ctx.stroke();

            ctx.setLineDash([]);


            // Range ring distance label

            ctx.font = '10px ui-monospace, SFMono-Regular, Menlo, monospace';

            ctx.fillStyle = isTracon ? 'rgba(34, 211, 238, 0.75)' : 'rgba(100, 116, 139, 0.7)';

            ctx.fillText(`${nm}NM`, centerPt.x + 4, centerPt.y - r + 11);

          }


          // Crosshair azimuth lines (N-S / E-W)

          ctx.strokeStyle = 'rgba(51, 78, 104, 0.25)';

          ctx.lineWidth = 1;

          ctx.beginPath();

          ctx.moveTo(centerPt.x - 70 * pxPerNM, centerPt.y);

          ctx.lineTo(centerPt.x + 70 * pxPerNM, centerPt.y);

          ctx.moveTo(centerPt.x, centerPt.y - 70 * pxPerNM);

          ctx.lineTo(centerPt.x, centerPt.y + 70 * pxPerNM);

          ctx.stroke();

        }


        // Compass Rose Ticks around outer 55 NM ring

        const roseR = 55 * pxPerNM;

        for (let deg = 0; deg < 360; deg += 10) {

          const rad = (deg - 90) * DEG_TO_RAD;

          const isMajor = deg % 30 === 0;

          const innerR = roseR - (isMajor ? 7 : 3);

          ctx.beginPath();

          ctx.moveTo(centerPt.x + Math.cos(rad) * innerR, centerPt.y + Math.sin(rad) * innerR);

          ctx.lineTo(centerPt.x + Math.cos(rad) * roseR, centerPt.y + Math.sin(rad) * roseR);

          ctx.strokeStyle = isMajor ? 'rgba(148, 163, 184, 0.5)' : 'rgba(100, 116, 139, 0.3)';

          ctx.lineWidth = 1;

          ctx.stroke();


          if (isMajor) {

            const labelR = roseR + 12;

            const lx = centerPt.x + Math.cos(rad) * labelR;

            const ly = centerPt.y + Math.sin(rad) * labelR;

            ctx.font = '10px ui-monospace, SFMono-Regular, Menlo, monospace';

            ctx.fillStyle = 'rgba(148, 163, 184, 0.65)';

            ctx.textAlign = 'center';

            ctx.textBaseline = 'middle';

            ctx.fillText(String(deg === 0 ? 360 : deg).padStart(3, '0'), lx, ly);

          }

        }

        ctx.textAlign = 'left';

        ctx.textBaseline = 'alphabetic';


        // Active Runways & Extended 15 NM Final Approach Centerline Feathers

        apt.runways.forEach((rwy, idx) => {

          const offsetPx = (idx - (apt.runways.length - 1) / 2) * 5;

          const rwyRad = (rwy.heading_deg - 90) * DEG_TO_RAD;

          const perpRad = rwyRad + Math.PI / 2;


          const rx = centerPt.x + Math.cos(perpRad) * offsetPx;

          const ry = centerPt.y + Math.sin(perpRad) * offsetPx;

          const halfLenPx = Math.max(8, (rwy.length_ft / 6076 / 2) * pxPerNM);


          // Runway pavement bar

          ctx.beginPath();

          ctx.moveTo(rx - Math.cos(rwyRad) * halfLenPx, ry - Math.sin(rwyRad) * halfLenPx);

          ctx.lineTo(rx + Math.cos(rwyRad) * halfLenPx, ry + Math.sin(rwyRad) * halfLenPx);

          ctx.strokeStyle = rwy.status === 'ACTIVE_ARR' ? '#22d3ee' : '#34d399';

          ctx.lineWidth = 2.5;

          ctx.stroke();


          // Extended 15 NM final approach feather on reciprocal heading for arrival runways

          if (rwy.status === 'ACTIVE_ARR') {

            const featherLenPx = 15 * pxPerNM;

            const startX = rx - Math.cos(rwyRad) * halfLenPx;

            const startY = ry - Math.sin(rwyRad) * halfLenPx;

            const endX = startX - Math.cos(rwyRad) * featherLenPx;

            const endY = startY - Math.sin(rwyRad) * featherLenPx;


            ctx.beginPath();

            ctx.moveTo(startX, startY);

            ctx.lineTo(endX, endY);

            ctx.strokeStyle = 'rgba(34, 211, 238, 0.35)';

            ctx.setLineDash([4, 4]);

            ctx.lineWidth = 1;

            ctx.stroke();

            ctx.setLineDash([]);

          }

        });


        // Airport Center Reference Label

        ctx.font = 'bold 11px ui-monospace, SFMono-Regular, Menlo, monospace';

        ctx.fillStyle = '#38bdf8';

        ctx.fillText(`${apt.icao} (${apt.elevation_ft}')`, centerPt.x + 8, centerPt.y + 14);

      }


      // ======================================================================

      // 9. RENDER AIRCRAFT TARGETS, VELOCITY VECTORS & DATA BLOCKS

      // ======================================================================

      const currentFlights = flightsRef.current;

      const visibleFlights =

        selectedSector === 'NAS-ALL'

          ? currentFlights.filter((f) => f.phase !== 'LANDED')

          : currentFlights.filter((f) => {

              if (f.phase === 'LANDED') return false;

              if (f.assigned_sector === selectedSector) return true;

              const apt = AIRPORT_MAP[selectedSector];

              return apt && distanceNM(f.lat, f.lon, apt.lat, apt.lon) <= 75;

            });


      const pulsePhase = (Math.sin(Date.now() / 220) + 1) / 2; // 0..1 smooth pulse


      visibleFlights.forEach((f) => {

        const pt = projectToScreen(f.lat, f.lon, W, H);

        if (pt.x < -60 || pt.x > W + 60 || pt.y < -60 || pt.y > H + 60) return;


        const isSelected = f.callsign === selectedCallsign;

        const alertSeverity = conflictCallsigns.get(f.callsign);

        const phaseStyle = PHASE_STYLES[f.phase] || PHASE_STYLES.CRUISE;

        const perf = AIRCRAFT_TYPES[f.ac_type];


        // A. STCA Conflict Ring (Red or Amber pulsing halo)

        if (alertSeverity) {

          const ringRadius = 15 + pulsePhase * 6;

          ctx.beginPath();

          ctx.arc(pt.x, pt.y, ringRadius, 0, Math.PI * 2);

          ctx.strokeStyle =

            alertSeverity === 'RED'

              ? `rgba(239, 68, 68, ${0.55 + pulsePhase * 0.45})`

              : `rgba(245, 158, 11, ${0.45 + pulsePhase * 0.45})`;

          ctx.lineWidth = alertSeverity === 'RED' ? 2.2 : 1.6;

          ctx.stroke();

        }


        // B. Selected Aircraft Target Reticle

        if (isSelected) {

          ctx.beginPath();

          ctx.arc(pt.x, pt.y, 12, 0, Math.PI * 2);

          ctx.strokeStyle = '#ffffff';

          ctx.lineWidth = 1.5;

          ctx.stroke();

        }


        // C. Velocity Leader Line (60-second lookahead vector)

        if (showLeaderLines && f.groundspeed_kts > 5) {

          const futurePos = movePosition(f.lat, f.lon, f.heading_deg, f.groundspeed_kts / 60);

          const fPt = projectToScreen(futurePos.lat, futurePos.lon, W, H);

          ctx.beginPath();

          ctx.moveTo(pt.x, pt.y);

          ctx.lineTo(fPt.x, fPt.y);

          ctx.strokeStyle = isSelected ? '#ffffff' : phaseStyle.color;

          ctx.globalAlpha = 0.7;

          ctx.lineWidth = 1.2;

          ctx.stroke();

          ctx.globalAlpha = 1.0;

        }


        // D. Directional Target Chevron oriented to heading_deg

        ctx.save();

        ctx.translate(pt.x, pt.y);

        ctx.rotate(f.heading_deg * DEG_TO_RAD);

        ctx.beginPath();

        ctx.moveTo(0, -6.5);

        ctx.lineTo(4.5, 5.5);

        ctx.lineTo(0, 2.8);

        ctx.lineTo(-4.5, 5.5);

        ctx.closePath();

        ctx.fillStyle = alertSeverity === 'RED' ? '#ef4444' : isSelected ? '#ffffff' : phaseStyle.color;

        ctx.fill();

        ctx.restore();


        // E. 3-Line Limited Data Block (LDB)

        // In NAS-ALL mode, show compact callsign labels unless selected/alerting to prevent clutter

        const showFullLDB = selectedSector !== 'NAS-ALL' || isSelected || Boolean(alertSeverity);

        const bx = pt.x + 10;

        const by = pt.y - 6;


        // Leader tick from target to data block

        ctx.beginPath();

        ctx.moveTo(pt.x + 3, pt.y - 2);

        ctx.lineTo(bx - 2, by);

        ctx.strokeStyle = 'rgba(148, 163, 184, 0.45)';

        ctx.lineWidth = 0.9;

        ctx.stroke();


        ctx.font = `${isSelected ? 'bold ' : ''}10px ui-monospace, SFMono-Regular, Menlo, monospace`;

        const textColor =

          alertSeverity === 'RED'

            ? '#fca5a5'

            : alertSeverity === 'AMBER'

            ? '#fcd34d'

            : isSelected

            ? '#ffffff'

            : phaseStyle.color;


        if (!showFullLDB) {

          ctx.fillStyle = textColor;

          ctx.fillText(f.callsign, bx, by + 3);

        } else {

          // Optional subtle backing box for selected target

          if (isSelected) {

            ctx.fillStyle = 'rgba(15, 23, 42, 0.85)';

            ctx.fillRect(bx - 3, by - 9, 86, 33);

            ctx.strokeStyle = 'rgba(255, 255, 255, 0.45)';

            ctx.lineWidth = 0.8;

            ctx.strokeRect(bx - 3, by - 9, 86, 33);

          }


          ctx.fillStyle = textColor;

          // Line 1: CALLSIGN + Wake Category

          ctx.fillText(`${f.callsign} ${perf?.wake || 'M'}`, bx, by);


          // Line 2: Altitude (FL/100) + Trend Arrow + Groundspeed (KTS/10)

          const altHundreds = String(Math.round(f.altitude_ft / 100)).padStart(3, '0');

          const trend = f.vertical_rate_fpm > 150 ? '↑' : f.vertical_rate_fpm < -150 ? '↓' : '=';

          const gsTens = String(Math.round(f.groundspeed_kts / 10)).padStart(2, '0');

          ctx.fillText(`${altHundreds}${trend} ${gsTens}`, bx, by + 11);


          // Line 3: Destination + Squawk

          ctx.fillStyle = isSelected ? '#93c5fd' : 'rgba(148, 163, 184, 0.85)';

          ctx.fillText(`${f.destination} ${f.squawk}`, bx, by + 22);

        }

      });


      ctx.restore();

      animId = requestAnimationFrame(render);

    };


    animId = requestAnimationFrame(render);

    return () => cancelAnimationFrame(animId);

  }, [selectedSector, selectedCallsign, radarZoom, panOffset, showLeaderLines, showRangeRings, projectToScreen]);


  // Canvas Mouse Click (Select Aircraft) & Drag Pan

  const handleCanvasMouseDown = (e) => {

    isDraggingRef.current = true;

    dragStartRef.current = { x: e.clientX - panOffset.x, y: e.clientY - panOffset.y, downX: e.clientX, downY: e.clientY };

  };


  const handleCanvasMouseMove = (e) => {

    if (!isDraggingRef.current) return;

    setPanOffset({

      x: e.clientX - dragStartRef.current.x,

      y: e.clientY - dragStartRef.current.y

    });

  };


  const handleCanvasMouseUp = (e) => {

    const movedDist = Math.hypot(e.clientX - dragStartRef.current.downX, e.clientY - dragStartRef.current.downY);

    isDraggingRef.current = false;


    // If click without drag (< 5px), hit-test aircraft targets

    if (movedDist < 5 && canvasRef.current) {

      const rect = canvasRef.current.getBoundingClientRect();

      const clickX = e.clientX - rect.left;

      const clickY = e.clientY - rect.top;


      let closestCallsign = null;

      let minPx = 24;


      flightsRef.current.forEach((f) => {

        if (f.phase === 'LANDED') return;

        const pt = projectToScreen(f.lat, f.lon, rect.width, rect.height);

        const d = Math.hypot(pt.x - clickX, pt.y - clickY);

        if (d < minPx) {

          minPx = d;

          closestCallsign = f.callsign;

        }

      });


      if (closestCallsign) {

        setSelectedCallsign(closestCallsign);

      }

    }

  };


  const handleCanvasWheel = (e) => {

    e.preventDefault();

    const factor = e.deltaY < 0 ? 1.15 : 0.87;

    setRadarZoom((z) => Math.min(4.5, Math.max(0.45, Number((z * factor).toFixed(2)))));

  };


  // ==========================================================================

  // 9. FILTERED FLIGHT STRIPS & SECTOR METRICS

  // ==========================================================================


  const sectorStats = useMemo(() => {

    const counts = { 'NAS-ALL': 0 };

    const alertCounts = { 'NAS-ALL': conflicts.length };


    AIRPORTS.forEach((a) => {

      counts[a.icao] = 0;

      alertCounts[a.icao] = 0;

    });


    flights.forEach((f) => {

      if (f.phase !== 'LANDED') {

        counts['NAS-ALL'] += 1;

        if (counts[f.assigned_sector] !== undefined) {

          counts[f.assigned_sector] += 1;

        }

      }

    });


    conflicts.forEach((c) => {

      if (alertCounts[c.sector] !== undefined) {

        alertCounts[c.sector] += 1;

      }

    });


    return { counts, alertCounts };

  }, [flights, conflicts]);


  const filteredStrips = useMemo(() => {

    return flights

      .filter((f) => {

        if (selectedSector !== 'NAS-ALL' && f.assigned_sector !== selectedSector) return false;

        if (stripFilter === 'DEP' && !['TAXI_OUT', 'HOLD_SHORT', 'TAKEOFF', 'CLIMB'].includes(f.phase)) return false;

        if (stripFilter === 'ARR' && !['DESCENT', 'APPROACH', 'HOLDING', 'LANDED'].includes(f.phase)) return false;

        if (stripFilter === 'OVER' && f.phase !== 'CRUISE') return false;

        if (searchQuery.trim()) {

          const q = searchQuery.trim().toUpperCase();

          return (

            f.callsign.includes(q) ||

            f.origin.includes(q) ||

            f.destination.includes(q) ||

            f.ac_type.includes(q)

          );

        }

        return true;

      })

      .sort((a, b) => a.callsign.localeCompare(b.callsign));

  }, [flights, selectedSector, stripFilter, searchQuery]);


  const activeAirport = selectedSector !== 'NAS-ALL' ? AIRPORT_MAP[selectedSector] : null;

  const redAlertCount = conflicts.filter((c) => c.severity === 'RED').length;


  // ==========================================================================

  // 10. UI RENDER

  // ==========================================================================


  return (

    <div className="flex flex-col h-screen w-full bg-[#060a10] text-slate-100 font-sans select-none overflow-hidden">

      {/* ==================================================================== */}

      {/* TOP BAR 1: GLOBAL TELEMETRY, CLOCK & SIMULATION TRANSPORT            */}

      {/* ==================================================================== */}

      <header className="flex flex-wrap items-center justify-between px-3 py-2 bg-[#0b121c] border-b border-slate-800/90 gap-2 shrink-0">

        <div className="flex items-center gap-2.5">

          <div className="flex items-center justify-center w-8 h-8 rounded-lg bg-cyan-500/15 border border-cyan-500/40 text-cyan-400">

            <Radar className="w-4 h-4" />

          </div>

          <div>

            <div className="flex items-center gap-2">

              <span className="text-xs font-bold tracking-wider uppercase text-cyan-300">

                STARS // NAS MULTI-TRACON ATC

              </span>

              <span className="px-1.5 py-0.5 text-[10px] font-mono rounded bg-emerald-500/15 text-emerald-300 border border-emerald-500/30">

                LIVE SIM

              </span>

            </div>

            <p className="text-[11px] text-slate-400 font-mono">

              10 HUB SECTORS • {sectorStats.counts['NAS-ALL']} ACTIVE AIRCRAFT

            </p>

          </div>

        </div>


        {/* Zulu Simulation Clock & Speed Controls */}

        <div className="flex items-center gap-2 bg-[#070c14] px-3 py-1.5 rounded-lg border border-slate-800">

          <Clock className="w-3.5 h-3.5 text-cyan-400" />

          <span className="font-mono text-sm font-bold tracking-widest text-cyan-300 mr-2">

            {formatZuluClock(elapsedSec)}

          </span>


          <div className="flex items-center gap-1 border-l border-slate-800 pl-2">

            {[

              { label: 'PAUSE', val: 0, icon: Pause },

              { label: '1X', val: 1 },

              { label: '2X', val: 2 },

              { label: '5X', val: 5 },

              { label: '10X', val: 10 }

            ].map((btn) => {

              const Icon = btn.icon;

              const active = simSpeed === btn.val;

              return (

                <button

                  key={btn.label}

                  onClick={() => setSimSpeed(btn.val)}

                  className={`px-2 py-1 text-[11px] font-mono font-semibold rounded transition-colors flex items-center gap-1 ${

                    active

                      ? btn.val === 0

                        ? 'bg-amber-500/25 text-amber-300 border border-amber-500/50'

                        : 'bg-cyan-500/25 text-cyan-200 border border-cyan-500/50'

                      : 'text-slate-400 hover:text-slate-200 hover:bg-slate-800/70'

                  }`}

                >

                  {Icon && <Icon className="w-3 h-3" />}

                  {btn.label}

                </button>

              );

            })}

          </div>


          <button

            onClick={handleResetSimulation}

            title="Reset Simulation to 16:00:00Z"

            className="ml-1 px-2 py-1 text-[11px] font-mono text-slate-300 hover:text-white bg-slate-800/80 hover:bg-slate-700 rounded border border-slate-700 flex items-center gap-1 transition-colors"

          >

            <RotateCcw className="w-3 h-3" />

            RESET

          </button>

        </div>


        {/* Global Conflict Status Pill */}

        <div className="flex items-center gap-2">

          <div

            className={`flex items-center gap-2 px-3 py-1.5 rounded-lg border font-mono text-xs ${

              redAlertCount > 0

                ? 'bg-red-500/20 border-red-500/60 text-red-200 animate-pulse'

                : conflicts.length > 0

                ? 'bg-amber-500/15 border-amber-500/50 text-amber-200'

                : 'bg-emerald-500/10 border-emerald-500/30 text-emerald-300'

            }`}

          >

            <ShieldAlert className="w-4 h-4" />

            <span>

              STCA ALERTS: <strong>{conflicts.length}</strong>

              {redAlertCount > 0 && ` (${redAlertCount} CRITICAL)`}

            </span>

          </div>

        </div>

      </header>


      {/* ==================================================================== */}

      {/* TOP BAR 2: SELECTABLE AIRPORT DASHBOARD TABS (NAS-ALL + 10 ICAOs)    */}

      {/* ==================================================================== */}

      <nav className="flex items-center gap-1.5 px-3 py-1.5 bg-[#080e17] border-b border-slate-800/80 overflow-x-auto shrink-0">

        {/* NAS-ALL Overview Tab */}

        <button

          onClick={() => handleSelectSector('NAS-ALL')}

          className={`flex items-center gap-2 px-2.5 py-1.5 rounded-md text-xs font-mono font-semibold border transition-all shrink-0 ${

            selectedSector === 'NAS-ALL'

              ? 'bg-cyan-500/20 border-cyan-400 text-cyan-200 shadow-[0_0_12px_rgba(34,211,238,0.2)]'

              : 'bg-[#0d1522] border-slate-800 text-slate-400 hover:text-slate-200 hover:border-slate-700'

          }`}

        >

          <Compass className="w-3.5 h-3.5 text-cyan-400" />

          <span>NAS-ALL</span>

          <span className="px-1.5 py-0.2 rounded bg-slate-800 text-[10px] text-slate-300">

            {sectorStats.counts['NAS-ALL']}

          </span>

        </button>


        <div className="h-5 w-px bg-slate-800 mx-0.5 shrink-0" />


        {/* 10 Individual Airport TRACON Dashboard Tabs */}

        {AIRPORTS.map((apt) => {

          const isSelected = selectedSector === apt.icao;

          const count = sectorStats.counts[apt.icao] || 0;

          const alertCnt = sectorStats.alertCounts[apt.icao] || 0;


          return (

            <button

              key={apt.icao}

              onClick={() => handleSelectSector(apt.icao)}

              className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-mono border transition-all shrink-0 ${

                isSelected

                  ? 'bg-cyan-500/20 border-cyan-400 text-white shadow-[0_0_12px_rgba(34,211,238,0.2)]'

                  : 'bg-[#0d1522] border-slate-800/90 text-slate-400 hover:text-slate-200 hover:border-slate-700'

              }`}

            >

              <span className="font-bold tracking-tight">{apt.icao}</span>

              <span

                className={`px-1.5 py-0.2 rounded text-[10px] ${

                  isSelected ? 'bg-cyan-500/30 text-cyan-100' : 'bg-slate-800/90 text-slate-300'

                }`}

              >

                {count}

              </span>

              {alertCnt > 0 && (

                <span className="px-1.5 py-0.2 rounded text-[10px] bg-red-500/30 border border-red-500/60 text-red-200 font-bold">

                  !{alertCnt}

                </span>

              )}

            </button>

          );

        })}

      </nav>


      {/* ==================================================================== */}

      {/* TOP BAR 3: DYNAMIC AIRPORT METAR & ACTIVE RUNWAY CONFIGURATION STRIP */}

      {/* ==================================================================== */}

      <div className="flex flex-wrap items-center justify-between px-3 py-1.5 bg-[#0a1019] border-b border-slate-800/80 text-[11px] font-mono text-slate-300 gap-2 shrink-0">

        {activeAirport ? (

          <>

            <div className="flex items-center gap-3">

              <span className="font-bold text-cyan-300">

                {activeAirport.icao} / {activeAirport.iata}

              </span>

              <span className="text-slate-400 hidden sm:inline">{activeAirport.name}</span>

              <span className="text-slate-500">|</span>

              <span>

                ELEV: <strong className="text-slate-200">{activeAirport.elevation_ft} FT</strong>

              </span>

              <span>

                TRACON: <strong className="text-slate-200">{activeAirport.tracon_radius_nm} NM</strong>

              </span>

              <span className="flex items-center gap-1 text-emerald-300">

                <Wind className="w-3 h-3" /> {activeAirport.wind}

              </span>

              <span>

                QNH: <strong className="text-slate-200">{activeAirport.altimeter}"</strong>

              </span>

            </div>


            <div className="flex items-center gap-2 overflow-x-auto">

              <span className="text-slate-500">RWYS:</span>

              {activeAirport.runways.map((r) => (

                <span

                  key={r.id}

                  className={`px-1.5 py-0.5 rounded border text-[10px] ${

                    r.status === 'ACTIVE_ARR'

                      ? 'bg-cyan-500/10 border-cyan-500/40 text-cyan-300'

                      : 'bg-emerald-500/10 border-emerald-500/40 text-emerald-300'

                  }`}

                >

                  {r.id} ({r.status === 'ACTIVE_ARR' ? 'ARR' : 'DEP'})

                </span>

              ))}

            </div>

          </>

        ) : (

          <div className="flex items-center justify-between w-full">

            <span className="text-cyan-300 font-semibold">

              CONUS NATIONAL AIRSPACE SYSTEM (NAS) — ALL 10 TRACON SECTORS & ARTCC EN-ROUTE CORRIDORS

            </span>

            <span className="text-slate-400">

              SELECT ANY ICAO TAB ABOVE FOR DEDICATED TERMINAL APPROACH RADAR & RUNWAY FEATHERS

            </span>

          </div>

        )}

      </div>


      {/* ==================================================================== */}

      {/* MAIN WORKSPACE: LEFT 65% PPI RADAR SCOPE | RIGHT 35% EFPS & COMMANDS */}

      {/* ==================================================================== */}

      <main className="flex flex-col lg:flex-row flex-1 min-h-0 overflow-hidden">

        {/* LEFT PANEL: HTML5 CANVAS PPI RADAR SCOPE */}

        <section className="relative w-full lg:w-[65%] h-[50vh] lg:h-full bg-[#05090e] border-b lg:border-b-0 lg:border-r border-slate-800 overflow-hidden">

          <canvas

            ref={canvasRef}

            onMouseDown={handleCanvasMouseDown}

            onMouseMove={handleCanvasMouseMove}

            onMouseUp={handleCanvasMouseUp}

            onMouseLeave={() => (isDraggingRef.current = false)}

            onWheel={handleCanvasWheel}

            className="block w-full h-full cursor-crosshair"

          />


          {/* Radar Scope Overlay Controls (Top-Left) */}

          <div className="absolute top-3 left-3 flex flex-wrap items-center gap-1.5 pointer-events-auto">

            <button

              onClick={() => setRadarZoom((z) => Math.min(4.5, Number((z * 1.2).toFixed(2))))}

              className="p-1.5 rounded bg-slate-900/85 hover:bg-slate-800 border border-slate-700 text-slate-200"

              title="Zoom In"

            >

              <ZoomIn className="w-3.5 h-3.5" />

            </button>

            <button

              onClick={() => setRadarZoom((z) => Math.max(0.45, Number((z * 0.83).toFixed(2))))}

              className="p-1.5 rounded bg-slate-900/85 hover:bg-slate-800 border border-slate-700 text-slate-200"

              title="Zoom Out"

            >

              <ZoomOut className="w-3.5 h-3.5" />

            </button>

            <button

              onClick={() => {

                setPanOffset({ x: 0, y: 0 });

                setRadarZoom(1.0);

              }}

              className="px-2 py-1.5 rounded bg-slate-900/85 hover:bg-slate-800 border border-slate-700 text-[10px] font-mono text-slate-200 flex items-center gap-1"

              title="Center Scope"

            >

              <LocateFixed className="w-3 h-3 text-cyan-400" />

              CENTER ({radarZoom.toFixed(1)}x)

            </button>

            <button

              onClick={() => setShowLeaderLines((v) => !v)}

              className={`px-2 py-1.5 rounded border text-[10px] font-mono ${

                showLeaderLines

                  ? 'bg-cyan-500/20 border-cyan-500/50 text-cyan-200'

                  : 'bg-slate-900/85 border-slate-700 text-slate-400'

              }`}

            >

              PTL 60S

            </button>

            {selectedSector !== 'NAS-ALL' && (

              <button

                onClick={() => setShowRangeRings((v) => !v)}

                className={`px-2 py-1.5 rounded border text-[10px] font-mono ${

                  showRangeRings

                    ? 'bg-cyan-500/20 border-cyan-500/50 text-cyan-200'

                    : 'bg-slate-900/85 border-slate-700 text-slate-400'

                }`}

              >

                RINGS

              </button>

            )}

          </div>


          {/* Radar Color Legend (Bottom-Left) */}

          <div className="absolute bottom-3 left-3 flex flex-wrap items-center gap-3 px-2.5 py-1.5 rounded bg-slate-950/85 border border-slate-800/90 text-[10px] font-mono pointer-events-none">

            <span className="flex items-center gap-1 text-cyan-300">

              <span className="w-2 h-2 rounded-full bg-cyan-400" /> ARR/APP

            </span>

            <span className="flex items-center gap-1 text-emerald-300">

              <span className="w-2 h-2 rounded-full bg-emerald-400" /> DEP/CLB

            </span>

            <span className="flex items-center gap-1 text-yellow-300">

              <span className="w-2 h-2 rounded-full bg-yellow-400" /> GND/TAXI

            </span>

            <span className="flex items-center gap-1 text-fuchsia-300">

              <span className="w-2 h-2 rounded-full bg-fuchsia-400" /> HOLD

            </span>

            <span className="flex items-center gap-1 text-slate-200">

              <span className="w-2 h-2 rounded-full bg-slate-200" /> CRUISE

            </span>

          </div>


          {/* Active STCA Alert Overlay Banner on Radar (Top-Right of Canvas) */}

          {conflicts.length > 0 && (

            <div className="absolute top-3 right-3 max-w-xs bg-slate-950/90 border border-red-500/60 rounded-lg p-2 shadow-lg backdrop-blur-sm">

              <div className="flex items-center gap-1.5 text-[11px] font-mono font-bold text-red-400 mb-1">

                <AlertTriangle className="w-3.5 h-3.5" />

                <span>STCA CONFLICT MONITOR ({conflicts.length})</span>

              </div>

              <div className="space-y-1 max-h-24 overflow-y-auto pr-1">

                {conflicts.slice(0, 4).map((c) => (

                  <button

                    key={c.id}

                    onClick={() => {

                      setSelectedSector(c.sector);

                      setSelectedCallsign(c.callsignA);

                    }}

                    className={`w-full text-left px-2 py-1 rounded text-[10px] font-mono flex items-center justify-between border ${

                      c.severity === 'RED'

                        ? 'bg-red-500/20 border-red-500/50 text-red-200'

                        : 'bg-amber-500/15 border-amber-500/40 text-amber-200'

                    }`}

                  >

                    <span>

                      <strong>{c.callsignA}</strong> / <strong>{c.callsignB}</strong> ({c.sector})

                    </span>

                    <span>

                      {c.horizNM}NM • {c.vertFt}FT

                    </span>

                  </button>

                ))}

              </div>

            </div>

          )}

        </section>


        {/* RIGHT PANEL: ELECTRONIC FLIGHT PROGRESS STRIPS (EFPS) & COMMAND DECK */}

        <aside className="w-full lg:w-[35%] h-[50vh] lg:h-full flex flex-col bg-[#090f18] overflow-hidden">

          {/* 1. TACTICAL CLEARANCE COMMAND DECK (Selected Aircraft) */}

          <div className="p-3 bg-[#0c1420] border-b border-slate-800 shrink-0">

            {selectedFlight ? (

              <>

                <div className="flex items-center justify-between mb-2">

                  <div className="flex items-center gap-2">

                    <Radio className="w-4 h-4 text-cyan-400" />

                    <span className="font-mono text-sm font-bold text-white">

                      {selectedFlight.callsign}

                    </span>

                    <span className="px-1.5 py-0.5 text-[10px] font-mono rounded bg-slate-800 text-slate-300 border border-slate-700">

                      {selectedFlight.ac_type} ({AIRCRAFT_TYPES[selectedFlight.ac_type]?.wake})

                    </span>

                    <span

                      className={`px-1.5 py-0.5 text-[10px] font-mono rounded border ${

                        PHASE_STYLES[selectedFlight.phase]?.bg

                      } ${PHASE_STYLES[selectedFlight.phase]?.text} ${

                        PHASE_STYLES[selectedFlight.phase]?.border

                      }`}

                    >

                      {selectedFlight.phase}

                    </span>

                  </div>

                  <span className="font-mono text-[11px] text-slate-400">

                    SQK <strong className="text-slate-200">{selectedFlight.squawk}</strong>

                  </span>

                </div>


                {/* Live Telemetry & Schedule Summary */}

                <div className="grid grid-cols-4 gap-1.5 mb-2.5 p-2 rounded bg-[#070c14] border border-slate-800/90 font-mono text-[11px]">

                  <div>

                    <div className="text-[9px] text-slate-500">ROUTE</div>

                    <div className="font-semibold text-slate-200">

                      {selectedFlight.origin}→{selectedFlight.destination}

                    </div>

                  </div>

                  <div>

                    <div className="text-[9px] text-slate-500">ALT / FL</div>

                    <div className="font-semibold text-cyan-300">

                      {Math.round(selectedFlight.altitude_ft).toLocaleString()}'

                    </div>

                  </div>

                  <div>

                    <div className="text-[9px] text-slate-500">HDG / GS</div>

                    <div className="font-semibold text-emerald-300">

                      {String(Math.round(selectedFlight.heading_deg)).padStart(3, '0')}° /{' '}

                      {Math.round(selectedFlight.groundspeed_kts)}KT

                    </div>

                  </div>

                  <div>

                    <div className="text-[9px] text-slate-500">ETD / ETA</div>

                    <div className="font-semibold text-slate-200">

                      {selectedFlight.etd_utc.slice(0, 5)}/{selectedFlight.eta_utc.slice(0, 5)}

                    </div>

                  </div>

                </div>


                {/* Vectoring Clearance Form (HDG, ALT, SPD) */}

                <form onSubmit={handleApplyVectorClearance} className="grid grid-cols-4 gap-1.5 mb-2">

                  <div>

                    <label className="block text-[9px] font-mono text-slate-400 mb-0.5">HDG (001-360)</label>

                    <input

                      type="number"

                      min="1"

                      max="360"

                      value={cmdHdg}

                      onChange={(e) => setCmdHdg(e.target.value)}

                      className="w-full px-2 py-1 bg-[#060a10] border border-slate-700 rounded font-mono text-xs text-cyan-200 focus:outline-none focus:border-cyan-400"

                    />

                  </div>

                  <div>

                    <label className="block text-[9px] font-mono text-slate-400 mb-0.5">ALT (FL/100)</label>

                    <input

                      type="number"

                      min="0"

                      max="430"

                      value={cmdAlt}

                      onChange={(e) => setCmdAlt(e.target.value)}

                      className="w-full px-2 py-1 bg-[#060a10] border border-slate-700 rounded font-mono text-xs text-cyan-200 focus:outline-none focus:border-cyan-400"

                    />

                  </div>

                  <div>

                    <label className="block text-[9px] font-mono text-slate-400 mb-0.5">SPD (KTS)</label>

                    <input

                      type="number"

                      min="0"

                      max="550"

                      value={cmdSpd}

                      onChange={(e) => setCmdSpd(e.target.value)}

                      className="w-full px-2 py-1 bg-[#060a10] border border-slate-700 rounded font-mono text-xs text-cyan-200 focus:outline-none focus:border-cyan-400"

                    />

                  </div>

                  <div className="flex items-end">

                    <button

                      type="submit"

                      className="w-full py-1 px-2 bg-cyan-600 hover:bg-cyan-500 text-white font-mono text-xs font-bold rounded transition-colors"

                    >

                      TRANSMIT

                    </button>

                  </div>

                </form>


                {/* Procedural ATC Action Buttons */}

                <div className="grid grid-cols-4 gap-1.5">

                  <button

                    type="button"

                    onClick={() => handleQuickAction('TAKEOFF')}

                    disabled={!['TAXI_OUT', 'HOLD_SHORT'].includes(selectedFlight.phase)}

                    className="py-1 px-1.5 rounded font-mono text-[10px] font-semibold border transition-colors bg-emerald-500/15 border-emerald-500/40 text-emerald-300 hover:bg-emerald-500/25 disabled:opacity-35 disabled:cursor-not-allowed"

                  >

                    CLR T/O

                  </button>

                  <button

                    type="button"

                    onClick={() => handleQuickAction('HOLD')}

                    disabled={['TAXI_OUT', 'HOLD_SHORT', 'LANDED'].includes(selectedFlight.phase)}

                    className="py-1 px-1.5 rounded font-mono text-[10px] font-semibold border transition-colors bg-fuchsia-500/15 border-fuchsia-500/40 text-fuchsia-300 hover:bg-fuchsia-500/25 disabled:opacity-35 disabled:cursor-not-allowed"

                  >

                    HOLD POS

                  </button>

                  <button

                    type="button"

                    onClick={() => handleQuickAction('APPROACH')}

                    disabled={['TAXI_OUT', 'HOLD_SHORT', 'LANDED'].includes(selectedFlight.phase)}

                    className="py-1 px-1.5 rounded font-mono text-[10px] font-semibold border transition-colors bg-cyan-500/15 border-cyan-500/40 text-cyan-300 hover:bg-cyan-500/25 disabled:opacity-35 disabled:cursor-not-allowed"

                  >

                    CLR ILS

                  </button>

                  <button

                    type="button"

                    onClick={() => handleQuickAction('GO_AROUND')}

                    disabled={selectedFlight.phase !== 'APPROACH'}

                    className="py-1 px-1.5 rounded font-mono text-[10px] font-semibold border transition-colors bg-amber-500/15 border-amber-500/40 text-amber-300 hover:bg-amber-500/25 disabled:opacity-35 disabled:cursor-not-allowed"

                  >

                    GO AROUND

                  </button>

                </div>


                {/* Envelope Validation / Transmission Feedback */}

                {cmdFeedback && (

                  <div

                    className={`mt-2 px-2 py-1 rounded text-[10px] font-mono flex items-center gap-1.5 border ${

                      cmdFeedback.ok

                        ? 'bg-emerald-500/10 border-emerald-500/40 text-emerald-300'

                        : 'bg-red-500/15 border-red-500/50 text-red-300'

                    }`}

                  >

                    {cmdFeedback.ok ? (

                      <CheckCircle2 className="w-3.5 h-3.5 shrink-0" />

                    ) : (

                      <XCircle className="w-3.5 h-3.5 shrink-0" />

                    )}

                    <span className="truncate">{cmdFeedback.msg}</span>

                  </div>

                )}

              </>

            ) : (

              <div className="text-xs font-mono text-slate-400 py-4 text-center">

                CLICK ANY RADAR TARGET OR FLIGHT STRIP TO OPEN CLEARANCE DECK

              </div>

            )}

          </div>


          {/* 2. ELECTRONIC FLIGHT PROGRESS STRIPS (EFPS) BAY */}

          <div className="flex flex-col flex-1 min-h-0 overflow-hidden">

            {/* Bay Filter Tabs & Search */}

            <div className="flex items-center justify-between px-3 py-2 bg-[#080d16] border-b border-slate-800 gap-2 shrink-0">

              <div className="flex items-center gap-1">

                {[

                  { id: 'ALL', label: 'ALL' },

                  { id: 'DEP', label: 'DEP' },

                  { id: 'ARR', label: 'ARR' },

                  { id: 'OVER', label: 'CRZ' }

                ].map((tab) => (

                  <button

                    key={tab.id}

                    onClick={() => setStripFilter(tab.id)}

                    className={`px-2 py-0.5 rounded text-[10px] font-mono font-bold transition-colors ${

                      stripFilter === tab.id

                        ? 'bg-cyan-500/25 text-cyan-200 border border-cyan-500/50'

                        : 'text-slate-400 hover:text-slate-200 bg-slate-900'

                    }`}

                  >

                    {tab.label}

                  </button>

                ))}

              </div>


              <input

                type="text"

                placeholder="Filter callsign / ICAO..."

                value={searchQuery}

                onChange={(e) => setSearchQuery(e.target.value)}

                className="w-36 px-2 py-0.5 bg-[#060a10] border border-slate-800 rounded text-[11px] font-mono text-slate-200 placeholder-slate-600 focus:outline-none focus:border-cyan-500"

              />

            </div>


            {/* Scrollable Flight Progress Strips List */}

            <div className="flex-1 overflow-y-auto p-2 space-y-1.5">

              {filteredStrips.map((f) => {

                const isSelected = f.callsign === selectedCallsign;

                const style = PHASE_STYLES[f.phase] || PHASE_STYLES.CRUISE;

                const apt = AIRPORT_MAP[f.assigned_sector];

                const dme = apt ? distanceNM(f.lat, f.lon, apt.lat, apt.lon).toFixed(1) : '--';

                const hasAlert = conflicts.some((c) => c.callsignA === f.callsign || c.callsignB === f.callsign);


                return (

                  <div

                    key={f.callsign}

                    onClick={() => setSelectedCallsign(f.callsign)}

                    className={`p-2 rounded-md border cursor-pointer transition-all font-mono text-[11px] ${

                      isSelected

                        ? 'bg-cyan-950/50 border-cyan-400 shadow-[0_0_10px_rgba(34,211,238,0.15)]'

                        : hasAlert

                        ? 'bg-red-950/30 border-red-500/60 hover:border-red-400'

                        : 'bg-[#0c131f] border-slate-800/90 hover:border-slate-700'

                    }`}

                  >

                    {/* Strip Row 1: Callsign, Type, Phase Badge, Sector/DME */}

                    <div className="flex items-center justify-between mb-1">

                      <div className="flex items-center gap-1.5">

                        <span className="font-bold text-white text-xs">{f.callsign}</span>

                        <span className="text-slate-400 text-[10px]">

                          {f.ac_type}/{AIRCRAFT_TYPES[f.ac_type]?.wake}

                        </span>

                        <span className={`px-1.5 py-0.2 rounded text-[9px] border ${style.bg} ${style.text} ${style.border}`}>

                          {style.label}

                        </span>

                      </div>

                      <div className="text-[10px] text-slate-400">

                        <span className="text-cyan-400 font-semibold">{f.assigned_sector}</span> • {dme}NM

                      </div>

                    </div>


                    {/* Strip Row 2: Route, Altitude, Speed, Schedule & Delay */}

                    <div className="flex items-center justify-between text-[10px] text-slate-300">

                      <div>

                        <span className="text-slate-400">RTE:</span>{' '}

                        <strong>

                          {f.origin}→{f.destination}

                        </strong>{' '}

                        <span className="text-slate-500">({f.filed_fl})</span>

                      </div>


                      <div className="flex items-center gap-2">

                        <span>

                          FL{String(Math.round(f.altitude_ft / 100)).padStart(3, '0')}

                          {f.vertical_rate_fpm > 150 ? '↑' : f.vertical_rate_fpm < -150 ? '↓' : ''}

                        </span>

                        <span>{Math.round(f.groundspeed_kts)}KT</span>

                        <span

                          className={

                            f.delay_min > 0 ? 'text-amber-400 font-semibold' : 'text-slate-400'

                          }

                        >

                          {['TAXI_OUT', 'HOLD_SHORT', 'TAKEOFF', 'CLIMB'].includes(f.phase)

                            ? `ETD ${f.etd_utc}`

                            : `ETA ${f.eta_utc}`}

                          {f.delay_min > 0 ? ` (+${f.delay_min}m)` : ''}

                        </span>

                      </div>

                    </div>

                  </div>

                );

              })}


              {filteredStrips.length === 0 && (

                <div className="text-center py-8 text-xs font-mono text-slate-500">

                  NO ACTIVE FLIGHT STRIPS MATCH CURRENT FILTER

                </div>

              )}

            </div>

          </div>


          {/* 3. APPEND-ONLY CLEARANCE & TELEMETRY AUDIT LOG */}

          <div className="h-24 bg-[#060a10] border-t border-slate-800 p-2 font-mono text-[10px] overflow-y-auto shrink-0">

            <div className="flex items-center gap-1 text-slate-500 mb-1 sticky top-0 bg-[#060a10]">

              <Terminal className="w-3 h-3 text-cyan-400" />

              <span>CLEARANCE & AUDIT LOG</span>

            </div>

            <div className="space-y-0.5">

              {auditLog.map((entry, idx) => (

                <div key={idx} className="text-slate-400 truncate">

                  <span className="text-slate-500">[{entry.time}]</span>{' '}

                  <span className="text-cyan-300 font-semibold">{entry.callsign}:</span>{' '}

                  <span className="text-slate-300">{entry.msg}</span>

                </div>

              ))}

            </div>

          </div>

        </aside>

      </main>

    </div>

  );

}

From <https://gemini.google.com/app/ce5456480fd65fce>  Google Gemini (4 Hydrogen)

Comments

Popular posts from this blog

#4297 ISS Astronaut Unable to Speak

#3356 PHP and JavaScript to Retrieve and Set an API_Key

#4188 Hybrid/GraphRAG