@font-face {
  font-family: "PingFangSG";
  src: url("./PingFangShiGuangTi-2.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: optional; /* 避免字体加载时的布局重计算问题 */
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #f6f6f6;
  color: #0e1e39;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; /* 优先使用系统字体避免加载问题 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%; /* 尊重系统文本缩放，避免可访问性问题 */
  overflow: hidden; /* 防止滚动 */
}

/* 开信封视频容器 */
.video-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: #f6f6f6;
  transition: opacity 0.8s ease-out, transform 0.8s ease-out;
  display: grid;
  place-items: center;
  padding: 2vh 3vw;
  /* 添加一个微妙的加载提示 */
  background-image: radial-gradient(circle at 50% 50%, rgba(14, 30, 57, 0.02) 0%, transparent 50%);
}

.video-container.hidden {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

.envelope-video {
  /* 使用与卡片完全相同的尺寸计算方式 */
  width: min(96vw, calc(96vh * 2272 / 4039)) !important;
  height: auto !important;
  max-width: min(96vw, calc(96vh * 2272 / 4039)) !important;
  max-height: calc(min(96vw, calc(96vh * 2272 / 4039)) * 4039 / 2272) !important;
  aspect-ratio: 2272 / 4039 !important; /* 与信件卡片相同的比例 */
  object-fit: cover !important;
  object-position: center !important;
  display: block !important;
  background: #f6f6f6;
  /* 隐藏所有视频控件和UI */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: none;
  outline: none;
}

/* 确保视频在所有浏览器中都隐藏控件 */
.envelope-video::-webkit-media-controls {
  display: none !important;
  -webkit-appearance: none;
}

.envelope-video::-webkit-media-controls-panel {
  display: none !important;
}

.envelope-video::-webkit-media-controls-play-button {
  display: none !important;
}

.envelope-video::-webkit-media-controls-start-playback-button {
  display: none !important;
}

.envelope-video::-webkit-media-controls-timeline {
  display: none !important;
}

.envelope-video::-webkit-media-controls-current-time-display {
  display: none !important;
}

.envelope-video::-webkit-media-controls-time-remaining-display {
  display: none !important;
}

.envelope-video::-webkit-media-controls-fullscreen-button {
  display: none !important;
}

.envelope-video::-webkit-media-controls-toggle-closed-captions-button {
  display: none !important;
}

.envelope-video::-webkit-media-controls-volume-slider {
  display: none !important;
}

.envelope-video::-webkit-media-controls-mute-button {
  display: none !important;
}

.video-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(96vw, calc(96vh * 2272 / 4039));
  aspect-ratio: 2272 / 4039;
  background: transparent;
  cursor: pointer;
  z-index: 1001;
  transition: opacity 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-overlay.playing {
  opacity: 0;
  pointer-events: none;
}

.video-play-hint {
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
  opacity: 0.8;
}

.video-play-hint p {
  margin: 0;
  font-weight: 400;
}

/* 信件舞台 */
.stage {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2vh 3vw;
  position: relative;
  z-index: 100;
}
.card {
  position: relative;
  /*
     宽度取“同时不超过视口宽与视口高所允许的最大宽度”
     - 96vw：留少量边距
     - 96vh * (2272/4039)：以高度为限制时的最大可用宽度
  */
  width: min(96vw, calc(96vh * 2272 / 4039));
  aspect-ratio: 2272 / 4039; /* exact image ratio: 2272x4039 */
  background: center / contain no-repeat url("./Component 1.png?v=20250917163408");
  background-color: #fefbf5; /* 先显示浅底色，等待背景图加载 */
  container-type: inline-size; /* 使用更稳定的容器类型，避免高度相关的计算问题 */
}

@supports (background-image: image-set(url("a.webp") type("image/webp"))) {
  .card {
    background-image: image-set(
      url("./Component 1.webp?v=20250917163408") type("image/webp"),
      url("./Component 1.png?v=20250917163408") type("image/png")
    );
  }
}

/* 纸张区域（相对于整张卡片的百分比）
   - 整体向右移：增大 --paper-left
   - 整体向下移：增大 --paper-top
   - 同比放大：增大 --paper-width 和 --paper-height
   - 同比缩小：减小 --paper-width 和 --paper-height
   文字可调参数（方便你快速微调）
   - 人名：--name-left / --name-top / --name-size-cqw / --name-size-cqh
   - 正文：--content-left / --content-top / --content-width / --content-size-* / --content-line
   - 落款：--from-right / --from-bottom / --from-size-*
*/
:root {
  /* 纸张框 */
  --paper-left: 15.8%;
  --paper-top: 26.4%;
  --paper-width: 68.4%;
  --paper-height: 62.2%;
  /* 人名 */
  --name-left: 18.3%;
  --name-top: 7.6%;
  --name-size-cqw: 5.0cqw; /* 统一字体大小 */
  --name-size-cqh: 5.4cqh;
  --name-prefix-shift: 0ch;
  /* 正文 */
  --content-left: 3%;
  --content-top: 18.8%;
  --content-width: 92%;
  --content-size-cqw: 5.0cqw; /* ↓ 改为与姓名和落款一致 */
  --content-size-cqh: 10cqh; /* 让默认以 cqw 为主 */
  --content-line: 1.75;
  --content-min-cqw: 4.8; /* ↓ 恢复原来的最小值 */

  /*正文和To之间的间距在这里改*/
  --content-gap: 25px; /* 正文与落款之间的保留间距 */
  --content-center-bias: 0px; /* 若需整体下移可在此设置偏移 */

  /* 落款 */
  --from-right: 3%;
  --from-size-cqw: 5.0cqw; /* 统一字体大小 */
  --from-size-cqh: 5.4cqh;
}
.paper {
  position: absolute;
  left: var(--paper-left);
  top: var(--paper-top);
  width: var(--paper-width);
  height: var(--paper-height);
}
.name {
  /* 人名定位（相对于纸张区域）
     - 左右移动：修改 --name-left 百分比（+ 往右，- 往左）
     - 上下移动：修改 --name-top 百分比（+ 往下，- 往上）
     - 大小：改 --name-size-cqw / --name-size-cqh
  */
  position: absolute;
  left: var(--name-left);
  top: var(--name-top);
  margin: 0;
  font-size: var(--name-size-cqw, 5.0cqw); /* 移除硬编码，完全依赖动态计算 */
  font-weight: 400;
  letter-spacing: 0.02em;
  mix-blend-mode: multiply;
  transform: translateX(calc(-1 * var(--name-prefix-shift, 0)));
}
.content {
  /* 正文定位（相对于纸张区域）
     - 位置：--content-left / --content-top；宽度：--content-width
     - 行距：--content-line；字号：--content-size-cqw / --content-size-cqh
  */
  position: absolute;
  left: var(--content-left);
  top: var(--content-top);
  width: var(--content-width);
  margin: 0;
  font-size: var(--content-size-cqw, 5.0cqw); /* 移除硬编码，完全依赖动态计算 */
  line-height: var(--content-line);
  font-weight: 400;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-wrap: break-word; /* 兼容旧版Safari */
  word-break: break-word; /* 额外换行保护 */
  hyphens: auto; /* 连字符换行 */
  -webkit-hyphens: auto;
  -webkit-text-size-adjust: auto; /* 允许文本正常缩放和换行 */
  min-width: 0; /* 避免最小宽度阻止换行 */
  max-width: 100%;
  box-sizing: border-box;
  /* 响应式：font-size 按容器与文案长度自动调节（见 index.html 脚本） */
  transform: translateY(calc(var(--content-offset, 0px) + var(--content-center-bias, 0px)));
  will-change: transform;
  mix-blend-mode: multiply;
}
.from {
  /* 落款定位（通过脚本动态计算顶部位置） */
  position: absolute;
  left: var(--from-left);
  right: auto;
  top: var(--content-top);
  font-size: var(--from-size-cqw, 5.0cqw); /* 移除硬编码，完全依赖动态计算 */
  font-weight: 400;
  text-align: right;
  mix-blend-mode: multiply;
  /* 确保可见性 */
  opacity: 1;
  visibility: visible;
  display: block;
}
/* Optional: toggle a calibration outline by adding class 'debug' to body */

/*
  :   360px   */
@supports (container-type: inline-size) {
  @container (width < 360px) {
    .card {
      --content-min-cqw: 6;
      --name-size-cqw: 6cqw;
      --content-size-cqw: 6cqw; /* ↑ 手机端也增大正文字体 */
      --from-size-cqw: 6cqw;
      --content-top: 18.2%;
    }
  }
}

/* 字体加载完成后应用自定义字体 */
body.fonts-loaded {
  font-family: "PingFangSG", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.debug .paper { outline: 2px dashed rgba(255,0,0,0.45); outline-offset: -2px; }

@supports (font-size: 1cqw) and (container-type: inline-size) {
  .name {
    font-size: var(--name-size-cqw, 5.0cqw); /* 移除最小值限制 */
  }
  .content {
    font-size: var(--content-size-cqw, 5.0cqw); /* 移除最小值限制 */
  }
  .from {
    font-size: var(--from-size-cqw, 5.0cqw); /* 移除最小值限制 */
  }
}

/* 为不支持Container Queries的浏览器提供fallback */
@supports not ((font-size: 1cqw) and (container-type: inline-size)) {
  .name {
    font-size: 18px;
  }
  .content {
    font-size: 16px;
    /* 额外的兼容性保护 */
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
  }
  .from {
    font-size: 16px;
  }

  /* 小屏设备的媒体查询fallback */
  @media (max-width: 360px) {
    .name {
      font-size: 20px;
    }
    .content {
      font-size: 18px;
    }
    .from {
      font-size: 18px;
    }
  }
}

/* 针对iOS Safari的额外兼容性保护 */
@media (-webkit-min-device-pixel-ratio: 1) {
  .content {
    /* 确保在Webkit内核中文本能够正确换行 */
    word-break: break-word;
    overflow-wrap: break-word;
  }
}
