:root {
  --bg: #0b0f17;
  --panel: rgba(14, 19, 30, 0.92);
  --card: #151c2b;
  --card-hi: #1b2438;
  --line: #243049;
  --text: #e8edf7;
  --muted: #8592ad;
  --accent: #ffb020;
  --accent-2: #4da3ff;
  --good: #3ddc97;
  --warn: #ffb020;
  --bad: #ff5d6c;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

#map { position: fixed; inset: 0; background: #0b0f17; }
.leaflet-container { background: #0b0f17; font-family: inherit; }
.leaflet-control-attribution { background: rgba(11,15,23,.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--card) !important; color: var(--text) !important; border-color: var(--line) !important; }

#panel {
  position: fixed; top: 16px; left: 16px; bottom: 16px; width: 400px; max-width: calc(100vw - 32px);
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px; overflow-y: auto; z-index: 1000;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, var(--accent), #ff7a1a); color: #111; transform: rotate(-8deg); }
.brand h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.brand .sub { margin: 0; font-size: 12px; color: var(--muted); }
.chip { margin-left: auto; background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; color: var(--muted); }
.chip.on { color: var(--accent); border-color: rgba(255,176,32,.4); }

#search { display: flex; gap: 8px; }
#search input { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 14px; outline: none; }
#search input:focus { border-color: var(--accent); }
#search button { background: var(--accent); color: #111; border: 0; border-radius: 12px; padding: 0 16px; font-weight: 700; }
.msg { font-size: 13px; color: var(--muted); min-height: 0; }
.msg:empty { display: none; }
.msg.error { color: var(--bad); }

/* Detail card */
#detail { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.d-top { display: flex; align-items: flex-start; gap: 10px; }
.d-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.d-airline { color: var(--muted); font-size: 13px; margin-top: 4px; }
.d-actions { margin-left: auto; display: flex; gap: 6px; }
.btn { background: var(--card-hi); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #111; border-color: transparent; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; margin-top: 12px; background: rgba(61,220,151,.12); color: var(--good); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ground { background: rgba(133,146,173,.15); color: var(--muted); }
.status.descend { background: rgba(77,163,255,.14); color: var(--accent-2); }
.status.alert { background: rgba(255,93,108,.15); color: var(--bad); }

.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; margin: 16px 0 10px; }
.route .ap { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.route .city { font-size: 12px; color: var(--muted); margin-top: 4px; }
.route .dest { text-align: right; }
.route .mid { color: var(--muted); font-size: 12px; padding-bottom: 6px; text-align: center; }

.progress { position: relative; height: 6px; background: var(--line); border-radius: 99px; margin: 14px 0 6px; }
.progress .fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 99px; }
.progress .plane { position: absolute; top: 50%; transform: translate(-50%, -50%) rotate(90deg); font-size: 16px; color: var(--accent);
  text-shadow: 0 0 10px rgba(255,176,32,.6); }
.prog-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.eta { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; padding: 12px 14px;
  background: var(--card-hi); border-radius: 12px; }
.eta .big { font-size: 22px; font-weight: 800; }
.eta .lbl { font-size: 12px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--card-hi); border-radius: 10px; padding: 10px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 15px; font-weight: 700; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.photo { margin-top: 12px; border-radius: 12px; overflow: hidden; position: relative; }
.photo img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.photo span { position: absolute; left: 8px; bottom: 6px; font-size: 11px; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 6px; }

/* My flights */
.list-head { display: flex; align-items: baseline; justify-content: space-between; }
.list h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
#updated { font-size: 11px; }
.fcard { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; transition: border-color .15s, background .15s; }
.fcard:hover { border-color: #33415f; background: var(--card-hi); }
.fcard.active { border-color: var(--accent); }
.fcard .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.fcard .cs { font-weight: 800; font-size: 16px; }
.fcard .rt { font-size: 13px; color: var(--muted); }
.fcard .mini { height: 4px; background: var(--line); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.fcard .mini div { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.fcard .s { font-size: 12px; font-weight: 600; }
.fcard .s.live { color: var(--good); }
.fcard .s.off { color: var(--muted); }
.hint { font-size: 13px; line-height: 1.5; }
footer { margin-top: auto; font-size: 11px; line-height: 1.5; }

/* Map markers */
.plane-icon { background: none; border: 0; }
.plane-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 1px 2px rgba(0,0,0,.7)); transition: transform .3s; }
.plane-label { background: rgba(14,19,30,.9); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  font-weight: 700; font-size: 11px; padding: 2px 6px; box-shadow: none; }
.plane-label::before { display: none; }
.ap-dot { background: var(--accent); border: 2px solid #111; border-radius: 50%; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { flex: 1; background: none; border: 0; border-radius: 9px; padding: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--card-hi); color: var(--text); }

/* ACARS messages */
.msgs-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; }
.msgs-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.msg-card { background: var(--card-hi); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; }
#feed .msg-card { background: var(--card); border-color: var(--line); cursor: pointer; }
#feed .msg-card:hover { border-color: #33415f; }
.msg-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.lbl-chip { font-family: "JetBrains Mono", monospace; font-weight: 700; background: rgba(77,163,255,.14); color: var(--accent-2);
  border-radius: 6px; padding: 1px 6px; font-size: 11px; }
.dir { font-weight: 700; }
.dir.down { color: var(--good); }
.dir.up { color: var(--accent); }
.msg-sum { font-weight: 700; margin: 6px 0 2px; }
.msg-type { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin-top: 6px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.raw summary { cursor: pointer; color: var(--muted); font-size: 11px; margin-top: 6px; user-select: none; }
.raw pre { white-space: pre-wrap; word-break: break-all; background: #0b0f17; border-radius: 8px; padding: 8px; margin: 6px 0 0;
  font-family: "JetBrains Mono", monospace; font-size: 11px; color: #c9d3e6; max-height: 220px; overflow: auto; }
.decoded-badge { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.decoded-badge.yes { color: var(--good); }

@media (max-width: 700px) {
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 58vh; border-radius: 18px; padding: 14px; }
  .route .ap { font-size: 24px; }
}

/* 3D view */
#map3d { position: fixed; inset: 0; background: #070a10; }
#map.hidden-2d { visibility: hidden; }
.view-switch { position: fixed; top: 16px; right: 16px; z-index: 1100; display: flex; gap: 4px; padding: 4px;
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 12px; }
.view-switch button { background: none; border: 0; border-radius: 9px; padding: 8px 14px; font-size: 13px; font-weight: 700; color: var(--muted); }
.view-switch button.active { background: var(--accent); color: #111; }
.label3d { position: absolute; transform: translate(-50%, -100%); pointer-events: none; z-index: 5; background: rgba(14,19,30,.92);
  border: 1px solid var(--accent); color: var(--text); font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 8px; white-space: nowrap; }
.maplibregl-ctrl-group { background: var(--card) !important; }
.maplibregl-ctrl-group button span { filter: invert(1); }
.maplibregl-ctrl-attrib { background: rgba(11,15,23,.7) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
@media (max-width: 700px) { .view-switch { top: 8px; right: 8px; } }
.canvas-tip { position: absolute; z-index: 650; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap; }

/* Aircraft card */
.acard { margin-top: 14px; background: var(--card-hi); border-radius: 14px; padding: 14px; }
.acard-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.acard-type { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.acard-chip { font-family: "JetBrains Mono", monospace; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 7px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.acard-class { font-size: 12px; color: var(--muted); margin-top: 2px; }
.acard .photo { display: block; margin-top: 12px; color: inherit; text-decoration: none; }
.photo.nophoto { display: grid; place-items: center; aspect-ratio: 16 / 9; background: var(--card); border-radius: 12px; }
.photo.nophoto svg { width: 40%; height: auto; }
.acard-grid { display: grid; grid-template-columns: 1fr .8fr 1.3fr; gap: 8px; margin-top: 12px; }
.acard-grid .k { font-size: 11px; color: var(--muted); }
.acard-grid .v { font-size: 14px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* link to the main TFS site */
.chip.tfs-link { margin-left: auto; text-decoration: none; color: var(--accent); border-color: rgba(255,176,32,.4); }
.chip.tfs-link + .chip { margin-left: 6px; }
footer a { color: var(--accent); text-decoration: none; }

/* TFS players (tfsPlayers.js) */
.chip.players-chip { margin-left: 6px; }
.chip.players-chip.on { color: #ff5cc8; border-color: rgba(255,92,200,.45); }
#playersView { margin-bottom: 14px; }
#playersView .fcard.player .cs { color: #ff5cc8; }
#playersView .fcard.player.active { border-color: #ff5cc8; }
.chip.players-chip { white-space: nowrap; }
#playersView .hint a { color: #ff5cc8; }
