/* チャートクローム: dataviz リファレンスパレット準拠 */
:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-direct: #2a78d6;   /* 直接乗車 */
  --series-transfer: #1baf7a; /* 接続・乗換流入 */
  --accent: #2a78d6;
  /* 種別の識別ドット(文字ラベル併記が前提) */
  --type-tokkyu: #e34948;
  --type-kyuko: #008300;
  --type-kukyu: #eda100;
  --type-kaisoku: #4a3aa7;
  --type-kakutei: #898781;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-direct: #3987e5;
    --series-transfer: #199e70;
    --accent: #3987e5;
    --type-kyuko: #2eb82e;
    --type-kaisoku: #9085e9;
  }
}

:root { --label-w: 260px; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
.page { max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; }

.site-header h1 { font-size: 26px; margin: 0 0 4px; }
.subtitle { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin-left: 8px; }
.lede { color: var(--text-secondary); margin: 0 0 8px; max-width: 64em; }
.data-source {
  font-size: 12px; color: var(--text-secondary);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; margin: 0 0 16px; display: inline-block;
}
.data-source a { color: var(--accent); }

/* コントロール行: チャート群の上に1行 */
.controls {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-bottom: 16px; align-items: end;
}
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.controls select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 10em;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.card h2 { font-size: 18px; margin: 0 0 8px; }
.card h3 { font-size: 14px; color: var(--text-secondary); margin: 20px 0 8px; }
.hint { font-size: 12.5px; color: var(--text-muted); margin: 8px 0 0; }

/* 凡例 */
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-secondary); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.s-direct { background: var(--series-direct); }
.s-transfer { background: var(--series-transfer); }

/* ===== 列車リスト(乗車区間の混雑帯) ===== */
.train-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.train-row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.train-row.selected { border-color: var(--accent); }
.train-row .meta {
  display: flex; align-items: center; gap: 8px;
  width: var(--label-w, 260px); flex: none; min-width: 0;
}
.train-row .dep-time { font-variant-numeric: tabular-nums; font-weight: 600; width: 3.2em; flex: none; }
.badge {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; padding: 1px 8px;
  border: 1px solid var(--border); border-radius: 999px; color: var(--text-primary);
  white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--text-muted)); }
.badge.type-tokkyu { --dot: var(--type-tokkyu); }
.badge.type-kyuko { --dot: var(--type-kyuko); }
.badge.type-kukyu { --dot: var(--type-kukyu); }
.badge.type-kaisoku { --dot: var(--type-kaisoku); }
.badge.type-kakutei { --dot: var(--type-kakutei); }
.train-row .origin { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 乗車区間の混雑帯: セグメント幅∝所要時間、色=混雑率 */
.ride-strip {
  flex: 1; display: flex; gap: 2px; height: 20px; min-width: 120px;
}
.ride-strip .segc { border-radius: 2px; min-width: 3px; cursor: pointer; }
.ride-strip .segc:first-child { border-radius: 4px 2px 2px 4px; }
.ride-strip .segc:last-child { border-radius: 2px 4px 4px 2px; }
.ride-strip .segc:hover { outline: 2px solid var(--text-primary); outline-offset: -1px; }
.ride-summary {
  flex: none; width: 252px; display: flex; align-items: baseline; gap: 6px;
  font-size: 12px; min-width: 0; white-space: nowrap;
}
.ride-summary b { font-size: 13px; font-variant-numeric: tabular-nums; }
.arr-info {
  color: var(--text-muted); font-size: 11.5px; margin-left: auto;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.status-word { font-size: 11px; font-weight: 500; color: var(--text-secondary); }

/* 混雑率の色凡例 */
.seq-swatches { display: inline-flex; }
.seq-swatches span { width: 22px; height: 12px; }
.seq-swatches span:first-child { border-radius: 3px 0 0 3px; }
.seq-swatches span:last-child { border-radius: 0 3px 3px 0; }
.seq-labels { display: flex; justify-content: space-between; width: 154px; font-size: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.seq-legend-box { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }

/* ===== 詳細 ===== */
.detail-summary { color: var(--text-secondary); font-size: 13.5px; margin: 4px 0 0; }
.chart { margin-top: 4px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-b-head { margin-top: 24px; }
.ghost-btn {
  font: inherit; font-size: 13px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 12px; cursor: pointer;
}
.ghost-btn:hover { background: color-mix(in srgb, var(--text-primary) 5%, transparent); }

.table-view { margin-top: 20px; }
.table-view summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { text-align: right; padding: 4px 10px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; }

/* ===== 設定 ===== */
.settings summary { cursor: pointer; list-style: none; }
.settings summary h2 { display: inline; }
.settings summary::before { content: "▸ "; color: var(--text-muted); }
.settings[open] summary::before { content: "▾ "; }
.settings-body { margin-top: 8px; }
.param-grid, .station-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
}
.station-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.param-grid label, .station-grid label {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-secondary);
}
.param-grid input, .station-grid input {
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 6px; width: 5.5em; text-align: right;
}
.json-controls { display: flex; gap: 8px; margin-bottom: 8px; }
.json-controls button {
  font: inherit; font-size: 13px; background: var(--page); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 14px; cursor: pointer;
}
.json-controls button:hover { background: color-mix(in srgb, var(--accent) 8%, var(--page)); }
#json-area {
  width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--text-primary); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}

.site-footer { font-size: 12.5px; color: var(--text-muted); }
.site-footer a { color: var(--accent); }

/* ツールチップ */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  padding: 8px 12px; font-size: 12.5px; max-width: 280px;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; color: var(--text-secondary); }
.tooltip .tt-row b { color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip .tt-key { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.chart-legend { margin: 2px 0 6px; }

@media (max-width: 640px) {
  .train-row { flex-wrap: wrap; }
  .train-row .meta { width: 100%; }
  .ride-summary { width: 100%; }
  :root { --label-w: 100%; }
}
