@font-face { font-display: swap; }

:root{
  --bg: #0b1220;
  --ocean: #0e1830;
  --land: #23324a;
  --land-stroke: #3c5170;
  --grid: rgba(140, 156, 184, 0.09);
  --gold: #e7a73c;
  --gold-soft: rgba(231, 167, 60, 0.32);
  --ember: #ff8a5c;
  --text: #f1ecdc;
  --text-dim: #8d9ab4;
  --text-dimmer: #56637f;
  --panel-bg: rgba(14, 20, 36, 0.86);
  --panel-border: rgba(140, 156, 184, 0.14);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', 'Noto Sans SC', -apple-system, sans-serif;
  --serif: 'Fraunces', 'Noto Serif SC', Georgia, serif;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
  overflow: hidden;
}

body{
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr 340px;
  grid-template-areas:
    "header header"
    "map    aside"
    "timeline aside";
  height: 100vh;
}

/* ---------- Header ---------- */
header.hud{
  grid-area: header;
  z-index: 20;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px 14px;
  background: linear-gradient(180deg, rgba(11,18,32,0.92) 0%, rgba(11,18,32,0.55) 70%, rgba(11,18,32,0) 100%);
  pointer-events: none;
}
header.hud .title-block{ pointer-events: auto; }
header.hud .eyebrow{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 4px;
}
header.hud h1{
  font-family: var(--serif);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--text);
}
header.hud h1 small{
  font-family: var(--mono);
  font-weight: 400;
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-left: 10px;
}

.hud-stats{
  display: flex;
  gap: 26px;
  pointer-events: auto;
}
.hud-stat{ text-align: right; }
.hud-stat .n{
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}
.hud-stat .n .unit{ font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 2px;}
.hud-stat .l{
  font-size: 10px;
  color: var(--text-dimmer);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 5px;
}

/* ---------- Map ---------- */
main.mapwrap{
  grid-area: map;
  position: relative;
  overflow: hidden;
}
svg#map{ display:block; width: 100%; height: 100%; cursor: grab; }
svg#map:active{ cursor: grabbing; }

.map-controls{
  position: absolute;
  right: 20px;
  bottom: 22px;
  z-index: 25;
  display: flex;
  gap: 8px;
}
.map-controls button{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 7px 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.map-controls button:hover{ color: var(--gold); border-color: var(--gold-soft); }

.sphere{ fill: var(--ocean); }
.graticule{ fill: none; stroke: var(--grid); stroke-width: 0.6; }
.land{ fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.6; }

.route-arc{
  fill: none;
  stroke: var(--gold);
  stroke-linecap: round;
  opacity: 0.55;
  transition: opacity 0.25s ease, stroke 0.25s ease;
}
.route-arc.dim{ opacity: 0.08; }
.route-arc.hot{ stroke: var(--ember); opacity: 0.95; }

.route-flow{
  fill: none;
  stroke: rgba(241,236,220,0.9);
  stroke-linecap: round;
  stroke-dasharray: 1 14;
  animation: flow 2.6s linear infinite;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce){
  .route-flow{ animation: none; opacity: 0; }
}
@keyframes flow{ to{ stroke-dashoffset: -300; } }

.airport-world{
  fill: var(--text-dimmer);
  opacity: 0.55;
}
.airport-visited{
  fill: var(--gold);
  stroke: rgba(11,18,32,0.9);
  stroke-width: 1;
  cursor: pointer;
  transition: fill 0.2s ease, opacity 0.2s ease;
}
.airport-visited.dim{ opacity: 0.18; }
.airport-visited.hot{ fill: var(--ember); }
.airport-hub{
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.1;
  opacity: 0.55;
  pointer-events: none;
  animation: pulse 2.8s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@media (prefers-reduced-motion: reduce){
  .airport-hub{ animation: none; }
}
@keyframes pulse{
  0%{ r: 4; opacity: 0.6; }
  100%{ r: 22; opacity: 0; }
}

.airport-label{
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--text-dim);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.airport-label.show{ opacity: 1; }

/* ---------- Tooltip ---------- */
#tooltip{
  position: fixed;
  pointer-events: none;
  z-index: 60;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 9px 12px;
  font-size: 12px;
  color: var(--text);
  max-width: 260px;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity 0.12s ease;
  backdrop-filter: blur(6px);
}
#tooltip.show{ opacity: 1; }
#tooltip .tt-title{
  font-family: var(--serif);
  font-size: 14px;
  color: var(--gold);
  margin: 0 0 4px;
}
#tooltip .tt-row{
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Aside panel ---------- */
aside.panel{
  grid-area: aside;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 20px 20px 30px;
  z-index: 15;
}
aside.panel::-webkit-scrollbar{ width: 6px; }
aside.panel::-webkit-scrollbar-thumb{ background: var(--land-stroke); border-radius: 3px; }

.signature{
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 18px;
  margin-bottom: 18px;
}
.signature .n{
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 600;
  color: var(--gold);
  line-height: 1;
  letter-spacing: -0.01em;
}
.signature .n .u{ font-size: 16px; color: var(--text-dim); font-weight: 400;}
.signature .d{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.6;
}
.signature .d b{ color: var(--text); font-weight: 500; }

.panel h2{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dimmer);
  margin: 0 0 12px;
}

.route-list{ list-style:none; margin:0 0 22px; padding:0; }
.route-list li{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--panel-border);
  cursor: pointer;
  font-size: 12.5px;
}
.route-list li:hover, .route-list li.active{ color: var(--gold); }
.route-list li .bar{
  height: 4px;
  background: var(--gold-soft);
  border-radius: 2px;
}
.route-list li.active .bar{ background: var(--ember); }
.route-list li .rname{ flex: 1; font-family: var(--sans); color: inherit; }
.route-list li .rcount{ font-family: var(--mono); color: var(--text-dim); font-size: 11px; }

#detail{
  min-height: 90px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.7;
}
#detail .dt-title{
  font-family: var(--serif);
  font-size: 17px;
  color: var(--text);
  margin: 0 0 6px;
}
#detail .dt-flights{
  margin-top: 10px;
  border-top: 1px solid var(--panel-border);
  padding-top: 8px;
  max-height: 220px;
  overflow-y: auto;
}
#detail .dt-flight{
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 3px 0;
  color: var(--text-dim);
}
#detail .dt-flight .fno{ color: var(--text); }
#detail .empty{ color: var(--text-dimmer); font-style: italic; }

.legend{
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
  font-size: 11px;
  color: var(--text-dimmer);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend .li{ display: flex; align-items: center; gap: 8px; }
.legend .sw{ width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .sw.gold{ background: var(--gold); }
.legend .sw.dim{ background: var(--text-dimmer); }
.legend .sw.line{ width: 16px; height: 2px; border-radius: 0; background: var(--gold); }

/* ---------- Timeline ---------- */
footer.timeline{
  grid-area: timeline;
  z-index: 20;
  background: linear-gradient(0deg, rgba(11,18,32,0.95) 0%, rgba(11,18,32,0.6) 80%, rgba(11,18,32,0) 100%);
  padding: 10px 22px 18px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  overflow-x: auto;
}
.year-btn{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 7px;
  font-family: var(--mono);
  color: var(--text-dimmer);
  flex: none;
}
.year-btn .bar{
  width: 18px;
  background: var(--text-dimmer);
  border-radius: 2px 2px 0 0;
  transition: background 0.2s ease;
}
.year-btn .lab{ font-size: 10px; letter-spacing: 0.02em; }
.year-btn:hover .bar, .year-btn.active .bar{ background: var(--gold); }
.year-btn:hover .lab, .year-btn.active .lab{ color: var(--gold); }
.year-btn.all{ border-right: 1px solid var(--panel-border); margin-right: 8px; padding-right: 15px; }
.year-btn.all .lab{ font-size: 11px; letter-spacing: 0.06em; }

/* ---------- Responsive ---------- */
@media (max-width: 880px){
  body{
    grid-template-columns: 1fr;
    grid-template-rows: auto 46vh auto 1fr;
    grid-template-areas:
      "header"
      "map"
      "timeline"
      "aside";
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
  }
  aside.panel{ border-left: none; border-top: 1px solid var(--panel-border); max-height: none; }
  header.hud{ flex-direction: column; gap: 10px; align-items: flex-start; }
  .hud-stats{ flex-wrap: wrap; gap: 16px; }
  .hud-stat{ text-align: left; }
}
