:root {
    --bg: #F1F5F8;
    --surface: #FFFFFF;
    --ink: #13202A;
    --muted: #55677A;
    --line: #D3DEE6;
    --closed: #2C6E9E;
    --closed-soft: #DCEAF3;
    --open: #D65F27;
    --warn-bg: #FFF1D6;
    --warn-ink: #7A4B00;
    --focus: #1A5FCC;
    --land: #E7EDF1;
    --land-line: #B9C6D0;
    --p-nagano: #2C6E9E;
    --p-gunma: #9C5B21;
    --p-gifu: #2F7D5B;
    --p-niigata: #6B4FA0;
    --f-body: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
    --f-display: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0E1921; --surface: #152430; --ink: #E7EFF4; --muted: #93A6B4; --line: #274052;
      --closed: #6FAEDB; --closed-soft: #1D3546; --open: #F28C58;
      --warn-bg: #3A2C10; --warn-ink: #F3D08A; --focus: #7DB0FF;
      --land: #1C2C38; --land-line: #35505F;
      --p-nagano: #6FAEDB; --p-gunma: #D69A5C; --p-gifu: #6FC79A; --p-niigata: #B39AE0;
    }
  }
  :root[data-theme="dark"] {
    --bg: #0E1921; --surface: #152430; --ink: #E7EFF4; --muted: #93A6B4; --line: #274052;
    --closed: #6FAEDB; --closed-soft: #1D3546; --open: #F28C58;
    --warn-bg: #3A2C10; --warn-ink: #F3D08A; --focus: #7DB0FF;
    --land: #1C2C38; --land-line: #35505F;
    --p-nagano: #6FAEDB; --p-gunma: #D69A5C; --p-gifu: #6FC79A; --p-niigata: #B39AE0;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 15px/1.6 var(--f-body);
    padding-inline: 16px; padding-block: 24px 48px;
  }
  .wrap { max-width: 980px; margin-inline: auto; }
  header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
  .eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--muted); }
  h1 { font: 900 30px/1.2 var(--f-display); margin: 0; letter-spacing: .02em; text-wrap: balance; }
  h1 { word-break: keep-all; overflow-wrap: anywhere; }
  .notice {
    display: flex; gap: 10px; align-items: flex-start;
    background: var(--warn-bg); color: var(--warn-ink);
    padding: 10px 12px; border-radius: 4px; font-size: 13.5px; line-height: 1.55;
  }
  .notice b { font-weight: 700; }
  a { color: var(--closed); }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  /* 検索・切替・県フィルタ */
  .controls { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
  .search { position: relative; }
  .search input {
    width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px 9px 34px;
  }
  .search input::placeholder { color: var(--muted); }
  .search svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
  .filter-group { display: flex; flex-direction: column; gap: 6px; }
  .filter-label { font: 700 12px var(--f-display); color: var(--muted); }
  .chiprow { display: flex; flex-wrap: wrap; gap: 6px; }
  .chip-btn {
    appearance: none; cursor: pointer; font: 700 13px var(--f-display); color: var(--muted);
    background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px 6px 10px;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .chip-btn .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
  .chip-btn[aria-pressed="true"] { color: #fff; background: var(--closed); border-color: var(--closed); }
  .chip-btn[aria-pressed="true"] .dot { background: #fff !important; }
  .chip-btn .n { opacity: .7; font-weight: 400; }

  .lede { color: var(--muted); font-size: 13.5px; margin: 14px 0 10px; }
  .legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
  .legend span { display: inline-flex; align-items: center; gap: 6px; }
  .sw-bar { width: 22px; height: 10px; background: var(--closed); border-radius: 2px; flex: none; }
  .sw-hatch { width: 22px; height: 10px; border-radius: 2px; flex: none;
    background: repeating-linear-gradient(135deg, var(--closed) 0 3px, transparent 3px 6px); border: 1px solid var(--closed); }
  .sw-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--open); flex: none; }
  .sw-diamond { width: 9px; height: 9px; background: var(--closed); border-radius: 2px; transform: rotate(45deg); flex: none; }

  /* 統合カレンダー（県ごとにグループ化した季節タイムライン） */
  .tl-scroll { overflow-x: auto; overflow-y: hidden; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; }
  .tl { position: relative; min-width: 700px; padding-bottom: 2px; }
  .tl-gridlines { position: absolute; top: 0; bottom: 0; left: 170px; right: 0; pointer-events: none; }
  .tl-head { display: grid; grid-template-columns: 170px 1fr; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
  .tl-head .tl-label { position: sticky; left: 0; z-index: 3; background: var(--surface); padding: 8px 10px; }
  .tl-months { position: relative; height: 30px; }
  .tl-months span { position: absolute; top: 8px; padding-left: 4px; }
  /* position:sticky は、幅いっぱいの単純なブロック要素だと効かない場合がある(包含ブロックが
     広すぎるため)。.tl-row と同じ「170px + 1fr」のグリッド構造にして、左側のラベル部分だけを
     sticky にすることで、路線名のラベルと同じ挙動(左端に固定)にする。 */
  .groupbar {
    display: grid; grid-template-columns: 170px 1fr; align-items: center; margin: 16px 10px 8px;
    border-radius: 6px; border-left: 4px solid var(--pc);
    background: color-mix(in srgb, var(--pc) 12%, var(--surface));
  }
  .group:first-child .groupbar { margin-top: 8px; }
  .groupbar-label {
    position: sticky; left: 0; display: flex; align-items: center; gap: 8px; padding: 7px 12px;
    background: color-mix(in srgb, var(--pc) 12%, var(--surface)); border-radius: 6px 0 0 6px;
  }
  .groupbar .dot, .rc-groupbar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--pc); flex: none; }
  .groupbar .gname, .rc-groupbar .gname { font: 900 14.5px var(--f-display); color: var(--pc); }
  .groupbar .n, .rc-groupbar .n { font: 400 12px var(--f-body); color: var(--muted); }
  /* 路線名の長さで行の高さが変わると見づらいので、行の高さは固定にし、名前・サブ行は
     それぞれ最大2行までに収めて(超える分は省略記号)、常に同じ高さで揃える。 */
  .tl-row { position: relative; display: grid; grid-template-columns: 170px 1fr; align-items: center; height: 72px; border-bottom: 1px solid var(--line); cursor: pointer; }
  .group:last-child .tl-row:last-child { border-bottom: 0; }
  .tl-row:hover .tl-label, .tl-row:hover .tl-track { background: color-mix(in srgb, var(--closed-soft) 45%, var(--surface)); }
  .tl-label { position: sticky; left: 0; z-index: 2; background: var(--surface); padding: 9px 10px; overflow: hidden; }
  .tl-label .name { font: 700 14px/1.3 var(--f-display); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .tl-label .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 400 11.5px var(--f-body); color: var(--muted); margin-top: 2px; }
  .tl-track { position: relative; height: 50px; }
  .tl-month { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); }
  .tl-bar { position: absolute; top: 19px; height: 12px; background: var(--closed); border-radius: 2px; }
  .tl-bar.hatch { background: repeating-linear-gradient(135deg, var(--closed) 0 3px, transparent 3px 6px); border: 1px solid var(--closed); }
  .tl-dot { position: absolute; top: 17px; width: 16px; height: 16px; margin-left: -8px; box-sizing: content-box; }
  .tl-dot.reopen { border-radius: 50%; background: var(--open); border: 3px solid var(--surface); }
  .tl-dot.closure { border-radius: 3px; background: var(--closed); border: 3px solid var(--surface); transform: rotate(45deg); }
  .tl-tag { position: absolute; top: 3px; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }
  .tl-tag.re { color: var(--open); }
  .tl-tag.cl { color: var(--closed); font-weight: 600; top: 36px; }
  .empty { padding: 26px 4px; color: var(--muted); font-size: 14px; text-align: center; }
  .idx {
    display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
    border-radius: 50%; background: var(--closed-soft); color: var(--closed); font: 700 11px var(--f-display); flex: none;
  }

  /* スマホ版の一覧（横スクロールが要る共通時間軸のガントチャートの代わりに、路線ごとの
     カードを縦に並べる。表示の切り替えはCSSメディアクエリのみで行い、生成するHTMLは
     PC版・スマホ版のどちらも同じデータから作って両方DOMに置いておく）*/
  .rc-list { display: none; }
  @media (max-width: 640px) {
    .tl-scroll { display: none; }
    .rc-list { display: block; }
    /* スマホ版は期間バーも閉鎖・開通のマークも表示しないので、それらを説明する凡例は不要 */
    .legend { display: none; }
  }
  .rc-groupbar {
    display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; padding: 7px 12px;
    border-radius: 6px; border-left: 4px solid var(--pc);
    background: color-mix(in srgb, var(--pc) 12%, var(--surface));
  }
  .group:first-child .rc-groupbar { margin-top: 0; }
  .rc {
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
    padding: 12px; margin-bottom: 8px; cursor: pointer;
  }
  .rc-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; justify-content: space-between; }
  .rc-name { font: 700 15px var(--f-display); }
  .rc-sub { font-size: 11.5px; color: var(--muted); }
  .rc-dates { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .rc-date { color: var(--closed); }
  .rc-date.re { color: var(--open); }
  .rc-arrow { color: var(--muted); font-weight: 400; }

  /* 詳細 */
  [hidden] { display: none !important; }
  .sheet { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 20px 20px 18px; }
  .sheet h1 { font: 900 24px/1.25 var(--f-display); margin: 0; letter-spacing: 0; word-break: keep-all; overflow-wrap: anywhere; }
  .crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
  .crumbs a { color: var(--muted); }
  .sitebar { font: 700 13px var(--f-display); margin-bottom: 14px; }
  .sitebar a { color: var(--muted); text-decoration: none; }
  .foot { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
  a.tl-row, a.rc { color: inherit; text-decoration: none; }
  a.rc { display: block; }
  .titlebar { display: flex; flex-direction: column; gap: 2px; }
  .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .chip { font-size: 11.5px; border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; color: var(--muted); background: var(--surface); }
  .big { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .big div { background: var(--bg); padding: 10px 12px; border-radius: 4px; }
  .big small { display: block; font-size: 12px; color: var(--muted); }
  .big strong { font: 900 22px/1.3 var(--f-display); font-variant-numeric: tabular-nums; }
  .big .re strong { color: var(--open); }
  .big em { font-style: normal; font-size: 13px; color: var(--muted); margin-left: 4px; }
  .tbl { overflow-x: auto; }
  table { border-collapse: collapse; width: 100%; min-width: 460px; font-size: 13px; }
  th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
  th { color: var(--muted); font-weight: 400; font-size: 12px; white-space: nowrap; }
  td.n { white-space: nowrap; font-variant-numeric: tabular-nums; }
  /* スマホでは横スクロールが要る表の代わりに、区間ごとのカードを縦に並べる。列見出し(距離/閉鎖/解除)は
     カード内のラベルとしてそのまま使う */
  .sc-list { display: none; }
  @media (max-width: 640px) {
    .tbl { display: none; }
    .sc-list { display: flex; flex-direction: column; gap: 8px; }
  }
  .sc { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
  .sc-route { margin-bottom: 6px; }
  .sc-fields { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; }
  .sc-k { color: var(--muted); margin-right: 4px; }
  .sc-v { font-variant-numeric: tabular-nums; }
  .src { font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
  .src a { overflow-wrap: anywhere; }
  .fine { font-size: 12.5px; color: var(--muted); }
  .warnbox { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 10px; border-radius: 4px; font-size: 13px; }
  h3 { font: 700 13px var(--f-display); margin: 0 0 4px; letter-spacing: .06em; color: var(--muted); }
  @media (max-width: 560px) {
    h1 { font-size: 26px; }
    .big strong { font-size: 19px; }
  }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
  a.tl-row.prev .tl-track, a.rc.prev .rc-dates { opacity: .6; }
  .prose h2 { font: 700 16px/1.4 var(--f-display); margin: 8px 0 -4px; }
  .prose p { margin: 0; font-size: 14px; }
  .footnav { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
  .footnav a { color: var(--muted); }
