/* ==========================================================================
   badge.css — 2027 纳新工牌页（/badge/）
   设计令牌全部来自主站 style.css 的 :root（本文件不重复定义任何令牌）。
   预隐藏态一律门控在 html.motion-ready 下：JS/GSAP 失效或 reduced-motion 时内容天然可见。
   ========================================================================== */

.badge-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.bd-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 主内容：顶栏固定，留出高度；单屏居中但允许滚动 */
#bdMain {
  flex: 1;
  padding-top: calc(var(--header-h) + 46px);
  padding-bottom: 88px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.bd-wrap {
  width: 100%;
  max-width: 760px;
  position: relative;            /* 供 .bd-gate.is-out 绝对定位脱离文档流 */
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bd-gate,
.bd-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bd-stage[hidden] { display: none; }   /* 必须显式写：display:flex 会盖掉 [hidden] 的 display:none */

/* ---------- 阶段切换 ---------- */
.bd-gate {
  transition: opacity .45s ease, transform .45s ease;
}
/* 退场必须脱离文档流：否则透明但占位的核验台会把工牌推到首屏之外 */
.bd-gate.is-out {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

/* ---------- 核验台 ---------- */
.bd-console {
  width: min(100%, 620px);
  margin-top: 8px;
}
.bd-console-body {
  border: 1px solid var(--hair);
  border-top: 0;
  background: rgba(0, 6, 92, .5);
  padding: 26px 26px 22px;
}

.bd-hint {
  font-size: 14.5px;
  color: var(--dim);
  line-height: 1.9;
  margin-bottom: 20px;
}
.bd-hint code,
.bd-hint strong {
  color: var(--cyan);
  font-weight: 700;
}
.bd-hint code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  border-bottom: 1px dashed rgba(143, 217, 255, .5);
  padding: 0 2px;
}

.bd-label {
  display: block;
  font-size: 12px;
  letter-spacing: .16em;
  color: var(--cyan);
  margin-bottom: 8px;
}

.bd-field-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.bd-input {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  letter-spacing: .08em;
  color: var(--ice);
  background: rgba(0, 4, 46, .6);
  border: 1px solid var(--hair);
  padding: 12px 16px;
  min-height: 48px;
  transition: border-color .18s, background .18s;
}
.bd-input::placeholder { color: #5A64A8; letter-spacing: .08em; }
.bd-input:hover { border-color: rgba(143, 217, 255, .5); }
.bd-input:focus {
  outline: none;
  border-color: var(--cyan);
  background: rgba(0, 4, 46, .85);
}
.bd-input.is-bad {
  border-color: #FF7A7A;
  animation: bdShake .34s ease;
}
@keyframes bdShake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-6px); }
  55% { transform: translateX(5px); }
  80% { transform: translateX(-3px); }
}

.bd-field-row .btn { flex-shrink: 0; }
.bd-field-row .btn:disabled {
  opacity: .58;
  cursor: default;
}

.bd-err {
  min-height: 22px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: #FF9C9C;
  letter-spacing: .02em;
}

/* ---------- 签发日志（等宽打字，装饰性） ---------- */
.bd-log {
  width: min(100%, 620px);
  margin-top: 20px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 2;
  color: #C6D2FF;
  background: rgba(0, 6, 92, .35);
  border: 1px dashed var(--hair);
  padding: 16px 18px;
  min-height: 118px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  text-align: left;
}
.bd-log:empty { display: none; }
.bd-log.is-typing::after {
  content: "▌";
  color: var(--cyan);
  animation: blink 1s steps(1) infinite;
}
.bd-log .bd-fail { color: #FF9C9C; }

.bd-noscript {
  margin-top: 20px;
  font-size: 13.5px;
  color: #FF9C9C;
  border: 1px solid rgba(255, 154, 154, .5);
  padding: 14px 16px;
  text-align: left;
}

/* ==========================================================================
   阶段 2：寄语 → 工牌
   桌面（≥981px）寄语在左、工牌在右，两侧同时可见；
   手机先读寄语，点「领取工牌」后寄语脱流淡出、整屏换成卡面。
   ========================================================================== */
.bd-stage > .eyebrow { margin-bottom: 26px; }

.bd-stage-grid {
  position: relative;            /* 供 .bd-letter 领取后绝对定位脱流（同 .bd-gate.is-out 手法） */
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- 寄语（终端窗口框：与核验台、卡面共用 win-bar 语汇） ---------- */
.bd-letter {
  width: min(100%, 620px);
  transition: opacity .4s ease, transform .4s ease;
}
.bd-letter-body {
  border: 1px solid var(--hair);
  border-top: 0;
  background: rgba(0, 6, 92, .5);
  padding: 24px 26px 26px;
}

/* 首行是核验结果（终端口吻），与正文之间用虚线断开 */
.bd-welcome {
  font-size: 12.5px;
  letter-spacing: .1em;
  color: var(--cyan);
  padding-bottom: 16px;
  border-bottom: 1px dashed rgba(143, 217, 255, .28);
  margin-bottom: 18px;
}
.bd-letter-open {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ice);
  letter-spacing: .04em;
  margin-bottom: 14px;
}
.bd-letter-body p:not(.bd-welcome):not(.bd-letter-open):not(.bd-letter-sign) {
  font-size: 14.5px;
  line-height: 2.05;
  color: #D7DEFF;
  margin-bottom: 14px;
  text-align: justify;           /* 中文信件两端对齐，右边缘齐整 */
}
.bd-letter-sign {
  font-size: 12.5px;
  line-height: 1.9;
  letter-spacing: .08em;
  color: var(--dim);
  text-align: right;
  margin-top: 22px;
}

/* 「领取工牌」只在手机出现：桌面两侧同时可见，不需要二次点击 */
.bd-claim {
  display: block;
  width: 100%;
  margin-top: 24px;
}

/* ---------- 工牌列（吊绳 + 卡面 + 操作按钮同列居中） ---------- */
.bd-ticket {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- 吊绳 ---------- */
.bd-cord {
  width: 2px;
  height: 64px;
  background: linear-gradient(180deg, transparent, rgba(143, 217, 255, .55));
  position: relative;
  transform-origin: top center;
}
.bd-cord .bd-clip {
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 34px;
  height: 24px;
  transform: translateX(-50%);
  border: 1px solid var(--cyan);
  background: rgba(0, 6, 92, .9);
  box-shadow: 0 0 14px rgba(143, 217, 255, .18);
}

/* ==========================================================================
   工牌卡面（竖版真实比例 54 : 86，直角，无圆角）
   ========================================================================== */
/* 尺寸容器：cqw 必须由「祖先」容器解析 —— 元素不能作为自己的容器，
   否则 4.6cqw 会退化成视口宽度（4.6% × 1280 ≈ 59px），卡面内容整体爆掉。 */
.bd-card-box {
  width: clamp(292px, 82vw, 352px);
  aspect-ratio: 54 / 86;
  container-type: inline-size;
  flex-shrink: 0;
}

.bd-card {
  position: relative;
  width: 100%;
  height: 100%;
  font-size: 16px;          /* 回退值（不支持 container query 单位时） */
  font-size: 4.6cqw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: .68em;
  padding: 1.5em 1.15em 1.15em;   /* 顶部留白带给吊绳孔 */
  color: var(--ice);
  background:
    radial-gradient(120% 80% at 12% 0%, rgba(0, 56, 215, .55), transparent 60%),
    linear-gradient(168deg, #021560 0%, var(--deep) 58%, #01073F 100%);
  border: 1px solid rgba(143, 217, 255, .38);
  box-shadow: 0 26px 60px rgba(0, 4, 46, .62), 0 0 0 1px rgba(255, 255, 255, .04);
  outline: none;
  transform-style: preserve-3d;
  will-change: transform;
}
.bd-card:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; }

/* 全息层：斜向箔纹 + 指针径向高光（--mx/--my 由 JS 每帧写入）。
   克制：整体低透明度，箔纹只提供质感，不压正文可读性。 */
.bd-holo {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  mix-blend-mode: screen;
  background-image:
    radial-gradient(38% 30% at var(--mx, 50%) var(--my, 12%), rgba(255, 255, 255, .26), transparent 70%),
    repeating-linear-gradient(115deg,
      rgba(143, 217, 255, .11) 0 5px,
      rgba(0, 56, 215, .09) 5px 11px,
      rgba(255, 255, 255, .06) 11px 16px,
      rgba(143, 217, 255, .03) 16px 24px);
  background-size: 100% 100%, 260% 260%;
  animation: holoDrift 14s linear infinite;
}
@keyframes holoDrift {
  from { background-position: 0 0, 0% 0%; }
  to { background-position: 0 0, 260% 0%; }
}

/* 入场扫光带：起止两端都写；终点彻底离开卡面并回到透明，避免留下一条常驻亮带 */
.bd-sheen {
  position: absolute;
  top: -30%;
  left: 0;
  width: 46%;
  height: 160%;
  pointer-events: none;
  transform: rotate(16deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .34), transparent);
  opacity: 0;
}

/* 吊绳孔（直角槽，落在卡面顶部留白带内，不与内容条重叠） */
.bd-notch {
  position: absolute;
  top: .55em;
  left: 50%;
  width: 2.6em;
  height: .5em;
  transform: translateX(-50%);
  background: rgba(0, 2, 29, .9);
  border: 1px solid rgba(143, 217, 255, .3);
  box-shadow: inset 0 0 5px rgba(0, 0, 0, .75);
}

/* 背景水印（完整落在卡内，避免产生可滚动溢出） */
.bd-watermark {
  position: absolute;
  right: .12em;
  bottom: .06em;
  font-family: var(--font-mono);
  font-size: 5.6em;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -.04em;
  color: rgba(143, 217, 255, .07);
  pointer-events: none;
  user-select: none;
}

/* 卡面条（等宽体 + 三个方块，主站 win-bar 语汇） */
.bd-strip {
  display: flex;
  align-items: center;
  gap: .5em;
  font-size: .6em;
  letter-spacing: .1em;
  color: var(--dim);
  padding-bottom: .5em;
  border-bottom: 1px solid rgba(143, 217, 255, .22);
  position: relative;
  z-index: 1;
}
.bd-strip span { color: var(--royal); font-size: .85em; }
.bd-strip em { font-style: normal; margin-left: auto; }

.bd-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .8em;
  position: relative;
  z-index: 1;
}
.bd-brand {
  display: flex;
  align-items: center;
  gap: .6em;
  min-width: 0;
}
.bd-logo {
  width: 2.1em;
  height: auto;
  max-height: 2.1em;
  object-fit: contain;
  flex-shrink: 0;
}
.bd-brand-text { display: flex; flex-direction: column; min-width: 0; }
.bd-brand-text b {
  font-size: .96em;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.3;
}
.bd-brand-text small {
  font-size: .5em;
  color: var(--dim);
  letter-spacing: .06em;
  line-height: 1.5;
  white-space: nowrap;
}
.bd-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .3em;
  flex-shrink: 0;
}
.bd-tag {
  font-size: .54em;
  letter-spacing: .1em;
  color: var(--cyan);
  border: 1px solid rgba(143, 217, 255, .55);
  padding: .12em .45em;
}
.bd-glogo {
  width: 2.5em;
  height: auto;
  max-height: 2.5em;
  object-fit: contain;
  opacity: .95;
}

.bd-name-block {
  position: relative;
  z-index: 1;
  padding-top: .2em;
}
.bd-name {
  font-size: 2.45em;
  font-weight: 900;
  letter-spacing: .06em;
  line-height: 1.15;
  text-shadow: 0 0 18px rgba(77, 93, 240, .55);
}
.bd-name-en {
  font-size: .58em;
  letter-spacing: .12em;
  color: var(--dim);
  margin-top: .5em;
}

.bd-rows {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}
.bd-row {
  display: flex;
  align-items: baseline;
  gap: .8em;
  padding: .36em 0;
  border-bottom: 1px dashed rgba(143, 217, 255, .2);
}
.bd-row dt {
  flex-shrink: 0;
  width: 3.4em;
  font-size: .58em;
  letter-spacing: .12em;
  color: var(--dim);
}
.bd-row dd {
  font-size: .8em;
  color: var(--ice);
  letter-spacing: .04em;
  word-break: break-all;
}
.bd-row dd.mono { letter-spacing: .1em; }

.bd-note {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .6em;
  border-left: 3px solid var(--royal);
  padding: .1em 0 .1em .9em;
}
.bd-note p {
  font-size: .78em;
  line-height: 1.85;
  color: #E4E9FF;
}
.bd-note cite {
  font-style: normal;
  font-size: .54em;
  letter-spacing: .08em;
  color: var(--dim);
}

.bd-strip-foot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: .8em;
  padding-top: .55em;
  border-top: 1px solid rgba(143, 217, 255, .22);
  font-size: .54em;
  letter-spacing: .08em;
  color: var(--dim);
}
.bd-barcode {
  flex: 1;
  height: 1.9em;
  min-width: 0;
  background-repeat: repeat-x;
  background-size: 52px 100%;
  opacity: .85;
}

/* ---------- CTA ---------- */
.bd-cta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 40px;
}

/* 复制成功反馈（沿用主站 qq-copy「已复制 ✓」的语义） */
.btn-ghost.copied {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* CTA 下方的即时反馈行（生成中 / 已开始下载 / 长按保存 / 生成失败） */
.bd-cta-tip {
  min-height: 20px;
  margin-top: 14px;
  font-size: 12.5px;
  letter-spacing: .04em;
  color: var(--cyan);
  text-align: center;
}

.bd-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 保存工牌图片浮层（微信等不支持下载的内置浏览器的兜底） ---------- */
.bd-save {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(0, 4, 46, .94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}
.bd-save[hidden] { display: none; }
.bd-save-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 420px;
}
.bd-save-tip {
  font-size: 13px;
  line-height: 1.8;
  color: var(--cyan);
  text-align: center;
  letter-spacing: .04em;
}
.bd-save-img {
  width: min(84vw, 320px);
  height: auto;
  border: 1px solid var(--hair);
  box-shadow: 0 0 40px rgba(77, 93, 240, .35);
}
.bd-save-alt {
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--dim);
  text-align: center;
  letter-spacing: .04em;
}

.bd-page-foot {
  flex-shrink: 0;
  font-size: 12px;
  letter-spacing: .06em;
  color: #7C8AE0;
  text-align: center;
  padding: 26px 24px calc(26px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--hair);
  background: var(--deep);
}
.bd-page-foot span { display: block; }
.bd-foot-icp { margin-top: 6px; }

/* ==========================================================================
   预隐藏态：仅在「JS 已就绪且会播动画」时生效（html.motion-ready 由 badge.js 添加）
   动画结束保留内联终点态，不用 clearProps。
   ========================================================================== */
@media (prefers-reduced-motion: no-preference) {
  html.motion-ready .bd-card { opacity: 0; }
  html.motion-ready .bd-field { opacity: 0; }
  html.motion-ready .bd-letter { opacity: 0; }
  html.motion-ready .bd-cord { transform: scaleY(0); }
}

/* 降级：不加过渡，阶段切换瞬时完成（内容照常可见） */
@media (prefers-reduced-motion: reduce) {
  .bd-gate,
  .bd-letter { transition: none; }
}

/* ==========================================================================
   响应式
   ========================================================================== */
@media (max-width: 980px) {
  #bdMain { padding-top: calc(var(--header-h) + 40px); padding-bottom: 64px; }

  /* 手机：先读寄语 —— 卡面在「领取工牌」之前不参与布局 */
  .bd-stage:not(.is-claimed) .bd-ticket { display: none; }
  /* 领取后寄语脱流（只改 opacity 会继续占高度，把卡面顶出首屏） */
  .bd-stage.is-claimed .bd-letter {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    opacity: 0;
    transform: translateY(-14px);
    pointer-events: none;
  }
}

/* 桌面：寄语在左、工牌在右，两侧同时可见 → 不需要「领取工牌」这一拍 */
@media (min-width: 981px) {
  .bd-wrap { max-width: 1180px; }
  .bd-stage-grid {
    display: grid;
    grid-template-columns: minmax(0, 760px) auto;
    gap: 56px;
    align-items: start;
    justify-content: center;
  }
  /* 加宽 + 收紧竖向节奏：整封寄语在 768 高的首屏内读完，不用滚动 */
  .bd-letter { width: 100%; margin-top: 6px; }
  .bd-stage > .eyebrow { margin-bottom: 12px; }
  .bd-letter-body { padding: 16px 24px; }
  .bd-welcome { padding-bottom: 12px; margin-bottom: 14px; }
  .bd-letter-open { margin-bottom: 10px; }
  .bd-letter-body p:not(.bd-welcome):not(.bd-letter-open):not(.bd-letter-sign) {
    line-height: 1.88;
    margin-bottom: 10px;
  }
  .bd-letter-sign { margin-top: 12px; }
  /* 吊绳 64px − 寄语 margin 6px：卡面顶边与寄语框平齐 */
  .bd-ticket { margin-top: -58px; }
  .bd-claim { display: none; }
}

@media (max-width: 640px) {
  #bdMain { padding-top: calc(var(--header-h) + 28px); }
  .bd-console-body { padding: 20px 18px 18px; }
  .bd-field-row { flex-direction: column; }
  .bd-field-row .btn { width: 100%; }
  .bd-input { font-size: 16px; }   /* 防 iOS 聚焦整页缩放 */
  .bd-cord { height: 56px; }
  .bd-cta {
    margin-top: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .bd-cta .btn { width: 100%; padding: 12px 10px; font-size: 14px; }
  .bd-nav .nav-link[href="/exam/"] { display: block; }
}

@media (max-width: 400px) {
  .bd-card-box { width: min(292px, 88vw); }
}

/* ==========================================================================
   打印：只留工牌，按真实尺寸 54mm × 86mm 输出（A4 一页）
   ========================================================================== */
@page { size: A4; margin: 14mm; }
@media print {
  body.badge-page { background: #fff; display: block; }
  .topbar,
  .bd-gate,
  .bd-log,
  .bd-cta,
  .bd-page-foot,
  .bd-cord,
  .bd-nav,
  .bd-save,
  .bd-sr,
  .bd-letter,          /* 寄语不印在纸上 */
  .bd-claim,
  .bd-stage > .eyebrow { display: none !important; }

  #bdMain { padding: 0; display: block; }
  .bd-stage,
  .bd-stage-grid { display: block !important; }
  /* 打印时不受手机端「未领取则隐藏卡面」约束 */
  .bd-ticket { display: block !important; }
  .bd-card-box {
    width: 54mm;
    height: 86mm;
    aspect-ratio: auto;
  }
  .bd-card {
    width: 100%;
    height: 100%;
    border: 1px solid #000;
    box-shadow: none;
    transform: none !important;   /* 干掉屏幕上的环境摇摆，否则打印出歪卡 */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    break-inside: avoid;
  }
  .bd-holo { opacity: .3; }
  .bd-sheen { display: none; }
}
