:root {
  --teal: #0B4A48;
  --teal-mid: #1F6E67;
  --gold: #B8924E;
  --ink: #14201E;
  --paper: #FBF8F1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Outfit', sans-serif;
  background: #16302C;
  color: var(--ink);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.toolbar button,
.toolbar a {
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 11px 18px;
  text-decoration: none;
  cursor: pointer;
}

.toolbar button {
  border: none;
  background: linear-gradient(135deg, var(--teal), var(--teal-mid));
  color: #fff;
}

.toolbar a {
  border: 1px solid rgba(251, 248, 241, 0.35);
  color: #FBF8F1;
}

.error {
  width: 100%;
  text-align: center;
  color: #FCE8E6;
  margin: 0;
}

.loading {
  text-align: center;
  color: #FBF8F1;
  padding: 40px;
}

.certificate {
  width: min(1100px, 96vw);
  aspect-ratio: 297 / 210;
  margin: 10px auto 40px;
  background:
    radial-gradient(ellipse at top left, rgba(31, 110, 103, 0.08), transparent 40%),
    radial-gradient(ellipse at bottom right, rgba(184, 146, 78, 0.12), transparent 35%),
    var(--paper);
  border: 1px solid rgba(184, 146, 78, 0.45);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  position: relative;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.certificate::before {
  content: '';
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(11, 74, 72, 0.25);
  pointer-events: none;
}

.ornament {
  position: absolute;
  width: 120px;
  height: 120px;
  border: 2px solid rgba(184, 146, 78, 0.45);
  pointer-events: none;
}

.ornament-tl {
  top: 28px;
  left: 28px;
  border-right: none;
  border-bottom: none;
}

.ornament-br {
  right: 28px;
  bottom: 28px;
  border-left: none;
  border-top: none;
}

.cert-brand {
  text-align: center;
  position: relative;
}

.brand-name {
  margin: 0;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--teal);
}

.brand-sub {
  margin: 6px 0 0;
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.4rem;
  color: var(--gold);
  letter-spacing: 0.2em;
}

.cert-label {
  text-align: center;
  margin: 18px 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--teal-mid);
  font-weight: 600;
  position: relative;
}

.cert-title {
  text-align: center;
  margin: 10px 0 0;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 500;
  font-size: 1.5rem;
  color: var(--ink);
  position: relative;
}

.cert-name {
  text-align: center;
  margin: 8px 0 0;
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(2.2rem, 4.5vw, 3.4rem);
  font-weight: 700;
  color: var(--teal);
  line-height: 1.1;
  position: relative;
}

.cert-body {
  text-align: center;
  max-width: 46ch;
  margin: 18px auto 0;
  font-size: 1.05rem;
  line-height: 1.55;
  color: #3C4A46;
  position: relative;
}

.cert-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-top: 28px;
  position: relative;
}

.sign {
  min-width: 220px;
  text-align: center;
}

.sign-line {
  height: 1px;
  background: rgba(20, 32, 30, 0.35);
  margin-bottom: 8px;
}

.sign p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted, #5C6B66);
}

.code-block {
  text-align: right;
}

.code-label {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6A7873;
}

.code-value {
  margin: 4px 0 0;
  font-family: ui-monospace, monospace;
  font-weight: 600;
  color: var(--teal);
  font-size: 0.95rem;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .toolbar,
  .loading {
    display: none !important;
  }

  .certificate {
    width: 297mm;
    height: 210mm;
    max-width: none;
    margin: 0;
    box-shadow: none;
    border: none;
    page-break-inside: avoid;
  }
}

@media (max-width: 700px) {
  .certificate {
    aspect-ratio: auto;
    min-height: 520px;
    padding: 36px 24px;
  }

  .cert-footer {
    flex-direction: column;
    align-items: center;
  }

  .code-block { text-align: center; }
}
