:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --text: #1b1e24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #1a73e8;
  --danger: #d93025;
  --ok: #0a8a3f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel-bg: #1d2026;
    --text: #eceef1;
    --muted: #9aa0a8;
    --border: #2c3038;
    --accent: #6aa8ff;
    --danger: #ff6b60;
    --ok: #46d17a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

body.static-page { height: auto; min-height: 100%; overflow: auto; }

/* --- ヘッダー / ハンバーガーメニュー --- */
.app-header {
  flex-shrink: 0;
  padding: 10px 16px 6px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
  position: relative;
}
.header-titles { text-align: center; }
.app-header h1 { margin: 0 0 2px; font-size: 1.3rem; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 860px) {
  .app-header { padding: 6px 16px 4px; }
  .app-header h1 { font-size: 1.05rem; }
  .subtitle { display: none; }
}

.menu-wrap { position: absolute; right: 16px; top: 8px; }
.icon-btn {
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  padding: 0;
  line-height: 1;
}
.menu-dropdown {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 1000;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
.menu-dropdown[hidden] { display: none; }
.menu-dropdown button,
.menu-dropdown a {
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  text-decoration: none;
  display: block;
}
.menu-dropdown button:hover,
.menu-dropdown a:hover { background: var(--bg); filter: none; }

/* --- メインレイアウト（地図フル表示 + フローティングパネル） --- */
main.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #eaf2ff;
}

.control-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  width: 240px;
  max-width: calc(100% - 24px);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

@media (max-width: 860px) {
  .control-overlay { top: auto; bottom: 10px; left: 10px; right: 10px; width: auto; }
}

.status-line {
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 8px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg);
}
.status-line.ok { background: rgba(10,138,63,0.12); color: var(--ok); }
.status-line.warn { background: rgba(217,48,37,0.12); color: var(--danger); }

.btn-row { display: flex; gap: 6px; }
.small-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.share-feedback {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--ok);
  text-align: center;
}
.share-feedback[hidden] { display: none; }

.confirmed-bar {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.confirmed-bar[hidden] { display: none; }
.confirmed-summary {
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0 2px;
  white-space: nowrap;
}
.confirmed-buttons { display: flex; gap: 6px; }
.confirmed-buttons .small-btn { flex: 1; }

/* 経路マーカー・ラインを青系の「かわいい」見た目に（確定した終点にも同じ装飾） */
.route-marker-start path,
.route-marker-end path,
.route-marker-stop path {
  filter: drop-shadow(0 1px 2px rgba(30, 70, 160, 0.35));
}
.route-line path {
  stroke-linecap: round;
  stroke-linejoin: round;
}
.route-marker-label {
  background: transparent;
  border: none;
  box-shadow: none;
  font-size: 0.68rem;
  font-weight: 700;
  color: #103a91;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}

/* 県域を超えるくらいまでズームアウトしたら、駅ラベルは邪魔になるので非表示にする */
#map.hide-station-labels .route-marker-label,
#map.hide-station-labels .candidate-marker-label {
  display: none;
}

/* 次に選べる候補駅：クリックできることが伝わるよう青く点滅させる */
.route-marker-candidate path {
  cursor: pointer;
  animation: candidate-pulse 1.4s ease-in-out infinite;
}
@keyframes candidate-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.candidate-marker-label {
  background: rgba(74, 141, 255, 0.95);
  border: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
}
.candidate-marker-label::before { display: none; }

/* 二股・行き止まりまでまとめて進める「飛ばし」候補：オレンジで点滅させ、青い候補と区別する */
#map.hide-station-labels .skip-marker-label { display: none; }
.route-marker-skip path {
  cursor: pointer;
  animation: skip-pulse 1.4s ease-in-out infinite;
}
@keyframes skip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.skip-marker-label {
  background: rgba(255, 159, 28, 0.95);
  border: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
}
.skip-marker-label::before { display: none; }

/* 通過済みのため選べない候補駅 */
.route-marker-blocked path { cursor: not-allowed; }

/* --- 共通パーツ --- */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.panel h2 { margin-top: 0; font-size: 1.05rem; }

.rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rules li { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.badge-auto { background: rgba(10,138,63,0.15); color: var(--ok); }
.badge-manual { background: rgba(107,114,128,0.15); color: var(--muted); }

.field-row { display: flex; gap: 8px; flex-wrap: wrap; }
#start-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

button {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button.secondary {
  background: transparent;
  color: var(--text);
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- 出発駅選択モーダル --- */
dialog#start-modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  background: var(--panel-bg);
  color: var(--text);
  width: min(420px, 92vw);
}
dialog#start-modal::backdrop { background: rgba(15, 20, 30, 0.55); }
#start-form { padding: 20px; }
#start-form h2 { margin: 0 0 14px; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* --- ルール専用ページ --- */
.static-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
}

.app-footer {
  flex-shrink: 0;
  max-width: 1160px;
  margin: 0 auto;
  padding: 4px 16px 6px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.35;
  width: 100%;
}
.app-footer p { margin: 2px 0; }
.app-footer a { color: var(--accent); }
