:root {
  --ui-bg:      #0d1117;
  --ui-surface: #161b22;
  --ui-border:  #30363d;
  --ui-text:    #e6edf3;
  --ui-muted:   #8b949e;
  --ui-accent:  #58a6ff;
  --ui-green:   #3fb950;
  --ui-red:     #f85149;
  --ui-yellow:  #d29922;
  --ui-font:    'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --ink:        #0f0e0c;
  --ink-mid:    #3a3830;
  --ink-soft:   #7a7060;
  --rule:       #c8bfaa;
  --gold:       #9a7c3a;
  --gold-lt:    #e8d9b0;
  --paper:      #ffffff;
  --cert-red:   #8b1a1a;
  --cert-green: #1a5c2a;
  --font-serif: 'EB Garamond', Georgia, serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--ui-bg);
  font-family: var(--ui-font);
  color: var(--ui-text);
  min-height: 100vh;
  padding: 2rem 1rem 4rem;
}

.page-header {
  max-width: 794px;
  margin: 0 auto 2rem;
  text-align: center;
}
.page-header h1 {
  font-size: 1.6rem;
  color: var(--ui-accent);
  letter-spacing: 0.05em;
  font-weight: 700;
}
.page-header p {
  color: var(--ui-muted);
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.back-link {
  display: inline-block; margin-top: 0.8rem; font-size: 0.78rem;
  color: var(--ui-muted); text-decoration: none; letter-spacing: 0.05em;
  border: 1px solid var(--ui-border); padding: 0.35rem 0.9rem;
  border-radius: 6px; transition: color 0.15s, border-color 0.15s;
}
.back-link:hover { color: var(--ui-accent); border-color: var(--ui-accent); }

.input-panel {
  max-width: 794px;
  margin: 0 auto 2.5rem;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 1.8rem 2rem;
}
.input-panel h2 {
  font-family: var(--ui-font);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ui-muted);
  margin-bottom: 1.2rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--ui-border);
}
.panel-note {
  font-size: 0.82rem;
  color: var(--ui-muted);
  margin-bottom: 1.2rem;
  line-height: 1.6;
}
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--ui-muted);
  margin-bottom: 0.3rem;
}
.field input, .field textarea {
  width: 100%;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  font-family: var(--ui-font);
  font-size: 0.82rem;
  color: var(--ui-text);
  padding: 0.6rem 0.8rem;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { border-color: var(--ui-accent); }
.field textarea { resize: vertical; min-height: 90px; }
.btn-group { display: flex; gap: 0.75rem; margin-top: 1.2rem; flex-wrap: wrap; }
button {
  font-family: var(--ui-font);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}
button:hover    { opacity: 0.85; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary   { background: var(--ui-accent); color: #0d1117; }
.btn-secondary { background: var(--ui-surface); color: var(--ui-accent); border: 1px solid var(--ui-border); }
.btn-print     { background: var(--ui-surface); color: var(--ui-text);   border: 1px solid var(--ui-border); }
.msg {
  margin-top: 1rem; padding: 0.7rem 1rem; border-radius: 6px;
  font-size: 0.82rem; display: none; line-height: 1.6;
}
.msg.show { display: block; }
.msg.err  { background: rgba(248,81,73,0.1);  border: 1px solid var(--ui-red);    color: var(--ui-red); }
.msg.ok   { background: rgba(63,185,80,0.1);  border: 1px solid var(--ui-green);  color: var(--ui-green); }
.msg.info { background: rgba(88,166,255,0.1); border: 1px solid var(--ui-accent); color: var(--ui-muted); }

.certificate {
  max-width: 794px;
  width: 100%;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--ui-border);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  position: relative;
  display: none;
  font-family: var(--font-serif);
  color: var(--ink);
}
.certificate.show { display: block; }
.cert-border {
  margin: 14px;
  border: 1px solid var(--gold);
  padding: 2.5rem 3rem 2rem;
  position: relative;
}
.cert-border::before, .cert-border::after {
  content: '✦';
  position: absolute;
  color: var(--gold);
  font-size: 0.9rem;
}
.cert-border::before { top: -0.55rem; left: 50%; transform: translateX(-50%); background: var(--paper); padding: 0 0.5rem; }
.cert-border::after  { bottom: -0.55rem; left: 50%; transform: translateX(-50%); background: var(--paper); padding: 0 0.5rem; }
.corner { position: absolute; width: 18px; height: 18px; border-color: var(--gold); border-style: solid; }
.corner.tl { top: 6px; left: 6px; border-width: 2px 0 0 2px; }
.corner.tr { top: 6px; right: 6px; border-width: 2px 2px 0 0; }
.corner.bl { bottom: 6px; left: 6px; border-width: 0 0 2px 2px; }
.corner.br { bottom: 6px; right: 6px; border-width: 0 2px 2px 0; }
.cert-header { text-align: center; margin-bottom: 2rem; }
.cert-emblem { font-size: 2.2rem; line-height: 1; margin-bottom: 0.5rem; color: var(--gold); }
.cert-title  { font-size: 1.75rem; font-weight: 600; letter-spacing: 0.04em; color: var(--ink); line-height: 1.2; }
.cert-subtitle { font-size: 0.8rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); margin-top: 0.3rem; }
.cert-rule { width: 120px; height: 1px; background: linear-gradient(to right, transparent, var(--gold), transparent); margin: 1rem auto; }
.cert-type-row { text-align: center; margin-bottom: 1rem; }
.tx-type-badge {
  display: inline-block; padding: 0.25rem 1rem; border: 1px solid var(--gold);
  border-radius: 2px; font-size: 0.7rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--gold); background: rgba(154,124,58,0.07);
}
.cert-status { text-align: center; margin: 0.8rem 0 1.8rem; }
.status-pill {
  display: inline-block; padding: 0.35rem 1.4rem; border-radius: 2px;
  font-size: 0.78rem; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 600;
}
.status-valid   { background: #e8f5ec; border: 1px solid #6ab080; color: var(--cert-green); }
.status-invalid { background: #fdf0f0; border: 1px solid #d9a0a0; color: var(--cert-red); }
.cert-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.cert-section { padding: 1.1rem 1.1rem 1.1rem 0; border-bottom: 1px solid var(--rule); }
.cert-section.col-right { padding-left: 1.1rem; border-left: 1px solid var(--rule); }
.cert-section.full      { grid-column: 1 / -1; padding: 1.1rem 0; border-left: none; }
.cert-section.no-border { border-bottom: none; }
.sect-label { font-size: 0.63rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.3rem; }
.sect-value { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink); word-break: break-all; line-height: 1.55; }
.sect-value.serif      { font-family: var(--font-serif); font-size: 1.05rem; font-style: italic; word-break: normal; }
.sect-value.amount-xrp { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 600; color: var(--ink); font-style: normal; }
.sect-value.amount-usd { font-family: var(--font-serif); font-size: 0.88rem; color: var(--ink-soft); font-style: italic; margin-top: 0.15rem; }
.transfer-arrow { grid-column: 1 / -1; text-align: center; padding: 0.6rem 0; font-size: 1.1rem; color: var(--gold); border-bottom: 1px solid var(--rule); }
.cert-divider { grid-column: 1 / -1; font-size: 0.6rem; letter-spacing: 0.25em; text-transform: uppercase; color: var(--ink-soft); padding: 0.7rem 0 0.3rem; border-bottom: 1px solid var(--rule); }
.cert-footer { display: flex; align-items: flex-start; gap: 2rem; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.qr-block { flex-shrink: 0; text-align: center; }
.qr-label { font-size: 0.62rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--ink-soft); margin-top: 0.5rem; }
#qrcode { width: 110px; height: 110px; }
#qrcode img, #qrcode canvas { width: 110px !important; height: 110px !important; }
.cert-legend { flex: 1; font-size: 0.78rem; color: var(--ink-mid); line-height: 1.8; }
.cert-legend strong { color: var(--ink); }
.legend-title { font-size: 0.63rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.4rem; }
.cert-seal { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; font-size: 0.7rem; color: var(--ink-soft); line-height: 1.6; }
.seal-stamp { font-size: 2.2rem; color: var(--gold); opacity: 0.35; line-height: 1; margin-bottom: 0.3rem; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--ui-border); border-top-color: var(--ui-accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 5px; }
@keyframes spin { to { transform: rotate(360deg); } }
.cert-notes { grid-column: 1 / -1; margin-top: 1rem; padding: 1rem 0 0; border-top: 1px solid var(--rule); }
.cert-notes .notes-label { font-size: 0.63rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.5rem; }
.cert-notes .notes-text { font-family: var(--font-serif); font-size: 0.9rem; color: var(--ink-mid); line-height: 1.8; white-space: pre-wrap; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; padding: 0; margin: 0; width: 210mm; height: 297mm; }
  .page-header, .input-panel, .btn-group, button { display: none !important; }
  .certificate { display: block !important; box-shadow: none; border: none; max-width: 100%; width: 210mm; min-height: 0; margin: 0; page-break-inside: avoid; }
  .cert-border { margin: 8mm; padding: 10mm 14mm 8mm; border-color: #bbb; }
  .corner { display: none; }
  .cert-header    { margin-bottom: 5mm; }
  .cert-emblem    { font-size: 1.4rem; margin-bottom: 2mm; }
  .cert-title     { font-size: 1.3rem; }
  .cert-subtitle  { font-size: 0.65rem; margin-top: 1mm; }
  .cert-rule      { margin: 3mm auto; }
  .cert-type-row  { margin-bottom: 2mm; }
  .tx-type-badge  { font-size: 0.6rem; padding: 0.15rem 0.7rem; }
  .cert-status    { margin: 2mm 0 4mm; }
  .status-pill    { font-size: 0.65rem; padding: 0.2rem 0.9rem; }
  .cert-section   { padding: 3mm 3mm 3mm 0; }
  .cert-section.col-right { padding-left: 3mm; }
  .cert-section.full      { padding: 3mm 0; }
  .sect-label     { font-size: 0.52rem; margin-bottom: 0.8mm; }
  .sect-value     { font-size: 0.6rem;  line-height: 1.4; }
  .sect-value.serif     { font-size: 0.85rem; }
  .sect-value.amount-xrp{ font-size: 1rem; }
  .sect-value.amount-usd{ font-size: 0.72rem; }
  .cert-divider   { font-size: 0.5rem; padding: 2mm 0 1mm; }
  .transfer-arrow { padding: 2mm 0; font-size: 0.85rem; }
  .cert-footer    { margin-top: 4mm; padding-top: 4mm; gap: 6mm; }
  #qrcode, #qrcode img, #qrcode canvas { width: 22mm !important; height: 22mm !important; }
  .qr-label       { font-size: 0.5rem; }
  .cert-legend    { font-size: 0.62rem; line-height: 1.5; }
  .legend-title   { font-size: 0.52rem; }
  .cert-seal      { font-size: 0.58rem; }
  .seal-stamp     { font-size: 1.4rem; }
  .cert-notes          { padding: 3mm 0 0; margin-top: 3mm; }
  .cert-notes .notes-label { font-size: 0.52rem; }
  .cert-notes .notes-text  { font-size: 0.75rem; line-height: 1.5; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}