/* ============================================================
   plateau-route-3d · Viewer
   Aesthetic: Aerospace Mission Console
   ============================================================ */

:root {
  --bg:          #070a0f;
  --bg-grid:     rgba(148, 163, 184, 0.05);
  --surface:     rgba(15, 21, 30, 0.78);
  --surface-2:   rgba(24, 32, 44, 0.92);
  --border:      rgba(148, 163, 184, 0.12);
  --border-2:    rgba(148, 163, 184, 0.22);
  --ink:         #e6edf5;
  --ink-mu:      #94a3b8;
  --ink-dim:     #64748b;
  --accent:      #3b82f6;
  --accent-a:    #22d3ee;
  --accent-b:    #e879f9;
  --danger:      #f43f5e;
  --ok:          #34d399;

  --font-jp:   "Zen Kaku Gothic New", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --header-h: 52px;
  --panel-w:  300px;
  --radius:   12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-jp);
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  color-scheme: dark;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at top, rgba(34, 211, 238, 0.05), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(232, 121, 249, 0.04), transparent 60%);
}

/* ============================================================
   Layout
   ============================================================ */

#app {
  position: relative;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header header"
    "panel  stage";
  height: 100%;
  width: 100%;
}

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #0d121a 0%, #0a0e14 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 40;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-mu);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: color .15s, border-color .15s, background .15s;
}
.back-link:hover,
.back-link:focus-visible {
  color: var(--ink);
  border-color: var(--border-2);
  background: rgba(148, 163, 184, 0.06);
}
.back-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand strong {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-a);
  box-shadow: 0 0 10px var(--accent-a);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(.85); }
}
@media (prefers-reduced-motion: reduce) {
  .brand-dot { animation: none; }
}

.modes {
  /* brand の右隣に配置。右端は固定の .lang-toggle のスペースとして空けておく
     (margin-left: auto を使うと右端に張り付き、言語切替ピルと被る) */
  margin-left: 8px;
  display: flex;
  gap: 4px;
  padding: 3px;
  background: rgba(15, 21, 30, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.modes button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--ink-mu);
  border: none;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: 999px;
  transition: background .15s, color .15s;
  touch-action: manipulation;
}
.modes button:hover { color: var(--ink); }
.modes button.active {
  background: var(--accent);
  color: #fff;
}
.modes button:focus-visible {
  outline: 2px solid var(--accent-a);
  outline-offset: 2px;
}

/* ============================================================
   Stage (map + overlays)
   ============================================================ */

.stage {
  grid-area: stage;
  position: relative;
  background: var(--bg);
}
#cesiumContainer {
  position: absolute;
  inset: 0;
}
.cesium-widget-credits {
  font-size: 10px !important;
  opacity: 0.6;
}

/* ============================================================
   Action Bar (floating over map, always visible)
   ============================================================ */

.action-bar {
  position: absolute;
  z-index: 32;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(10, 14, 20, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  max-width: calc(100% - 24px);
}

.ab-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mu);
  white-space: nowrap;
}
.ab-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(15, 21, 30, 0.85);
  border: 1px solid var(--border-2);
  font-weight: 700;
  font-size: 10.5px;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.ab-dot-label { color: var(--ink-dim); }
.ab-dot-a.ab-dot { border-color: rgba(34, 211, 238, 0.3); }
.ab-dot-b.ab-dot { border-color: rgba(232, 121, 249, 0.3); }

/* Set states: drive from #app[data-ab-*=set] */
#app[data-ab-a="set"] .ab-dot-a {
  background: var(--accent-a);
  border-color: var(--accent-a);
  color: #02131a;
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.55);
}
#app[data-ab-a="set"] .ab-dot-a .ab-dot-label { color: #02131a; }
#app[data-ab-b="set"] .ab-dot-b {
  background: var(--accent-b);
  border-color: var(--accent-b);
  color: #180224;
  box-shadow: 0 0 10px rgba(232, 121, 249, 0.55);
}
#app[data-ab-b="set"] .ab-dot-b .ab-dot-label { color: #180224; }

.ab-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  display: inline-block;
}
.ab-dist {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ab-dist-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.action-btns {
  display: inline-flex;
  gap: 6px;
}

.btn-compact {
  padding: 8px 12px;
  min-height: 36px;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 9px;
  white-space: nowrap;
}

/* アクションバー上のフローティングリセット
   メニュー奥のリセットボタンが目につかない問題への対処として、Play/Stop と並べて常設。
   既定では薄めに見せて、Play/取得 の主動線を邪魔しないようにする。 */
.btn-reset-float {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border-2);
  color: var(--ink-mu);
  letter-spacing: 0.02em;
}
.btn-reset-float:hover:not(:disabled) {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.55);
  color: #fecdd3;
}
.btn-reset-float .reset-icon { font-size: 14px; line-height: 1; }
.btn-reset-float .reset-label { margin-left: 4px; }

/* A/B クリア (フロート) — リセットと同系統 ghost 系、ホバー色だけ控えめ。
   位置はそのまま A/B + 経由地 + ルート + 3D を消す軽量操作。 */
.btn-clear-ab-float {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border-2);
  color: var(--ink-mu);
  letter-spacing: 0.02em;
}
.btn-clear-ab-float:hover:not(:disabled) {
  background: rgba(34, 211, 238, 0.18);
  border-color: rgba(34, 211, 238, 0.55);
  color: #cffafe;
}
.btn-clear-ab-float .clear-ab-icon { font-size: 14px; line-height: 1; }
.btn-clear-ab-float .clear-ab-label { margin-left: 4px; }

#ab-warning {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  max-width: calc(100vw - 24px);
  padding: 8px 12px;
  background: rgba(244, 63, 94, 0.95);
  color: #fff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(244, 63, 94, 0.4);
  white-space: nowrap;
}
#ab-warning:not(:empty) { display: block; }

/* ============================================================
   Panel / Sidebar
   ============================================================ */

.panel {
  grid-area: panel;
  position: relative;
  background: linear-gradient(180deg, #0d121a 0%, #0a0e14 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 24px;
  padding-left: max(16px, env(safe-area-inset-left));
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.sheet-handle { display: none; }
.sheet-close  { display: none; }

.panel-sec + .panel-sec {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.sec-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 12px;
}

.kv {
  display: grid;
  gap: 6px;
  margin: 0;
}
.kv-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}
.kv-row dt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-mu);
  font-weight: 500;
  margin: 0;
  min-width: 0;
}
.kv-row dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.dot-a { background: var(--accent-a); box-shadow: 0 0 8px var(--accent-a); }
.dot-b { background: var(--accent-b); box-shadow: 0 0 8px var(--accent-b); }
.dot-wp { background: #fbbf24; box-shadow: 0 0 8px #fbbf24; }

/* 経由地リスト */
.waypoint-row { align-items: flex-start; }
.waypoint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.waypoint-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
}
.wp-name {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #fbbf24;
  flex-shrink: 0;
  min-width: 22px;
}
.wp-coord {
  font-family: var(--font-mono);
  color: var(--ink-mu);
  font-size: 11px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.wp-actions {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
}
.wp-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border-2);
  background: rgba(148, 163, 184, 0.10);
  color: var(--ink-mu);
  font-size: 12px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.wp-btn:hover:not(:disabled) {
  background: rgba(34, 211, 238, 0.18);
  border-color: rgba(34, 211, 238, 0.55);
  color: #cffafe;
}
.wp-btn.wp-del:hover:not(:disabled) {
  background: rgba(244, 63, 94, 0.20);
  border-color: rgba(244, 63, 94, 0.55);
  color: #fecdd3;
}
.wp-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.wp-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.5;
}
.panel-actions {
  display: flex;
  gap: 8px;
}
.panel-actions .btn {
  flex: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  font-family: var(--font-jp);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  touch-action: manipulation;
  width: 100%;
  min-height: 40px;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent-a); outline-offset: 2px; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-compact { width: auto; }

.btn-primary {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset, 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
}

.btn-accent {
  background: linear-gradient(180deg, #06b6d4, #0891b2);
  color: #02131a;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 4px 14px rgba(34, 211, 238, 0.35);
}
.btn-accent:hover:not(:disabled) {
  background: linear-gradient(180deg, #22d3ee, #06b6d4);
}

.btn-ghost {
  background: rgba(148, 163, 184, 0.08);
  color: var(--ink);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.15);
  border-color: var(--border-2);
}

/* Camera panel */
.cam-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.cam-presets button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 6px;
  background: rgba(15, 21, 30, 0.7);
  border: 1px solid var(--border);
  color: var(--ink-mu);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-jp);
  font-size: 11.5px;
  transition: background .15s, border-color .15s, color .15s;
  touch-action: manipulation;
  min-height: 52px;
}
.cam-presets button:hover { color: var(--ink); border-color: var(--border-2); }
.cam-presets button.active {
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.18), rgba(34, 211, 238, 0.08));
  border-color: var(--accent-a);
  color: var(--ink);
}
.cam-presets button:focus-visible {
  outline: 2px solid var(--accent-a);
  outline-offset: 2px;
}
.preset-icon {
  font-family: var(--font-mono);
  color: var(--accent-a);
  font-size: 13px;
  line-height: 1;
}
.cam-presets button:not(.active) .preset-icon { color: var(--ink-dim); }

.cam-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cam-inputs label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-mu);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.input-wrap {
  display: flex;
  align-items: center;
  background: rgba(15, 21, 30, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.input-wrap:focus-within {
  border-color: var(--accent-a);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}
.cam-inputs input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--ink);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.cam-inputs input:focus { outline: none; }
.input-suffix {
  padding: 0 10px 0 0;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* LOD (building detail level) selector */
.lod-select {
  display: grid;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-mu);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.lod-select select {
  background: rgba(15, 21, 30, 0.7);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  appearance: none;
  cursor: pointer;
}
.lod-select select:focus {
  outline: none;
  border-color: var(--accent-a);
}
.lod-select select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.lod-hint {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
}

/* Samples chips */
.sample-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.sample-chips button.sample {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  background: rgba(15, 21, 30, 0.7);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-jp);
  font-size: 12px;
  line-height: 1.2;
  transition: background .15s, border-color .15s, transform .1s;
  touch-action: manipulation;
  white-space: nowrap;
}
.sample-chips button.sample:hover {
  background: rgba(148, 163, 184, 0.1);
  border-color: var(--border-2);
}
.sample-chips button.sample:active { transform: translateY(1px); }
.sample-chips button.sample:focus-visible {
  outline: 2px solid var(--accent-a);
  outline-offset: 2px;
}

/* ============================================================
   FAB + Scrim (mobile sheet)
   ============================================================ */

.sheet-fab {
  display: none;
  position: absolute;
  z-index: 33;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  align-items: center;
  gap: 8px;
  padding: 11px 16px 11px 13px;
  border-radius: 999px;
  background: linear-gradient(180deg, #1e3a8a, #1e40af);
  border: 1px solid rgba(59, 130, 246, 0.6);
  color: #fff;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.5), 0 1px 0 rgba(255, 255, 255, 0.12) inset;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .15s, background .15s;
  font-family: var(--font-jp);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.sheet-fab:active { transform: scale(0.96); }
.sheet-fab:focus-visible { outline: 2px solid var(--accent-a); outline-offset: 3px; }
.sheet-fab-label { letter-spacing: 0.02em; }

.scrim {
  display: none;
  position: absolute;
  inset: var(--header-h) 0 0 0;
  z-index: 35;
  background: rgba(3, 5, 8, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .2s;
}

/* ============================================================
   Responsive — Mobile (≤899px)
   ============================================================ */

@media (max-width: 899px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
      "header"
      "stage";
  }

  .app-header {
    gap: 10px;
    padding: 0 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .back-link-text { display: none; }
  .brand strong { font-size: 12px; }
  .modes button { padding: 5px 10px; font-size: 11px; }
  .modes button span:first-child + span { display: none; }

  .sheet-fab { display: inline-flex; }

  /* Action bar: full width at top of stage */
  .action-bar {
    top: 10px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 8px 10px;
    gap: 8px;
  }
  .action-btns {
    width: 100%;
    justify-content: stretch;
  }
  .action-btns .btn {
    flex: 1;
    padding: 9px 6px;
    font-size: 12px;
  }
  /* モバイルではリセット / A/B クリアはアイコン中心に縮めて、Fetch/Play/Stop の幅を確保 */
  .action-btns .btn-reset-float,
  .action-btns .btn-clear-ab-float {
    flex: 0 0 auto;
    padding: 9px 10px;
    min-width: 38px;
  }
  .btn-reset-float .reset-label,
  .btn-clear-ab-float .clear-ab-label { display: none; }

  /* Sheet from bottom */
  .panel {
    position: absolute;
    z-index: 36;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-height: 72vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(28px + env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.22, .8, .28, 1);
    box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45);
    background: linear-gradient(180deg, #0f1520 0%, #0a0e14 100%);
  }

  #app[data-sheet="expanded"] .panel {
    transform: translateY(0);
  }
  #app[data-sheet="expanded"] .scrim {
    display: block;
    opacity: 1;
  }

  .sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(148, 163, 184, 0.35);
    border-radius: 2px;
    margin: 6px auto 8px;
    cursor: pointer;
  }
  .sheet-close {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: absolute;
    top: 10px;
    right: 14px;
    padding: 6px 12px 6px 10px;
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid var(--border-2);
    color: var(--ink);
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font-jp);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    touch-action: manipulation;
    z-index: 2;
    transition: background .15s, border-color .15s;
  }
  .sheet-close:hover { background: rgba(148, 163, 184, 0.18); }
  .sheet-close:focus-visible { outline: 2px solid var(--accent-a); outline-offset: 2px; }

  /* Shift FAB to leave room for close button above when sheet is open */
  #app[data-sheet="expanded"] .sheet-fab {
    background: linear-gradient(180deg, #334155, #1f2937);
    border-color: var(--border-2);
  }
}

@media (max-width: 420px) {
  .app-header { gap: 6px; padding: 0 8px; }
  .brand strong { font-size: 11px; }
  .modes { padding: 2px; }
  .modes button { padding: 4px 8px; font-size: 11px; }

  .ab-dots { gap: 4px; padding: 0 2px; }
  .ab-dot { width: 20px; height: 20px; font-size: 10px; }
  .ab-dist { font-size: 11px; }
  .action-btns .btn { padding: 9px 4px; font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .scrim, .sheet-fab, .btn, .modes button, .ab-dot { transition: none; }
}

/* ------------------------------------------------------------
   Share modal (preset URL/JSON copy & paste)
   ------------------------------------------------------------ */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(7, 10, 15, 0.78);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--accent-a);
  border-radius: var(--radius);
  width: min(640px, 92vw);
  max-height: 86vh; overflow: auto;
  padding: 18px 20px;
  font-family: var(--font-mono);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  margin: 0; font-size: 15px; letter-spacing: 0.04em;
  color: var(--accent-a);
}
.modal-close {
  background: transparent; color: var(--ink-mu); border: none;
  font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px; border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--ink); background: rgba(148, 163, 184, 0.08); }

.share-section { margin-top: 16px; }
.share-section h3 {
  margin: 0 0 8px;
  font-size: 11px; letter-spacing: 0.08em;
  color: var(--accent-b); text-transform: uppercase;
  font-family: var(--font-mono);
}
.share-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 8px;
}
.share-actions .btn {
  font-size: 12px; padding: 6px 12px;
  width: auto;
}
.share-preview {
  background: rgba(7, 10, 15, 0.6);
  color: var(--ink-mu);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin: 0;
  font-size: 11px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-all;
  max-height: 180px; overflow: auto;
  font-family: var(--font-mono);
}
#share-paste {
  width: 100%;
  box-sizing: border-box;
  background: rgba(7, 10, 15, 0.6);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px;
  resize: vertical;
  min-height: 100px;
}
#share-paste:focus {
  outline: none;
  border-color: var(--accent-a);
}
.share-error {
  color: var(--danger);
  font-size: 12px;
  margin: 8px 0 0;
}

@media (max-width: 599px) {
  .modal-panel { width: 96vw; padding: 14px; max-height: 92vh; }
  .modal-head h2 { font-size: 13px; }
  .share-actions .btn { font-size: 11px; padding: 5px 10px; }
}

/* ============================================================
   Place Search (Panel section above ROUTE · A/B)
   PC: パネル幅 300px に収まる縦組
   Mobile: ボトムシート幅いっぱい
   ============================================================ */
.place-search-section { padding-top: 0; }

.place-search { position: relative; }

.place-search-label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  transition: border-color .18s ease;
}
.place-search-label:focus-within { border-color: var(--accent-a); }

.place-search-icon {
  font-size: 13px;
  color: var(--ink-mu);
  flex: 0 0 auto;
}

.place-search-input {
  flex: 1 1 auto;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: var(--font-jp);
  font-size: 14px;
  padding: 9px 0;
  min-width: 0;
}
.place-search-input::placeholder { color: var(--ink-dim); }

.place-search-clear {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  color: var(--ink-mu);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.place-search-clear:hover { background: rgba(148, 163, 184, 0.12); color: var(--ink); }

.place-search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  z-index: 30;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  -webkit-overflow-scrolling: touch;
}

.suggest-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.suggest-item.active,
.suggest-item:hover { background: rgba(34, 211, 238, 0.10); }

.suggest-primary {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggest-secondary {
  font-size: 11px;
  color: var(--ink-mu);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-search-message {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
}
.place-search-message[data-kind="warn"] {
  background: rgba(244, 63, 94, 0.10);
  border: 1px solid rgba(244, 63, 94, 0.42);
  color: #fda4af;
}
.place-search-message[data-kind="info"] {
  background: rgba(148, 163, 184, 0.10);
  border: 1px solid rgba(148, 163, 184, 0.30);
  color: var(--ink-mu);
}
.place-search-message[data-kind="error"] {
  background: rgba(244, 63, 94, 0.16);
  border: 1px solid var(--danger);
  color: #fecdd3;
}

.place-search-roles {
  margin-top: 8px;
  padding: 8px;
  background: rgba(34, 211, 238, 0.06);
  border: 1px dashed var(--accent-a);
  border-radius: var(--radius-sm);
}

.place-search-selected {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}
.place-search-selected .sel-primary {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-search-selected .sel-secondary {
  font-size: 11px;
  color: var(--ink-mu);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-search-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.place-search-buttons .btn {
  font-size: 11px;
  padding: 6px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-search-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.45;
}

/* PC: パネル幅 300px に対しては 3 列ボタンが詰まりすぎるので 2 行に */
@media (min-width: 900px) and (max-width: 1100px) {
  .place-search-buttons { grid-template-columns: 1fr 1fr; }
  .place-search-buttons .place-search-set-wp { grid-column: 1 / -1; }
}

/* Mobile (≤899px): ボトムシート上で見やすく */
@media (max-width: 899px) {
  .place-search-input { font-size: 16px; padding: 11px 0; }
  /* iOS で 16px 未満だとフォーカス時に拡大されるため最低 16px */
  .suggest-item { padding: 10px 12px; }
  .suggest-primary { font-size: 14px; white-space: normal; }
  .suggest-secondary { font-size: 12px; white-space: normal; }
  .place-search-suggestions { max-height: 320px; }
  .place-search-buttons { grid-template-columns: 1fr 1fr; }
  .place-search-buttons .place-search-set-wp { grid-column: 1 / -1; }
  .place-search-buttons .btn { font-size: 12px; padding: 9px 6px; min-height: 38px; }
}

/* 極小幅 (≤420px): 1 列縦積み */
@media (max-width: 420px) {
  .place-search-buttons { grid-template-columns: 1fr; }
  .place-search-buttons .place-search-set-wp { grid-column: auto; }
}

/* ============================================================
   Mobile docking slot: floating place-search above the map
   PC では使わない。≤899px のとき index.html 側 JS で
   .place-search-section が #place-search-mobile-slot に移される。
   設定パネルを開かなくても検索できるようにする目的。
   ============================================================ */

.place-search-mobile-slot { display: none; }

@media (max-width: 899px) {
  .place-search-mobile-slot {
    display: block;
    position: absolute;
    z-index: 31;
    left: 8px;
    right: 8px;
    /* アクションバー (top:10px) が flex-wrap で 2 行になるので、その下に配置 */
    top: calc(10px + 100px + 6px);
    pointer-events: none;
  }
  .place-search-mobile-slot > .place-search-section {
    pointer-events: auto;
    margin: 0;
    padding: 8px 10px;
    background: rgba(10, 14, 20, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .place-search-mobile-slot > .place-search-section .sec-label {
    margin: 0 0 6px;
    font-size: 10px;
  }
  /* hint はモバイル floating では省略してコンパクトに */
  .place-search-mobile-slot > .place-search-section .place-search-hint { display: none; }
}

/* 極小幅: アクションバー 2 行が縦に伸びるので docking slot をやや下にずらす */
@media (max-width: 420px) {
  .place-search-mobile-slot {
    top: calc(10px + 110px + 6px);
  }
}
