@font-face {
  font-family: "Snell Roundhand Exact";
  src: local("Snell Roundhand"), local("SnellRoundhand");
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #f8f5ef;
  --surface: #ffffff;
  --surface-warm: #fbf8f3;
  --text: #352820;
  --muted: #776f68;
  --border: #ded6cd;
  --border-strong: #c8b9aa;
  --walnut: #6b4e37;
  --walnut-dark: #503826;
  --sage: #6f8b64;
  --sage-dark: #58734f;
  --danger: #a14335;
  --shadow: 0 22px 55px rgba(74, 56, 42, 0.12), 0 4px 12px rgba(74, 56, 42, 0.07);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button, select, input[type="radio"], input[type="checkbox"], input[type="color"] { cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(111, 139, 100, 0.35);
  outline-offset: 2px;
}

.app-header {
  min-height: 86px;
  padding: 18px clamp(22px, 3vw, 46px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--surface);
  background: var(--walnut);
  font: 700 22px/1 "Snell Roundhand Exact", "Snell Roundhand", cursive;
}
.brand h1 { margin: 0; font-size: clamp(1.18rem, 2vw, 1.48rem); letter-spacing: -0.025em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.86rem; }
.local-note { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

.workspace {
  display: grid;
  grid-template-columns: minmax(410px, 0.8fr) minmax(540px, 1.3fr);
  min-height: calc(100vh - 146px);
}

.controls-panel {
  padding: 20px clamp(22px, 2.6vw, 40px);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.form-section { margin-bottom: 15px; }
.form-section--intro { margin-top: 0; }
label, legend { color: var(--text); font-size: 0.84rem; font-weight: 720; }
fieldset { border: 0; padding: 0; margin-inline: 0; min-width: 0; }
legend { margin-bottom: 9px; }

textarea, select, input[type="number"], input[type="text"] {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea { display: block; margin-top: 7px; padding: 9px 11px; resize: vertical; line-height: 1.4; }
select { height: 38px; padding: 0 36px 0 11px; }
input[type="number"] { height: 38px; padding: 0 42px 0 11px; }
input[type="text"] { height: 38px; padding: 0 11px; }
textarea:hover, select:hover, input[type="number"]:hover, input[type="text"]:hover { border-color: #b6a390; }
textarea:focus, select:focus, input[type="number"]:focus, input[type="text"]:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(111, 139, 100, 0.12); outline: 0; }

.field-help {
  margin: 7px 0 0;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--muted);
  font-size: 0.75rem;
}
code { padding: 1px 4px; border-radius: 4px; color: var(--walnut-dark); background: #f0ebe5; }

.section-heading-row { margin-bottom: 7px; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.section-heading-row > span { color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.guest-add-row { display: grid; grid-template-columns: minmax(0, 1fr) 38px; gap: 8px; }
.icon-action {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--sage);
  border: 0;
  border-radius: 8px;
}
.icon-action:hover { background: var(--sage-dark); }
.icon-action svg, .text-action svg, .preview-customize-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.guest-selection-bar {
  min-height: 32px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.7rem;
}
.select-all-row { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: inherit; font-weight: 620; }
.select-all-row input, .guest-row input[type="checkbox"] { accent-color: var(--sage); }
.guest-selection-bar button { padding: 0; color: var(--walnut); background: none; border: 0; font-size: inherit; font-weight: 650; }
.guest-selection-bar > span { justify-self: end; }
.guest-list {
  max-height: 174px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}
.guest-list:empty::before {
  content: "Nessun invitato. Aggiungi il primo nome qui sopra.";
  min-height: 62px;
  padding: 12px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.73rem;
}
.guest-row {
  min-height: 42px;
  padding: 4px 6px 4px 10px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid var(--border);
  transition: background 140ms ease;
}
.guest-row:last-child { border-bottom: 0; }
.guest-row.is-selected { background: #f3f7f0; }
.guest-row.is-current { box-shadow: inset 3px 0 0 var(--walnut); }
.guest-row input[type="text"] { height: 32px; padding-inline: 7px; border-color: transparent; background: transparent; font-size: 0.78rem; font-weight: 620; }
.guest-row input[type="text"]:hover { border-color: var(--border); }
.guest-row input[type="text"]:focus { background: white; }
.guest-remove {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
}
.guest-remove:hover { color: var(--danger); background: #fbefed; }
.guest-remove svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.message-editor-section { padding-top: 13px; border-top: 1px solid var(--border); }
.mixed-message {
  margin: 0 0 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--walnut-dark);
  background: #f7f1e9;
  border-left: 3px solid var(--walnut);
  border-radius: 6px;
  font-size: 0.7rem;
}
.mixed-message[hidden] { display: none; }
.mixed-message span { color: var(--muted); }
.message-lines { display: grid; gap: 6px; }
.message-line {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 6px;
}
.message-line > span { color: var(--muted); font: 0.7rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.message-line input { height: 34px; font-size: 0.78rem; }
.message-line input.is-name-line { color: var(--walnut-dark); background: #f7f3ed; border-style: dashed; font-weight: 700; }
.message-line button { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 6px; }
.message-line button:hover:not(:disabled) { color: var(--danger); background: #fbefed; }
.message-line button:disabled { opacity: 0.3; cursor: default; }
.message-line button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.message-tools { min-height: 32px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.message-tools > span { color: var(--muted); font-size: 0.68rem; }
.text-action { padding: 0; display: inline-flex; align-items: center; gap: 5px; color: var(--walnut); background: transparent; border: 0; font-size: 0.7rem; font-weight: 680; }
.text-action svg { width: 14px; height: 14px; }
.message-apply-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.secondary-action { min-height: 36px; padding: 7px 10px; color: var(--walnut); background: white; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.72rem; font-weight: 700; }
.secondary-action:hover:not(:disabled) { background: #f7f2ec; border-color: var(--walnut); }
.secondary-action--accent { color: white; background: var(--walnut); border-color: var(--walnut); }
.secondary-action--accent:hover:not(:disabled) { color: white; background: var(--walnut-dark); }
.secondary-action:disabled { cursor: default; opacity: 0.42; }

.layout-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.layout-option { position: relative; }
.layout-option input { position: absolute; opacity: 0; pointer-events: none; }
.layout-option > span {
  min-height: 58px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.layout-option small { display: block; color: var(--muted); font-size: 0.68rem; font-weight: 500; }
.layout-option input:checked + span { color: var(--walnut-dark); border-color: var(--walnut); background: #fbf7f2; box-shadow: inset 0 0 0 1px var(--walnut); }
.layout-option input:focus-visible + span { outline: 3px solid rgba(111, 139, 100, 0.35); outline-offset: 2px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.field label { display: block; margin-bottom: 5px; }
.number-field { position: relative; }
.number-field span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.76rem; pointer-events: none; }
.color-field { height: 38px; display: flex; align-items: center; gap: 10px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 8px; }
.color-field input { width: 27px; height: 27px; padding: 0; border: 0; background: none; }
.color-field output { color: var(--muted); font: 0.78rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }

.inline-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: end; }
.alignment-fieldset legend { margin-bottom: 7px; }
.segmented-control { height: 40px; display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; border: 1px solid var(--border-strong); border-radius: 8px; }
.segmented-control label { position: relative; display: grid; place-items: center; border-right: 1px solid var(--border); }
.segmented-control label:last-child { border-right: 0; }
.segmented-control input { position: absolute; opacity: 0; }
.segmented-control label > span[aria-hidden] { width: 24px; font-size: 1.3rem; font-weight: 500; line-height: 1; }
.segmented-control label:nth-child(1) > span[aria-hidden] { text-align: left; }
.segmented-control label:nth-child(2) > span[aria-hidden] { text-align: center; }
.segmented-control label:nth-child(3) > span[aria-hidden] { text-align: right; }
.segmented-control label:has(input:checked) { color: var(--walnut); background: #eee9e2; }

.switch-row { min-height: 47px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.switch-row > span:first-child { display: flex; flex-direction: column; gap: 3px; }
.switch-row small { color: var(--muted); font-size: 0.67rem; font-weight: 500; }
.switch { position: relative; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch > span { width: 42px; height: 24px; display: block; border-radius: 99px; background: #c9c4bd; transition: background 160ms ease; }
.switch > span::after { content: ""; width: 18px; height: 18px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.22); transition: transform 160ms ease; }
.switch input:checked + span { background: var(--sage); }
.switch input:checked + span::after { transform: translateX(18px); }

.font-upload { margin: -3px 0 12px; display: flex; align-items: center; gap: 12px; }
.font-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.font-upload > span { color: var(--muted); font-size: 0.7rem; line-height: 1.35; }
.secondary-button { flex: 0 0 auto; padding: 8px 10px; color: var(--walnut); border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.73rem; background: var(--surface); }

.primary-button {
  width: 100%;
  min-height: 52px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  color: white;
  border: 0;
  border-radius: 9px;
  background: var(--sage);
  box-shadow: 0 8px 20px rgba(88, 115, 79, 0.18);
  font-size: 1rem;
  font-weight: 750;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.primary-button:hover { background: var(--sage-dark); box-shadow: 0 10px 24px rgba(88, 115, 79, 0.24); transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: 0.72; transform: none; }
.primary-button svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.status-message { min-height: 18px; margin: 7px 0 -10px; text-align: center; color: var(--muted); font-size: 0.75rem; }
.status-message.is-error { color: var(--danger); }

.preview-panel { min-width: 0; padding: 24px clamp(26px, 3.8vw, 64px) 30px; display: flex; flex-direction: column; background: var(--surface-warm); }
.preview-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.preview-heading p { margin: 0 0 4px; color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.preview-heading h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.015em; }
.preview-heading-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.preview-heading-actions > span { color: var(--walnut); font-size: 0.75rem; font-weight: 650; }
.preview-customize-button { padding: 6px 9px; display: inline-flex; align-items: center; gap: 6px; color: var(--walnut); background: rgba(255, 255, 255, 0.6); border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.7rem; font-weight: 700; }
.preview-customize-button:hover:not(:disabled) { background: white; border-color: var(--walnut); }
.preview-customize-button:disabled { opacity: 0.4; cursor: default; }

.preview-stage { flex: 1; min-height: 410px; padding: 30px 0 22px; display: grid; place-items: center; }
.card-preview {
  width: min(100%, 690px);
  aspect-ratio: 3 / 2;
  position: relative;
  display: grid;
  place-items: center;
  color: var(--walnut);
  background-color: #fffdf9;
  border: 1px solid #ece4d9;
  box-shadow: var(--shadow);
  transition: width 220ms ease, aspect-ratio 220ms ease;
}
.card-preview.is-vertical { width: min(64%, 440px); aspect-ratio: 2 / 3; }
.card-safe-area { width: calc(100% - 46px); height: calc(100% - 46px); padding: 7%; display: flex; flex-direction: column; justify-content: center; overflow: hidden; border: 1px dashed rgba(107, 78, 55, 0.30); }
.card-line { max-width: 100%; line-height: var(--line-height, 1.25); font-family: var(--card-font, "Snell Roundhand Exact", "Snell Roundhand", cursive); white-space: nowrap; }
.card-line.is-name { font-size: var(--name-size, 44px); }
.card-line:not(.is-name) { font-size: var(--text-size, 22px); }

.guest-nav { width: min(100%, 540px); margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; }
.guest-nav > span { min-width: 112px; text-align: center; color: var(--muted); font-size: 0.78rem; font-weight: 650; }
.nav-button { min-height: 40px; padding: 0 14px; display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--walnut); background: transparent; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.78rem; font-weight: 650; }
.nav-button:hover:not(:disabled) { background: #f4eee7; }
.nav-button:disabled { opacity: 0.35; cursor: default; }
.nav-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.print-note { min-height: 60px; padding: 14px 24px; display: flex; justify-content: center; align-items: center; gap: 10px; color: var(--muted); background: #f3eee6; border-top: 1px solid var(--border); font-size: 0.78rem; }
.print-note svg { width: 22px; height: 22px; flex: 0 0 auto; fill: none; stroke: var(--walnut); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: minmax(360px, 0.9fr) minmax(430px, 1.1fr); }
  .controls-panel { padding-inline: 22px; }
  .preview-panel { padding-inline: 28px; }
  .layout-options { grid-template-columns: 1fr; }
  .layout-option > span { min-height: 48px; flex-direction: row; justify-content: space-between; padding-inline: 12px; text-align: left; }
}

@media (max-width: 780px) {
  .app-header { min-height: 76px; padding: 14px 18px; }
  .brand-mark { width: 40px; height: 40px; }
  .brand p, .local-note { display: none; }
  .workspace { display: flex; flex-direction: column; }
  .controls-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .preview-panel { min-height: 620px; order: -1; padding: 20px 18px 24px; }
  .preview-stage { min-height: 330px; padding-block: 26px; }
  .card-preview { width: min(100%, 620px); }
  .card-preview.is-vertical { width: min(66%, 390px); }
}

@media (max-width: 520px) {
  .preview-panel { min-height: 510px; }
  .preview-heading-actions { max-width: 168px; }
  .preview-heading-actions > span { text-align: right; }
  .preview-customize-button { max-width: 160px; justify-content: center; text-align: left; }
  .preview-stage { min-height: 280px; padding-block: 22px; }
  .card-safe-area { width: calc(100% - 26px); height: calc(100% - 26px); }
  .guest-nav { gap: 7px; }
  .nav-button { padding-inline: 9px; font-size: 0; }
  .nav-button svg { width: 21px; height: 21px; }
  .settings-grid { gap: 13px 10px; }
  .inline-settings { grid-template-columns: 1fr; align-items: stretch; }
  .guest-selection-bar { grid-template-columns: auto auto; }
  .guest-selection-bar > span { grid-column: 1 / -1; justify-self: start; margin-top: -5px; }
  .message-apply-actions { grid-template-columns: 1fr; }
  .font-upload { align-items: flex-start; flex-direction: column; }
  .print-note { align-items: flex-start; font-size: 0.73rem; }
}

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