/* 入口画面（選択画面）
   軸は「朔から車で何分か」。一乗谷の実写の上に、
   ①朔から伸びる道（家紋が歩いて、行ける時間を決める）
   ②花頭窓（禅寺の窓）の形のカード（中身はその場所の航空写真・国土地理院）
   の2つだけを置く。動きは、最初の入場・時間を変えたときの家紋と数字・地図へ開くワイプに絞る。 */
.skip-intro #intro { display: none; }

#intro {
  position: fixed; inset: 0; z-index: 3000; overflow: hidden auto; color: #fff; background: #0f1c2b;
  --pad: clamp(20px, 4.2vw, 64px);
  --ch: clamp(220px, 34vh, 380px);          /* カードの高さ */
  clip-path: inset(0 0 0 0);
  transition: clip-path .95s cubic-bezier(.76, 0, .18, 1);
}
/* 閉じるときだけ、ワイプが終わってから visibility を切る（開くときは即座に操作できる） */
#intro.is-leaving { clip-path: inset(0 0 100% 0); visibility: hidden; pointer-events: none; transition: clip-path .95s cubic-bezier(.76, 0, .18, 1), visibility 0s linear .95s; }

/* ---- 背景の写真 ---- */
.hero { position: relative; height: 100vh; height: 100svh; min-height: 620px; overflow: hidden; }
.i-bg { position: absolute; inset: 0; }
.i-bg img { width: 100%; height: 100%; object-fit: cover; object-position: 38% 42%; transform: scale(1.1); filter: saturate(1.1) brightness(1.06); }
.is-ready .i-bg img { animation: bgIn 2.4s cubic-bezier(.16, .7, .2, 1) forwards; }
@keyframes bgIn { to { transform: scale(1); } }
.i-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(15, 28, 43, .42) 0%, rgba(15, 28, 43, 0) 50%),
    linear-gradient(180deg, rgba(15, 28, 43, .3) 0%, rgba(15, 28, 43, 0) 24%, rgba(15, 28, 43, 0) 56%, rgba(15, 28, 43, .72) 100%);
}

/* ---- 並び ---- */
.i-inner { position: relative; height: 100%; display: flex; flex-direction: column; padding: max(18px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom)); }
.i-head { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--pad); }
.i-brand { display: inline-flex; align-items: center; gap: 10px; font: 600 15px/1 var(--serif); letter-spacing: .12em; }
.i-brand img { width: 26px; height: 26px; }
.i-skip {
  padding: 11px 18px; font: 500 14px/1 var(--sans); color: #fff; background: rgba(15, 28, 43, .38);
  border: 1px solid rgba(255, 255, 255, .7); border-radius: 999px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background .25s, color .25s;
}
.i-skip:hover { background: #fff; color: var(--ink); }

.i-title { margin-top: auto; padding: clamp(10px, 2.4vh, 32px) var(--pad) 0; }
.i-title h1 { margin: 0; font: 700 clamp(44px, min(13vh, 19vw), 140px)/1.1 var(--serif); letter-spacing: .1em; filter: drop-shadow(0 2px 22px rgba(8, 16, 26, .5)); }
.i-title h1 .ln { display: block; overflow: hidden; padding-bottom: .06em; white-space: nowrap; }
.i-title h1 .ln > span { display: block; transform: translateY(112%); }
.is-ready .i-title h1 .ln > span { animation: lineUp 1.1s cubic-bezier(.2, .8, .2, 1) forwards; animation-delay: calc(.2s + var(--l) * .12s); }
@keyframes lineUp { to { transform: none; } }
.i-title p { max-width: 30em; margin: clamp(8px, 1.6vh, 16px) 0 0; font: 500 clamp(14px, 1.5vh + 4px, 17px)/1.8 var(--sans); text-wrap: pretty; text-shadow: 0 1px 14px rgba(8, 16, 26, .75); opacity: 0; }
.is-ready .i-title p { animation: fadeIn .9s ease .6s forwards; }
@keyframes fadeIn { to { opacity: 1; } }

/* ---- 朔から伸びる道：家紋が歩いて、行ける時間を決める ---- */
.i-time { padding: clamp(10px, 2vh, 22px) var(--pad) 0; opacity: 0; }
.is-ready .i-time { animation: fadeIn .9s ease .75s forwards; }
.i-time-label { display: block; font: 600 14px/1 var(--serif); letter-spacing: .14em; text-shadow: 0 1px 10px rgba(8, 16, 26, .7); }
.road { position: relative; width: min(100%, 560px); margin-top: 24px; display: grid; grid-template-columns: repeat(5, 1fr); }
.road::before, .road .done { content: ""; position: absolute; left: 10%; top: 15.5px; height: 0; }
.road::before { right: 10%; border-top: 3px dotted rgba(255, 255, 255, .75); }
.road .done { border-top: 3px solid #e9bd6a; width: calc(var(--at, 90) * 1% - 10%); transition: width .9s cubic-bezier(.45, .05, .3, 1); }
.road .origin, .road .stop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0; background: none; border: 0; color: #fff; font: 600 13px/1.2 var(--sans); text-shadow: 0 1px 8px rgba(8, 16, 26, .8); }
.road .stop { cursor: pointer; padding-bottom: 4px; }
.road .dot { width: 14px; height: 14px; margin-top: 10px; border-radius: 50%; background: #fff; border: 3px solid #e9bd6a; box-sizing: border-box; transition: transform .3s; }
.road .origin .dot { width: 14px; background: #e9bd6a; }
.road .stop:hover .dot { transform: scale(1.35); }
.road .stop[aria-checked="true"] { font-weight: 800; }
/* 道を走る車。タイヤが線に乗る高さに置く。押すとプップーと鳴らして走る */
.road .walker { position: absolute; top: -13px; left: calc(var(--at, 90) * 1%); width: 56px; height: 32px; margin-left: -28px; pointer-events: none; transition: left .9s cubic-bezier(.45, .05, .3, 1); }
.road .car { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 3px 6px rgba(5, 12, 20, .55)); }
.road .car-body { fill: #e9bd6a; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.road .car-win { fill: var(--ink); }
.road .car-light { fill: #fff; }
.road .wheel circle { fill: var(--ink); stroke: #fff; stroke-width: 1.6; }
.road .wheel path { stroke: #fff; stroke-width: 1.2; stroke-linecap: round; }
.road .walker.is-back .car { transform: scaleX(-1); }
.road .walker.is-driving .car { animation: carBounce .3s ease-in-out 3; }
.road .walker.is-driving .wheel { animation: wheelSpin .45s linear 2; }
@keyframes carBounce { 50% { translate: 0 -2.5px; rotate: -2deg; } }
@keyframes wheelSpin { to { transform: rotate(360deg); } }
.road .honk { position: absolute; left: 50%; bottom: 100%; margin-bottom: 4px; padding: 3px 9px; white-space: nowrap; font: 800 12px/1.3 var(--sans); color: var(--ink); background: #fff; border-radius: 999px; opacity: 0; transform: translate(-50%, 6px) scale(.7); }
.road .walker.is-driving .honk { animation: honk 1s ease-out; }
@keyframes honk { 12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 22% { transform: translate(-50%, 0) scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -6px) scale(1); } }
.road .puff { position: absolute; left: -4px; bottom: 5px; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, .85); opacity: 0; }
.road .walker.is-back .puff { left: auto; right: -4px; }
.road .walker.is-driving .puff { animation: puff .5s ease-out 2; }
.road .walker.is-driving .puff + .puff { animation-delay: .22s; }
@keyframes puff { 0% { opacity: .9; transform: none; } 100% { opacity: 0; transform: translate(-14px, -8px) scale(1.9); } }
.road .walker.is-back.is-driving .puff { animation-name: puffR; }
@keyframes puffR { 0% { opacity: .9; transform: none; } 100% { opacity: 0; transform: translate(14px, -8px) scale(1.9); } }
.road .stop:focus-visible { outline: 3px solid #e9bd6a; outline-offset: 4px; border-radius: 8px; }

/* ---- カードの列 ---- */
.rail {
  position: relative; margin-top: clamp(10px, 2.2vh, 24px); overflow-x: auto; overflow-y: hidden;
  padding: 12px var(--pad) 10px; scroll-snap-type: x proximity; scroll-padding-inline: var(--pad);
  scrollbar-width: none; cursor: grab; overscroll-behavior-x: contain;
}
.rail::-webkit-scrollbar { display: none; }
.rail.is-drag { cursor: grabbing; scroll-snap-type: none; }
.rail.is-drag .card { pointer-events: none; }
.track { display: flex; align-items: flex-start; gap: clamp(26px, 3.6vw, 56px); width: max-content; padding-right: calc(var(--pad) + 120px); }

.card {
  position: relative; flex: none; display: block; height: var(--ch); width: calc(var(--ch) * .8); color: #fff; text-decoration: none;
  scroll-snap-align: start; -webkit-user-drag: none; user-select: none; filter: drop-shadow(0 14px 22px rgba(5, 12, 20, .4));
  opacity: 0;
}
.is-ready .card { animation: fadeIn .8s ease forwards; animation-delay: calc(.8s + var(--i) * .07s); }
.card:focus-visible { outline: none; }
/* 窓と縁取りは同じ形（花頭窓）を同じ箱に当てる。縁取りはSVGの線なので太さが変わらない */
.card .win { position: absolute; inset: 0; overflow: hidden; background: #1a2733; clip-path: url(#kato); }
.card .outline { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.card .outline path { fill: none; stroke: rgba(255, 255, 255, .95); stroke-width: 2px; vector-effect: non-scaling-stroke; transition: stroke .3s, stroke-width .3s; }
.card:hover .outline path { stroke: #e9bd6a; stroke-width: 3px; }
.card:focus-visible .outline path { stroke: #e9bd6a; stroke-width: 6px; }
.card .win img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scale(1.03); transition: transform 1.2s cubic-bezier(.2, .8, .2, 1), filter .5s; -webkit-user-drag: none; filter: brightness(1.2) saturate(1.05); }
.card:hover .win img, .card:focus-visible .win img { transform: scale(1.1); }
.card .tint { position: absolute; inset: 0; background: var(--tint); mix-blend-mode: multiply; opacity: .4; }
.card .picto { position: absolute; left: 50%; top: 19%; width: 44px; height: 44px; margin-left: -22px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 8px rgba(8, 16, 26, .55)); transition: transform .6s cubic-bezier(.2, .8, .2, 1); }
.card:hover .picto, .card:focus-visible .picto { transform: translateY(-3px); }
.card.is-photo .tint { opacity: .06; }
.card .fade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(8, 16, 26, 0) 42%, rgba(8, 16, 26, .82) 100%); }

/* 件数は小さく、題名の脇に。主役は窓から見える景色 */
.card .body { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 clamp(16px, 2.2vh, 22px) clamp(14px, 2.2vh, 22px); }
.card h2 { text-wrap: balance; margin: 0; font: 700 clamp(19px, 2.9vh, 25px)/1.35 var(--serif); letter-spacing: .06em; }
.card .meta { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; font-family: var(--serif); }
.card .meta b { font: 700 clamp(26px, 4.2vh, 38px)/1 var(--serif); font-variant-numeric: tabular-nums; }
.card .meta small { font: 600 13px var(--serif); letter-spacing: .08em; }
.card p { margin: 6px 0 0; font: 400 13.5px/1.65 var(--sans); text-wrap: pretty; }
.card.is-empty .win img { filter: grayscale(1) brightness(.7); }
.card.is-empty .meta b { opacity: .7; }

/* ---- 操作と出典 ---- */
.i-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: auto; padding: 0 var(--pad); }
.i-credit { margin: 0; font-size: 12px; line-height: 1.6; color: rgba(255, 255, 255, .88); text-shadow: 0 1px 8px rgba(8, 16, 26, .7); }
.i-credit a { color: inherit; }
.i-nav { display: flex; align-items: center; gap: 10px; }
.i-count { min-width: 3.6em; text-align: center; font: 600 14px/1 var(--serif); letter-spacing: .1em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 8px rgba(8, 16, 26, .7); }
.i-nav button { width: 44px; height: 44px; display: grid; place-items: center; color: #fff; background: rgba(15, 28, 43, .38); border: 1px solid rgba(255, 255, 255, .7); border-radius: 50%; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: background .25s, color .25s, opacity .25s; }
.i-nav button:hover:not(:disabled) { background: #fff; color: var(--ink); }
.i-nav button:disabled { opacity: .4; cursor: default; }
.i-nav svg { width: 18px; height: 18px; }

:focus-visible { outline-color: #e9bd6a; }
.i-skip:focus-visible, .i-nav button:focus-visible { outline: 3px solid #e9bd6a; outline-offset: 3px; }

/* 地図側：入口へ戻る見出しをボタンにする */
button.topbar { border: 0; font: inherit; color: #fff; cursor: pointer; }
button.topbar:hover { background: #22364d; }

@media (max-width: 700px) {
  #intro { --ch: clamp(210px, 33vh, 340px); }
  .track { gap: 28px; }
  .i-credit { max-width: 56%; }
  .road .origin, .road .stop { font-size: 12px; }
}
@media (max-height: 640px) {
  .i-title p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #intro, #intro.is-leaving, .card .win img, .card .outline path, .card .picto, .road .done, .road .walker, .road .dot { transition: none; }
  .road .walker.is-driving .car, .road .walker.is-driving .wheel, .road .walker.is-driving .puff { animation: none; }
  #intro[data-card="shiori"] .card, #intro[data-card="shiori"] .card:hover { transform: none; transition: none; }
  .is-ready .i-bg img, .is-ready .i-title h1 .ln > span, .is-ready .i-title p, .is-ready .i-time, .is-ready .card { animation-duration: .01s; animation-delay: 0s; }
  .i-bg img { transform: none; }
  .card:hover .win img, .card:focus-visible .win img { transform: scale(1.03); }
}

/* ---- カードを「しおり（栞）」の形にする：角を落とした札に、ひも穴とひも。少し傾けて、押すとまっすぐになる ----
   花頭窓に戻すときは index.html の #intro を data-card="kato" にする */
#intro[data-card="shiori"] { --ch: clamp(210px, 30vh, 350px); }
#intro[data-card="shiori"] .rail { padding-top: 44px; }
#intro[data-card="shiori"] .card { width: calc(var(--ch) * .82); transform-origin: 50% 7.5%; transform: rotate(var(--tilt, -1.6deg)); transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
#intro[data-card="shiori"] .card:nth-child(even) { --tilt: 1.5deg; }
#intro[data-card="shiori"] .card:nth-child(3n) { --tilt: -.6deg; }
#intro[data-card="shiori"] .card:hover, #intro[data-card="shiori"] .card:focus-visible { transform: rotate(0deg) translateY(-6px); }
#intro[data-card="shiori"] .card .win { clip-path: url(#shiori); }
#intro[data-card="shiori"] .card .win::after { content: ""; position: absolute; inset: 7px; border: 1px solid rgba(255, 255, 255, .55); pointer-events: none; clip-path: polygon(13% 0, 87% 0, 100% 10.5%, 100% 100%, 0 100%, 0 10.5%); }
#intro[data-card="shiori"] .card .picto { top: 17%; width: 40px; height: 40px; margin-left: -20px; }
.card .ribbon { position: absolute; left: 50%; top: calc(7.5% - 45px); width: 34px; height: 51px; margin-left: -17px; overflow: visible; pointer-events: none; fill: none; stroke: #e9bd6a; stroke-width: 3.4; stroke-linecap: round; filter: drop-shadow(0 2px 3px rgba(5, 12, 20, .5)); }
#intro[data-card="shiori"] .card h2 { font-size: clamp(17px, 2.5vh, 22px); letter-spacing: .03em; }
#intro[data-card="shiori"] .card .body { padding: 0 16px 16px; }
#intro[data-card="shiori"] .card p { font-size: 12.5px; }

/* しおりのマーク：濃紺の丸を敷く（写真が明るくても見えるように） */
.card .picto { width: 54px; height: 54px; margin-left: -27px; filter: drop-shadow(0 2px 6px rgba(8, 16, 26, .35)); }
.card .picto .picto-disc { fill: rgba(22, 39, 58, .82); stroke: none; }
#intro[data-card="shiori"] .card .picto { width: 48px; height: 48px; margin-left: -24px; }
