:root {
  --color-background: #eef0f3;
  --color-surface: #f8f9fa;
  --color-surface-raised: #ffffff;
  --color-foreground: #20242b;
  --color-muted: #616a75;
  --color-border: #bcc3ca;
  --color-primary: #273a50;
  --color-primary-hover: #1d3046;
  --color-accent: #4c698a;
  --color-success: #376747;
  --color-error: #a63c3c;
  --color-ring: #405a79;
  --shadow-panel: 0 24px 64px rgba(33, 41, 52, 0.14);
  --shadow-preview: 0 20px 46px rgba(40, 48, 58, 0.2);
  --z-skip: 100;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--color-foreground);
  background:
    linear-gradient(rgba(76, 87, 101, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(76, 87, 101, 0.045) 1px, transparent 1px),
    var(--color-background);
  background-size: 32px 32px;
  font-family: "Avenir Next", "PingFang TC", "Noto Sans TC", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.6;
  overscroll-behavior-y: contain;
}

button,
input,
select {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button,
input,
label,
select {
  touch-action: manipulation;
}

.skip-link {
  position: fixed;
  z-index: var(--z-skip);
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: #fff;
  background: var(--color-primary);
  transform: translateY(-160%);
  transition: transform 180ms ease-out;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(85, 94, 105, 0.24);
}

.brand {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--color-foreground);
  border: 1px solid #0e1116;
  box-shadow: inset 0 0 0 3px #dfe2e6;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  letter-spacing: -0.05em;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 2px;
  color: var(--color-muted);
  font-size: 10px;
  letter-spacing: 0.22em;
}

.privacy-note {
  padding-left: 18px;
  color: var(--color-muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  position: relative;
}

.privacy-note::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c9175;
  transform: translateY(-50%);
  box-shadow: 0 0 0 4px rgba(108, 145, 117, 0.13);
}

.privacy-short {
  display: none;
}

.workspace {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 76px 0 88px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  align-items: end;
  gap: 44px;
  margin-bottom: 46px;
}

.eyebrow {
  grid-column: 1 / -1;
  margin: 0 0 -22px;
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.intro h1 {
  margin: 0;
  max-width: 780px;
  font-family: Georgia, "Noto Serif TC", "Songti TC", serif;
  font-size: clamp(44px, 5.8vw, 78px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.intro-copy {
  margin: 0 0 8px;
  color: var(--color-muted);
  font-size: 16px;
  line-height: 1.85;
}

.maker {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
  min-height: 760px;
  background: var(--color-surface);
  border: 1px solid rgba(74, 82, 92, 0.24);
  box-shadow: var(--shadow-panel);
}

.control-panel,
.preview-panel {
  padding: clamp(28px, 4vw, 54px);
}

.control-panel {
  border-right: 1px solid var(--color-border);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  margin-bottom: 22px;
}

.step-number {
  color: var(--color-accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  line-height: 24px;
}

.panel-heading h2,
.preview-heading h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif TC", "Songti TC", serif;
  font-size: 22px;
  font-weight: 400;
}

.panel-heading p {
  margin: 5px 0 0;
  color: var(--color-muted);
  font-size: 13px;
}

.upload-box {
  min-height: 112px;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--color-surface-raised);
  border: 1px dashed #9ca4ae;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-box:hover,
.upload-box:focus-within {
  background: #f1f4f7;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(64, 90, 121, 0.12);
}

.upload-box.is-dragging {
  background: #e8eef4;
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary), 0 0 0 4px rgba(64, 90, 121, 0.12);
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.upload-icon {
  width: 48px;
  height: 48px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  background: var(--color-primary);
}

.upload-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-box strong,
.upload-box small {
  display: block;
}

.upload-box strong {
  font-size: 16px;
  font-weight: 600;
}

.upload-box small {
  margin-top: 6px;
  color: var(--color-muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.batch-panel {
  margin-top: 16px;
  padding: 16px;
  background: #e9edf1;
  border: 1px solid #c2c9d0;
}

.batch-heading {
  margin-bottom: 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.batch-heading strong,
.batch-kicker {
  display: block;
}

.batch-heading strong {
  font-family: Georgia, "Noto Serif TC", "Songti TC", serif;
  font-size: 16px;
  font-weight: 400;
}

.batch-kicker {
  margin-bottom: 2px;
  color: var(--color-accent);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

#batch-count {
  color: var(--color-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.batch-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.batch-photo {
  position: relative;
  min-width: 0;
  padding: 4px;
  color: var(--color-foreground);
  background: #f9fafb;
  border: 1px solid #aeb6bf;
  cursor: pointer;
}

.batch-photo::after {
  content: attr(data-number);
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(32, 36, 43, 0.84);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.batch-photo img {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: block;
  object-fit: cover;
}

.batch-photo[aria-current="true"] {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}

.batch-photo:focus-visible,
.remove-photo-button:focus-visible,
.print-button:focus-visible {
  outline: 3px solid rgba(64, 90, 121, 0.35);
  outline-offset: 3px;
}

.remove-photo-button {
  min-height: 44px;
  margin-top: 10px;
  padding: 8px 0;
  color: #6c3333;
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  font-size: 12px;
  cursor: pointer;
}

.crop-controls {
  margin-top: 22px;
  padding: 18px 20px 14px;
  background: #eceff2;
  border-left: 2px solid var(--color-accent);
}

.mobile-live-preview {
  display: none;
}

.crop-controls label {
  display: grid;
  grid-template-columns: 88px minmax(100px, 1fr) 46px;
  align-items: center;
  gap: 10px;
  margin-bottom: 11px;
  color: #4f5863;
  font-size: 13px;
}

.crop-controls output {
  color: var(--color-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  min-height: 44px;
  accent-color: var(--color-primary);
}

.text-button {
  min-height: 44px;
  padding: 8px 0;
  color: var(--color-primary);
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  font-size: 13px;
  cursor: pointer;
}

.section-rule {
  margin: 38px 0 34px;
  border-top: 1px solid var(--color-border);
}

.member-lookup {
  margin-bottom: 24px;
  padding: 18px;
  background: #e9edf1;
  border: 1px solid #c6ccd3;
  border-top: 3px solid var(--color-primary);
}

.lookup-heading {
  margin-bottom: 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.lookup-heading strong {
  font-size: 14px;
}

.lookup-heading > span {
  flex: 0 0 auto;
  color: var(--color-muted);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.lookup-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.lookup-field {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.lookup-field > span {
  color: #505965;
  font-size: 12px;
  font-weight: 600;
}

.lookup-field select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 38px 0 12px;
  color: var(--color-foreground);
  background: #fff;
  border: 1px solid #b9c0c8;
  border-radius: 0;
  outline: none;
  font-size: 15px;
}

.lookup-field select:focus {
  border-color: var(--color-ring);
  box-shadow: 0 0 0 3px rgba(64, 90, 121, 0.12);
}

.lookup-field select:disabled {
  color: #8c949d;
  background: #f0f2f4;
  cursor: not-allowed;
}

.lookup-status {
  margin: 12px 0 0;
  color: var(--color-muted);
  font-size: 11px;
  line-height: 1.55;
}

.lookup-status[data-state="success"] {
  color: var(--color-success);
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span {
  color: #505965;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.field input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  color: var(--color-foreground);
  background: #fff;
  border: 1px solid #c6cbd1;
  border-radius: 0;
  outline: none;
  font-size: 16px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field input:focus {
  border-color: var(--color-ring);
  box-shadow: 0 0 0 3px rgba(64, 90, 121, 0.12);
}

.form-status {
  min-height: 48px;
  margin: 24px 0 0;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #4d5661;
  background: #eef1f4;
  border: 1px solid #d1d6dc;
  font-size: 13px;
  line-height: 1.6;
}

.status-mark {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.form-status[data-state="success"] {
  color: var(--color-success);
  background: #eef6f0;
  border-color: #b9d0c0;
}

.form-status[data-state="success"] .status-mark {
  background: currentColor;
  box-shadow: inset 0 0 0 2px #eef6f0;
}

.form-status[data-state="error"] {
  color: var(--color-error);
  background: #fbefef;
  border-color: #e2bcbc;
}

.preview-panel {
  position: relative;
  overflow: clip;
  background:
    radial-gradient(circle at 72% 12%, rgba(255, 255, 255, 0.82), transparent 34%),
    #dfe3e7;
}

.preview-inner {
  position: sticky;
  z-index: 1;
  top: 24px;
}

.preview-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(118deg, transparent 0 13px, rgba(255, 255, 255, 0.12) 13px 14px);
  mix-blend-mode: soft-light;
}

.preview-heading,
.card-stage,
.download-button,
.download-status,
.print-button,
.print-status {
  position: relative;
  z-index: 1;
}

.preview-heading {
  margin-bottom: 22px;
  display: flex;
  align-items: end;
  justify-content: space-between;
}

.preview-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--color-accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.size-badge {
  padding: 5px 8px;
  color: #6d747d;
  border: 1px solid #adb4bc;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
}

.card-stage {
  width: min(100%, 470px);
  margin: 0 auto;
  padding: 16px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(86, 95, 105, 0.27);
  box-shadow: var(--shadow-preview);
}

#card-canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #d6d8da;
}

.download-button,
.print-button {
  width: min(100%, 470px);
  min-height: 62px;
  margin: 20px auto 0;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  color: #fff;
  background: var(--color-primary);
  border: 1px solid #172331;
  cursor: pointer;
  transition: background 180ms ease-out, box-shadow 180ms ease-out, opacity 180ms ease-out;
}

.download-button:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: 0 8px 18px rgba(39, 58, 80, 0.24);
}

.print-button {
  margin-top: 10px;
  color: var(--color-primary);
  background: rgba(255, 255, 255, 0.72);
  border-color: #8e99a5;
}

.print-button:hover:not(:disabled) {
  background: #fff;
  box-shadow: 0 8px 18px rgba(39, 58, 80, 0.14);
}

.download-button:active:not(:disabled) {
  background: #17283a;
}

.download-button:focus-visible,
.print-button:focus-visible,
.text-button:focus-visible,
.brand:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid rgba(64, 90, 121, 0.35);
  outline-offset: 3px;
}

.download-button:disabled {
  color: #a2a7ae;
  background: #d2d5d9;
  border-color: #bec3c9;
  cursor: not-allowed;
  opacity: 0.72;
}

.print-button:disabled {
  color: #9299a2;
  background: rgba(218, 222, 226, 0.82);
  border-color: #bec3c9;
  cursor: not-allowed;
  opacity: 0.72;
}

.download-button svg,
.print-button svg {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.download-copy {
  display: grid;
  gap: 1px;
  text-align: left;
}

.download-button strong,
.print-button strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.download-button small,
.print-button small {
  font-size: 10px;
  letter-spacing: 0.1em;
  opacity: 0.74;
}

.download-status {
  min-height: 24px;
  margin: 8px auto 0;
  color: var(--color-success);
  font-size: 12px;
  text-align: center;
}

.print-status {
  min-height: 24px;
  margin: 8px auto 0;
  color: var(--color-success);
  font-size: 12px;
  text-align: center;
}

.print-sheet {
  display: none;
}

footer {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 38px;
  display: flex;
  justify-content: space-between;
  color: #5e6772;
  border-top: 1px solid rgba(85, 94, 105, 0.24);
  font-size: 12px;
  letter-spacing: 0.08em;
}

footer p {
  margin: 0;
}

.credit {
  opacity: 0.55;
}

@media (max-width: 880px) {
  .workspace {
    padding-top: 52px;
  }

  .intro {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .eyebrow {
    margin-bottom: -4px;
  }

  .intro-copy {
    max-width: 600px;
  }

  .maker {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }

  .preview-inner {
    position: static;
  }
}

@media (max-width: 560px) {
  .site-header,
  .workspace,
  footer {
    width: min(100% - 28px, 1280px);
  }

  .site-header {
    padding-top: 18px;
  }

  .privacy-note {
    width: auto;
    font-size: 12px;
    line-height: 1.45;
  }

  .privacy-full {
    display: none;
  }

  .privacy-short {
    display: inline;
  }

  .workspace {
    padding: 42px 0 58px;
  }

  .intro {
    margin-bottom: 30px;
  }

  .intro h1 {
    font-size: 40px;
    line-height: 1.12;
  }

  .intro-copy {
    font-size: 16px;
  }

  .control-panel,
  .preview-panel {
    padding: 26px 20px;
  }

  .mobile-live-preview {
    margin: 0 0 20px;
    padding-bottom: 20px;
    display: block;
    border-bottom: 1px solid #c7cdd4;
  }

  .mobile-live-heading {
    margin-bottom: 12px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .mobile-live-heading strong {
    color: var(--color-foreground);
    font-family: Georgia, "Noto Serif TC", "Songti TC", serif;
    font-size: 17px;
    font-weight: 400;
  }

  .mobile-live-heading span {
    color: var(--color-muted);
    font-size: 11px;
  }

  .mobile-card-stage {
    width: min(100%, 264px);
    margin: 0 auto;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(86, 95, 105, 0.27);
    box-shadow: 0 12px 28px rgba(40, 48, 58, 0.18);
  }

  #mobile-card-canvas {
    width: 100%;
    height: auto;
    display: block;
    background: #d6d8da;
  }

  .preview-panel .preview-heading,
  .preview-panel .card-stage {
    display: none;
  }

  .preview-panel {
    padding-top: 0;
  }

  .fields {
    grid-template-columns: 1fr;
  }

  .lookup-fields {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .download-button {
    margin-top: 0;
    align-items: center;
  }

  .print-button {
    align-items: center;
  }

  .batch-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  footer {
    gap: 12px;
    flex-direction: column;
  }
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  body {
    background: #fff !important;
  }

  body > :not(.print-sheet) {
    display: none !important;
  }

  .print-sheet {
    width: 186mm;
    margin: 0 auto;
    display: grid !important;
    grid-template-columns: repeat(3, 54mm);
    grid-auto-rows: 72mm;
    justify-content: center;
    align-content: start;
    gap: 7mm 6mm;
  }

  .print-card {
    width: 54mm;
    height: 72mm;
    position: relative;
    break-inside: avoid;
    page-break-inside: avoid;
    outline: 0.2mm dashed #777;
    outline-offset: 1mm;
  }

  .print-card img {
    width: 100%;
    height: 100%;
    display: block;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

@media (max-width: 390px) {
  .site-header,
  .workspace,
  footer {
    width: min(100% - 24px, 1280px);
  }

  .intro h1 {
    font-size: 36px;
  }

  .control-panel,
  .preview-panel {
    padding-inline: 16px;
  }

  .crop-controls {
    padding-inline: 14px;
  }

  .crop-controls label {
    grid-template-columns: 78px minmax(90px, 1fr) 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
