/* ===== PashaYard Map — メカニカルHUDデザイン ===== */
:root {
  --bg: #070b12;
  --panel: rgba(10, 16, 26, .88);
  --panel-solid: #0c1220;
  --line: #1e3a52;
  --line-hi: #2e5a7a;
  --cyan: #00e5ff;
  --cyan-dim: #0a90a8;
  --orange: #ff9e2c;
  --green: #7ac943;
  --red: #ff5252;
  --text: #cfe8f5;
  --text-dim: #6f93a8;
  --mono: 'Consolas', 'Courier New', 'SF Mono', monospace;
  --sans: system-ui, -apple-system, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--bg); font-family: var(--sans); color: var(--text); }
#map { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ===== 共通パネル: 角落とし+スキャンライン ===== */
.hud-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  position: relative;
}
.hud-panel::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 229, 255, .015) 2px 4px);
}

/* ===== ボタン ===== */
.mech-btn {
  background: linear-gradient(180deg, #12202f, #0a1420);
  border: 1px solid var(--line-hi);
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 16px;
  min-width: 40px; min-height: 40px;
  cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  transition: background .15s, color .15s;
  user-select: none;
}
.mech-btn:active { background: #1a3348; }
.mech-btn.on { color: #041016; background: linear-gradient(180deg, var(--cyan), var(--cyan-dim)); border-color: var(--cyan); }
.mech-btn.accent { color: var(--orange); border-color: #7a5a2c; }
.mech-btn.sm { min-width: 30px; min-height: 30px; font-size: 13px; }
.mech-btn.wide { width: 100%; font-size: 13px; flex-direction: row; gap: 6px; }
.mech-btn.ctl { width: 44px; height: 44px; font-size: 19px; }
.btn-sub, .ctl-sub { font-size: 8px; letter-spacing: .1em; color: var(--text-dim); line-height: 1; }
.mech-btn.on .btn-sub, .mech-btn.on .ctl-sub { color: #062830; }

/* ===== 上部HUD ===== */
#hudTop {
  position: fixed; top: calc(6px + var(--sat)); left: 6px; right: 6px; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
}
.hud-left { display: flex; align-items: center; gap: 10px; }
.logo { font-family: var(--mono); font-weight: 700; font-size: 15px; letter-spacing: .12em; color: var(--text); white-space: nowrap; }
.logo span { color: var(--cyan); }
.logo-ver { font-size: 9px; color: var(--orange) !important; vertical-align: super; margin-left: 4px; }
.hud-center { display: flex; flex: 1; gap: 14px; overflow: hidden; justify-content: center; flex-wrap: wrap; }
.ro-item { display: flex; align-items: baseline; gap: 5px; font-family: var(--mono); white-space: nowrap; }
.ro-k { font-size: 9px; color: var(--cyan-dim); letter-spacing: .15em; }
.ro-v { font-size: 12px; color: var(--text); }
.move-only { display: none; }
body.moving .move-only { display: flex; }
body.moving #roSpd { color: var(--orange); font-weight: 700; }
.hud-right { display: flex; gap: 6px; }

/* ===== レイヤーメニュー ===== */
#layerMenu {
  position: fixed; top: calc(64px + var(--sat)); left: 6px; bottom: calc(30px + var(--sab)); z-index: 40;
  width: 320px; max-width: calc(100vw - 12px);
  display: flex; flex-direction: column;
  transform: translateX(calc(-100% - 20px));
  transition: transform .22s ease;
}
#layerMenu.open { transform: none; }
.lm-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.lm-title { font-family: var(--mono); font-size: 12px; letter-spacing: .18em; color: var(--cyan); flex: 1; }
.lm-count { font-family: var(--mono); font-size: 10px; color: var(--orange); }
.lm-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 0; }
.lm-foot { padding: 8px; border-top: 1px solid var(--line); }

/* カテゴリ（階層メニュー） */
.cat { border-bottom: 1px solid rgba(30, 58, 82, .5); }
.cat-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; user-select: none;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .06em;
}
.cat-head:hover { background: rgba(0, 229, 255, .05); }
.cat-arrow { color: var(--cyan-dim); font-size: 10px; transition: transform .15s; width: 12px; }
.cat.open .cat-arrow { transform: rotate(90deg); }
.cat-icon { width: 18px; text-align: center; }
.cat-name { flex: 1; }
.cat-badge { font-size: 9px; color: var(--orange); font-family: var(--mono); }
.cat-items { display: none; padding: 0 0 6px; }
.cat.open .cat-items { display: block; }

/* レイヤー行 */
.lyr {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px 7px 30px; cursor: pointer; user-select: none;
  font-size: 12.5px;
}
.lyr:hover { background: rgba(0, 229, 255, .05); }
.lyr .led {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: #14202c; border: 1px solid var(--line-hi);
  box-shadow: 0 0 0 rgba(0, 229, 255, 0);
  transition: all .15s;
}
.lyr.on .led { background: var(--cyan); box-shadow: 0 0 7px var(--cyan); border-color: var(--cyan); }
.lyr .lyr-name { flex: 1; }
.lyr .lyr-tag { font-size: 9px; font-family: var(--mono); color: var(--text-dim); }
.lyr.soon { opacity: .42; cursor: default; }
.lyr.soon .lyr-tag { color: var(--orange); }
.lyr.excl.on .lyr-name { color: var(--cyan); }
.lyr-action { font-size: 10px; color: var(--orange); border: 1px solid #7a5a2c; padding: 2px 6px; font-family: var(--mono); }
.lyr-action:active { background: #33270f; }
.lyr-note { padding: 2px 12px 6px 47px; font-size: 10px; color: var(--text-dim); line-height: 1.5; }
.lm-slider { display: flex; align-items: center; gap: 8px; padding: 4px 12px 8px 30px; font-size: 10px; color: var(--text-dim); font-family: var(--mono); }
.lm-slider input[type=range] { flex: 1; accent-color: var(--cyan); height: 18px; }

/* ===== 右コントロール ===== */
#mapCtrl {
  position: fixed; right: 6px; top: 50%; transform: translateY(-50%); z-index: 25;
  display: flex; flex-direction: column; gap: 7px;
}
.ctl-zoom { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
#compassRose { transition: none; }
#btnCompass.tracking { color: var(--orange); }

/* ===== 計測バー ===== */
#measureBar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(34px + var(--sab)); z-index: 35;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  font-family: var(--mono); font-size: 13px; color: var(--orange);
  max-width: calc(100vw - 20px);
}
#measureInfo { white-space: nowrap; overflow-x: auto; }

/* ===== 情報パネル ===== */
#infoPanel {
  position: fixed; z-index: 45;
  right: 6px; bottom: calc(30px + var(--sab));
  width: 340px; max-width: calc(100vw - 12px); max-height: 55vh;
  display: flex; flex-direction: column;
}
.ip-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12px; letter-spacing: .12em; color: var(--orange); }
.ip-body { overflow-y: auto; padding: 10px 12px; font-size: 13px; line-height: 1.65; }
.ip-body .kv { display: flex; gap: 10px; padding: 3px 0; border-bottom: 1px dashed rgba(30, 58, 82, .4); }
.ip-body .kv .k { color: var(--text-dim); font-size: 11px; min-width: 72px; padding-top: 2px; }
.ip-body .kv .v { flex: 1; }
.ip-body .big { font-size: 19px; font-weight: 700; color: var(--cyan); font-family: var(--mono); }
.ip-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ===== モーダル ===== */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(3, 6, 10, .6); display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal-box { width: 420px; max-width: 100%; max-height: 86vh; display: flex; flex-direction: column; }
.modal-body { overflow-y: auto; padding: 12px 14px; font-size: 13px; }
.cfg-sec { margin-bottom: 14px; }
.cfg-sec h4 { font-family: var(--mono); font-size: 11px; letter-spacing: .15em; color: var(--cyan-dim); margin-bottom: 6px; }
.cfg-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed rgba(30, 58, 82, .4); }
.cfg-row .lbl { flex: 1; }
.cfg-row .sub { font-size: 10px; color: var(--text-dim); }
.chip-group { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { font-size: 11px; font-family: var(--mono); padding: 4px 9px; border: 1px solid var(--line-hi); color: var(--text-dim); cursor: pointer; user-select: none; }
.chip.on { color: #041016; background: var(--cyan); border-color: var(--cyan); }

/* ===== ポイント編集 ===== */
.pm-field { margin-bottom: 10px; }
.pm-field label { display: block; font-size: 10px; font-family: var(--mono); color: var(--cyan-dim); letter-spacing: .12em; margin-bottom: 3px; }
.pm-field input[type=text], .pm-field textarea {
  width: 100%; background: #0a1018; border: 1px solid var(--line-hi); color: var(--text);
  padding: 7px 9px; font-size: 14px; font-family: var(--sans);
}
.pm-field textarea { min-height: 64px; resize: vertical; }
.stars { display: flex; gap: 4px; }
.stars .st { font-size: 24px; color: #26404f; cursor: pointer; }
.stars .st.on { color: var(--orange); text-shadow: 0 0 8px rgba(255, 158, 44, .6); }
.pm-photos { display: flex; gap: 6px; flex-wrap: wrap; }
.pm-photos img { width: 68px; height: 68px; object-fit: cover; border: 1px solid var(--line-hi); }
.pm-photos .del-ph { position: absolute; top: -6px; right: -6px; }
.ph-wrap { position: relative; }
.pm-actions { display: flex; gap: 8px; margin-top: 12px; }
.pm-actions .mech-btn { flex: 1; font-size: 13px; flex-direction: row; }

/* ポイントマーカー */
.pt-marker { width: 26px; height: 26px; cursor: pointer; }
.pt-marker svg { filter: drop-shadow(0 1px 3px rgba(0,0,0,.7)); }

/* 地番ラベル */
.chiban-label {
  font-family: var(--mono); font-size: 10px; color: #d8ffc0;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 3px #000;
  white-space: nowrap; pointer-events: none; transform: translate(-50%, -50%);
}
.measure-label {
  font-family: var(--mono); font-size: 11px; color: var(--orange); background: rgba(7, 11, 18, .8);
  padding: 1px 5px; border: 1px solid #7a5a2c; white-space: nowrap; pointer-events: none;
}

/* ===== 十字（交点＝HUDの経緯度） ===== */
.maplibregl-canvas-container.maplibregl-interactive { cursor: crosshair; }
.maplibregl-canvas-container.maplibregl-interactive:active { cursor: crosshair; }
#reticle {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 52px; height: 52px; pointer-events: none; z-index: 15; display: none;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .9));
}
@media (pointer: coarse) { #reticle { display: block; } }
body.clean #reticle { display: none !important; }

/* 現在地ドット */
.me-dot { width: 18px; height: 18px; position: relative; }
.me-dot::before { content: ''; position: absolute; inset: 0; border-radius: 50%; background: rgba(0, 229, 255, .25); animation: pulse 2s infinite; }
.me-dot::after { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: var(--cyan); border: 2px solid #fff; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(3); opacity: 0; } }

/* ===== 全消しモード ===== */
body.clean #hudTop, body.clean #mapCtrl, body.clean #layerMenu, body.clean #infoPanel, body.clean #measureBar { display: none; }
#btnRestore { position: fixed; right: 8px; top: calc(8px + var(--sat)); z-index: 50; opacity: .55; }
/* .hidden の !important に勝つ必要がある（これが無いとCLEANから戻れなくなる） */
body.clean #btnRestore { display: inline-flex !important; }

/* ===== トースト・出典 ===== */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(72px + var(--sab)); z-index: 70;
  background: var(--panel-solid); border: 1px solid var(--orange); color: var(--orange);
  font-family: var(--mono); font-size: 12px; padding: 8px 16px; max-width: 90vw;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
#attrib {
  position: fixed; left: 4px; bottom: calc(2px + var(--sab)); z-index: 20;
  font-size: 9px; color: rgba(160, 190, 210, .75); text-shadow: 0 0 2px #000;
  max-width: 80vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.clean #attrib { opacity: .9; }

/* ===== 夜間モード ===== */
body.night { --panel: rgba(6, 9, 14, .92); }
body.night #map { filter: brightness(.82); }
body.night #hudTop .logo span { color: var(--orange); }

/* ===== スマホ調整 ===== */
@media (max-width: 700px) {
  #hudTop { flex-wrap: wrap; padding: 5px 8px; gap: 6px; }
  /* 1段目はアイコンだけ（英字ラベルは幅不足で切れるため非表示） */
  #hudTop .btn-sub { display: none; }
  #hudTop .mech-btn { min-width: 38px; min-height: 38px; font-size: 17px; }
  .hud-left { flex: 1; }
  /* 2段目: ロゴの下に情報を1行で（折返さず横スクロール）。flex-basis:100%で必ず2段目へ */
  .hud-center {
    order: 3; flex: 0 0 100%; width: 100%; justify-content: flex-start; gap: 12px;
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 1px;
  }
  .hud-center::-webkit-scrollbar { display: none; }
  .ro-item { gap: 3px; flex-shrink: 0; }
  .ro-v { font-size: 11px; }
  .logo { font-size: 13px; }
  #layerMenu { top: calc(96px + var(--sat)); width: 300px; }
  #infoPanel { left: 6px; width: auto; max-height: 46vh; }
  #mapCtrl { right: 4px; }
  .mech-btn.ctl { width: 42px; height: 42px; }
}
/* スクロールバー */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--line-hi); }
::-webkit-scrollbar-track { background: transparent; }
