/* P4 (Material Archives): LP 物語・検索ドロワー・タグ5軸。motion.css のあとに読む。契約は spec/p4.md */

/* --- 物語: sticky の背景スタックと全幅チャプター --- */
.lp-story { position: relative; background: #14110d; }

.lp-bgs {
  position: sticky;
  top: 0;
  height: 100svh;
  margin-bottom: -100svh;
  overflow: hidden;
}
.lp-bgs img { position: absolute; inset: 0; opacity: 0; }
.lp-bgs img:first-child { opacity: 1; }
html[data-motion="on"] .lp-bgs img {
  opacity: 0;
  transform: scale(1.06);
  transition: opacity 1.1s ease, transform 2.6s cubic-bezier(.22,.61,.21,1);
}
html[data-motion="on"] .lp-bgs img.is-on,
html[data-motion="on"] .lp-bgs:not(:has(img.is-on)) img:first-child { opacity: 1; transform: scale(1); }
.lp-bgs::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(14,11,8,.66) 0%, rgba(14,11,8,.34) 48%, rgba(14,11,8,.12) 100%);
}

.lp-ch {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: flex;
  align-items: center;
  color: #fff;
}
.lp-ch-in {
  width: min(var(--max), calc(100% - var(--pad) * 2));
  margin: 0 auto;
  padding: 96px 0;
}
.lp-ch-in > * { max-width: 560px; }
html[data-motion="on"] .lp-ch-in {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .8s ease, transform .8s cubic-bezier(.22,.61,.21,1);
}
html[data-motion="on"] .lp-ch.is-live .lp-ch-in,
html[data-motion="on"] .lp-story:not(:has(.lp-ch.is-live)) .lp-ch.is-intro .lp-ch-in { opacity: 1; transform: none; }

.lp-story.is-instant .lp-bgs img,
.lp-story.is-instant .lp-ch-in { transition: none; }

/* 最終到達: 最終章は 100svh のまま viewport に収め、フッターは物語の下端に紙地で重ねる（契約は spec/p4.md） */
.page:has(.lp-story) { position: relative; }
.main:has(.lp-story) { padding-bottom: 0; }
.page:has(.lp-story) .footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  background: var(--bg);
}
.lp-ch:last-child {
  box-sizing: border-box;
  min-height: 100svh;
  padding-bottom: var(--lp-footer-h, 0px);
}

.lp-kicker { font-size: var(--fs-small); letter-spacing: .18em; color: rgba(255,255,255,.78); margin-bottom: 20px; }
.lp-brand {
  font-family: var(--font-h);
  font-weight: var(--fw-h);
  font-size: calc(var(--fs-h1) * 1.6);
  letter-spacing: .1em;
  line-height: 1.3;
  text-shadow: 0 1px 12px rgba(0,0,0,.4);
  margin-bottom: 28px;
}
.lp-title {
  font-size: calc(var(--fs-h1) * 1.1);
  letter-spacing: .1em;
  line-height: 1.4;
  margin-bottom: 28px;
  text-shadow: 0 1px 12px rgba(0,0,0,.4);
}
.lp-lead { line-height: 2.1; margin-bottom: 1.4em; text-shadow: 0 1px 8px rgba(0,0,0,.45); }
.lp-prompt {
  margin-top: 2.2em;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,.4);
  font-size: .9375rem;
  color: rgba(255,255,255,.92);
}

.lp-cue {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  font-size: .6875rem;
  letter-spacing: .3em;
  color: rgba(255,255,255,.85);
  text-align: center;
}
.lp-cue::after {
  content: "";
  display: block;
  width: 1px;
  height: 44px;
  background: rgba(255,255,255,.6);
  margin: 10px auto 0;
}

.lp-fields { display: flex; flex-wrap: wrap; gap: 28px 36px; margin-top: 40px; max-width: none; }
.lp-fields a { display: grid; gap: 6px; color: #fff; }
.lp-field-kanji { font-family: var(--font-h); font-size: calc(var(--fs-h1) * 1.4); line-height: 1; }
.lp-field-en { font-size: .6875rem; letter-spacing: .18em; color: rgba(255,255,255,.75); }

.lp-actions { display: flex; flex-wrap: wrap; gap: 14px 28px; margin-top: 48px; align-items: center; max-width: none; }
.lp-textlink { color: #fff; border-bottom: 1px solid rgba(255,255,255,.6); padding-bottom: 3px; font-size: .875rem; }
.lp-openbtn {
  border: 1px solid rgba(255,255,255,.85);
  background: transparent;
  color: #fff;
  padding: 12px 22px;
  cursor: pointer;
  font-size: .875rem;
  letter-spacing: .1em;
}

@media (hover: hover) and (pointer: fine) {
  .lp-fields a, .lp-textlink, .lp-openbtn { transition: opacity .5s ease; }
  .lp-fields a:hover, .lp-textlink:hover, .lp-openbtn:hover { opacity: .68; }
}

/* --- 右端タブ（事例 / 素材の2連）とドロワー --- */
.lp-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
}
.lp-tab-btn {
  writing-mode: vertical-rl;
  letter-spacing: .14em;
  width: 52px;
  min-height: 88px;
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  background: var(--ink);
  color: var(--bg);
  font-size: .875rem;
}
.lp-tab-btn + .lp-tab-btn { border-top: 1px solid rgba(246,241,231,.28); }
@media (hover: hover) and (pointer: fine) {
  .lp-tab-btn { transition: background .3s ease; }
  .lp-tab-btn:hover { background: #000; }
}

.lp-scrim {
  position: fixed;
  inset: 0;
  z-index: 34;
  background: rgba(20,16,11,.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease;
}
.lp-scrim.is-open { opacity: 1; pointer-events: auto; }

.lp-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 36;
  width: 0;
  overflow: hidden;
  visibility: hidden;
  transition: width .55s cubic-bezier(.22,.61,.21,1), visibility 0s .55s;
}
.lp-drawer.is-open {
  width: 80vw;
  visibility: visible;
  transition: width .55s cubic-bezier(.22,.61,.21,1);
}
.lp-drawer-in {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80vw;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 44px 56px 64px;
}

.lp-drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.lp-drawer-title { font-family: var(--font-h); font-weight: var(--fw-h); font-size: calc(var(--fs-h2) * .92); letter-spacing: .12em; }
.lp-close {
  border: 0;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  width: 44px;
  height: 44px;
  margin: -8px -8px 0 0;
}
.lp-close:hover { color: var(--ink); }

/* モードのトグル（セグメント。ピルにしない） */
.lp-switch {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--ink);
}
.lp-switch-btn {
  min-height: 48px;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  font-size: .875rem;
  letter-spacing: .12em;
  transition: background .3s ease, color .3s ease;
}
.lp-switch-btn + .lp-switch-btn { border-left: 1px solid var(--ink); }
.lp-switch-btn.is-on { background: var(--ink); color: var(--bg); }

.lp-count { margin-top: 12px; color: var(--muted); font-size: .8125rem; letter-spacing: .08em; }

/* 軸: 索引の組版（太い上罫＋hairline＋明朝の軸見出し） */
.lp-axes { margin-top: 20px; border-top: 1px solid var(--ink); }
.lp-drawer .lp-axis {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 6px 28px;
  align-items: start;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}
.lp-drawer .lp-axis-label {
  font-family: var(--font-h);
  font-weight: var(--fw-h);
  font-size: .9375rem;
  letter-spacing: .12em;
  color: var(--ink);
  padding-top: 11px;
}

/* --- タグ群（ドロワーと結果ページ共通） --- */
.lp-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.lp-tag {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  padding: 12px 18px;
  min-height: 44px;
  cursor: pointer;
  font-size: .875rem;
  letter-spacing: .08em;
  transition: background .45s cubic-bezier(.22,.61,.21,1), color .45s cubic-bezier(.22,.61,.21,1), border-color .45s cubic-bezier(.22,.61,.21,1);
}
@media (hover: hover) and (pointer: fine) {
  .lp-tag:hover { border-color: var(--ink); }
}
.lp-tag.is-on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.lp-tag--tone {
  font-family: var(--font-h);
  font-size: 1rem;
  min-width: 48px;
  padding: 12px 14px;
  text-align: center;
}

.lp-results { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 20px; }
.lp-drawer .lp-results { grid-template-columns: repeat(2, 1fr); gap: 2px; }

.lp-sel { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 20px; }
.lp-sel-label { font-size: var(--fs-small); color: var(--muted); letter-spacing: .12em; margin-bottom: 10px; }
.lp-sel .lp-tag::after { content: "×"; margin-left: 8px; }
.lp-clearall {
  border: 0;
  background: none;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
  margin-top: 14px;
  font-size: .8125rem;
  letter-spacing: .08em;
}
.lp-clearall:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* --- 結果ページのインラインタグ行 --- */
.search-page { padding-top: var(--space-block); }
.search-page h1 { letter-spacing: .12em; }
.lp-searchpage { margin-top: 28px; }
.lp-searchpage .lp-switch { margin-top: 0; }
.lp-searchpage .lp-axes { margin-top: 8px; }

.lp-tagbar { margin-top: 36px; border-top: 1px solid var(--line); padding-top: 8px; }
.lp-tagbar .lp-axis { display: grid; grid-template-columns: 96px 1fr; gap: 8px 20px; margin-top: 16px; align-items: start; }
.lp-tagbar .lp-axis-label { font-size: var(--fs-small); letter-spacing: .12em; color: var(--muted); padding-top: 9px; }

@media (max-width: 900px) {
  .lp-brand { font-size: calc(var(--fs-h1) * 1.1); }
  .lp-title { font-size: calc(var(--fs-h1) * .94); }
  .lp-ch-in { padding: 72px 0; }
  .lp-drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 0;
    transition: height .55s cubic-bezier(.22,.61,.21,1), visibility 0s .55s;
  }
  .lp-drawer.is-open { width: 100%; height: 80vh; height: 80dvh; transition: height .55s cubic-bezier(.22,.61,.21,1); }
  .lp-drawer-in {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 80vh;
    height: 80dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 20px 20px 44px;
  }
  .lp-drawer .lp-axis { grid-template-columns: 1fr; gap: 10px; padding: 18px 0; }
  .lp-drawer .lp-axis-label { padding-top: 0; }
  .lp-tagbar .lp-axis { grid-template-columns: 1fr; }
  .lp-tagbar .lp-axis-label { padding-top: 0; }
  .lp-drawer .lp-results { grid-template-columns: 1fr; }
}

/* --- 素材詳細のストーリー枠（歴史 / 地域 / 特徴）。契約は spec/p4.md --- */
/* パネルは .columns の全幅（--max / --pad）に広げ、章を写真と文の2カラムにする */
.column-panel { max-width: none; }

.story-ch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: clamp(44px, 5vw, 72px);
  row-gap: 20px;
  align-items: center;
  margin-top: clamp(64px, 8vw, 104px);
}
.column-panel .story-ch:first-of-type { margin-top: 0; }
.story-ch .column-fig { margin: 0; }
.story-body > p { margin-bottom: 1.2em; }
.story-body > p:last-child { margin-bottom: 0; }
.story-lead { font-family: var(--serif); font-size: 1.125rem; line-height: 1.9; }
.column-panel .column-spec { max-width: 880px; }

/* 奇数章は写真左・文右（DOM 順そのまま）、偶数章は逆 */
@media (min-width: 901px) {
  .story-ch:nth-of-type(even) .story-fig { grid-column: 2; }
  .story-ch:nth-of-type(even) .story-body { grid-column: 1; grid-row: 1; }
}

/* 据わり。静止状態は常に最終形。隠し始めるのは motion 明示のときだけ */
html[data-motion="on"] .story-body > p {
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity .7s ease var(--pd, 0ms),
    transform .7s cubic-bezier(.22,.61,.21,1) var(--pd, 0ms);
}
html[data-motion="on"] .story-body > p.is-visible { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .story-ch { grid-template-columns: 1fr; margin-top: 56px; }
}

/* --- AIに質問（墨の円形吹き出し）。契約は spec/p4.md --- */
.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}
.ai-fab svg { width: 24px; height: 24px; }

.ai-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 30;
  width: min(360px, calc(100vw - 48px));
  background: var(--bg);
  border: 1px solid var(--ink);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .12);
}
/* 開閉はドロワーと同じ .55 秒の据わり。隠し始めるのは motion 明示のときだけ */
html[data-motion="on"] .ai-panel {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .55s cubic-bezier(.22, .61, .21, 1), transform .55s cubic-bezier(.22, .61, .21, 1);
}
html[data-motion="on"] .ai-panel.is-open { opacity: 1; transform: none; }

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.ai-head p { font-family: var(--serif); font-size: .9375rem; letter-spacing: .08em; }
.ai-head button {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  width: 44px;
  height: 44px;
  margin: -6px -12px -6px 0;
  display: grid;
  place-items: center;
}
.ai-head button:hover { color: var(--ink); }
.ai-body { padding: 20px; }
.ai-body .note { font-size: .8125rem; }
.ai-form { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.ai-form input { flex: 1; min-width: 0; min-height: 44px; border: 1px solid var(--line); padding: 10px 12px; background: var(--bg); }
.ai-form button {
  border: 1px solid var(--ink);
  background: var(--bg);
  min-height: 44px;
  padding: 0 18px;
  cursor: pointer;
  letter-spacing: .08em;
}
@media (hover: hover) and (pointer: fine) {
  .ai-form button { transition: background .3s ease, color .3s ease; }
  .ai-form button:hover { background: var(--ink); color: var(--bg); }
}

@media (max-width: 900px) {
  .ai-fab { right: 16px; bottom: 16px; }
  .ai-panel { right: 16px; bottom: 84px; width: min(360px, calc(100vw - 32px)); }
}

/* --- 地域の2段（地方→都道府県）と結果カードの差し替え。契約は spec/p4.md「地域は地方→都道府県の2段」「検索まわりの据わり」 --- */
.lp-regions { display: grid; align-content: start; }

.lp-tag--region { position: relative; padding-right: 36px; }
.lp-tag--region::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-68%) rotate(45deg);
}
html[data-motion="on"] .lp-tag--region::after { transition: transform .45s cubic-bezier(.22,.61,.21,1); }
.lp-tag--region.is-open { border-color: var(--ink); }
.lp-tag--region.is-open::after { transform: translateY(-32%) rotate(225deg); }

/* 県の開閉は高さアニメーション。閉じた群は高さ 0・隙間 0（margin も開いたときだけ）。visibility でフォーカスごと隠す */
.lp-prefgroup { display: grid; grid-template-rows: 0fr; visibility: hidden; margin-top: 0; }
.lp-prefgroup.is-open { grid-template-rows: 1fr; visibility: visible; margin-top: 12px; }
.lp-prefgroup > .lp-tags { min-height: 0; overflow: hidden; }
html[data-motion="on"] .lp-prefgroup {
  transition: grid-template-rows .5s cubic-bezier(.22,.61,.21,1), margin-top .5s cubic-bezier(.22,.61,.21,1), visibility 0s .5s;
}
html[data-motion="on"] .lp-prefgroup.is-open {
  transition: grid-template-rows .5s cubic-bezier(.22,.61,.21,1), margin-top .5s cubic-bezier(.22,.61,.21,1);
}

/* 結果カードの差し替え。グリッド自体は stagger を掛けず即 is-visible（app.js の skipStagger） */
html[data-motion="on"] [data-lp-results] > *,
html[data-motion="on"] [data-search-results] > * {
  animation: lp-swap-in .55s cubic-bezier(.22,.61,.21,1) both;
}
@keyframes lp-swap-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
