:root {
  --bg: #0b1220;
  --bg-elev: #121b30;
  --bg-elev-2: #182444;
  --border: #263257;
  --text: #e7ecf7;
  --text-dim: #90a0c2;
  --accent: #4da3ff;
  --accent-2: #ffb454;
  --ok: #3ddc84;
  --warn: #ffcc4d;
  --danger: #ff5c72;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1f9;
  --border: #d8deee;
  --text: #16213a;
  --text-dim: #5b6a8d;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

header.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
header.topbar h1 {
  font-size: 18px; margin: 0; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
header.topbar h1 .plane { font-size: 20px; }
.spacer { flex: 1; }
.clock {
  font-family: var(--mono); font-size: 13px; color: var(--text-dim);
}
.icon-btn {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.icon-btn:hover { border-color: var(--accent); }
select, input[type="text"], input[type="search"], input[type="password"] {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-family: var(--sans);
}
input::placeholder { color: var(--text-dim); }

.atc-bar {
  display: none;
  align-items: center; gap: 10px; padding: 8px 20px;
  background: var(--bg-elev-2); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.atc-bar.show { display: flex; }
.atc-bar .atc-label { font-size: 15px; }
.atc-bar audio { height: 32px; max-width: 320px; flex: 1; min-width: 200px; }
.icon-btn.small { padding: 4px 8px; font-size: 12px; }

.weather-bar {
  display: none; align-items: center; gap: 12px; padding: 8px 20px;
  background: var(--bg-elev-2); border-bottom: 1px solid var(--border); flex-wrap: wrap;
  font-size: 13px;
}
.weather-bar.show { display: flex; }
.weather-bar #weatherRunwayHint { color: var(--accent-2); font-size: 12px; }
.weather-raw {
  width: 100%; font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  background: var(--bg); padding: 8px; border-radius: 6px;
}

.reg-info { font-size: 10px; color: var(--text-dim); font-family: var(--mono); margin-top: 2px; }
.reg-info.watch-match { color: var(--warn); font-weight: 700; }

.modal-help { font-size: 12px; color: var(--text-dim); line-height: 1.6; margin: 0 0 10px; }
.atc-list { list-style: none; margin: 12px 0 0; padding: 0; max-height: 160px; overflow-y: auto; }
.atc-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.atc-list li .atc-item-name { font-weight: 600; }
.atc-list li .atc-item-url { color: var(--text-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.atc-list li button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 12px; }

nav.tabs {
  display: flex; gap: 4px; padding: 10px 20px 0; background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
nav.tabs button {
  background: transparent; border: none; color: var(--text-dim);
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); background: var(--bg-elev-2); }
nav.tabs button:hover { color: var(--text); }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  background: var(--bg-elev); border: none; color: var(--text-dim);
  padding: 7px 14px; font-size: 13px; cursor: pointer; border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent); color: #06172e; font-weight: 700; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-chip {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 20px;
  padding: 5px 12px; font-size: 12px; color: var(--text-dim); display: flex; gap: 6px; align-items: center;
}
.stat-chip b { color: var(--text); font-size: 13px; }
.stat-chip.warn b { color: var(--warn); }
.stat-chip.danger b { color: var(--danger); }
.stat-chip.ok b { color: var(--ok); }

main { flex: 1; padding: 8px 20px 24px; overflow-x: auto; overflow-y: auto; min-height: 0; }

.note {
  margin: 8px 20px 0; padding: 10px 14px; border-radius: 8px; font-size: 12px; line-height: 1.6;
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim);
  display: none;
}
.note.show { display: block; }
.other-airlines { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.other-airlines a {
  color: var(--text); text-decoration: none; font-size: 11px; font-weight: 600;
  background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 14px; padding: 4px 10px;
}
.other-airlines a:hover { color: var(--accent); border-color: var(--accent); }

.banner {
  margin: 8px 20px 0; padding: 10px 14px; border-radius: 8px; font-size: 13px;
  background: rgba(255, 92, 114, 0.12); border: 1px solid var(--danger); color: var(--danger);
  display: none;
}
.banner.show { display: block; }

table.flights {
  width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px;
}
table.flights thead th {
  text-align: left; color: var(--text-dim); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg);
}
table.flights tbody tr {
  border-bottom: 1px solid var(--border);
}
table.flights tbody tr:hover { background: var(--bg-elev); }
table.flights td { padding: 9px 10px; vertical-align: middle; }

.airline-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 22px; border-radius: 5px; font-weight: 800; font-size: 11px;
  font-family: var(--mono);
}
.airline-badge.ANA { background: #0a2f6b; color: #7fc4ff; border: 1px solid #1d5fb0; }
.airline-badge.JAL { background: #5c0a1e; color: #ff9fb2; border: 1px solid #a02040; }

.flight-no { font-family: var(--mono); font-weight: 700; letter-spacing: 0.02em; }
.route { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.route .arrow { color: var(--text-dim); }
.route .code { font-family: var(--mono); font-weight: 700; }
.route .city { color: var(--text-dim); font-size: 11px; margin-left: 2px; }

.time-leg { font-family: var(--mono); white-space: nowrap; }
.time-leg + .time-leg { margin-top: 2px; }
.time-leg .sched.strike { text-decoration: line-through; color: var(--text-dim); }
.time-leg .actual { font-weight: 700; }
.leg-label { font-family: var(--sans); font-size: 10px; color: var(--text-dim); margin-right: 2px; }
.delay-badge {
  font-size: 11px; margin-left: 6px; padding: 1px 6px; border-radius: 10px; font-family: var(--sans);
}
.delay-badge.late { background: rgba(255,204,77,0.15); color: var(--warn); }
.delay-badge.verylate { background: rgba(255,92,114,0.15); color: var(--danger); }

.status-badge {
  display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.status-badge.ok { background: rgba(61,220,132,0.15); color: var(--ok); }
.status-badge.info { background: rgba(77,163,255,0.15); color: var(--accent); }
.status-badge.warn { background: rgba(255,204,77,0.15); color: var(--warn); }
.status-badge.danger { background: rgba(255,92,114,0.15); color: var(--danger); }
.status-badge.neutral { background: var(--bg-elev-2); color: var(--text-dim); }
.status-badge.flying { background: rgba(178,138,255,0.18); color: #b28aff; }

.remark { font-size: 11px; color: var(--warn); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr24-link {
  color: var(--text-dim); text-decoration: none; font-size: 11px; border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 7px; white-space: nowrap;
}
.fr24-link:hover { color: var(--accent); border-color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }

footer.appfooter {
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg-elev);
  font-size: 12px; color: var(--text-dim); display: flex; gap: 16px; flex-wrap: wrap; align-items: center;
}
footer.appfooter a { color: var(--accent); text-decoration: none; }
footer.appfooter a:hover { text-decoration: underline; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: 420px; max-width: 90vw;
}
.modal h2 { margin: 0 0 12px; font-size: 15px; }
.modal label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 4px; }
.modal input[type="text"], .modal input[type="password"], .modal select { width: 100%; }
.modal .row { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; }
.modal .primary { background: var(--accent); color: #06172e; border: none; font-weight: 700; }
.modal { max-height: 85vh; overflow-y: auto; }

@media (max-width: 720px) {
  header.topbar { padding: 8px 12px; gap: 8px; }
  header.topbar h1 { font-size: 14px; }
  header.topbar .clock { font-size: 11px; }
  header.topbar .icon-btn, .toolbar .icon-btn { padding: 5px 8px; font-size: 11px; }
  header.topbar .icon-btn .label { display: none; }
  nav.tabs { padding: 6px 12px 0; }
  nav.tabs button { padding: 7px 10px; font-size: 13px; }
  .toolbar { padding: 8px 12px; gap: 6px; }
  .toolbar select, .toolbar input[type="search"] { font-size: 12px; padding: 5px 8px; }
  .stats { display: none; } /* 便数等の統計はモバイルでは省略してスペース確保 */
  main { padding: 6px 12px 24px; }
  .note, .banner, .weather-bar, .atc-bar { margin-left: 12px; margin-right: 12px; padding-left: 12px; padding-right: 12px; }
  .note {
    max-height: 56px; overflow-y: auto; font-size: 11px; padding-top: 6px; padding-bottom: 6px;
  }
  .note .other-airlines { margin-top: 4px; }

  /* テーブルをカード型に変形 */
  table.flights { min-width: 0; width: 100%; }
  table.flights thead { display: none; }
  table.flights tbody { display: block; }
  table.flights tr {
    display: block; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--bg-elev); padding: 8px 10px;
  }
  table.flights td {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 5px 2px; border-bottom: 1px dashed var(--border); text-align: right;
  }
  table.flights td:last-child { border-bottom: none; }
  table.flights td[data-label]::before {
    content: attr(data-label); font-size: 11px; color: var(--text-dim); font-weight: 600;
    text-align: left; flex-shrink: 0;
  }
  table.flights td[data-label=""]::before { content: none; }
  table.flights td .route { white-space: normal; justify-content: flex-end; }
  table.flights td .remark { max-width: 60%; white-space: normal; text-align: right; }
}
