/* lore.html - 設定資料集（絵巻） */

.lore {
  --ink: #2a1a14;
  --ink-muted: #6b5546;
  --vermilion: #a3352b;

  flex: 1;
  padding: 32px 16px 56px;
}

/* ---------- 篇の目次 ---------- */

.lore-bar {
  max-width: 960px;
  margin: 0 auto 28px;
  text-align: center;
}

.lore-label {
  margin: 0 0 10px;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 13px;
  letter-spacing: .4em;
  color: var(--gold);
}

.lore-toc {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 24px;
}

.lore-toc a {
  padding: 6px 2px;
  border-bottom: 1px solid transparent;
  color: var(--text-secondary);
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 14px;
  letter-spacing: .12em;
  text-decoration: none;
  transition: color .2s ease, border-color .2s ease;
}

.lore-toc a:hover,
.lore-toc a.is-current {
  color: var(--gold-light);
  border-bottom-color: var(--gold);
}

.lore-toc-no {
  margin-right: .5em;
  font-size: 12px;
  color: var(--muted);
}

.lore-progress {
  display: none;
}

.lore-hint {
  display: none;
}

/* ---------- 巻物（スマートフォン：上に軸、下に巻き） ----------
   素材は元画像の紙の帯（高さ 535px）を基準に --k 倍して配置する */

.lore-stage {
  position: relative;
  container-type: inline-size;
  width: calc(100% - 16px);
  max-width: 600px;
  margin: 0 auto;
}

.lore-frame {
  --k: calc(100cqw / 535);
  --band-a: calc(43 * var(--k));
  --band-b: calc(49 * var(--k));
  --endcap: calc(140 * var(--k));
  --roll: calc(154 * var(--k));
  position: relative;
  display: flex;
  flex-direction: column;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, .45));
}

.lore-rod {
  position: relative;
  z-index: 2;
  order: -1;
  flex: none;
  width: calc(564 * var(--k));
  height: calc(38 * var(--k));
  margin-left: calc(-12 * var(--k));
  background: url('../img/lore/rod-only-v.webp') 0 0 / 100% 100% no-repeat;
}

.lore-scroll {
  position: relative;
  z-index: 1;
  margin-top: calc(-19 * var(--k));
}

.lore-scroll:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.lore-paper {
  position: relative;
  display: block;
  padding:
    calc(var(--endcap) + 28px)
    calc(var(--band-b) + 14px)
    calc(var(--roll) / 2 + 40px)
    calc(var(--band-a) + 14px);
  background:
    url('../img/lore/band-top-v.webp') 0 0 / var(--band-a) auto repeat-y,
    url('../img/lore/band-bottom-v.webp') 100% 0 / var(--band-b) auto repeat-y,
    url('../img/lore/paper-v.webp') var(--band-a) 0 / calc(443 * var(--k)) auto repeat-y,
    #f1ebdf;
  color: var(--ink);
  font-family: 'Harenosora', 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 15px;
  line-height: 2;
  letter-spacing: .06em;
}

/* 巻き始めの縁 */
.lore-paper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--endcap);
  background: url('../img/lore/endcap-v.webp') 0 0 / 100% 100% no-repeat;
  pointer-events: none;
}

.lore-roll {
  position: relative;
  z-index: 2;
  height: var(--roll);
  margin: calc(var(--roll) / -2) -22px 0;
  border-style: solid;
  border-width: 0 22px;
  border-image: url('../img/lore/roll-v.webp') 0 83 0 66 fill / 0 22px 0 22px stretch;
}

/* ---------- 本文 ---------- */

.lore-paper p {
  margin: 0 0 1.3em;
  text-indent: 1em;
}

.lore-hen {
  scroll-margin-top: calc(var(--header-h, 72px) + 16px);
}

.lore-hen:focus {
  outline: none;
}

.lore-hen + .lore-hen {
  margin-block-start: 3.5em;
  padding-block-start: 3.5em;
  border-block-start: 1px solid rgba(163, 53, 43, .38);
}

/* 題 */
.lore-title {
  margin: 0 0 1.6em;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1.8;
  letter-spacing: .14em;
  color: var(--ink);
}

.lore-title rt {
  font-size: .32em;
  letter-spacing: .1em;
  color: var(--ink-muted);
}

.lore-title-sub {
  display: block;
  font-size: .6em;
  color: var(--vermilion);
}

.lore-paper .lore-name {
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 1.15em;
  text-indent: 0;
  padding-inline-start: 2em;
}

.lore-name rt {
  font-size: .45em;
  color: var(--ink-muted);
}

/* 篇の見出し */
.lore-paper .lore-hen-no {
  margin: 0 0 .2em;
  text-indent: 0;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: .85em;
  letter-spacing: .3em;
  color: var(--vermilion);
}

.lore-hen-title {
  margin: 0 0 .6em;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .18em;
  color: var(--ink);
}

.lore-paper .lore-lead {
  margin-block-end: 2.2em;
  text-indent: 0;
  color: var(--ink-muted);
}

.lore-paper h3 {
  margin: 2.2em 0 .8em;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 1.15em;
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--vermilion);
}

.lore-paper h3::before {
  content: '◇';
  margin-inline-end: .4em;
}

.lore-paper .lore-quote {
  text-indent: 0;
  padding-inline-start: 1em;
}

/* 古い書や言い伝えの引用 */
.lore-verse {
  margin: 2em 0;
  padding-inline-start: 2em;
  font-family: 'Soukou Mincho', 'Yu Mincho', serif;
  font-size: 1.1em;
  line-height: 2.3;
  letter-spacing: .14em;
  color: var(--vermilion);
}

.lore-paper .lore-verse p {
  margin: 0;
  text-indent: 0;
}

.lore-verse--final {
  margin-block-end: 0;
}

/* 狭い画面では段落内の改行を解き、自然に折り返す */
@media (max-width: 480px) {
  .lore-paper p:not(.lore-quote) br {
    display: none;
  }

  .lore-paper .lore-verse p br {
    display: inline;
  }
}

/* ---------- 横長の画面：縦書き・右から左への絵巻（右に軸、左に巻き） ---------- */

@media (min-width: 921px) and (min-height: 620px) {
  .lore {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-h, 72px));
    height: calc(100dvh - var(--header-h, 72px));
    min-height: 0;
    flex: none;
    padding: 20px 0 12px;
    box-sizing: border-box;
  }

  .lore-bar {
    flex: none;
    width: min(960px, calc(100% - 96px));
    margin-bottom: 14px;
  }

  .lore-progress {
    display: block;
    position: relative;
    height: 1px;
    margin-top: 12px;
    background: rgba(212, 175, 55, .2);
  }

  .lore-progress span {
    position: absolute;
    inset: 0;
    background: var(--gold);
    transform: scaleX(0);
    transform-origin: right center;
  }

  /* 巻きの高さ（元画像 684px）がステージの高さに収まる倍率 */
  .lore-stage {
    flex: 1;
    min-height: 0;
    max-height: 860px;
    width: calc(100% - 48px);
    max-width: none;
    container-type: size;
  }

  .lore-frame {
    --k: calc(100cqh / 684);
    position: absolute;
    top: calc(66 * var(--k));
    left: 0;
    right: calc(234 * var(--k));
    height: calc(535 * var(--k));
  }

  .lore-rod {
    position: absolute;
    top: calc(-12 * var(--k));
    left: calc(100% - 36 * var(--k));
    width: calc(270 * var(--k));
    height: calc(570 * var(--k));
    margin: 0;
    background-image: url('../img/lore/rod.webp');
  }

  .lore-roll {
    position: absolute;
    top: calc(-66 * var(--k));
    left: 0;
    width: var(--roll);
    height: calc(684 * var(--k));
    margin: 0;
    border: 0;
    border-image: none;
    background: url('../img/lore/roll.webp') 0 0 / 100% 100% no-repeat;
  }

  .lore-scroll {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--roll) / 2);
    right: calc(18 * var(--k));
    margin: 0;
    writing-mode: vertical-rl;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .lore-scroll::-webkit-scrollbar {
    display: none;
  }

  .lore-paper {
    min-inline-size: 100%;
    block-size: auto;
    box-sizing: border-box;
    padding-block: calc(var(--endcap) + 40px) calc(var(--roll) / 2 + 56px);
    padding-inline: calc(var(--band-a) + 22px) calc(var(--band-b) + 22px);
    background:
      url('../img/lore/band-top.webp') 0 0 / auto var(--band-a) repeat-x,
      url('../img/lore/band-bottom.webp') 0 100% / auto var(--band-b) repeat-x,
      url('../img/lore/paper.webp') 0 var(--band-a) / auto calc(443 * var(--k)) repeat-x,
      #f1ebdf;
    font-size: 16px;
    line-height: 2.1;
  }

  .lore-paper::before {
    top: 0;
    bottom: 0;
    left: auto;
    right: 0;
    width: var(--endcap);
    height: auto;
    background-image: url('../img/lore/endcap.webp');
  }

  .lore-paper p {
    margin-block-end: 1.1em;
  }

  .lore-hen + .lore-hen {
    margin-block-start: 4em;
    padding-block-start: 4em;
  }

  /* 低い画面でも見出しが1列に収まるよう、画面の高さに合わせて縮める */
  .lore-title {
    font-size: clamp(1.6rem, 4vh, 2.2rem);
    margin-block-end: 1.4em;
  }

  .lore-hen-title {
    font-size: clamp(1.3rem, 3.2vh, 1.7rem);
    padding-inline-start: 1em;
  }

  .lore-paper .lore-lead {
    padding-inline-start: 2em;
  }

  .lore-paper h3 {
    margin-block-start: 2em;
  }

  .lore-verse {
    padding-inline-start: 3em;
  }

  .lore-hint {
    display: block;
    flex: none;
    margin: 10px 0 0;
    text-align: center;
    font-size: 12px;
    letter-spacing: .1em;
    color: var(--muted);
  }

  /* 開く演出の初期状態：巻きを軸の隣に寄せ、紙を閉じておく */
  .lore-intro .lore-roll {
    left: calc(100% - 36 * var(--k) - var(--roll) * .9);
  }

  .lore-intro .lore-scroll {
    clip-path: inset(0 0 0 100%);
  }
}

/* 開く演出の初期状態（共通） */
.lore-intro .lore-ink {
  opacity: 0;
}

@media not ((min-width: 921px) and (min-height: 620px)) {
  .lore-intro .lore-scroll {
    clip-path: inset(0 0 100% 0);
  }

  .lore-intro .lore-roll {
    visibility: hidden;
  }
}
