/* iOS Safari 不支持 .ttc 的 @font-face，需用从 TTC 拆出的 .ttf（见 font/simsun.ttf） */
@font-face {
  font-family: "SongtiTC";
  src: url("font/simsun.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #12121a;
  color: #e8e6e3;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* 上方：邀请函完整可见，按宽度适配、限制高度避免遮挡下方控件 */
.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 12px 8px;
  padding-top: max(12px, env(safe-area-inset-top));
}

.stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  /* 用 svh 替代 dvh：滚动时动态视口变化会导致预览图忽大忽小，姓名百分比定位看起来「偏移」 */
  max-height: min(68vh, calc(100vh - 280px));
  line-height: 0;
}

.invite-img {
  display: block;
  max-width: 100%;
  max-height: min(68vh, calc(100vh - 280px));
  width: auto;
  height: auto;
  object-fit: contain;
  vertical-align: top;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

@supports (height: 1svh) {
  .stage {
    max-height: min(68svh, calc(100svh - 280px));
  }

  .invite-img {
    max-height: min(68svh, calc(100svh - 280px));
  }
}

.name-layer {
  position: absolute;
  /* 整行左缘锚定：尊敬的 + 姓名 + 称谓 作为一行 flex 排版 */
  left: var(--name-x, 16%);
  top: var(--name-y, 47.84%);
  transform: translateY(-50%);
  z-index: 2;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  max-width: 86%;
  text-align: left;
  /* 覆盖 .stage 的 line-height:0，避免姓名行盒高度为 0 导致看不见或 seemingly 不更新 */
  line-height: 1.35;
  --name-font-stack: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --name-font-weight: 400;
  -webkit-user-select: none;
  user-select: none;
}

.name-layer.is-dragging {
  cursor: grabbing;
}

.name-line {
  display: inline-flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-start;
  flex-wrap: nowrap;
  /* 以姓名字号为基准，前缀/姓名/称谓之间等距 */
  font-size: var(--name-size, 24px);
  gap: 0.38em;
  max-width: 100%;
  white-space: nowrap;
  line-height: 1;
}

.name-prefix,
.name-suffix {
  flex: 0 0 auto;
  font-size: var(--salutation-size, 13px);
  font-family: "SongtiTC", "Songti SC", STSong, serif;
  font-weight: 400;
  color: #3a3a3a;
  letter-spacing: 0.02em;
  white-space: nowrap;
  line-height: 1;
}

.name-text {
  display: inline-block;
  flex: 0 1 auto;
  font-size: var(--name-size, 24px);
  font-family: var(--name-font-stack);
  font-weight: var(--name-font-weight);
  color: #d4af37;
  letter-spacing: 0.06em;
  word-break: keep-all;
  white-space: nowrap;
  text-align: left;
  line-height: 1;
  /* 书法字体字框偏高，微调后与前后缀同一视觉基线 */
  transform: translateY(0.1em);
}

.panel {
  flex: 0 0 auto;
  position: relative;
  z-index: 10;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #1e1e2a 0%, #16161f 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.panel-title {
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

/* 编辑区：姓名 + 称谓同一行（移动端优先） */
.field-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}

.field-row .field {
  margin-bottom: 0;
}

.field-row-name {
  flex: 1 1 0;
  min-width: 0;
}

.field-row-honorific {
  flex: 0 0 auto;
  width: min(34vw, 132px);
}

.field-row-honorific .select {
  width: 100%;
}

.field-label {
  font-size: 0.8rem;
  color: #9a97af;
}

.input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #f5f3f0;
}

.input::placeholder {
  color: #6b6778;
}

.input:focus {
  outline: none;
  border-color: #7c6cf0;
  box-shadow: 0 0 0 2px rgba(124, 108, 240, 0.25);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239a97af' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

.row2 {
  display: flex;
  gap: 12px;
}

.row2 .grow {
  flex: 1;
  margin-bottom: 14px;
}

.range {
  width: 100%;
  height: 36px;
  accent-color: #7c6cf0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1 1 calc(50% - 5px);
  min-width: 120px;
  padding: 13px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #e8e6e3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(135deg, #6b5ce7, #8b7cf0);
  border-color: transparent;
  color: #fff;
}

.hint {
  margin: 14px 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #6d6a7d;
}

.hint code {
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.drag-hint {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #9a97af;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.drag-hint strong {
  color: #cfcae3;
  font-weight: 600;
}

output {
  font-variant-numeric: tabular-nums;
}

/* 生成结果全屏查看 */
.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.result-overlay[hidden] {
  display: none !important;
}

.result-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.result-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #252532 0%, #1a1a24 100%);
  border-radius: 16px 16px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: none;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.result-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.result-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #e8e6e3;
}

.result-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #c8c4dc;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}

.result-close:active {
  background: rgba(255, 255, 255, 0.14);
}

.result-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  text-align: center;
}

.result-image {
  display: inline-block;
  max-width: 100%;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  vertical-align: top;
}

.result-foot {
  flex: 0 0 auto;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.result-tip {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #9a97af;
  text-align: center;
}
