:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #d1d1d6;
  --accent: #007aff;
  --warn: #ff9500;
  --danger: #ff3b30;
  --ok: #34c759;
  --bar: rgba(255, 255, 255, 0.92);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989d;
    --line: #38383a;
    --accent: #0a84ff;
    --bar: rgba(28, 28, 30, 0.92);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Helvetica Neue", sans-serif; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
select, input[type=text], input[type=password], input[type=number], textarea { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
textarea { width: 100%; min-height: 90px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* 画面の大きさ: --bar-h(上のバー)・--panel-w(右の一覧の幅)・--panel-h(スマートフォンの下の一覧の高さ)・--ui(文字とボタンの倍率) */
body { --bar-h: 48px; --panel-w: 300px; --panel-h: 40vh; --ui: 1; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); touch-action: manipulation; overscroll-behavior: none; }
body.touch { --bar-h: 56px; }
body.panel-closed { --panel-w: 0px; --panel-h: 0px; }
/* 大きさ(--ui)は文字の大きさ・em で変える。CSS の zoom は iPad・iPhone の Safari で文字がぼやけるため使わない(5.7.2) */
#bar { position: fixed; top: 0; left: 0; right: 0; height: calc(var(--bar-h) * var(--ui) + var(--safe-t)); padding: var(--safe-t) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l)); display: flex; align-items: center; gap: calc(6px * var(--ui)); background: var(--bar); border-bottom: 1px solid var(--line); z-index: 50; overflow-x: auto; scrollbar-width: none; font-size: calc(14px * var(--ui)); }
#bar button, #bar select { padding: .36em .72em; }
#bar::-webkit-scrollbar { display: none; }
#bar .brand { font-weight: 700; white-space: nowrap; }
#bar button, #bar select { white-space: nowrap; flex: none; }
#bar .brand span { color: var(--accent); }
#bar .spacer { flex: 1; }
#fleet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }

#main { position: fixed; top: calc(var(--bar-h) * var(--ui) + var(--safe-t)); left: 0; right: 0; bottom: 0; }
#map { position: absolute; inset: 0; right: var(--panel-w); background: #dfe6ea; }
body.panel-closed #panel { display: none; }

.tm { overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.tm.dragging { cursor: grabbing; }
.tm-tiles, .tm-markers { position: absolute; inset: 0; }
.tm-layer { position: absolute; inset: 0; }
.tm-tile { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; image-rendering: auto; background-repeat: no-repeat; }
.tm-layer.pixel .tm-tile { image-rendering: pixelated; }
.tm-canvas { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 20; }
.tm-markers { z-index: 30; pointer-events: none; }
.tm-marker { position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; }

/* 自社の機体 */
.ac { display: flex; flex-direction: column; align-items: center; }
.ac svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
/* 名前は印の下に重ねる(印の箱 = 機体の図だけにして、図の中心がちょうど位置に来るようにする) */
.ac .lbl, .adsb .lbl { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); pointer-events: none; }
.ac .lbl { margin-top: 1px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 0 4px; border-radius: 3px; white-space: nowrap; }
.ac.stale svg { opacity: .45; }
.ac.sel .lbl { background: var(--accent); }

/* ADS-B */
.adsb { display: flex; flex-direction: column; align-items: center; }
.adsb .lbl { background: rgba(0,0,0,.55); color: #fff; font-size: 9px; padding: 0 3px; border-radius: 3px; white-space: nowrap; }
.adsb svg { filter: drop-shadow(0 0 1px #000); }

/* METAR */
.myloc { width: 16px; height: 16px; border-radius: 50%; background: #007aff; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 1px 4px rgba(0,0,0,.4); pointer-events: none; }
.metar { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 2px #000; }

/* ライブカメラ */
.cam { display: flex; flex-direction: column; align-items: center; }
.cam .th { width: 112px; height: 63px; background: #222 center/cover no-repeat; border: 2px solid #fff; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.5); position: relative; }
.cam .th b { position: absolute; left: 3px; top: 3px; background: #e53935; color: #fff; font-size: 9px; padding: 0 4px; border-radius: 3px; }
.cam .ic { font-size: 20px; text-shadow: 0 0 3px #fff, 0 1px 3px rgba(0,0,0,.6); }

#mapBtns { position: absolute; right: calc(var(--panel-w) + 10px + var(--safe-r)); top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 40; }
#mapBtns button { min-width: calc(44px * var(--ui)); font-size: calc(14px * var(--ui)); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
#wxbar { position: absolute; left: calc(10px + var(--safe-l)); top: 10px; z-index: 40; display: flex; align-items: center; gap: .57em; background: var(--bar); padding: .43em .72em; border-radius: 10px; font-size: calc(14px * var(--ui)); box-shadow: 0 1px 6px rgba(0,0,0,.25); max-width: calc(100% - var(--panel-w) - 90px); flex-wrap: wrap; }
#wxSlider { width: calc(220px * var(--ui)); }
#wxbar button { padding: .3em .7em; }
#wxTime { font-variant-numeric: tabular-nums; white-space: nowrap; }
#wxLegend { font-size: .79em; white-space: nowrap; }
/* ADS-B の表示も、文字・ボタンの大きさ(--ui)に合わせる(5.7。スマートフォン・ブラウザ版は標準で小さめ) */
#adsbStatus { font-size: calc(11px * var(--ui)); }
#wxLegend i { display: inline-block; width: 12px; height: 10px; margin: 0 1px 0 4px; vertical-align: middle; border: 1px solid rgba(0,0,0,.2); }
.pill { position: absolute; left: 50%; transform: translateX(-50%); top: 10px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 6px; z-index: 40; pointer-events: none; }
.pill.err { color: #ff8a80; }
#hover { position: absolute; z-index: 60; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.3); pointer-events: none; white-space: pre-wrap; }
#attr { position: absolute; left: calc(6px + var(--safe-l)); bottom: 4px; right: calc(var(--panel-w) + 6px); font-size: 10px; color: #333; z-index: 40; pointer-events: none; }
#attr span { background: rgba(255,255,255,.75); padding: 0 4px; }

/* 機体の一覧: PC・タブレットは右、スマートフォンは下。端をドラッグして大きさを変える */
#panel { position: absolute; top: 0; right: 0; bottom: 0; width: var(--panel-w); background: var(--bg); border-left: 1px solid var(--line); z-index: 45; display: flex; flex-direction: column; padding-right: var(--safe-r); }
#panelGrip { position: absolute; left: -6px; top: 0; bottom: 0; width: 12px; cursor: ew-resize; touch-action: none; z-index: 2; }
#panelGrip::after { content: ''; position: absolute; left: 4px; top: 50%; width: 4px; height: 44px; margin-top: -22px; border-radius: 2px; background: var(--line); }
#panelGrip:hover::after, #panelGrip.dragging::after { background: var(--accent); }
#panelHead { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: calc(14px * var(--ui)); }
#panelHead b { flex: 1; font-size: .93em; }
#panelHead button { padding: .25em .67em; font-size: .86em; }
#panelBody { flex: 1; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; font-size: calc(14px * var(--ui)); }
#conn { font-size: .86em; margin: 2px 4px 8px; }
/* 簡易表示: 機体ごとに1〜2行 */
body.panel-compact .card { padding: .43em .71em; margin-bottom: 6px; }
body.panel-compact .card .sub, body.panel-compact .card .note { display: none; }
body.panel-compact .card .grid { grid-template-columns: repeat(3, 1fr); margin-top: 4px; gap: 2px 8px; }
body.panel-compact .card .grid > div:nth-child(n+4) { display: none; }
body.panel-compact .card .grid b { font-size: 1.07em; }
#conn.err { color: var(--danger); }
.card { background: var(--card); border-radius: 12px; padding: .71em .86em; margin-bottom: 8px; border: 2px solid transparent; cursor: pointer; }
.card.sel { border-color: var(--accent); }
.card .t { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 1.07em; }
.card .dot { width: 10px; height: 10px; border-radius: 50%; }
.card .sub { color: var(--muted); font-size: .86em; margin-top: 1px; }
.card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: .29em .71em; margin-top: .57em; }
.card .grid div { display: flex; flex-direction: column; }
.card .grid small { color: var(--muted); font-size: .79em; }
.card .grid b { font-size: 1.29em; font-variant-numeric: tabular-nums; }
.card .warn { color: var(--danger); font-weight: 700; }
.card .note { font-size: .79em; color: var(--muted); margin-top: 6px; }
.badge { font-size: .79em; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--text); font-weight: 600; }
.badge.live { background: var(--ok); color: #fff; }
.badge.stale { background: var(--warn); color: #fff; }

/* 浮かぶ窓(ライブカメラ) */
#windows { position: absolute; inset: 0; pointer-events: none; z-index: 70; }
.win { max-width: calc(100% - 16px); position: absolute; pointer-events: auto; background: #1c1c1e; box-shadow: 0 6px 24px rgba(0,0,0,.45); border-radius: 8px; overflow: hidden; resize: both; min-width: 220px; min-height: 160px; display: flex; flex-direction: column; }
.win .wh { height: 32px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 4px 0 10px; background: #2c2c2e; color: #fff; cursor: move; font-size: 13px; font-weight: 600; }
.win .wh span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win .wh button { background: transparent; border: none; color: #fff; padding: 2px 6px; }
.win .wb { flex: 1; position: relative; background: #000; }
.win .wb iframe, .win .wb video, .win .wb img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: contain; }
.win.dragging iframe { pointer-events: none; }

/* 汎用の画面 */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px 16px; overflow-y: auto; }
#modal .sheet { background: var(--bg); border-radius: 14px; width: min(720px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.sheet-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
#modalBody { padding: 12px 16px 18px; }
.sec { background: var(--card); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.sec h3 { margin: 2px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.row:last-child { border-bottom: none; }
.row label { flex: 1; min-width: 140px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow div:first-child { font-weight: 600; }
.list-item .grow div + div { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err-text { color: var(--danger); white-space: pre-wrap; }

#toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 8px 16px; border-radius: 10px; z-index: 200; max-width: 80vw; }

/* スマートフォンの配置: 一覧は下から引き出す(上の端をドラッグで高さを変える) */
body.lay-mobile #map { right: 0; bottom: var(--panel-h); }
body.lay-mobile #panel { top: auto; left: 0; width: auto; height: var(--panel-h); border-left: none; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.18); padding: 0 var(--safe-r) var(--safe-b) var(--safe-l); }
body.lay-mobile #panelGrip { left: 0; right: 0; top: -10px; bottom: auto; width: auto; height: 28px; cursor: ns-resize; }
body.lay-mobile #panelGrip::after { left: 50%; top: 12px; width: 44px; height: 5px; margin: 0 0 0 -22px; }
body.lay-mobile #mapBtns { right: calc(10px + var(--safe-r)); }
body.lay-mobile #attr { right: 6px; bottom: calc(var(--panel-h) + 4px); }
body.lay-mobile #wxbar { max-width: calc(100% - 90px); }
body.lay-mobile #wxSlider { width: 140px; }
body.lay-mobile #wxLegend { display: none; }
/* 幅が狭いとき(スマートフォン・縦のタブレット): 上のバーのレイヤーの切り替えは「表示」の画面にまとめる */
#btnLayers { display: none; }
body.bar-compact #btnLayers { display: inline-block; }
body.bar-compact #bar .tg, body.bar-compact #bar #mapSource, body.bar-compact #fleet, body.bar-compact #btnData, body.bar-compact #btnNav { display: none; }
body.lay-mobile #modal { padding: calc(8px + var(--safe-t)) 8px 8px; }
body.lay-mobile #modal .sheet { width: 100%; }

/* タッチ操作: 押しやすい大きさ(44px 以上)・入力時に拡大されない文字の大きさ */
body.touch button, body.touch select { min-height: 40px; padding: 8px 12px; }
body.touch #bar button, body.touch #bar select { min-height: calc(40px * var(--ui)); padding: .5em .8em; }
body.touch #wxbar button { min-height: calc(36px * var(--ui)); padding: .4em .8em; }
body.touch #mapBtns button { min-width: calc(48px * var(--ui)); min-height: calc(48px * var(--ui)); font-size: calc(17px * var(--ui)); }
body.touch #panelHead button { min-height: calc(36px * var(--ui)); padding: .3em .8em; }
body.touch input[type=text], body.touch input[type=password], body.touch input[type=number], body.touch select, body.touch textarea { font-size: 16px; padding: 8px 10px; }
body.touch .card { padding: .86em 1em; }
body.touch #panelGrip { left: -11px; width: 22px; }
body.touch.lay-mobile #panelGrip { left: 0; width: auto; top: -14px; height: 36px; }
/* 押せる範囲だけを広げる(印は .tm-marker の position: absolute のまま。relative にすると位置がずれる) */
body.touch .metar::before { content: ''; position: absolute; inset: -14px; }
body.touch .win .wh { height: 40px; }
body.touch .win .wh button { min-height: 36px; min-width: 36px; }
body.touch #hover { font-size: 14px; max-width: min(360px, calc(100vw - 24px)); pointer-events: auto; }
.layer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.layer-grid button { min-height: 48px; font-size: 15px; }
#modalBody .muted { overflow-wrap: anywhere; }

/* ログインの画面 */
body.login-page { overflow-y: auto; }
.login { max-width: 420px; margin: 0 auto; padding: 32px 16px; }
.login .brand { font-weight: 700; font-size: 22px; margin-bottom: 8px; }
.login .brand span { color: var(--accent); }
.login label { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-weight: 600; }
.login input { font-size: 16px; padding: 10px 12px; }
.login button { padding: 10px 14px; margin: 6px 6px 0 0; font-size: 15px; }
.login .muted { line-height: 1.6; }
.login .small { font-size: 12px; }
a.button { display: inline-block; text-decoration: none; border-radius: 8px; padding: 10px 14px; border: 1px solid var(--line); }
a.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.keybox { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.keybox code { font: 15px ui-monospace, Menlo, Consolas, monospace; background: var(--bg); padding: 6px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.list-item .grow div.issued { font: 600 20px ui-monospace, Menlo, Consolas, monospace; color: var(--text); background: var(--bg); padding: 8px 10px; border-radius: 8px; user-select: all; white-space: normal; margin-top: 4px; letter-spacing: .05em; }
.loglist { max-height: 220px; overflow-y: auto; font-size: 12px; }
.loglist div { padding: 2px 0; border-bottom: 1px solid var(--line); }
input.inl { width: 100%; }
.login label.keep { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
[hidden] { display: none !important; }

/* ---- 5.3: ナビ・データ・過去の航跡の凡例 ---- */
.navcard { margin-top: 8px; padding: 6px 9px; border-radius: 9px; border: 1px solid rgba(126,87,194,.45); background: rgba(126,87,194,.09); font-size: .93em; }
.navcard .nh { display: flex; justify-content: space-between; gap: 6px; color: #7e57c2; font-weight: 600; font-size: .92em; }
.navcard .big { font-size: 1.23em; font-weight: 700; font-variant-numeric: tabular-nums; }
#navBar { position: absolute; left: calc(10px + var(--safe-l)); right: calc(var(--panel-w) + 70px); bottom: 22px; z-index: 50; display: flex; align-items: center; gap: 6px; background: var(--bar); padding: 6px 10px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.3); }
#navBar .grow, .list-item .grow { flex: 1; min-width: 0; }
#histLegend { position: absolute; left: calc(10px + var(--safe-l)); bottom: 70px; z-index: 40; display: flex; gap: 6px; align-items: flex-end; }
#histLegend .lg { background: var(--bar); border-radius: 10px; padding: 6px 10px; font-size: 11px; cursor: pointer; box-shadow: 0 1px 6px rgba(0,0,0,.25); }
#histLegend .lg b { display: block; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
#histLegend i { display: inline-block; width: 14px; height: 9px; margin-right: 6px; vertical-align: middle; }
.pick { cursor: pointer; }

/* 手動のポート転送の案内(5.4) */
.extguide { margin: 6px 0 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.extguide p { margin: 0 0 6px; }
.extguide ul { margin: 6px 0; padding-left: 18px; font-size: 12px; }
.extguide table.kv { border-collapse: collapse; font-size: 13px; }
.extguide table.kv td { padding: 2px 12px 2px 0; }
.extguide table.kv td:first-child { color: var(--muted); }
.extguide table.kv td:last-child { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; }

/* 低速通信モードで止めている表示(5.5) */
button.tg.lowbw { opacity: .45; text-decoration: line-through; }

/* 外から見られるようにする(自動)の進み具合(5.6) */
.steps { margin: 6px 0; }
.steps .step { display: flex; gap: 8px; padding: 4px 0; align-items: flex-start; }
.steps .mark { width: 18px; text-align: center; font-weight: 700; }
.steps .ok .mark { color: #34c759; }
.steps .ng .mark { color: #ff3b30; }
.steps .warn .mark { color: #ff9f0a; }
.steps .wait .mark { color: var(--muted); }
.steps .muted { font-size: 12px; }

/* 登録用のリンクと QR コード(5.6) */
.liclink { margin: 6px 0 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.liclink .qr { display: flex; justify-content: center; padding: 8px 0; }
.liclink .qr svg { width: 220px; height: 220px; max-width: 70vw; max-height: 70vw; border-radius: 6px; }
.login { padding-top: calc(32px + env(safe-area-inset-top, 0px)); }
