/* 标题字：思源宋体 SC SemiBold 的 9 字形子集（以圣杯之名残夜序章）
   版权与许可见 assets/fonts/OFL.txt，SIL Open Font License 1.1 */
@font-face {
  font-family: "Chalice Serif";
  src: url("../../assets/fonts/chalice-title.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ---------- 标题起始页：横屏 / 竖屏都能看到游戏标题 ---------- */
.title {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--paper);
  background: #050404;
  opacity: 0;
  transition: opacity .68s var(--ease-in-out);
}
.title[hidden] { display: none; }
.title.is-on { opacity: 1; }

/* 底图：压暗 + 极慢推近，避免一张死图 */
.title__bg {
  position: absolute;
  inset: -2%;
  width: 104%;
  height: 104%;
  object-fit: cover;
  object-position: center;
  filter: brightness(.36) saturate(.62) blur(2px);
  transform: scale(1);
  will-change: transform;
  animation: title-breathe 44s var(--ease-in-out) infinite alternate;
}
@keyframes title-breathe {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to   { transform: scale(1.05) translate3d(-1%, -1.2%, 0); }
}

/* 暗角：四周压成深井，暖光交给下面的 .title__light */
.title__veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 46%,
      transparent 22%, rgba(5, 4, 4, .58) 74%, rgba(5, 4, 4, .95) 100%),
    linear-gradient(180deg,
      rgba(5, 4, 4, .8), rgba(5, 4, 4, .4) 32%,
      rgba(5, 4, 4, .56) 72%, rgba(5, 4, 4, .96));
}

/* 烛光：跟随鼠标做小幅视差（--lx / --ly 由 ui/title.js 写入），并轻微闪烁 */
.title__light {
  position: absolute;
  inset: -8%;
  pointer-events: none;
  background:
    radial-gradient(ellipse 34% 30% at 50% 44%,
      rgba(240, 178, 74, .17), rgba(240, 178, 74, .05) 46%, transparent 72%);
  transform: translate3d(var(--lx, 0px), var(--ly, 0px), 0);
  animation: title-flicker 5.6s var(--ease-in-out) infinite;
  will-change: transform;
}
@keyframes title-flicker {
  0%, 100% { opacity: .82; }
  13%      { opacity: .96; }
  27%      { opacity: .78; }
  41%      { opacity: 1; }
  58%      { opacity: .86; }
  74%      { opacity: .94; }
  88%      { opacity: .8; }
}

/* 胶片颗粒：极淡，只负责去掉"数码感" */
.title__grain {
  position: absolute;
  inset: 0;
  opacity: .055;
  mix-blend-mode: overlay;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

/* 浮尘：慢慢往上飘，给静止画面一点"空气" */
.title__dust {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.title__dust i {
  position: absolute;
  bottom: -4svh;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: rgba(240, 200, 130, .6);
  box-shadow: 0 0 6px 1px rgba(240, 178, 74, .32);
  opacity: 0;
  animation: title-dust 24s linear infinite;
}
.title__dust i:nth-child(1) { left: 14%; animation-delay: 0s;    animation-duration: 26s; }
.title__dust i:nth-child(2) { left: 27%; animation-delay: 5.5s;  animation-duration: 31s; }
.title__dust i:nth-child(3) { left: 41%; animation-delay: 2.2s;  animation-duration: 22s; }
.title__dust i:nth-child(4) { left: 53%; animation-delay: 9s;    animation-duration: 34s; }
.title__dust i:nth-child(5) { left: 66%; animation-delay: 3.4s;  animation-duration: 24s; }
.title__dust i:nth-child(6) { left: 78%; animation-delay: 12s;   animation-duration: 29s; }
.title__dust i:nth-child(7) { left: 90%; animation-delay: 7s;    animation-duration: 27s; }
@keyframes title-dust {
  0%   { opacity: 0; transform: translate3d(0, 0, 0) scale(.6); }
  12%  { opacity: .75; }
  68%  { opacity: .45; }
  100% { opacity: 0; transform: translate3d(3.4vw, -104svh, 0) scale(1.1); }
}

/* ---------- 标题字排 ---------- */
.title__inner {
  position: relative;
  z-index: 2;
  width: min(86vw, 1000px);
  padding: 3svh 4vw 5svh;
  text-align: center;
  text-shadow: 0 2px 24px rgba(0, 0, 0, .85);
}

/* 圣杯徽记：细线印章，不抢字 */
.title__crest {
  width: clamp(44px, 4.8vw, 66px);
  margin: 0 auto 3.4svh;
  color: rgba(200, 163, 90, .88);
  filter: drop-shadow(0 0 16px rgba(240, 178, 74, .26));
}
.title__crest svg { display: block; width: 100%; height: auto; overflow: visible; }
.title__crest .crest-ring,
.title__crest .crest-tick,
.title__crest .crest-cup,
.title__crest .crest-stem,
.title__crest .crest-foot {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.title__crest .crest-ring--inner { opacity: .3; }
.title__crest .crest-tick { opacity: .42; }
.title__crest .crest-cup { stroke-width: 1.15; }
.title__crest .crest-gem { fill: currentColor; opacity: .78; }

/* 主标题：黄铜渐变 + 压印 + 定期扫过的一道高光 */
.title__name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(44px, 7.2vw, 116px);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: .08em;
  text-indent: .08em;
  white-space: nowrap;
  color: transparent;
  background-image:
    linear-gradient(104deg,
      rgba(255, 250, 230, 0) 30%, rgba(255, 250, 230, .95) 50%, rgba(255, 250, 230, 0) 70%),
    linear-gradient(166deg,
      #fff6d6 0%, #f2d190 16%, #dcae56 38%, #b8862d 54%, #f4d89c 72%, #d7a747 100%);
  background-size: 22% 100%, 100% 100%;
  background-position: -60% 0, 0 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  filter:
    drop-shadow(0 2px 0 rgba(28, 16, 4, .82))
    drop-shadow(0 12px 34px rgba(240, 178, 74, .22));
}

/* 副标题：小字 + 宽字距 + 两侧细线，把金属高光让给主标题 */
.title__sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 1.6vw, 26px);
  margin: 2.6svh 0 0;
  font-family: var(--font-display);
  font-size: clamp(14px, 1.45vw, 23px);
  font-weight: 600;
  color: rgba(240, 200, 130, .82);
  text-shadow: 0 2px 14px rgba(0, 0, 0, .8);
}
.title__sub span {
  letter-spacing: .6em;
  padding-left: .6em;      /* 抵消最后一个字后的字距，视觉居中 */
  line-height: 1.2;
}
.title__sub::before,
.title__sub::after {
  content: "";
  width: clamp(20px, 4vw, 68px);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(200, 163, 90, .55));
}
.title__sub::after { transform: scaleX(-1); }

/* 分隔线：左淡右淡 + 中间一颗黄铜菱钉 */
.title__rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1vw, 16px);
  margin: 3.8svh 0 0;
}
.title__rule span {
  display: block;
  width: clamp(34px, 7vw, 128px);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(200, 163, 90, .58));
}
.title__rule span:last-child { transform: scaleX(-1); }
.title__rule i {
  width: 5px;
  height: 5px;
  background: var(--gold);
  transform: rotate(45deg);
  box-shadow: 0 0 10px rgba(240, 178, 74, .65);
}

.title__tag {
  margin: 2.4svh 0 0;
  font-size: clamp(12px, .9vw, 15px);
  letter-spacing: .4em;
  text-indent: .4em;
  color: rgba(232, 214, 172, .6);
}

/* ---------- 按钮 ---------- */
.title__acts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.4svh;
  margin-top: 5.8svh;
}

/* 主按钮：黄铜牌位，内嵌细线 + 悬停一道扫光 */
.title__main {
  position: relative;
  min-width: min(30vw, 280px);
  min-height: 52px;
  padding: 0 3.4em;
  overflow: hidden;
  font-family: var(--font-title);
  font-size: clamp(14px, 1.05vw, 17px);
  letter-spacing: .6em;
  text-indent: .6em;
  color: #efd9a8;
  background: linear-gradient(180deg,
    rgba(200, 163, 90, .16), rgba(34, 25, 14, .55) 58%, rgba(12, 9, 6, .82));
  border: 1px solid rgba(200, 163, 90, .38);
  box-shadow:
    inset 0 0 26px rgba(240, 178, 74, .07),
    0 12px 34px rgba(0, 0, 0, .45);
  transition:
    color var(--dur), border-color var(--dur),
    box-shadow var(--dur), transform var(--dur-fast);
}
.title__main::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(200, 163, 90, .14);
  pointer-events: none;
  transition: border-color var(--dur);
}
.title__main::after {
  content: "";
  position: absolute;
  top: -30%;
  bottom: -30%;
  left: -60%;
  width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 240, 200, .18), transparent);
  transform: skewX(-16deg);
  pointer-events: none;
  transition: left .6s var(--ease-out);
}
.title__main:hover,
.title__main:focus-visible {
  color: #fff2ca;
  border-color: rgba(240, 200, 130, .82);
  box-shadow:
    inset 0 0 30px rgba(240, 178, 74, .16),
    0 14px 40px rgba(0, 0, 0, .5),
    0 0 26px rgba(240, 178, 74, .16);
}
.title__main:hover::before,
.title__main:focus-visible::before { border-color: rgba(240, 200, 130, .28); }
.title__main:hover::after { left: 118%; }
.title__main:active { transform: translateY(1px); }

.title__new {
  min-height: 36px;
  padding: 0 1.4em;
  font-family: var(--font-title);
  font-size: clamp(13px, .95vw, 15px);
  letter-spacing: .3em;
  text-indent: .3em;
  color: rgba(200, 163, 90, .72);
  transition: color var(--dur);
}
.title__new:hover { color: var(--gold); }

.title__minor {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.6vw;
  margin-top: 3.2svh;
}
.title__link {
  position: relative;
  padding: .6svh .2em;
  font-family: var(--font-title);
  font-size: clamp(13px, .95vw, 15px);
  letter-spacing: .32em;
  text-indent: .32em;
  color: rgba(200, 163, 90, .68);
  transition: color var(--dur);
}
.title__link::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: .1svh;
  width: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  transform: translateX(-50%);
  transition: width var(--dur) var(--ease-out);
}
.title__link:hover,
.title__link:focus-visible { color: var(--gold); }
.title__link:hover::after,
.title__link:focus-visible::after { width: 86%; }
.title__link:not([hidden]) + .title__link:not([hidden])::before {
  content: "·";
  position: absolute;
  left: -1.3em;
  color: rgba(200, 163, 90, .32);
  letter-spacing: 0;
  text-indent: 0;
}

.title button:focus-visible {
  outline: 1px solid rgba(240, 200, 130, .72);
  outline-offset: 3px;
}

/* ---------- 入场：一件一件浮上来 ---------- */
.title__crest,
.title__name,
.title__sub,
.title__rule,
.title__tag,
.title__acts,
.title__minor { opacity: 0; }

.title.is-on .title__crest  { animation: title-in .9s  var(--ease-out) .05s both; }
.title.is-on .title__name   {
  animation:
    title-in 1s var(--ease-out) .26s both,
    title-sheen 7.5s ease-in-out 2.4s infinite;
}
.title.is-on .title__sub    { animation: title-in .8s  var(--ease-out) .5s both; }
.title.is-on .title__rule   { animation: title-in .8s  var(--ease-out) .7s both; }
.title.is-on .title__tag    { animation: title-in .8s  var(--ease-out) .82s both; }
.title.is-on .title__acts   { animation: title-in .9s  var(--ease-out) .96s both; }
.title.is-on .title__minor  { animation: title-in .8s  var(--ease-out) 1.14s both; }

@keyframes title-in {
  from { opacity: 0; transform: translateY(1.6svh); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes title-sheen {
  0%, 58%   { background-position: -60% 0, 0 0; }
  86%, 100% { background-position: 160% 0, 0 0; }
}

/* 竖屏点开始/继续：把全局横屏提示抬到标题页之上，先别进游戏 */
/* 被拦下时无论视口多宽都要把提示显示出来，别让“开始”变成没反应的死键 */
body.is-title-blocked .rotate-hint { display: flex; z-index: 310; }

.title__portrait-tip {
  display: none;
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: max(5.6svh, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  font-size: 12px;
  letter-spacing: .18em;
  color: rgba(232, 214, 172, .42);
  white-space: nowrap;
}
.title__ver {
  position: absolute;
  z-index: 2;
  right: max(2.4vw, env(safe-area-inset-right));
  bottom: max(2.4svh, env(safe-area-inset-bottom));
  margin: 0;
  font-family: var(--font-sans);
  font-size: 10px;
  letter-spacing: .3em;
  color: rgba(232, 214, 172, .3);
}

/* ---------- 标题页设置 / 确认 ---------- */
.title__panel,
.title__confirm {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(300px, calc(100vw - 40px));
  padding: 20px;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #2b2015, #0c0907);
  border: 1px solid rgba(200, 163, 90, .5);
  /* 100vmax 阴影当遮罩用，省掉一个 DOM 层 */
  box-shadow: 0 0 0 100vmax rgba(4, 3, 3, .62), 0 22px 56px rgba(0, 0, 0, .8);
}
.title__panel[hidden],
.title__confirm[hidden] { display: none; }
.title__panel::before,
.title__confirm::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -1px;
  width: 44%;
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(240, 200, 130, .9), transparent);
}
.title__panel-head {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: .3em;
  color: rgba(200, 163, 90, .7);
}
.title__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  padding: 8px 0;
  font: inherit;
  font-size: 14px;
  color: var(--paper);
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(200, 163, 90, .16);
}
.title__toggle b {
  font-weight: 400;
  color: rgba(200, 163, 90, .8);
}
.title__credits {
  margin: 10px 0 0;
  font-size: 10px;
  line-height: 1.7;
  letter-spacing: .04em;
  text-align: left;
  color: rgba(200, 163, 90, .5);
}
.title__panel-close {
  width: 100%;
  min-height: 38px;
  margin-top: 14px;
  font: inherit;
  font-size: 13px;
  letter-spacing: .16em;
  color: rgba(232, 214, 172, .72);
  background: none;
  border: 1px solid rgba(200, 163, 90, .3);
}
.title__panel-close:hover { color: var(--amber); border-color: var(--gold); }

/* ---------- 新游戏确认 ---------- */
.title__confirm {
  z-index: 5;
  width: min(420px, calc(100vw - 40px));
  padding: 24px;
  text-align: center;
  border-color: rgba(200, 163, 90, .62);
}
.title__confirm p {
  margin: 0 0 18px;
  font-size: clamp(13px, 1vw, 15px);
  line-height: 1.9;
  color: rgba(232, 214, 172, .8);
}
.title__confirm-acts {
  display: flex;
  justify-content: center;
  gap: 12px;
}
/* 确认框里的按钮跟着标题页走：去掉通用按钮的斜切角 */
.title__confirm-acts .btn {
  min-width: 118px;
  min-height: 42px;
  padding: 0 1.3em;
  font-family: var(--font-title);
  font-size: 13px;
  letter-spacing: .22em;
  text-indent: .22em;
  color: rgba(232, 214, 172, .8);
  background: linear-gradient(180deg, rgba(200, 163, 90, .1), rgba(12, 9, 6, .82));
  border: 1px solid rgba(200, 163, 90, .34);
  clip-path: none;
  transition: color var(--dur), border-color var(--dur), box-shadow var(--dur);
}
.title__confirm-acts .btn:hover {
  color: #f6e3b6;
  border-color: rgba(240, 200, 130, .72);
  box-shadow: 0 0 18px rgba(240, 178, 74, .14);
}
.title__confirm-acts .btn--primary {
  color: #ffeec4;
  background: linear-gradient(180deg, rgba(200, 163, 90, .34), rgba(66, 47, 25, .62));
  border-color: rgba(240, 200, 130, .82);
  box-shadow: inset 0 0 0 1px rgba(240, 200, 130, .2), 0 0 22px rgba(240, 178, 74, .18);
}
.title__confirm-acts .btn--primary:hover { color: #fff4d2; border-color: rgba(250, 220, 150, .95); }

/* ---------- 适配 ---------- */
@media (orientation: portrait) {
  .title__inner { width: 88vw; padding: 8svh 4vw 17svh; }
  .title__crest { width: clamp(40px, 11vw, 56px); margin-bottom: 3.2svh; }
  .title__name {
    font-size: clamp(36px, 11.4vw, 72px);
    letter-spacing: .06em;
    text-indent: .06em;
  }
  .title__sub {
    font-size: clamp(12px, 3.6vw, 16px);
    gap: 10px;
  }
  .title__sub::before,
  .title__sub::after { width: 18vw; }
  .title__rule { margin-top: 4svh; }
  .title__rule span { width: 26vw; }
  .title__tag { display: none; }
  .title__acts { margin-top: 6.6svh; }
  .title__main { min-width: 70vw; }
  .title__minor { gap: 9vw; margin-top: 3.4svh; }
  .title__portrait-tip { display: block; }
  .title__bg {
    object-position: 58% center;
    filter: brightness(.32) saturate(.6) blur(2.4px);
    animation: none;
  }
  .title__ver { bottom: max(2.2svh, env(safe-area-inset-bottom)); }
}

@media (max-height: 560px) and (orientation: landscape) {
  .title__inner { padding: 2svh 4vw 3svh; }
  .title__crest { display: none; }
  .title__name {
    font-size: clamp(30px, 6.4vw, 70px);
    letter-spacing: .06em;
    text-indent: .06em;
  }
  .title__sub {
    margin-top: 1.8svh;
    font-size: clamp(11px, 1.9vw, 14px);
  }
  .title__rule { margin-top: 3.4svh; }
  .title__tag { display: none; }
  .title__acts { margin-top: 3.6svh; gap: 1.6svh; }
  .title__main { min-height: 44px; }
  .title__minor { margin-top: 1.4svh; }
}

@media (prefers-reduced-motion: reduce) {
  .title { transition: none; }
  .title__bg,
  .title__light,
  .title__dust i { animation: none; }
  .title.is-on .title__crest,
  .title.is-on .title__name,
  .title.is-on .title__sub,
  .title.is-on .title__rule,
  .title.is-on .title__tag,
  .title.is-on .title__acts,
  .title.is-on .title__minor {
    animation: none;
    opacity: 1;
  }
}
