.line,
.char {
  transform: translate3d(0, 100%, 0);
}

.texture {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  background: url('../public/texture/wall_texture.webp') center / cover no-repeat;
  opacity: 0.4;
  pointer-events: none;
}

.container {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;

  transform-origin: center center;
  will-change: transform;

  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 2;
    pointer-events: none;

    opacity: 0;
    transition: opacity 0.45s ease-in-out;
  }
}

.grid {
  position: absolute;
  width: max-content;
  height: max-content;
  display: flex;
  gap: 5vw;
}

.--is-loaded {
  overflow: hidden;

  .grid {
    transition: transform 0.45s cubic-bezier(0.33, 1, 0.68, 1);
    cursor: grab;
  }
}

.column {
  display: flex;
  flex-direction: column;
  gap: 5vw;
}

.column:nth-child(even) {
  margin-top: 10vw;
}

.product {
  position: relative;
  width: 18.5vw;
  aspect-ratio: 1 / 1;

  div {
    width: 18.5vw;
    aspect-ratio: 1 / 1;
  }

  img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
    will-change: transform;
    transition: transform 300ms ease-in-out;
  }

  :hover {
    transform: scale(1.05);
  }
}

/* 手机：并成 5 列（见 app.js 的 stackColumns），物件放大一些 */
@media (max-width: 600px) {
  .grid,
  .column {
    gap: 8vw;
  }

  .column:nth-child(even) {
    margin-top: 22vw;
  }

  .product,
  .product div {
    width: 40vw;
  }
}

p {
  font-size: 0.85rem;
  margin-bottom: 1vw;
}

.--is-details-showing {
  cursor: pointer;

  .grid {
    pointer-events: none;
  }

  /* &:before {
    opacity: .35;
  } */
}

/* ---------- 物品名字：悬停时出现在物件下方 ---------- */

/* top / left 由 app.js 按图片里物件的实际下沿和水平中心设置 */
.product__name {
  position: absolute;
  top: 100%;
  left: 50%;
  font-family: 'Songti SC', 'STSong', 'Noto Serif SC', 'Source Han Serif SC', serif;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: #2b2724;
  opacity: 0;
  transform: translate(-50%, 1.1rem);
  transition: opacity 300ms ease-in-out, transform 300ms ease-in-out;
  pointer-events: none;
}

@media (hover: hover) {
  .--is-loaded .product:hover .product__name {
    opacity: 1;
    transform: translate(-50%, 0.75rem);
  }
}

/* 拖动画布时不显示 */
.--is-loaded .grid.--is-dragging .product__name {
  opacity: 0;
}

/* ---------- 左上角导航（样式见 nav.css） ---------- */

/* 开场动画结束后出现；打开故事页、切换到地图时隐藏 */
.container ~ .site-nav {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s;
}

.container.--is-loaded ~ .site-nav {
  opacity: 1;
  visibility: visible;
}

.--is-story .container ~ .site-nav,
.--is-leaving .container ~ .site-nav {
  opacity: 0;
  visibility: hidden;
}

/* ---------- 首次进入：介绍弹窗（是否显示、进出场动画见 app.js 的 welcome）；卡片样式在 nav.css，和 logo 悬停介绍共用 ---------- */

/* 下面垫一层 30% 黑 + 模糊，透出广角镜头下的整面物件墙 */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.3);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);

  &[hidden] {
    display: none;
  }
}

.welcome__start {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 44px;
  border: 1px solid rgba(26, 26, 26, 0.3);
  border-radius: 999px;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: #1a1a1a;
  cursor: pointer;
  transition: background-color 0.3s, border-color 0.3s;

  svg {
    width: 16px;
    height: 16px;
    transition: transform 0.35s cubic-bezier(0.33, 1, 0.68, 1);
  }

  &:hover {
    background-color: rgba(26, 26, 26, 0.04);
    border-color: rgba(26, 26, 26, 0.55);

    svg {
      transform: translateX(3px);
    }
  }

  &:focus-visible {
    outline: 1px solid #1a1a1a;
    outline-offset: 3px;
  }
}


/* ---------- 故事页 ---------- */

.story {
  position: fixed;
  inset: 0;
  z-index: 6;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* 轻滑时停回全景图，用力滑才离开 */
  scroll-snap-type: y proximity;
  visibility: hidden;
  opacity: 0;

  &.--is-locked {
    overflow-y: hidden;
  }
}

.story__hero {
  position: relative;
  height: 100vh;
  height: 100svh;
}

.story__intro {
  position: absolute;
  /* 文字块的垂直中心与模型中心对齐 */
  top: var(--model-center, 50vh);
  left: calc(var(--model-right, 63vw) + 4vw);
  max-width: 22rem;
  transform: translateY(-50%);

  @media (max-width: 600px) {
    top: calc(var(--model-bottom, 55vh) + 2.5rem);
    left: 50%;
    /* 绝对定位 + left: 50% 时默认只有半屏宽，英文长标题会折成很多行 */
    width: max-content;
    max-width: calc(100vw - 48px);
    transform: translateX(-50%);
    text-align: center;
  }
}

.story__title {
  margin-bottom: 1.1rem;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

/* 英文界面下标题下方的中文名（app.js 的 renderIntro），中文界面为空、不占位 */
.story__subtitle {
  margin: -0.55rem 0 1.1rem;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', serif;
  font-size: 15px;
  letter-spacing: 0.08em;
  line-height: 1.4;
  color: #4a4541;

  &:empty {
    display: none;
  }
}

.story__meta {
  list-style: none;
  display: grid;
  gap: 0.45rem;
  font-size: 14px;
  color: #4a4541;

  li {
    display: flex;
    align-items: center;
    gap: 0.45rem;

    @media (max-width: 600px) {
      justify-content: center;
    }
  }

  svg {
    flex: none;
    width: 1em;
    height: 1em;
  }
}

/* 全景图在屏幕中居中后停住，停留距离 = --pano-hold */
.story__pin {
  --pano-hold: 90vh;
  position: relative;
  /* 盖在结尾区上面：没有历史解说时，掉落的模型也从全景图下沿后面出来 */
  z-index: 2;

  /* 停留距离要占内容高度（sticky 不会进入 padding） */
  &::after {
    content: '';
    display: block;
    height: var(--pano-hold);
  }
}

.story__snap {
  position: absolute;
  top: calc(-1 * var(--pano-top, 0px));
  width: 1px;
  height: 1px;
  scroll-snap-align: start;
}

.story__pano {
  position: sticky;
  top: var(--pano-top, 0px);
  width: 100%;
  background-color: #2b2622;

  img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* 透明底的抠图：不垫深色底，露出页面背景 */
  &.--is-cutout {
    background-color: transparent;
  }

  &.--is-placeholder {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2rem;
    background: repeating-linear-gradient(-45deg, #d9d3ca 0 1px, #e6e1d9 1px 14px);
    color: #857c72;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
  }
}

/* 全景图之后的内容（历史解说等） */
.story__more {
  min-height: 100vh;
}

/* ---------- 历史解说（百叶窗切换） ---------- */

/* 每张图大约占一屏的滚动距离 */
.history {
  position: relative;
  /* 盖在结尾区上面：掉落的模型从全景图下沿后面出来 */
  z-index: 2;
  height: calc(var(--count) * 100vh);
}

.history__stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4vw;
  padding-left: 5vw;

  @media (max-width: 600px) {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 1.5rem;
    padding: 4.5rem 16px 16px;
  }
}

.history__texts {
  position: relative;
  display: grid;
  max-width: 32rem;

  @media (max-width: 600px) {
    grid-row: 2;
  }
}

.history__txt {
  grid-area: 1 / -1;
  align-self: center;

  @media (max-width: 600px) {
    align-self: start;
  }

  h3 {
    margin-bottom: 1.25rem;
    font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', serif;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.3;

    @media (max-width: 600px) {
      margin-bottom: 0.75rem;
      font-size: 22px;
    }
  }
}

.history__body p {
  margin-bottom: 1.1em;
  font-size: 14px;
  line-height: 1.7;
  color: #2b2724;

  @media (max-width: 600px) {
    font-size: 13px;
  }
}

/* 右侧整列：高度铺满屏幕，宽度与图片相同（图片比例见 app.js 的 HISTORY_RATIO） */
.history__frame {
  position: relative;
  align-self: stretch;
  width: min(61vw, 80vh * 1.6);

  @media (max-width: 600px) {
    grid-row: 1;
    width: 100%;
    aspect-ratio: 1.6;
  }
}

.history__layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.story__model {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;

  > div {
    position: absolute;
  }

  img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}

.story__close {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 8;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid rgba(26, 26, 26, 0.25);
  border-radius: 50%;
  background: rgba(245, 241, 235, 0.7);
  backdrop-filter: blur(6px);
  color: #1a1a1a;
  cursor: pointer;
  visibility: hidden;
  opacity: 0;

  svg {
    width: 1.1rem;
    height: 1.1rem;
  }
}

/* 最后一张图放大铺满后融入全景图；全景图上的透镜画在 canvas 里 */
.history__finale {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  background-color: #2b2622;

  img,
  canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  img {
    object-fit: cover;
  }
}

.history__zoom {
  position: absolute;
  z-index: 2;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;

  img {
    position: absolute;
    max-width: none;
  }
}

/* 全景图底部说明文字：贴着屏幕内可见区域的底边（全景图比屏幕高时底部会被裁掉一点） */
.story__caption {
  position: absolute;
  left: 50%;
  bottom: calc(max(0px, -1 * var(--pano-top, 0px)) + 1.5rem);
  transform: translateX(-50%);
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* 全景图上的说明文字（items.js 的 pano.labels），left / top 是文字中心；字号约为全景图宽度的 1.7% */
.story__label {
  position: absolute;
  transform: translate(-50%, -50%);
  margin: 0;
  font-family: 'Songti SC', 'STSong', 'Noto Serif SC', 'Source Han Serif SC', serif;
  font-size: clamp(12px, 1.71vw, 30px);
  line-height: 1.2;
  white-space: nowrap;
  color: var(--color-text);
  pointer-events: none;
}

/* ---------- 结尾：模型掉落到手掌上 ---------- */

/* 左边“我的故事”，中间手掌，右边留言区；手机上留言区排在手掌下面 */
.ending {
  position: relative;
  z-index: 1;
  scroll-snap-align: start;

  /* 手的宽度；图片比例 1122 × 1402，手腕底部稍微超出屏幕 */
  --hand-w: min(40vw, 70vh);

  @media (max-width: 600px) {
    --hand-w: 82vw;
  }
}

/* 一屏高，模型从它上沿后面掉进来 */
.ending__stage {
  position: relative;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.ending__hand {
  position: absolute;
  left: 50%;
  bottom: calc(var(--hand-w) * -0.125);
  width: var(--hand-w);
  aspect-ratio: 1122 / 1402;
  margin-left: calc(var(--hand-w) / -2);

  @media (max-width: 600px) {
    bottom: calc(var(--hand-w) * -0.35);
  }
}

/* 手是白底线稿：正片叠底去掉白色，只留线条，透出墙面纹理 */
.ending__palm {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.55;
  mix-blend-mode: multiply;
}

/* 模型落在掌心：位置和大小按手图比例 */
.ending__model {
  position: absolute;
  left: 20%;
  top: 23%;
  width: 65%;
  will-change: transform;
}

.ending__text {
  position: absolute;
  right: calc(50% + var(--hand-w) / 2);
  top: 30%;
  width: min(460px, calc(50vw - var(--hand-w) / 2 - 7vw));

  @media (max-width: 600px) {
    left: 16px;
    right: 16px;
    top: 4.5rem;
    width: auto;
  }

  h3 {
    margin-bottom: 1rem;
    font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', serif;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.3;

    @media (max-width: 600px) {
      font-size: 22px;
      margin-bottom: 0.6rem;
    }
  }

  p {
    margin-bottom: 0.9em;
    font-size: 14px;
    line-height: 1.6;
    color: #2b2724;
  }
}

/* ---------- 留言区 ---------- */

.comments {
  position: absolute;
  left: calc(50% + var(--hand-w) / 2);
  top: calc(30% + 0.6rem);
  bottom: 5vh;
  display: flex;
  flex-direction: column;
  width: min(480px, calc(50vw - var(--hand-w) / 2 - 7vw));

  @media (max-width: 600px) {
    position: static;
    width: auto;
    padding: 2.5rem 16px 4rem;
  }
}

/* 没有“我的故事”的物品：全景图下面单独一栏留言区 */
.guestbook {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  /* 标题和有“我的故事”的物品一样，落在一屏高度的 30% 左右 */
  padding: 28vh 16px 12vh;

  @media (max-width: 600px) {
    padding-top: 18vh;
  }

  h3 {
    margin-bottom: 1.4rem;
    font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', serif;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.3;

    @media (max-width: 600px) {
      font-size: 22px;
    }
  }

  .comments {
    position: static;
    width: auto;
    padding: 0;
  }
}

.comments__form {
  display: flex;
  align-items: center;
  gap: 12px;

  &.--is-open {
    align-items: flex-end;
  }
}

.comments__box {
  flex: 1;
  min-width: 0;
  padding: 9px 16px;
  border: 1px solid rgba(26, 26, 26, 0.35);
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.3);
  transition: border-color 0.3s;

  .--is-open & {
    border-color: rgba(26, 26, 26, 0.55);
  }
}

.comments__body,
.comments__name {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: #2b2724;
  outline: none;

  &::placeholder {
    color: #8a8079;
  }
}

.comments__body {
  height: 1.6em;
  resize: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: height 0.35s cubic-bezier(0.22, 1, 0.36, 1);

  .--is-open & {
    height: 8em;
    overflow-y: auto;
    white-space: pre-wrap;
  }
}

/* 名字栏：展开后才出现在输入框底部 */
.comments__name {
  display: none;
  margin-top: 10px;
  padding: 8px 10px 0;
  border-top: 1px solid rgba(26, 26, 26, 0.3);

  .--is-open & {
    display: block;
  }
}

.comments__send {
  flex: none;
  padding: 0.5em 1.3em;
  border: 1px solid rgba(26, 26, 26, 0.35);
  border-radius: 999px;
  background-color: transparent;
  font: inherit;
  font-size: 14px;
  color: #2b2724;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;

  &:not(:disabled) {
    border-color: #1a1a1a;
    background-color: #1a1a1a;
    color: #fff;
  }

  &:disabled {
    cursor: default;
  }
}

.comments__error {
  margin-top: 0.6rem;
  font-size: 13px;
  color: #9a3b2c;
}

.comments__list {
  list-style: none;
  flex: 1;
  min-height: 0;
  margin-top: 2.2rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.comments__item {
  padding: 10px 6px;
  border-bottom: 1px solid rgba(26, 26, 26, 0.15);

  p {
    margin-bottom: 0;
  }

  &:last-child {
    border-bottom: 0;
  }
}

.comments__author {
  font-size: 13px;
  font-style: italic;
  color: #857c72;
}

.comments__text {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.6;
  color: #2b2724;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comments__date {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  text-align: right;
  color: #857c72;
}

.ending__shop {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.5em 1.3em;
  border: 1px solid rgba(26, 26, 26, 0.35);
  border-radius: 999px;
  font-size: 14px;
  color: #2b2724;
  text-decoration: none;
  transition: background-color 0.3s, border-color 0.3s;

  &:hover {
    background-color: rgba(255, 255, 255, 0.5);
    border-color: rgba(26, 26, 26, 0.6);
  }
}

/* ---------- 英文界面（js/i18n.js 把 <html lang> 设为 en） ---------- */

/* 英文标题用 EB Garamond（只有 500 一种字重），去掉给中文用的字距 */
:root:lang(en) {
  .story__title,
  .history__txt h3,
  .ending__text h3,
  .guestbook h3,
  .product__name,
  .story__label {
    font-family: 'EB Garamond', 'Noto Serif SC', 'Songti SC', serif;
    font-weight: 500;
    letter-spacing: 0;
  }

  .story__title {
    font-size: 28px;
    line-height: 1.15;
  }

  .history__txt h3,
  .ending__text h3,
  .guestbook h3 {
    font-size: 36px;
    line-height: 1.15;

    @media (max-width: 600px) {
      font-size: 26px;
    }
  }

  /* 英文名字较长：限制宽度、居中换行 */
  .product__name {
    width: max-content;
    max-width: 15em;
    font-size: 16px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
  }
}
