* { box-sizing: border-box; }

/* 英文介面：Arial；繁中介面：楷書 */
html[lang="en"] .theme-ancient,
html[lang="en"] .theme-ancient input,
html[lang="en"] .theme-ancient select,
html[lang="en"] .theme-ancient textarea,
html[lang="en"] .theme-ancient button {
  font-family: Arial, Helvetica, "Segoe UI", "Microsoft YaHei", sans-serif;
}

html[lang="zh-Hant"] .theme-ancient,
html[lang="zh-Hant"] .theme-ancient input,
html[lang="zh-Hant"] .theme-ancient select,
html[lang="zh-Hant"] .theme-ancient textarea,
html[lang="zh-Hant"] .theme-ancient button {
  font-family: "KaiTi", "BiauKai", "DFKai-SB", "標楷體", "STKaiti", "华文楷体", "Iowan Old Style", "Songti SC", "Noto Serif TC", Georgia, serif;
}

body.theme-ancient {
  margin: 0;
  background: #e8dfd0
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='%23c4b59c' fill-opacity='0.12'%3E%3Cpath d='M0 0h40v40H0zm40 40h40v40H40z'/%3E%3C/g%3E%3C/svg%3E");
  color: #2c2416;
  min-height: 100vh;
}

.wrap {
  max-width: 920px;
  margin: 28px auto;
  padding: 0 14px;
}

.card-ancient {
  background: linear-gradient(165deg, #faf6ee 0%, #f3eadc 100%);
  border: 2px solid #8b7355;
  border-radius: 4px;
  padding: 52px 20px 18px;
  box-shadow: 0 4px 24px rgba(60, 40, 20, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  position: relative;
}

.card-ancient::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(139, 115, 85, 0.35);
  border-radius: 2px;
  pointer-events: none;
}

.form-title {
  margin: 0 0 18px;
  padding-top: 4px;
  font-size: 1.55rem;
  font-weight: 700;
  color: #4a3020;
  text-align: center;
  letter-spacing: 0.12em;
  line-height: 1.45;
  border-bottom: 2px solid #a67c52;
  padding-bottom: 14px;
}

.section-title {
  margin: 16px 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: #5c3d2e;
  letter-spacing: 0.08em;
  border-left: 4px solid #8b2500;
  padding-left: 10px;
}

.section-hint {
  margin: 0 0 10px;
  padding: 10px 12px;
  background: rgba(255, 248, 235, 0.85);
  border: 1px solid #c9b896;
  border-radius: 4px;
  font-size: 13px;
  color: #4a3f32;
  line-height: 1.6;
}

.label-tip {
  display: block;
  font-size: 12px;
  font-weight: normal;
  color: #6b5c4a;
  line-height: 1.4;
  margin-top: -2px;
}

.label-main {
  font-weight: 600;
  color: #4a3020;
}

.hint {
  margin: -2px 0 0;
  color: #5c4d3d;
  font-size: 12px;
  line-height: 1.45;
}
.hint.warn {
  color: #8b2500;
}

.preview-tip {
  margin: 0 0 10px;
  font-size: 12px;
  color: #5c4d3d;
  line-height: 1.45;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  /* 同列多欄時標籤／說明行數不同，改以「控制項底邊」對齊 */
  align-items: end;
}

/* 整列跨欄區塊維持由上往下排，勿沉到列底 */
.grid > .full {
  align-self: stretch;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #3d3228;
  min-width: 0;
}

/* 單行文字框與下拉高度一致（含英文介面） */
#collectForm input[type="text"],
#collectForm input[type="tel"],
#collectForm select {
  min-height: 2.75rem;
  line-height: 1.35;
}

#collectForm select {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.date-row {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: flex-end;
  overflow: visible;
}
.date-row > label {
  min-width: 0;
  flex: 1 1 0;
  gap: 4px;
  font-size: 12px;
}
/* 閏月勾選勿與年月日欄一樣拉寬，否則方框與文字會被撐開 */
.date-row > label.checkbox-inline {
  flex: 0 0 auto;
}
.date-row > label > select,
.date-row > label > input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.date-row input,
.date-row select {
  padding: 7px 6px;
  font-size: 12px;
}
.date-row .checkbox-inline {
  flex: 0 0 auto;
  align-self: flex-end;
  padding-top: 0;
  margin-bottom: 2px;
  font-size: 12px;
  min-width: 0;
}

/* 勾選列：方框與文字緊貼，勿拉滿整列造成「中間一大段空白」 */
label.checkbox-inline {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  flex-wrap: nowrap;
  cursor: pointer;
}

label.checkbox-inline input[type="checkbox"] {
  flex-shrink: 0;
  margin: 0;
  width: 1.05rem;
  height: 1.05rem;
}

label.checkbox-inline span {
  flex: 0 1 auto;
  line-height: 1.35;
  word-break: keep-all;
}

.checkbox-inline {
  padding-top: 24px;
}

/* 窄螢幕：日期改直向排列，避免擠壓裁字、標籤高低不一 */
@media (max-width: 640px) {
  .date-row {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
  }
  .date-row > label:not(.checkbox-inline) {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
  }
  .date-row .checkbox-inline {
    width: fit-content;
    max-width: 100%;
    margin-bottom: 0;
    padding-top: 0;
    align-self: flex-start;
  }
  .checkbox-inline {
    padding-top: 0;
  }
}

input,
select,
textarea,
button {
  border: 1px solid #a69076;
  border-radius: 4px;
  padding: 9px 10px;
  font-size: 14px;
  background: rgba(255, 252, 245, 0.95);
  color: #2c2416;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #8b2500;
  box-shadow: 0 0 0 2px rgba(139, 37, 0, 0.15);
}

.full {
  grid-column: 1 / -1;
}

button {
  background: #f5ebe0;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  color: #6b5c4a;
}

.primary {
  background: linear-gradient(180deg, #7a3e2e 0%, #5c2e22 100%);
  color: #fffaf3;
  border-color: #4a2519;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.primary:hover {
  filter: brightness(1.05);
}

.spouse-item {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  border: 1px dashed #9a8268;
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 10px;
  background: rgba(255, 250, 240, 0.5);
  align-items: end;
}

.spouse-item > .full,
.spouse-item > .spouse-photo-row,
.spouse-item > .spouse-item-title {
  align-self: stretch;
}

.spouse-item input:not([type="checkbox"]):not([type="file"]),
.spouse-item select {
  min-height: 2.75rem;
  line-height: 1.35;
}

.spouse-item select {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.spouse-item-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: #5c3d2e;
  letter-spacing: 0.06em;
}

.spouse-residence-wrap {
  margin-top: 2px;
}

/* 隱藏原生 file，改由按鈕觸發 */
.sr-only-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  max-width: 100%;
}

.photo-actions .photo-action-btn {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 8px 12px;
  font-size: 13px;
}

.spouse-photo-actions {
  margin-top: 6px;
}

.spouse-photo-actions .photo-action-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 120px;
}

/* 照片 */
.photo-block {
  padding: 12px 14px;
  background: rgba(255, 248, 235, 0.7);
  border: 1px solid #c9b896;
  border-radius: 4px;
  overflow: hidden;
  max-width: 100%;
}
.photo-block-self .label-main {
  display: block;
  margin-bottom: 4px;
}
.photo-preview-wrap {
  margin-top: 10px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.photo-preview-wrap img,
.spouse-photo-thumb {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border: 2px solid #8b7355;
  border-radius: 4px;
  background: #e8dfd0;
}
.photo-clear-btn {
  font-size: 13px;
  padding: 6px 12px;
  background: #f0e6d8;
  border-color: #a69076;
}
.spouse-photo-row {
  grid-column: 1 / -1;
  padding: 8px 0 4px;
  border-top: 1px dashed #c9b896;
  margin-top: 4px;
}
.spouse-photo-row .label-tip {
  margin-bottom: 6px;
}
.spouse-photo-preview {
  margin-top: 8px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.msg {
  min-height: 20px;
  margin: 0;
  color: #5a4a32;
}
.hidden {
  display: none !important;
}

.preview {
  margin-top: 10px;
}
.preview h3 {
  margin: 0 0 8px;
  color: #5c3d2e;
  font-size: 1.1rem;
}

.preview-body {
  margin: 12px 0 0;
  max-height: min(60vh, 420px);
  overflow: auto;
  background: #faf6ef;
  color: #3d3228;
  border-radius: 4px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
  border: 1px solid #c9b896;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.preview-section {
  font-weight: 600;
  color: #5c3d2e;
  margin-top: 0.35em;
  font-size: 15px;
}
.preview-spacer {
  height: 0.65em;
}
.preview-line {
  margin: 0.15em 0;
  white-space: pre-wrap;
}
.preview-inline-photo {
  display: block;
  max-width: 100%;
  max-height: 220px;
  width: auto;
  height: auto;
  margin: 6px 0 12px;
  border-radius: 6px;
  border: 1px solid #c9b896;
  object-fit: contain;
}

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

.link-btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  border: 1px solid #a69076;
  border-radius: 4px;
  padding: 10px 12px;
  color: #4a3020;
  background: #f5ebe0;
}
.link-btn:hover {
  background: #ebe0d0;
}

.site-footer {
  margin-top: 22px;
  padding: 14px 8px 6px;
  border-top: 1px solid #c9b896;
  font-size: 13px;
  color: #6b5c4a;
  text-align: center;
  line-height: 1.6;
  letter-spacing: 0.06em;
}

.lang-bar {
  position: absolute;
  top: 10px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 3;
}

.lang-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #9a8268;
  background: #faf6ee;
  color: #4a3020;
  cursor: pointer;
}

.lang-btn:hover {
  background: #f0e8dc;
}

.lang-btn.lang-active {
  font-weight: 700;
  border-color: #8b2500;
  color: #6b1a00;
  box-shadow: inset 0 0 0 1px rgba(139, 37, 0, 0.2);
}

#addSpouseBtn {
  background: #ebe0d0;
  border-color: #9a8268;
}
