* { box-sizing: border-box; }

:root {
  --bg: #0b1020;
  --panel: rgba(15, 21, 40, 0.88);
  --panel-border: rgba(148, 163, 255, 0.18);
  --text: #e6e9f5;
  --muted: #94a0c0;
  --accent: #7c8cff;
  --accent-2: #38e1c6;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", -apple-system, sans-serif;
  overflow: hidden;
}

#map { position: fixed; inset: 0; background: #0b1020; }
body.light-map #map { background: #dfe6ee; }
/* 国土地理院の淡色地図を反転して夜間風に */
.tiles-dark { filter: invert(1) hue-rotate(195deg) brightness(0.78) contrast(0.92) saturate(0.6); }
.leaflet-control-layers { background: var(--panel) !important; color: var(--text); border: 1px solid var(--panel-border) !important; border-radius: 10px !important; }
.leaflet-control-layers-toggle { filter: invert(0.85); }

.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { background: rgba(10, 14, 28, 0.7) !important; color: #8892b0 !important; }
.leaflet-control-attribution a { color: #a9b4ff !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--panel-border); }
.leaflet-bar a:hover { background: #1c2547; color: #fff; }

/* ---- 上部バー ---- */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 1000;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.topbar .back { color: var(--muted); text-decoration: none; font-size: 20px; padding: 0 4px; }
.topbar .back:hover { color: #fff; }
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar .title { flex: 1; min-width: 0; }
.stats { display: flex; align-items: center; gap: 18px; font-variant-numeric: tabular-nums; }
.stats > div:first-child span { font-size: 22px; font-weight: 700; color: var(--accent-2); }
.stats small { margin-left: 3px; color: var(--muted); }
.stats .live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 2s infinite; }
.dot.err { background: #ef4444; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }

/* 開始・停止ボタン */
.run {
  border: 1px solid var(--panel-border); background: rgba(255,255,255,0.05); color: var(--text);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-family: inherit; cursor: pointer;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.run:hover { background: rgba(124,140,255,0.16); }
.run.start { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.run.start:hover { filter: brightness(1.1); }
.dot.paused { background: #f59e0b; }
body.paused .ac .plane { opacity: .55; }
body.paused .ac .label { opacity: .7; }

/* ---- 左パネル ---- */
.panel {
  position: fixed; top: 84px; left: 12px; z-index: 1000; width: 270px;
  max-height: calc(100% - 110px); overflow-y: auto;
  padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  backdrop-filter: blur(8px);
}
.panel.collapsed { display: none; }
.panel section { margin-bottom: 14px; }
.panel h2 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .08em; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.presets button, .seg button {
  border: 1px solid var(--panel-border); background: rgba(255,255,255,0.04); color: var(--text);
  padding: 7px 6px; border-radius: 8px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.presets button:hover, .seg button:hover { background: rgba(124,140,255,0.16); }
.presets button.on, .seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.presets button.wide { grid-column: span 2; }
.seg { display: flex; gap: 4px; }
.seg button { flex: 1; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 8px; cursor: pointer; }
#search {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.05); color: var(--text); font-size: 13px; font-family: inherit;
}
#search::placeholder { color: #6b7699; }
.alt-bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, #f59e0b, #facc15, #4ade80, #22d3ee, #818cf8, #e879f9); }
.alt-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; }
.note { margin: 6px 0 0; font-size: 11px; color: #6b7699; line-height: 1.5; }

.panel-toggle {
  display: none; position: fixed; left: 12px; bottom: 28px; z-index: 1001;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--panel-border); background: var(--panel); color: var(--text); font-size: 18px; cursor: pointer;
}

/* ---- 航空機マーカー ---- */
.ac-icon { background: none; border: none; }
.ac {
  position: relative; width: 0; height: 0;
}
.ac .plane {
  position: absolute; left: -11px; top: -11px; width: 22px; height: 22px;
  filter: drop-shadow(0 0 2px rgba(0,0,0,.9));
  transition: transform .3s;
  cursor: pointer;
}
.ac .plane svg { width: 22px; height: 22px; display: block; }
.ac.ground .plane { opacity: .55; }
.ac.sel .plane { filter: drop-shadow(0 0 6px #fff); }
.ac .label {
  position: absolute; left: 13px; top: -14px;
  white-space: nowrap; pointer-events: auto; cursor: pointer;
  padding: 2px 6px 3px; border-radius: 5px;
  background: rgba(8, 12, 26, 0.82); border: 1px solid rgba(148,163,255,0.22);
  border-left: 3px solid var(--c, #7c8cff);
  font-size: 10.5px; line-height: 1.32; color: #e6e9f5;
  font-variant-numeric: tabular-nums;
}
.ac .label b { font-size: 11.5px; letter-spacing: .02em; }
.ac .label .rt { color: #b9c3e6; }
.ac .label .al { color: var(--c, #7c8cff); font-weight: 600; }
.ac .label .vr { color: var(--muted); margin-left: 2px; }
.ac.nolabel .label { display: none; }
.ac.sel .label { border-color: #fff; background: rgba(30, 40, 80, 0.95); z-index: 2; }
.ac.match .label { border-color: #facc15; }

/* 空港 */
.apt-icon { background: none; border: none; }
.apt {
  position: relative; width: 0; height: 0;
}
.apt i {
  position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 2px;
  background: #38e1c6; box-shadow: 0 0 0 2px rgba(56,225,198,.25);
}
.apt span {
  position: absolute; left: 7px; top: -8px; font-size: 10px; color: #7ee8d6; white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}

/* 選択中の機体の航跡・目的地線 */
.trail { stroke-linecap: round; }

/* ---- 詳細パネル ---- */
.detail {
  position: fixed; right: 12px; top: 84px; z-index: 1000; width: 300px;
  padding: 16px 18px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  backdrop-filter: blur(8px);
}
.detail.hidden, .toast.hidden { display: none; }
.detail .close {
  position: absolute; right: 10px; top: 8px; background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer;
}
.detail h3 { margin: 0; font-size: 22px; letter-spacing: .03em; }
.detail .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.detail .route {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  margin: 14px 0; padding: 12px; border-radius: 10px; background: rgba(255,255,255,0.04);
}
.detail .route .code { font-size: 22px; font-weight: 700; }
.detail .route .name { font-size: 11px; color: var(--muted); line-height: 1.35; }
.detail .route .arrow { color: var(--accent); font-size: 18px; }
.detail .route .to { text-align: right; }
.detail .est { font-size: 11px; color: #facc15; margin: -6px 0 10px; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 1100;
  background: rgba(127, 29, 29, 0.92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  max-width: min(90vw, 760px); line-height: 1.5;
}

@media (max-width: 760px) {
  .topbar p { display: none; }
  .panel { top: auto; bottom: 84px; width: calc(100% - 24px); max-height: 50%; }
  .panel.collapsed { display: none; }
  .panel-toggle { display: block; }
  .detail { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; }
}
