@font-face { font-family: 'LINE Seed JP'; src: url('fonts/LINESeedJP_OTF_Bd.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #0b0f17; --bg2: #111827; --panel: #131b2a; --line: #233046; --text: #e6ecf5; --muted: #8b97ab;
  --accent: #7dd3fc; --font: 'LINE Seed JP', 'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP', system-ui, sans-serif;
  --lane-label-w: 168px; --axis-h: 56px; --era-h: 34px; --row-h: 30px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* スマホのブラウザはアドレスバーの分だけ 100% が実際の表示域より高くなるので、見えている高さに合わせる */
@supports (height: 100dvh) { body { height: 100dvh; } }
body { background: radial-gradient(1200px 600px at 20% -10%, #1a2740 0%, var(--bg) 55%), var(--bg); color: var(--text); font-family: var(--font); font-weight: 700; display: flex; flex-direction: column; overflow: hidden; }
button, input { font: inherit; }

/* ---------- ヘッダー ---------- */
.top { display: flex; align-items: center; gap: 24px; padding: 14px 22px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: .04em; background: linear-gradient(90deg, #fff, #9ec5ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
#search { width: 190px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); outline: none; }
#search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; font-size: 12px; transition: .15s; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.chip.off { opacity: .4; }
/* ジャンル切替（AI / 各国首脳 …）。レーンチップより一段強い見た目にする */
.chips.genres { padding: 3px; border-radius: 999px; background: rgba(125,211,252,.07); border: 1px solid var(--line); gap: 3px; }
.chip.genre { border-color: transparent; background: transparent; padding: 6px 12px; font-size: 12.5px; }
.chip.genre:not(.off) { background: color-mix(in srgb, var(--accent) 24%, var(--bg2)); border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: #fff; }
.chip.genre.off { opacity: .55; }
.chip.genre.off:hover { opacity: .85; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.zoom { display: flex; gap: 4px; }
.zoom button { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; }
.zoom button:hover { border-color: var(--accent); }
.count { color: var(--muted); font-size: 12px; min-width: 60px; }

/* ---------- 年表 ---------- */
.stage { flex: 1; display: flex; min-height: 0; }
.timeline { flex: 1; overflow: auto; position: relative; outline: none; }
.canvas { position: relative; min-height: 100%; }

.axis { position: sticky; top: 0; height: var(--axis-h); z-index: 5; background: linear-gradient(var(--bg) 70%, transparent); }
.axis .year { position: absolute; top: 8px; font-size: 20px; color: var(--text); padding-left: 8px; border-left: 2px solid var(--line); height: 40px; }
.axis .year small { display: block; font-size: 10px; color: var(--muted); }
/* 年ラベルを間引いて表示するとき（10 年 / 世紀 段階）は小さく、節目だけ強調 */
.axis .year.sparse { font-size: 13px; color: var(--muted); top: 14px; height: 32px; }
.axis .year.sparse.major { font-size: 18px; color: var(--text); border-left-color: #3b4c6b; }
.axis .month { position: absolute; top: 36px; height: 12px; border-left: 1px solid var(--line); font-size: 9px; color: var(--muted); padding-left: 3px; }
.axis .month.q { height: 18px; top: 30px; }
.axis .month.big { top: 14px; height: 34px; font-size: 14px; color: var(--text); border-left-color: #3b4c6b; }
.axis .day { position: absolute; top: 42px; height: 8px; border-left: 1px solid rgba(255,255,255,.12); font-size: 9px; color: var(--muted); padding-left: 2px; line-height: 6px; }
.mode { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode button { padding: 6px 10px; border: 0; background: var(--bg2); color: var(--muted); cursor: pointer; font-size: 12px; }
.mode button + button { border-left: 1px solid var(--line); }
.mode button.on { background: color-mix(in srgb, var(--accent) 22%, var(--bg2)); color: #fff; }
/* 「年」を押したときに出る目盛りの刻み。.mode と同じ見た目で、選択中だけ強調する */
.ystep { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ystep[hidden] { display: none; }
.ystep button { padding: 6px 10px; border: 0; background: var(--bg2); color: var(--muted); cursor: pointer; font-size: 12px; white-space: nowrap; }
.ystep button + button { border-left: 1px solid var(--line); }
.ystep button:hover { color: var(--text); }
.ystep button.on { background: color-mix(in srgb, var(--accent) 22%, var(--bg2)); color: #fff; }
.day-level .item .lbl small { color: #c9d4e6; }

.eras { position: relative; height: var(--era-h); margin-top: 4px; }
.era { position: absolute; top: 4px; height: 26px; border-radius: 6px; padding: 0 10px; font-size: 12px; line-height: 26px; white-space: nowrap; display: flex; color: #dbe7ff; background: linear-gradient(90deg, rgba(125,211,252,.22), rgba(125,211,252,.06)); border: 1px solid rgba(125,211,252,.25); cursor: help; }
.era span { position: sticky; left: calc(var(--lane-label-w) + 10px); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1500px) { .brand .sub { display: none; } }
.era.alt { background: linear-gradient(90deg, rgba(217,140,255,.2), rgba(217,140,255,.05)); border-color: rgba(217,140,255,.25); }

.axis, .eras { margin-left: var(--lane-label-w); }
.lanes { position: relative; }
.lane { position: relative; display: flex; border-top: 1px solid var(--line); }
.lane-label { position: sticky; left: 0; z-index: 4; flex: none; width: var(--lane-label-w); padding: 12px 14px; background: linear-gradient(90deg, var(--bg) 78%, transparent); }
.lane-label b { display: block; font-size: 14px; color: var(--c); }
.lane-label span { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
/* 国名の下のバッジ（G7・G20 など）。スマホでは説明文を隠すが、バッジは残す */
.lane-label .badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; font-style: normal; }
.lane-label .badges em { font-style: normal; font-size: 9px; font-weight: 700; line-height: 1; letter-spacing: .03em; padding: 2px 4px 1px; border-radius: 3px; color: var(--muted); border: 1px solid var(--line); }
.lane-label .badges em[data-b="G7"] { color: #f2c94c; border-color: rgba(242, 201, 76, .45); background: rgba(242, 201, 76, .10); }
.lane-label .badges em[data-b="G20"] { color: #7fb8ff; border-color: rgba(127, 184, 255, .40); background: rgba(127, 184, 255, .08); }
.lane-body { position: relative; flex: 1; }
.lane-body::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed rgba(255,255,255,.05); }
.gridline { position: absolute; top: 0; bottom: 0; border-left: 1px solid rgba(255,255,255,.04); }

.item { position: absolute; display: flex; align-items: center; gap: 6px; height: var(--row-h); transform: translateX(-7px); cursor: pointer; white-space: nowrap; color: var(--text); user-select: none; }
.item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px rgba(0,0,0,.35), 0 0 12px var(--c); flex: none; }
.item .lbl { font-size: 12px; max-width: var(--maxw, 160px); overflow: hidden; text-overflow: ellipsis; opacity: .9; }
.item .lbl small { color: var(--muted); font-size: 10px; margin-left: 4px; }
.item.major .dot { width: 14px; height: 14px; }
.item.major .lbl { font-size: 13px; opacity: 1; }
.item.approx .dot { background: transparent; border: 2px solid var(--c); box-shadow: 0 0 10px var(--c); }
.item:hover .lbl, .item.active .lbl { color: #fff; text-shadow: 0 0 10px var(--c); }
.item.active .dot { transform: scale(1.4); }
.item.dim { opacity: .18; pointer-events: none; }
/* 世紀 / 10 年 段階：点だけ表示（ラベルはホバーと詳細パネルで） */
.item.dotonly { width: 14px; justify-content: center; }
.item.dotonly:hover .dot { transform: scale(1.5); }

/* ---------- 帯（在任期間など） ---------- */
.band { position: absolute; height: 24px; display: flex; align-items: center; padding: 0 5px; border-radius: 3px; font-size: 11px; line-height: 1; white-space: nowrap; overflow: hidden; cursor: pointer; user-select: none; color: #f2f6ff;
  background: color-mix(in srgb, var(--c) 30%, var(--bg2)); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  /* 連続する任期がのっぺり繋がって見えないよう、左端に濃い区切りを入れる */
  border-left: 2px solid rgba(8,11,18,.85); }
/* 隣り合う帯の濃淡を交互に変えて境界を読めるようにする */
.band.odd { background: color-mix(in srgb, var(--c) 16%, var(--bg2)); }
.band.major { background: color-mix(in srgb, var(--c) 46%, var(--bg2)); font-weight: 700; }
.band.current { border-right: 2px dashed #ff8a8a; } /* 現職（今日まで） */
.band .blbl { overflow: hidden; text-overflow: clip; }
.band.cramped .blbl { font-size: 10px; letter-spacing: -.02em; } /* 幅が足りない：入るところまで */
.band.tiny { padding: 0; } /* ラベルが入らない短い任期。名前はホバー（title）と詳細パネルで見せる */
.band.tiny::after { content: ''; position: absolute; inset: -4px -3px; } /* 当たり判定を広げる */
.band:hover { z-index: 3; border-color: #fff; background: color-mix(in srgb, var(--c) 55%, var(--bg2)); }
.band.active { z-index: 4; outline: 2px solid #fff; background: color-mix(in srgb, var(--c) 62%, var(--bg2)); box-shadow: 0 0 16px var(--c); }
.band.dim { opacity: .12; pointer-events: none; }

/* 時の縦線。掛かった帯（.hit）だけ明るく、他は沈める */
.cursor { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px solid var(--accent); z-index: 6; pointer-events: none; box-shadow: 0 0 12px rgba(125,211,252,.5); }
.cursor[hidden] { display: none; }
.cursor-handle { position: sticky; top: 30px; transform: translateX(-50%); pointer-events: auto; touch-action: none; cursor: ew-resize; white-space: nowrap;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--accent); background: #0e2233; color: #fff; font-size: 12px; }
.cursor-handle.drag { background: var(--accent); color: #0b0f17; }
.canvas.cursoring .band:not(.hit):not(.active):not(.dim) { opacity: .3; }
.canvas.cursoring .item:not(.active):not(.dim) { opacity: .45; }
.band.hit { background: color-mix(in srgb, var(--c) 58%, var(--bg2)); }
.ctag { position: absolute; z-index: 5; height: 24px; margin-top: 0; padding: 0 8px; border: 0; border-left: 3px solid var(--c); border-radius: 0 4px 4px 0; background: #0e1726; color: #fff; font-size: 11.5px; white-space: nowrap; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.ctag:hover { background: #16233a; }
.axis { cursor: crosshair; }
.at { margin: 14px 0 4px; padding: 12px 14px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); background: rgba(125,211,252,.05); }
.at:empty { display: none; }
.at-h { font-size: 11px; color: var(--accent); letter-spacing: .08em; }
.at p { margin: 6px 0 4px; font-size: 14px; line-height: 1.7; }
.at .nw { white-space: nowrap; }
.at small { color: var(--muted); font-size: 11px; }
.atlink { padding: 0 2px; border: 0; background: none; color: var(--accent); font-size: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.today { position: absolute; top: var(--axis-h); bottom: 0; border-left: 1px dashed #ff8a8a; z-index: 3; pointer-events: none; }
.today span { position: absolute; top: 0; left: 4px; font-size: 10px; color: #ff8a8a; }

/* ---------- 詳細パネル ---------- */
.panel { width: 400px; flex: none; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.4); animation: slide .2s ease-out; }
.panel[hidden] { display: none; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.panel-head { display: flex; gap: 6px; padding: 10px; justify-content: flex-end; border-bottom: 1px solid var(--line); }
.nav { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; font-size: 18px; }
.nav.close { margin-left: auto; }
.panel-body { padding: 18px 20px 30px; overflow: auto; }
.panel-body .kind { font-size: 11px; color: var(--c); letter-spacing: .1em; text-transform: uppercase; }
.panel-body h2 { margin: 6px 0 4px; font-size: 22px; line-height: 1.3; }
.panel-body .date { color: var(--muted); font-size: 13px; }
.panel-body .lanebadge { display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); font-size: 11px; border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.tag { padding: 2px 8px; border-radius: 6px; background: var(--bg2); border: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.summary { line-height: 1.75; font-size: 14px; margin: 8px 0 16px; }
.specs { width: 100%; border-collapse: collapse; font-size: 13px; }
.specs th, .specs td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.specs th { width: 34%; color: var(--muted); font-weight: 700; white-space: nowrap; }
.specs td { line-height: 1.5; }
/* 同一人物の他の期（吉田茂・安倍晋三・クリーブランドなど） */
.sibs { margin: 4px 0 18px; padding: 10px 12px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); }
.sibs-h { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.sib { display: block; width: 100%; text-align: left; margin-top: 4px; padding: 6px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-size: 12px; }
.sib:hover { border-color: var(--c); }
.sib small { color: var(--muted); font-size: 11px; margin-left: 8px; }

.links { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.links a { color: var(--accent); text-decoration: none; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.links a:hover { border-color: var(--accent); }
.note { margin-top: 14px; padding: 8px 12px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }
.share { margin-top: 18px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--accent); cursor: pointer; font-size: 12px; }
.share:hover { border-color: var(--accent); }

.foot a { color: var(--muted); }
.foot { display: flex; justify-content: space-between; gap: 16px; padding: 8px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; flex-wrap: wrap; }
code { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }

/* スマホ用の畳み表示の部品。PC では出さない */
.bar-sum, .ftoggle { display: none; }

@media (max-width: 900px) {
  .stage { flex-direction: column; }
  .panel { width: auto; height: 45%; border-left: 0; border-top: 1px solid var(--line); }
  :root { --lane-label-w: 110px; }
  /* スマホではレーン名だけにして、長い名前も 2 行で収める（説明文は入りきらないので出さない） */
  .lane-label { padding: 8px 8px 8px 10px; }
  .lane-label b { font-size: 12px; line-height: 1.3; word-break: break-all; }
  .lane-label span { display: none; }
  .foot { display: none; }
}
/* スマホ横向きなど背の低い画面: 詳細パネルは横に置く */
@media (max-height: 520px) {
  .stage { flex-direction: row; }
  .panel { width: 300px; height: auto; border-top: 0; border-left: 1px solid var(--line); }
  .foot { display: none; }
}

/* スマホ（縦・横）: 条件を畳んでヘッダーを 1 行にし、年表の高さを最大にする。
   以前はチップを横スクロール 1 行にしてもヘッダーが縦画面の約 1/3 を占めていた。
   「条件」を押すと、ヘッダーの下から年表の上に重ねて、少し行き過ぎて戻る動きで出す（開いても年表の高さは変わらない） */
@media (max-width: 900px), (max-height: 520px) {
  .top { position: relative; z-index: 30; flex-wrap: nowrap; gap: 10px; padding: 8px 12px; }
  .brand { display: block; flex: none; }
  .brand h1 { font-size: 20px; }
  .bar-sum { display: block; flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ftoggle { display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 13px; cursor: pointer; }
  .ftoggle i { width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform .25s; }
  .top.open .ftoggle { border-color: var(--accent); color: var(--accent); }
  .top.open .ftoggle i { transform: translateY(2px) rotate(-135deg); }
  .controls { position: absolute; top: calc(100% + 6px); left: 8px; right: 8px; margin: 0; width: auto; max-height: min(72dvh, 560px); overflow: hidden auto;
    flex-wrap: wrap; gap: 8px; padding: 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 18px 40px rgba(0,0,0,.55);
    opacity: 0; visibility: hidden; transform: translateY(-14px) scale(.96); transform-origin: top right;
    transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s; }
  .top.open .controls { opacity: 1; visibility: visible; transform: none; transition: opacity .2s ease, transform .42s cubic-bezier(.34, 1.56, .64, 1), visibility 0s; }
  .controls > * { flex: none; }
  .controls > .chips, .controls > .chips.genres { width: 100%; flex-wrap: wrap; }
  .chips.genres { border-radius: 14px; }
  #search { width: 100%; }
  /* 開いている間は年表を少し暗くして、外をタップすれば閉じることを示す */
  .stage { transition: filter .2s; }
  .top.open ~ .stage { filter: brightness(.55); }
}
@media (prefers-reduced-motion: reduce) {
  .controls, .top.open .controls, .ftoggle i, .stage { transition: none !important; }
}
