/* ============================================================
   Shared certificate styles
   ------------------------------------------------------------
   Used by cert/issue.html (staff) and cert/verify.html (public).
   The certificate paper follows the "24G Certificate.svg" art:
   portrait A4, left-aligned, with the 24G brand palette
   (teal / navy / red / orange) and an award medal.
   Page-specific layout (the form, the verification card)
   is in <style> blocks inside the individual HTML pages.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600;700;800&family=Lato:wght@400;700&display=swap");

:root {
  /* Brand — overridden inline per site */
  --brand: #38bca9;
  --brand-deep: #1f8e7f;
  --ink: #1a1a1a;
  --ink-2: #3a3d44;
  --muted: #6b6f78;
  --line: #d8d9dd;
  --paper: #ffffff;
  --paper-soft: #ffffff;
  --accent: var(--brand);

  /* 24G certificate palette (from 24G Certificate.svg) */
  --c-teal:      #38bca9;
  --c-navy:      #222e51;
  --c-navy-2:    #314aa0;
  --c-red:       #ee1f4c;
  --c-orange:    #f99d1e;
  --c-gold:      #fcb439;
  --c-gray:      #8e939c;

  /* Font stacks — Montserrat/Lato when available (online), else system sans */
  --font-display: "Montserrat", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body:    "Lato", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.cert-shell {
  min-height: 100vh;
  background: #ebe9e3;
  font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  padding: 32px 16px 64px;
  -webkit-font-smoothing: antialiased;
}

.cert-shell a { color: var(--brand); text-decoration: none; }
.cert-shell a:hover { text-decoration: underline; }

/* ----- Toolbar shown above the certificate ----- */
.cert-toolbar {
  max-width: 297mm;
  margin: 0 auto 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
}
.cert-toolbar .crumb { color: var(--muted); }
.cert-toolbar .crumb a { color: var(--ink-2); border-bottom: 1px dashed var(--line); padding-bottom: 1px; }
.cert-toolbar .crumb a:hover { color: var(--brand); }
.cert-toolbar button,
.cert-toolbar .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.cert-toolbar button:hover,
.cert-toolbar .btn:hover { border-color: var(--brand); color: var(--brand); }
.cert-toolbar .btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.cert-toolbar .btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.cert-toolbar .lang-toggle button { padding: 4px 10px; }
.cert-toolbar .lang-toggle button.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.cert-toolbar .dl-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.cert-toolbar .dl-buttons button { font-size: 12.5px; }

/* ============================================================
   The certificate paper — portrait A4, 24G "Award" style
   (modelled on 24G Certificate.svg)
   ============================================================ */
.cert-page {
  width: 210mm;
  height: 297mm;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  color: var(--c-navy);
}

/* Decorative corners are drawn with diagonal linear-gradients (no clip-path),
   so html2canvas reproduces them faithfully in the PNG/PDF exports. */

/* faint bottom-left wedge for balance (echoes the SVG base polygon) */
.cert-page::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 80mm; height: 48mm;
  background: linear-gradient(45deg,
    rgba(142,147,156,.16) 0,
    rgba(142,147,156,.05) 30%,
    transparent 34%);
  z-index: 0;
}

/* ----- Decorative top-right corner: teal→navy diagonal swoosh ----- */
.cert-deco { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.cert-deco::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 104mm; height: 96mm;
  background: linear-gradient(225deg,
    var(--c-teal) 0,
    var(--c-navy-2) 40%,
    transparent 40%);
}
.cert-deco::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 70mm; height: 64mm;
  background: linear-gradient(225deg,
    rgba(255,255,255,.18) 0,
    rgba(255,255,255,.18) 26%,
    transparent 26%);
}

.cert-content {
  position: relative;
  z-index: 2;
  padding: 22mm 20mm 18mm;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ----- Header: 24G logo + brand on the left, award medal on the right ----- */
.cert-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12mm;
  margin-bottom: 13mm;
}
.cert-brandwrap { display: flex; align-items: center; gap: 5mm; }
.cert-logo img,
.cert-logo svg { height: 13mm; width: auto; display: block; }
.cert-brand {
  font-family: var(--font-display);
  font-size: 8.5pt;
  line-height: 1.45;
  letter-spacing: .4px;
  color: var(--c-gray);
  margin-top: 1.5mm;
}
.cert-brand strong {
  display: block;
  font-weight: 800;
  font-size: 15pt;
  letter-spacing: 2px;
  color: var(--c-navy);
  margin-bottom: .5mm;
}
.cert-medal { width: 24mm; height: auto; display: block; flex-shrink: 0; }

/* ----- Body: left-aligned award copy ----- */
.cert-body { flex: 1; text-align: left; }

/* big award title, e.g. "Certificate of Achievement" */
.cert-eyebrow {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 33pt;
  line-height: 1.02;
  letter-spacing: -.01em;
  color: var(--c-red);
  text-transform: none;
  margin-bottom: 11mm;
}
.cert-eyebrow::before {
  content: "";
  display: block;
  width: 22mm; height: 3px;
  background: var(--c-orange);
  margin-bottom: 6mm;
}

.cert-award-label {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 12pt;
  color: var(--c-navy);
  margin-bottom: 1.5mm;
}
.cert-award {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15pt;
  letter-spacing: .2px;
  color: var(--c-orange);
  margin-bottom: 10mm;
}

.cert-statement {
  font-family: var(--font-body);
  font-size: 11pt;
  font-style: italic;
  color: var(--c-gray);
  margin-bottom: 2.5mm;
}
.cert-name {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 46pt;
  line-height: 1.04;
  color: var(--c-navy);
  margin: 0 0 6mm;
}
.cert-meta {
  font-family: var(--font-body);
  font-size: 11pt;
  color: var(--ink-2);
}
.cert-meta strong { color: var(--c-navy); font-weight: 700; }
.cert-meta .sep { color: var(--c-gray); margin: 0 6pt; }

/* ----- Footer: issuer · QR · signature ----- */
.cert-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10mm;
  align-items: end;
  padding-top: 7mm;
  border-top: 1px solid var(--line);
  margin-top: 6mm;
}
.cert-foot-cell {
  font-family: var(--font-body);
  font-size: 8.5pt;
  color: var(--c-gray);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.cert-foot-cell strong {
  display: block;
  font-family: var(--font-display);
  color: var(--c-navy);
  text-transform: none;
  letter-spacing: 0;
  font-size: 11pt;
  font-weight: 700;
  margin-top: 1.5mm;
}

.cert-qr-wrap { text-align: center; }
.cert-qr {
  width: 24mm; height: 24mm;
  margin: 0 auto 2mm;
  background: #fff;
  padding: 1.5mm;
  display: inline-block;
  border: 1px solid var(--line);
}
.cert-qr canvas,
.cert-qr img {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.cert-qr-label {
  font-family: var(--font-body);
  font-size: 7pt;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--c-gray);
  margin-bottom: 1mm;
}
.cert-qr-id {
  font-family: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
  font-size: 8pt;
  letter-spacing: 1px;
  color: var(--c-navy);
}

.cert-signed { text-align: right; }
.cert-signed .sig {
  display: inline-block;
  min-width: 48mm;
  border-bottom: 1.5px solid var(--c-navy);
  padding-bottom: 1.5mm;
  margin-bottom: 1.5mm;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11pt;
  color: var(--c-navy);
}

/* ----- Verification result banner ----- */
.cert-status {
  max-width: 297mm;
  margin: 0 auto 18px;
  padding: 14px 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.cert-status .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 999px;
  font-weight: 700;
  flex-shrink: 0;
}
.cert-status.is-valid .badge { background: #1d6f44; color: #fff; }
.cert-status.is-invalid .badge { background: #c0392b; color: #fff; }
.cert-status.is-info .badge { background: var(--ink); color: #fff; }
.cert-status .body strong { display: block; color: var(--ink); margin-bottom: 2px; }
.cert-status .body span { color: var(--muted); }

/* ----- Lookup form (verify.html when no params) ----- */
.cert-lookup {
  max-width: 540px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 4px 18px rgba(0,0,0,.04);
}
.cert-lookup h2 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--ink);
}
.cert-lookup p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.cert-lookup label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.cert-lookup textarea {
  width: 100%;
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  resize: vertical;
}
.cert-lookup button {
  margin-top: 14px;
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}
.cert-lookup button:hover { background: var(--brand-deep); }
.cert-lookup .hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ----- Issue form (issue.html) ----- */
.issue-grid {
  max-width: 297mm;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 1.8fr;
  gap: 24px;
  align-items: start;
}
.issue-form {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}
.issue-form h2 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--ink);
}
.issue-form .lede { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.issue-form .field { margin-bottom: 14px; }
.issue-form label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.issue-form input,
.issue-form select,
.issue-form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  background: #fff;
}
.issue-form input:focus,
.issue-form select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.issue-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.issue-form .row .field { margin-bottom: 0; }

.issue-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.issue-form button {
  font: inherit;
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 11px 22px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.issue-form button.secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
}
.issue-form button:hover { background: var(--brand-deep); }
.issue-form button.secondary:hover { border-color: var(--ink); }

.issue-output {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  font-size: 13px;
  margin-top: 18px;
  display: none;
}
.issue-output.is-shown { display: block; }
.issue-output h3 { margin: 0 0 10px; font-size: 15px; color: var(--ink); }
.issue-output .row { display: grid; grid-template-columns: 110px 1fr; gap: 8px 14px; margin-bottom: 6px; }
.issue-output .label { color: var(--muted); }
.issue-output .value { color: var(--ink); word-break: break-all; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.issue-output .copy-btn {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.issue-output .copy-btn:hover { border-color: var(--brand); color: var(--brand); }

/* ----- Bilingual text helper ----- */
.t-en { display: inline; }
.t-zh { display: none; }
body[data-lang="zh"] .t-en { display: none; }
body[data-lang="zh"] .t-zh { display: inline; }

/* ============================================================
   Fitting the full-size A4-portrait paper into the screen
   ------------------------------------------------------------
   The paper keeps its true 210×297mm box (so Print/PDF/PNG stay
   pixel-perfect); we only scale it down visually with transform.
   transform does not change offsetWidth/Height, so html2canvas
   still captures it at full resolution.
   ============================================================ */

/* Issue page: a fitted preview that sits beside the form. The wrapper
   reserves exactly the scaled footprint so layout stays tidy. */
.cert-preview {
  --s: .6;
  width: calc(210mm * var(--s));
  height: calc(297mm * var(--s));
}
.cert-preview .cert-page {
  margin: 0;
  transform: scale(var(--s));
  transform-origin: top left;
  box-shadow: 0 16px 44px rgba(0,0,0,.16);
}

@media (max-width: 900px) {
  .issue-grid { grid-template-columns: 1fr; }
  .cert-preview { --s: .56; margin: 0 auto; }
}
@media (max-width: 560px) {
  .cert-preview { --s: .4; }
}

/* Verify page (standalone #cert, a direct child of .cert-shell):
   full size on desktop, scaled from the top-left on smaller screens. */
@media (max-width: 880px) {
  .cert-shell > .cert-page {
    transform: scale(.62);
    transform-origin: top left;
    margin: 0 0 calc(297mm * -0.38);
  }
}
@media (max-width: 560px) {
  .cert-shell > .cert-page {
    transform: scale(.42);
    margin: 0 0 calc(297mm * -0.58);
  }
}

/* ----- Print: A4 portrait, just the certificate at true size ----- */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; }
  .cert-shell { background: #fff; padding: 0; }
  .cert-toolbar, .cert-status, .cert-lookup, .issue-form, .issue-output { display: none !important; }
  .cert-preview { width: auto; height: auto; }
  .cert-preview .cert-page,
  .cert-shell > .cert-page,
  .cert-page {
    box-shadow: none;
    width: 210mm; height: 297mm;
    transform: none !important;
    margin: 0 !important;
  }
  .issue-grid { display: block; }
}
