/* app.css -- dark theme, iPad-first layout. Tap targets sized 44pt+ for touch. */

:root {
  --bg: #0b1220;
  --panel: #16213a;
  --panel-2: #1f2f4d;
  --border: #3a4d6b;
  --text: #e5edf7;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --danger: #f87171;
  --ok-dot: #34d399;
  --miss-dot: #475569;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* このファイルのあちこちで要素に直接 display:flex 等を指定しているため、
   何も指定しなければ [hidden] を上書きしてしまう(UAデフォルトの [hidden]{display:none}
   は「作者スタイル」に必ず負ける)。hidden 属性が常に勝つよう、ここで一括して保証する。 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

#header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.seg {
  display: flex;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segBtn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.seg.small .segBtn { min-height: 38px; padding: 6px 12px; font-size: 13px; }
.seg.tiny .segBtn { min-height: 36px; padding: 4px 10px; font-size: 13px; }
.segBtn.active {
  background: var(--accent);
  color: #05202e;
}

#timeDisplay {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
}
#timeUtc { font-size: 18px; font-weight: 700; }
#timeJst { font-size: 12px; color: var(--text-dim); }

#headerActions { display: flex; gap: 8px; align-items: center; }

.iconBtn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  padding: 0 12px;
}
.iconBtn.primary {
  background: var(--accent);
  color: #05202e;
  border-color: var(--accent);
  font-weight: 700;
}
.iconBtn.active { background: var(--accent-strong); color: #05202e; }
.iconBtn:disabled { opacity: 0.4; }

#main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

#stage {
  flex: 1 1 auto;
  position: relative;
  /* canvas 自体もこの色で塗る(viewer.js の STAGE_BG と揃える)。JMA の画像はほぼ黒に
     近い濃紺なので、ページ全体の --bg と同じ色にすると画像との境目が分からなくなる。 */
  background: #1b2740;
  touch-action: none;
  overflow: hidden;
}
#viewCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  max-width: 70%;
  pointer-events: none;
}
#sourceCredit {
  position: absolute;
  bottom: 8px; left: 12px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.8;
  pointer-events: none;
}

/* --- 3Dスタック(経度断面)表示 ------------------------------------------------ */

#scene3dHost {
  position: absolute;
  inset: 0;
  /* 断面画像は透過PNGで矢羽根などが黒描画のため、シーン全体を明色にする
     (viewer.js の IMAGE_BACKING と同じ理由・同じ色)。 */
  background: #ffffff;
  overflow: hidden;
}
.stackViewport {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1400px;
  touch-action: none;
  overflow: hidden;
}
.stackInner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-style: preserve-3d;
}
.pane {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 688px;
  height: 395px;
  margin-left: -344px;
  margin-top: -197.5px;
  transform-style: preserve-3d;
  transition: opacity 0.15s;
}
.pane.floorPane {
  width: 780px;
  height: 580px;
  margin-left: -390px;
  margin-top: -290px;
  opacity: 0.7 !important;
}
.paneClip {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.pane.paneMissing .paneClip {
  background: repeating-linear-gradient(45deg, #e2e8f0, #e2e8f0 8px, #f1f5f9 8px, #f1f5f9 16px);
}
.paneImg {
  position: absolute;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
.paneTag {
  position: absolute;
  top: -24px;
  left: 0;
  background: #0b1220;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  transform-origin: center;
}
/* 裏側(東西反転した視点)から見ているときだけ、タグを左右反転して正しく読めるようにする。
   backface-visibility による表裏2枚差し替えは、preserve-3d が2階層ネストする
   この構成では実機で信頼できなかった(検証で確認済み)ため、JS側で yaw に応じて
   このクラスを全パネル一括で切り替える方式にしている(stack3d.js の _updateHud)。 */
.paneTag.mirrored { transform: scaleX(-1); }

#orbitHud {
  position: absolute;
  top: 10px;
  right: 12px;
  background: rgba(11, 18, 32, 0.75);
  color: #fff;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
  pointer-events: none;
}

#ladderPane {
  flex: 0 0 132px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#ladderPane.wide { flex-basis: 240px; }
#crossGroupSeg { margin: 8px; justify-content: center; }

#ladder {
  flex: 1;
  overflow-y: auto;
  touch-action: none;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}
.ladderItem {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 14px;
  color: var(--text-dim);
  border-left: 3px solid transparent;
}
.ladderItem .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ladderItem .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--miss-dot);
  flex: none;
  margin-left: 6px;
}
.ladderItem .dot.have { background: var(--ok-dot); }
.ladderItem.current {
  color: var(--text);
  font-weight: 700;
  background: var(--panel-2);
  border-left-color: var(--accent);
}

/* --- 3Dモードのサイドパネル --------------------------------------------------- */

#stack3dPanel {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.s3dSection {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.s3dSection:last-child { border-bottom: none; padding-bottom: 0; }
.s3dSectionTitle {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.s3dSlider {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.s3dSlider input[type="range"] { width: 100%; accent-color: var(--accent); }
.s3dSlider select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  font-size: 13px;
}
.s3dPresetRow { display: flex; gap: 6px; }
.s3dPresetRow .btn { flex: 1; }

#meridianList {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
}
.meridianItem {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 2px 4px;
  font-size: 13px;
  color: var(--text-dim);
  border-radius: 6px;
}
.meridianItem.enabled { color: var(--text); }
.meridianItem input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.meridianItem .lbl { flex: 1; }
.meridianItem .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--miss-dot); flex: none;
}
.meridianItem .dot.have { background: var(--ok-dot); }

.checkRow.small { font-size: 12px; margin: 0; gap: 8px; }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 12px; }

#timeRailWrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.railBtn {
  min-width: 48px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.railBtn:disabled { opacity: 0.35; }

#timeRail {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  touch-action: none;
  padding: 2px;
}
.railChip {
  flex: none;
  min-width: 56px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  gap: 3px;
  padding: 4px 6px;
}
.railChip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--miss-dot); }
.railChip .dot.have { background: var(--ok-dot); }
.railChip.current {
  color: #05202e;
  background: var(--accent);
  font-weight: 700;
  border-color: var(--accent);
}
.railChip.current .dot.have { background: #05202e; }
.railChip.pinned { position: relative; }
.railChip.pinned::after {
  content: "\1F4CC";
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 10px;
  line-height: 1;
}
.railSep {
  flex: none;
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 4px 2px;
}

#statusBar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
#playControls { display: flex; align-items: center; gap: 10px; }
#statusInfo { display: flex; gap: 14px; }
#statusInfo .warn { color: #fbbf24; }
#statusInfo .stale { color: var(--danger); }

.modal {
  position: fixed; inset: 0;
  background: rgba(2, 6, 15, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modalCard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: min(480px, 100%);
  max-height: 80vh;
  overflow-y: auto;
}
.modalCard h2 { margin: 0 0 12px; font-size: 17px; }
.modalActions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #05202e; border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.checkRow { display: flex; align-items: center; gap: 10px; margin: 14px 0; font-size: 14px; }
.checkRow input { width: 20px; height: 20px; }

.summaryLine { margin: 6px 0; font-size: 14px; }
.summaryLine b { color: var(--accent); }
.summaryLine.del b { color: var(--danger); }
.summaryLine.pin b { color: #fbbf24; }

.progressTrack { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; margin-top: 12px; }
.progressFill { height: 100%; background: var(--accent); width: 0%; transition: width 0.15s linear; }
#syncProgressLabel { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 6px; }

.cacheFrameRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.cacheFrameRow .meta { color: var(--text-dim); font-size: 12px; }
.cacheFrameRow .rowActions { display: flex; gap: 8px; }
.cacheFrameRow button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: calc(70px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 60;
  max-width: 90%;
  text-align: center;
}

@media (max-width: 820px), (orientation: portrait) {
  #main { flex-direction: column; }
  #ladderPane {
    flex: 0 0 84px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  /* 3Dパネルはスライダー等が縦に並ぶため、狭幅時は横ストリップ化せず
     高さ制限付きのスクロール領域として残す。 */
  #ladderPane.wide {
    flex: 0 0 auto;
    max-height: 42vh;
  }
  #crossGroupSeg { margin: 6px; }
  #ladder {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .ladderItem {
    flex-direction: column;
    min-width: 64px;
    min-height: unset;
    height: 100%;
    justify-content: center;
    border-left: none;
    border-bottom: 3px solid transparent;
    gap: 2px;
  }
  .ladderItem.current { border-left-color: transparent; border-bottom-color: var(--accent); }
  .ladderItem .dot { margin-left: 0; }
}
