* { box-sizing: border-box; }

@font-face {
  font-family: 'Marck Script';
  src: url('MarckScript-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --page-bg: #fbf3ec;
  --panel-bg: #ffffff;
  --ink: #3a2d2a;
  --ink-soft: #8a7771;
  --muted: #8a7771;
  --page-bg: #fbf3ec;
  --page-glow1: radial-gradient(900px 500px at 85% -10%, #ffe3d3 0%, rgba(255, 227, 211, 0) 60%);
  --page-glow2: radial-gradient(700px 420px at -10% 110%, #ffe9f0 0%, rgba(255, 233, 240, 0) 55%);
  --line: #eedfd4;
  --accent: #e0665a;
  --accent-dark: #c94f43;
  --shadow: 0 18px 40px -18px rgba(120, 70, 50, 0.35);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--page-glow1), var(--page-glow2), var(--page-bg);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
}

body[data-bg="rose"] {
  --page-bg: #fdf0f3;
  --page-glow1: radial-gradient(900px 500px at 85% -10%, #ffd9e2 0%, rgba(255, 217, 226, 0) 60%);
  --page-glow2: radial-gradient(700px 420px at -10% 110%, #ffc4d4 0%, rgba(255, 196, 212, 0) 55%);
}

body[data-bg="mint"] {
  --page-bg: #eefbf3;
  --page-glow1: radial-gradient(900px 500px at 85% -10%, #d0f2de 0%, rgba(208, 242, 222, 0) 60%);
  --page-glow2: radial-gradient(700px 420px at -10% 110%, #c3edd7 0%, rgba(195, 237, 215, 0) 55%);
}

body[data-bg="violet"] {
  --page-bg: #f5f2fd;
  --page-glow1: radial-gradient(900px 500px at 85% -10%, #e2d9f8 0%, rgba(226, 217, 248, 0) 60%);
  --page-glow2: radial-gradient(700px 420px at -10% 110%, #d6c9f5 0%, rgba(214, 201, 245, 0) 55%);
}

body[data-bg="dark"] {
  --page-bg: linear-gradient(160deg, #262230, #191622);
  --page-glow1: radial-gradient(900px 500px at 85% -10%, rgba(122, 92, 168, 0.35) 0%, rgba(122, 92, 168, 0) 60%);
  --page-glow2: radial-gradient(700px 420px at -10% 110%, rgba(224, 102, 90, 0.22) 0%, rgba(224, 102, 90, 0) 55%);
  --muted: #b7acc0;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.6);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-size: 34px;
  filter: drop-shadow(0 4px 8px rgba(200, 100, 70, 0.35));
}

.brand h1 {
  margin: 0;
  font-family: 'Marck Script', 'Segoe Script', 'Segoe Print', cursive;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.1;
  color: var(--accent-dark);
}

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-bg);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 26px;
  padding: 10px 28px 30px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 18px;
  font-size: 18px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field-hint {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

input, select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fffdfb;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 102, 90, 0.15);
}

textarea { resize: vertical; min-height: 52px; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a7771' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

.themes { display: flex; gap: 10px; flex-wrap: wrap; }

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.swatch:hover { transform: scale(1.1); }

.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.sw-rose { background: linear-gradient(135deg, #fecdd3, #fda4af); }
.sw-sky { background: linear-gradient(135deg, #bfdbfe, #93c5fd); }
.sw-gold { background: linear-gradient(135deg, #fde68a, #fcd34d); }
.sw-emerald { background: linear-gradient(135deg, #a7f3d0, #6ee7b7); }
.sw-violet { background: linear-gradient(135deg, #ddd6fe, #c4b5fd); }
.sw-sunset { background: linear-gradient(135deg, #fdba74, #fb923c); }

.sw-bg-warm { background: linear-gradient(135deg, #fdf1e7, #f6e3d3); }
.sw-bg-rose { background: linear-gradient(135deg, #ffe9ef, #fccfda); }
.sw-bg-mint { background: linear-gradient(135deg, #e7f7ee, #c6ecd7); }
.sw-bg-violet { background: linear-gradient(135deg, #efeafa, #d7caf4); }
.sw-bg-dark { background: linear-gradient(135deg, #2b2736, #191622); }

.btn-primary {
  width: 100%;
  margin-top: 6px;
  border: none;
  border-radius: 13px;
  padding: 14px;
  font-size: 15.5px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  cursor: pointer;
  box-shadow: 0 12px 24px -10px rgba(224, 102, 90, 0.7);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.65; cursor: default; transform: none; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.preview-panel { min-height: 460px; }

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.model-badge {
  font-size: 12px;
  color: var(--ink-soft);
  background: #faf1ea;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

.card-stage { display: flex; justify-content: center; padding: 12px 0 8px; }

.card {
  --card-font: Georgia, "Times New Roman", serif;
  --card-head-font: 'Marck Script', Georgia, "Times New Roman", serif;
  --card-sign-font: 'Marck Script', Georgia, "Times New Roman", serif;
  width: 100%;
  max-width: 560px;
  border-radius: 20px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: background 0.4s ease;
}

.card.no-anim .card-inner, .card.no-anim * { animation: none !important; transition: none !important; }

.card.theme-rose { background: linear-gradient(160deg, #fff1f2, #fce7f3 55%, #ffd6dc); }
.card.theme-sky { background: linear-gradient(160deg, #eff6ff, #e0eaff 55%, #cfe0ff); }
.card.theme-gold { background: linear-gradient(160deg, #fffbeb, #fef3c7 55%, #fde9a8); }
.card.theme-emerald { background: linear-gradient(160deg, #ecfdf5, #d1fae5 55%, #b7efd1); }
.card.theme-violet { background: linear-gradient(160deg, #f5f3ff, #e9e5ff 55%, #ddd4ff); }
.card.theme-sunset { background: linear-gradient(160deg, #fff7ed, #ffedd5 55%, #ffd9b3); }

.card[data-font="handwrite"] {
  --card-font: 'Marck Script', "Segoe Script", cursive;
  --card-head-font: 'Marck Script', "Segoe Script", cursive;
  --card-sign-font: 'Marck Script', "Segoe Script", cursive;
}

.card[data-font="elegant"] {
  --card-font: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --card-head-font: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --card-sign-font: "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

.card[data-font="modern"] {
  --card-font: "Segoe UI", Arial, sans-serif;
  --card-head-font: "Segoe UI", Arial, sans-serif;
  --card-sign-font: "Segoe UI", Arial, sans-serif;
}

.card[data-font="comic"] {
  --card-font: "Comic Sans MS", "Segoe Print", "Segoe Script", cursive;
  --card-head-font: 'Marck Script', Georgia, serif;
  --card-sign-font: 'Marck Script', Georgia, serif;
}

.card[data-font="strict"] {
  --card-font: "Times New Roman", Georgia, serif;
  --card-head-font: "Times New Roman", Georgia, serif;
  --card-sign-font: "Times New Roman", Georgia, serif;
}

.card[data-font="handwrite"] .card-text { font-size: 20px; }
.card[data-font="handwrite"] .card-occasion { font-size: 33px; }
.card[data-font="handwrite"] .card-signature strong { font-size: 24px; }
.card[data-font="comic"] .card-text { font-size: 17px; }
.card[data-font="modern"] .card-text { font-size: 16px; line-height: 1.7; }
.card[data-font="modern"] .card-occasion { font-size: 28px; }
.card[data-font="modern"] .card-signature strong { font-size: 20px; }
.card[data-font="elegant"] .card-text { font-size: 17.5px; line-height: 1.7; }
.card[data-font="strict"] .card-text { font-size: 16.5px; }

.orn {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2.5px solid rgba(90, 50, 40, 0.25);
  border-radius: 6px;
  opacity: 0.55;
}

.orn-tl { top: 16px; left: 16px; border-right: none; border-bottom: none; border-top-left-radius: 12px; }
.orn-tr { top: 16px; right: 16px; border-left: none; border-bottom: none; border-top-right-radius: 12px; }
.orn-bl { bottom: 16px; left: 16px; border-right: none; border-top: none; border-bottom-left-radius: 12px; }
.orn-br { bottom: 16px; right: 16px; border-left: none; border-top: none; border-bottom-right-radius: 12px; }

.card-inner {
  border: 1.5px solid rgba(90, 50, 40, 0.22);
  border-radius: 14px;
  padding: 30px 30px 26px;
  text-align: center;
  background: rgba(255, 255, 255, 0.55);
  animation: cardIn 0.5s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.card-icon {
  font-size: 46px;
  line-height: 1;
  animation: floaty 3.4s ease-in-out infinite;
  display: inline-block;
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.card-occasion {
  margin: 14px 0 0;
  font-family: var(--card-head-font);
  font-size: 31px;
  font-weight: 400;
  color: #4a322c;
}

.card-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  color: rgba(90, 50, 40, 0.45);
  font-size: 13px;
  margin: 12px 0;
}

.card-divider span { height: 1px; width: 64px; background: rgba(90, 50, 40, 0.3); }

.card-text {
  font-family: var(--card-font);
  font-size: 16.5px;
  line-height: 1.62;
  color: #4c3630;
  text-align: center;
}

.card-text p { margin: 0 0 12px; }
.card-text p:last-child { margin-bottom: 0; }

.card-signature {
  margin-top: 22px;
  font-family: Georgia, "Times New Roman", serif;
  color: #6a4f46;
}

.card-signature span { display: block; font-style: italic; font-size: 14px; }
.card-signature strong { display: block; font-family: var(--card-sign-font); font-weight: 400; font-size: 22px; margin-top: 3px; letter-spacing: 0.5px; }

.card-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.btn-ghost {
  border: 1.5px solid var(--line);
  background: #fffdfb;
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.btn-ghost:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }

.btn-sm { padding: 7px 12px; font-size: 12.5px; margin-top: 8px; }

.footer {
  text-align: center;
  padding: 14px 20px 26px;
  color: var(--muted);
  font-size: 12.5px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(60, 35, 25, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--panel-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 430px;
  box-shadow: 0 30px 70px -20px rgba(60, 30, 20, 0.5);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
}

.modal-head h2 { margin: 0; font-size: 18px; }

.modal-body { padding: 18px 22px 6px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 22px 20px;
}

.modal-foot .btn-primary { width: auto; margin: 0; padding: 11px 22px; }

.conn-status {
  font-size: 13px;
  min-height: 20px;
  margin-top: 4px;
}

.conn-status.ok { color: #15803d; }
.conn-status.err { color: #b91c1c; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #3a2d2a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 90vw;
  animation: toastIn 0.25s ease both;
}

.toast.err { background: #b3261e; }

.notice {
  max-width: 1124px;
  margin: 0 auto 14px;
  padding: 14px 18px;
  background: #fff4d6;
  border: 1px solid #f0d488;
  border-radius: 14px;
  color: #7a5b1e;
  font-size: 14px;
  line-height: 1.55;
}

.notice code {
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid #e4c97f;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 13px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .card { max-width: 640px; }
}

@media (max-width: 480px) {
  .topbar { padding: 14px 16px; }
  .layout { padding: 6px 14px 24px; }
  .card-inner { padding: 22px 18px 20px; }
  .card-text { font-size: 15.5px; }
  .card-occasion { font-size: 21px; }
}
