:root {
  color-scheme: light;
  --paper: #faf9f6;
  --surface: #fffefa;
  --ink: #302c29;
  --muted: #746c66;
  --line: #675c53;
  --accent: #a32c25;
  --accent-hover: #87231e;
  --error: #a12b24;
  --radius: 12px 9px 14px 10px;
  --font: WenKai, 'Kaiti SC', 'STKaiti', serif;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, a { -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, input, a { touch-action: manipulation; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 5px;
}
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.workspace {
  max-width: 1120px;
  min-height: 100svh;
  margin: auto;
  padding: 48px 40px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  align-items: center;
  gap: 96px;
}
.editor { padding-bottom: 24px; }
h1 { font-size: 36px; font-weight: 400; line-height: 1.4; margin: 0 0 48px; }
.fields { display: grid; gap: 28px; }
.field { min-width: 0; }
label { display: block; margin-bottom: 12px; font-size: 18px; line-height: 24px; }
.optional { color: var(--muted); font-size: 16px; }
input {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--surface);
  color: var(--ink);
  font-size: 18px;
  line-height: 24px;
  box-shadow: 2px 2px 0 #e4dfd8;
  transition: border-color 160ms, box-shadow 160ms;
}
input:hover { border-color: var(--ink); }
input:focus { border-color: var(--accent); box-shadow: 2px 2px 0 #e6c7bf; }
input[aria-invalid='true'] { border-color: var(--error); }
.field-error { margin: 8px 0 0; font-size: 15px; line-height: 1.6; color: var(--error); }
.actions { margin-top: 40px; }
.download-button {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 20px;
  border: 1.5px solid #78251e;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fffefa;
  box-shadow: 3px 4px 0 #d8c7bd;
  font-size: 19px;
  transition: background 160ms, transform 160ms, box-shadow 160ms;
}
.download-button:not(:disabled):hover { background: var(--accent-hover); }
.download-button:not(:disabled):active { transform: translate(1px, 2px); box-shadow: 2px 2px 0 #d8c7bd; }
.download-button:disabled { background: #e7e2dd; border-color: #c3b9b0; color: #79716b; box-shadow: 2px 2px 0 #e2dbd4; }
.status { color: var(--error); font-size: 15px; line-height: 1.6; margin: 12px 0 0; }
.text-button { min-height: 44px; padding: 8px 0; border: 0; background: none; color: var(--accent); text-decoration: underline; text-underline-offset: 4px; font-size: 16px; }
.preview { display: flex; align-items: center; justify-content: center; min-width: 0; }
.poster-frame {
  display: block;
  padding: 8px;
  max-width: 100%;
  width: min(100%, 544px, calc((100svh - 112px) * .75));
  min-width: 0;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 5px 3px 6px 4px;
  box-shadow: 5px 6px 0 #ded8cf;
  cursor: zoom-in;
}
.poster-frame:disabled { cursor: default; }
.poster-frame canvas { display: block; width: 100%; height: auto; background: center / cover url('assets/invitation-template.png'); }
body:has(dialog[open]) { overflow: hidden; }
dialog {
  max-width: min(940px, calc(100vw - 48px));
  max-height: calc(100svh - 48px);
  padding: 0 20px 20px;
  border: 1.5px solid var(--line);
  border-radius: 14px 10px 16px 12px;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(35 27 23 / 65%); }
.dialog-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; background: var(--paper); padding: 8px 0; gap: 24px; }
h2 { font-size: 20px; font-weight: 400; margin: 0; }
.close-button { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
#fullImage { display: block; width: 100%; height: auto; -webkit-touch-callout: default; user-select: auto; }
.save-hint { font-size: 16px; margin: 0 0 12px; }
.fallback-download { display: flex; align-items: center; justify-content: center; min-height: 48px; margin-top: 16px; color: var(--accent); text-underline-offset: 4px; font-size: 18px; }
.noscript { position: fixed; inset: 0; margin: 0; display: grid; place-items: center; background: var(--paper); }

@media (max-width: 760px), (max-width: 1000px) and (max-height: 600px) {
  .workspace { display: flex; flex-direction: column; align-items: stretch; gap: 28px; min-height: 100svh; max-width: 560px; padding: 24px 20px calc(116px + env(safe-area-inset-bottom)); }
  .editor { padding: 0; }
  h1 { font-size: 28px; margin-bottom: 24px; }
  .fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
  label { font-size: 17px; margin-bottom: 8px; }
  .optional { font-size: 14px; }
  input { min-height: 48px; font-size: 16px; padding: 10px 12px; }
  .actions { position: fixed; z-index: 2; bottom: 0; left: 0; right: 0; margin: 0; padding: 12px max(20px, calc((100vw - 520px) / 2)) calc(16px + env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid #dfd9d2; }
  .download-button { min-height: 52px; font-size: 18px; }
  .poster-frame { width: 100%; max-width: 480px; padding: 6px; box-shadow: 3px 4px 0 #ded8cf; }
  .field-error { font-size: 14px; }
  .status { margin-top: 8px; }
  .keyboard-open .actions { position: static; padding: 0; border: 0; margin-top: 20px; }
  dialog { width: calc(100vw - 24px); max-width: 560px; max-height: calc(100svh - 24px); padding: 0 12px 12px; }
}
@media (max-width: 350px) {
  .workspace { padding-left: 16px; padding-right: 16px; }
  .fields { gap: 12px; }
  .optional { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
