:root {
  --paper: #f5eee2;
  --paper-deep: #ebe2d2;
  --ink: #2c3d5e;
  --ink-soft: #566076;
  --dress: #8aa8c2;
  --dress-wash: #dfe6ea;
  --wall: #bbab9a;
  --line: #8e7f6e;
  --leaf: #6c7340;
  --error: #9a3b2e;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --latin: "Cormorant Garamond", "Noto Serif TC", "Songti TC", serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--wall) var(--paper);
}

body {
  margin: 0;
  background: var(--paper) url("img/paper.jpg") repeat;
  background-size: 180px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.8;
  caret-color: var(--ink);
}

::selection { background: var(--dress); color: #16233b; }

a { color: inherit; text-decoration-color: var(--wall); text-underline-offset: 0.3em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--ink); }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }

.invitation { display: block; }

.nb { white-space: nowrap; }

/* 插畫就是紙本身：邊緣淡出，和頁面的紙張紋理接在一起 */
.portrait { margin: 0; }
.portrait img {
  display: block;
  width: 100%;
  height: auto;
  -webkit-mask-image: linear-gradient(to bottom, #000 93%, transparent);
  mask-image: linear-gradient(to bottom, #000 93%, transparent);
  animation: bloom 1.4s var(--ease-out) both;
}

@keyframes bloom {
  from { opacity: 0.6; filter: blur(4px); }
  to { opacity: 1; filter: blur(0); }
}

.letter {
  width: min(100%, 34rem);
  margin: 0 auto;
  padding: 0.5rem 1.5rem calc(3rem + env(safe-area-inset-bottom));
}

.names h1 {
  margin: 0;
  font-size: clamp(2rem, 9vw, 2.75rem);
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.amp {
  font-family: var(--latin);
  font-style: italic;
  font-weight: 400;
  color: var(--dress);
  padding: 0 0.04em;
}

.lede { margin: 1rem 0 0; color: var(--ink-soft); }

.details { margin-top: 3rem; }

.date {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-family: var(--latin);
  font-size: clamp(3rem, 15vw, 4.25rem);
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: lining-nums;
}
.date span { font-family: var(--serif); font-size: 1.0625rem; letter-spacing: 0.1em; color: var(--ink-soft); }

.times { display: flex; gap: 2.5rem; margin: 1.5rem 0 0; }
.times div { display: flex; align-items: baseline; gap: 0.6rem; }
.times dt { color: var(--ink-soft); font-size: 0.9375rem; letter-spacing: 0.1em; }
.times dd { margin: 0; font-family: var(--latin); font-size: 1.875rem; line-height: 1.2; font-variant-numeric: lining-nums; }

address { margin-top: 1.5rem; font-style: normal; color: var(--ink-soft); }
address strong { color: var(--ink); font-weight: 600; }

.links { list-style: none; margin: 1.25rem 0 0; padding: 0; }
.links li { border-top: 1px solid rgba(187, 171, 154, 0.65); }
.links li:last-child { border-bottom: 1px solid rgba(187, 171, 154, 0.65); }
.links a {
  display: block;
  padding: 0.7rem 0;
  text-decoration: none;
  transition: padding-left 0.3s var(--ease-out);
}
.links a:hover { padding-left: 0.4rem; }

.rsvp { margin-top: 4.5rem; scroll-margin-top: 1.5rem; }
.rsvp h2 { margin: 0; font-size: 1.75rem; font-weight: 500; letter-spacing: 0.08em; line-height: 1.4; }
.deadline { margin: 0.4rem 0 0; color: var(--ink-soft); }

form { margin-top: 2rem; }

.field { margin: 0 0 1.75rem; padding: 0; border: 0; min-width: 0; }

legend, .field > label { display: block; padding: 0; margin-bottom: 0.5rem; font-weight: 500; }
.field small, .stepper-label small { font-size: 0.875rem; font-weight: 400; color: var(--ink-soft); }
.hint { margin: -0.3rem 0 0.5rem; font-size: 0.9375rem; line-height: 1.6; color: var(--ink-soft); }

input[type="text"], textarea {
  display: block;
  width: 100%;
  padding: 0.65rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  /* 16px 以上，iOS 點輸入框時才不會自動放大 */
  font-size: 1.0625rem;
  transition: border-color 0.2s;
  appearance: none;
}
textarea { resize: vertical; line-height: 1.7; }
input[type="text"]:hover, textarea:hover { border-bottom-color: var(--ink); }
input[type="text"]:focus-visible, textarea:focus-visible {
  outline: none;
  border-bottom-color: var(--ink);
  box-shadow: 0 1px 0 var(--ink);
}

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 0.625rem; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.choice span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  text-align: center;
  line-height: 1.4;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.choice:hover span { border-color: var(--ink); background: rgba(138, 168, 194, 0.14); }
.choice input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.choice input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }

.party {
  margin: -0.25rem 0 1.75rem;
  border-top: 1px solid rgba(187, 171, 154, 0.65);
}
.party[hidden] { display: none; }
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(187, 171, 154, 0.65);
}
.stepper-row[hidden] { display: none; }
.stepper-label { display: flex; flex-direction: column; line-height: 1.45; font-weight: 500; }
.stepper { display: flex; align-items: center; flex: none; }
.stepper button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  touch-action: manipulation;
}
.stepper button svg { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.stepper button:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.stepper button:disabled { opacity: 0.35; cursor: not-allowed; }
.stepper input {
  width: 2.75rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--latin);
  font-size: 1.625rem;
  font-variant-numeric: lining-nums tabular-nums;
  text-align: center;
  padding: 0;
  outline: none;
}

.error { margin: 0.45rem 0 0; color: var(--error); font-size: 0.9375rem; }
.field.invalid input[type="text"] { border-bottom-color: var(--error); }
.field.invalid .choice span { border-color: var(--error); }

.trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-error {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: rgba(154, 59, 46, 0.09);
  color: var(--error);
  border-radius: 3px;
  line-height: 1.65;
  font-size: 0.9375rem;
}

.form-error.note { background: rgba(138, 168, 194, 0.18); color: var(--ink); }

.submit {
  display: block;
  width: 100%;
  min-height: 3.5rem;
  border: 1px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 500;
  letter-spacing: 0.2em;
  cursor: pointer;
  transition: background-color 0.2s, box-shadow 0.3s var(--ease-out);
  touch-action: manipulation;
}
.submit:hover:not(:disabled) { background: #1f2e4c; box-shadow: 0 6px 16px rgba(44, 61, 94, 0.22); }
.submit:disabled { opacity: 0.65; cursor: progress; }

.thanks { margin-top: 2rem; padding: 2rem 0; border-top: 1px solid var(--wall); border-bottom: 1px solid var(--wall); outline: none; }
.thanks[hidden] { display: none; }
.thanks-title { margin: 0 0 0.5rem; font-size: 1.5rem; font-weight: 500; line-height: 1.5; }
.thanks p:not(.thanks-title) { margin: 0; color: var(--ink-soft); overflow-wrap: anywhere; }
.edit {
  margin-top: 1.25rem;
  padding: 0.5rem 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--wall);
  text-underline-offset: 0.3em;
  cursor: pointer;
}
.edit:hover { text-decoration-color: var(--ink); }

.signoff { margin-top: 4rem; text-align: center; color: var(--ink-soft); letter-spacing: 0.08em; font-size: 0.9375rem; }
.signoff .amp { font-size: 1.1em; }

/* 電腦版：像攤開的對開卡片，左頁插畫固定，右頁可捲動 */
@media (min-width: 960px) {
  .invitation {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(30rem, 1fr);
    max-width: 1500px;
    margin: 0 auto;
  }
  .portrait {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  .portrait picture { display: contents; }
  .portrait img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    -webkit-mask-image: none;
    mask-image: none;
  }
  .letter {
    width: min(100%, 32rem);
    margin: 0;
    padding: clamp(3rem, 11vh, 7rem) 3rem 4rem clamp(2.5rem, 5vw, 5rem);
  }
  .names h1 { font-size: 2.875rem; }
  .date { font-size: 4.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .portrait img { animation: none; }
  * { transition: none !important; }
}
