:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #b8860b;
  --accent-ink: #ffffff;
  --pop: #0f172a;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
  /* certificate paper serif + default accent (overridden per-cert via --cert-accent) */
  --cert-serif: "Georgia", "Times New Roman", "Times", serif;
  --cert-script: "Palatino Linotype", "Book Antiqua", "Palatino", "Georgia", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 17px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 18px; }

/* header / footer / crumbs */
.site-head { border-bottom: 1px solid var(--line); background: var(--card); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; height: 58px; }
.brand { font-weight: 800; font-size: 19px; color: var(--pop); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.nav a { color: var(--muted); font-size: 15px; margin-left: 18px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 18px 0 4px; }
.crumbs a { color: var(--muted); }
h1 { font-size: 28px; line-height: 1.2; letter-spacing: -.02em; margin: 10px 0 14px; }
.lead { color: var(--muted); margin: 0 0 20px; }
h2 { font-size: 20px; margin: 30px 0 12px; letter-spacing: -.01em; }
.site-foot { border-top: 1px solid var(--line); margin-top: 40px; padding: 22px 0 50px; color: var(--muted); font-size: 14px; background: var(--card); }
.site-foot a { color: var(--muted); }
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* controls */
.controls { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 8px 0 18px; }
.controls label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 14px; }
.row > div { flex: 1; min-width: 150px; max-width: 300px; }
.controls input, .controls select { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.ctl-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.print-btn { font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 11px 20px; }
.print-btn:hover { filter: brightness(1.1); }
.hint { color: var(--muted); font-size: 13px; flex: 1; min-width: 220px; }

/* ---- the certificate paper (stage sizes the sheet) ---- */
.cert-stage { margin: 0 0 20px; }
.cert-doc {
  --cert-accent: #b8860b;
  position: relative;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 11 / 8.5;              /* landscape letter */
  margin: 0 auto;
  background: #fffdf8;
  box-shadow: var(--shadow);
  color: #2a2a28;
  font-family: var(--cert-serif);
  overflow: hidden;
}
.cert-stage.portrait .cert-doc { aspect-ratio: 8.5 / 11; }

/* the drawn border layer */
.cert-frame { position: absolute; inset: 3.2%; pointer-events: none; z-index: 1; }

/* content sits above the frame */
.cert-inner {
  position: relative; z-index: 2;
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 8% 11%;
}
.cert-doc [contenteditable] { outline: none; border-radius: 3px; }
.cert-doc [contenteditable]:hover { background: rgba(184,134,11,.07); }
.cert-doc [contenteditable]:focus { background: rgba(184,134,11,.12); box-shadow: 0 0 0 2px rgba(184,134,11,.22); }

.cert-emblem { font-size: clamp(26px, 5.2vw, 46px); line-height: 1; margin-bottom: .35em; }
.cert-heading {
  font-family: var(--cert-serif);
  font-size: clamp(20px, 4.4vw, 40px);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--cert-accent);
  margin: 0;
}
.cert-rule { width: 30%; max-width: 240px; height: 2px; background: var(--cert-accent); opacity: .8; margin: 3.2% 0; }
.cert-sub {
  font-size: clamp(12px, 1.9vw, 17px);
  font-style: italic;
  color: #5b5a55;
  letter-spacing: .02em;
}
.cert-name {
  font-family: var(--cert-script);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(28px, 6.4vw, 58px);
  line-height: 1.1;
  color: #23252b;
  margin: 2.4% 0 2%;
  padding: 0 .3em .12em;
  border-bottom: 1.5px solid var(--cert-accent);
  min-width: 45%;
}
.cert-body {
  font-size: clamp(12px, 2vw, 18px);
  line-height: 1.5;
  color: #45443f;
  max-width: 80%;
  margin: 0 auto;
}

/* gift-certificate extras */
.cert-gift { margin-top: 3.2%; display: flex; flex-direction: column; align-items: center; gap: .35em; }
.gift-amount {
  font-family: var(--cert-serif);
  font-size: clamp(24px, 5vw, 46px);
  font-weight: 800;
  color: var(--cert-accent);
  letter-spacing: .01em;
}
.gift-redeem { font-size: clamp(12px, 1.9vw, 17px); font-style: italic; color: #45443f; }
.gift-expiry { font-size: clamp(11px, 1.6vw, 14px); color: #6b6a63; }
.gift-expiry-label { text-transform: uppercase; letter-spacing: .08em; font-size: .85em; }
.gift-expiry-date { display: inline-block; min-width: 120px; border-bottom: 1px solid #b9b6ab; padding: 0 4px; }

/* signatures */
.cert-foot {
  margin-top: auto;
  padding-top: 4%;
  width: 100%;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 6%;
}
.sig { flex: 1; max-width: 34%; }
.sig-line { border-bottom: 1.4px solid #33322e; min-height: 1.4em; margin-bottom: 4px; }
.sig-label { font-size: clamp(10px, 1.4vw, 13px); text-transform: uppercase; letter-spacing: .12em; color: #6b6a63; }
.cert-seal {
  flex: 0 0 auto;
  width: clamp(34px, 6vw, 58px); height: clamp(34px, 6vw, 58px);
  border-radius: 50%;
  border: 2px solid var(--cert-accent);
  color: var(--cert-accent);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(18px, 3vw, 30px);
  align-self: center;
}

/* ---- border styles (swapped by tool.js) ---- */
/* classic: double line */
.border-classic .cert-frame { border: 5px double var(--cert-accent); }
/* simple: single hairline */
.border-simple .cert-frame { border: 1.5px solid var(--cert-accent); }
/* ornate: heavy outer + thin inner line */
.border-ribbon .cert-frame { border: 6px solid var(--cert-accent); }
.border-ribbon .cert-frame::after {
  content: ""; position: absolute; inset: 5px; border: 1.5px solid var(--cert-accent);
}
/* corners: thin line + L-bracket ornaments at each corner */
.border-corners .cert-frame { border: 1.5px solid var(--cert-accent); }
.corner { display: none; position: absolute; z-index: 1; width: 5.5%; padding-bottom: 5.5%; pointer-events: none; }
.border-corners .corner { display: block; }
.corner.tl { top: 3.2%; left: 3.2%; border-top: 3px solid var(--cert-accent); border-left: 3px solid var(--cert-accent); }
.corner.tr { top: 3.2%; right: 3.2%; border-top: 3px solid var(--cert-accent); border-right: 3px solid var(--cert-accent); }
.corner.bl { bottom: 3.2%; left: 3.2%; border-bottom: 3px solid var(--cert-accent); border-left: 3px solid var(--cert-accent); }
.corner.br { bottom: 3.2%; right: 3.2%; border-bottom: 3px solid var(--cert-accent); border-right: 3px solid var(--cert-accent); }

/* link grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin-bottom: 10px; }
.grid a { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; color: var(--ink); font-size: 15px; }
.grid a:hover { border-color: var(--accent); text-decoration: none; }
.chip-emoji { margin-right: 6px; }

/* prose + ads */
.prose { margin: 22px 0; }
.prose p { margin: 0 0 14px; }
.fineprint { font-size: 13px; color: var(--muted); }
.ad-slot {
  margin: 22px 0;
  min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(45deg, #eef2f6, #eef2f6 10px, #f4f7fa 10px, #f4f7fa 20px);
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  color: #94a3b8; font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
}

@media (max-width: 620px) {
  h1 { font-size: 23px; }
  .cert-inner { padding: 7% 8%; }
  .cert-body { max-width: 92%; }
  .cert-foot { gap: 4%; }
}

/* print: the certificate is the page, everything else disappears */
@media print {
  @page { size: letter landscape; margin: 0.35in; }
  body { background: #fff; }
  .no-print, .ad-slot { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .cert-stage { margin: 0; }
  .cert-doc {
    max-width: none; width: 100%; height: 100vh; aspect-ratio: auto;
    box-shadow: none; background: #fff;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .cert-doc [contenteditable]:hover, .cert-doc [contenteditable]:focus { background: none; box-shadow: none; }
  .cert-frame, .cert-frame::after, .corner, .cert-rule, .cert-seal, .cert-name, .cert-heading, .gift-amount {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
