:root {
    --bg: #f2ede6;
    --surface: rgba(255, 255, 255, 0.92);
    --surface-strong: #ffffff;
    --ink: #231f20;
    --muted: #6d6970;
    --primary: #244d88;
    --accent: #f7941d;
    --line: rgba(36, 77, 136, 0.12);
    --shadow: 0 24px 60px rgba(30, 45, 85, 0.14);
    --certificate-width: 3514px;
    --certificate-height: 2490px;
    --preview-scale: 0.28;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Poppins", Arial, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(247, 148, 29, 0.18), transparent 18%),
        radial-gradient(circle at top right, rgba(36, 77, 136, 0.22), transparent 26%),
        linear-gradient(180deg, #f8f4ee 0%, #efe8de 100%);
    padding: 28px;
}

.page-shell {
    max-width: 1600px;
    margin: 0 auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 24px;
}

.hero-copy {
    max-width: 760px;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 8px 14px;
    background: rgba(36, 77, 136, 0.08);
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.page-header h1 {
    margin: 12px 0 8px;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.05;
}

.page-header p {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.75;
}

.header-actions,
.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.search-panel,
.preview-panel {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.search-panel {
    padding: 26px;
}

.preview-panel {
    padding: 26px;
    overflow: hidden;
}

.panel-head h2,
.preview-head h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.panel-head p,
.preview-head p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
}

.panel-head code,
.preview-head code {
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(36, 77, 136, 0.08);
    color: var(--primary);
    font-size: 13px;
}

.search-form {
    display: grid;
    gap: 14px;
    margin-top: 22px;
}

.input-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--primary);
}

.search-form input {
    width: 100%;
    padding: 16px 18px;
    border: 1px solid rgba(36, 77, 136, 0.14);
    border-radius: 18px;
    font: inherit;
    font-size: 16px;
    color: var(--ink);
    background: var(--surface-strong);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.search-form input:focus {
    border-color: rgba(36, 77, 136, 0.44);
    box-shadow: 0 0 0 4px rgba(36, 77, 136, 0.08);
    transform: translateY(-1px);
}

.primary-btn,
.ghost-btn {
    border: 0;
    border-radius: 16px;
    padding: 14px 18px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.primary-btn {
    background: linear-gradient(135deg, #244d88 0%, #3065ad 55%, #f7941d 150%);
    color: #fff;
    box-shadow: 0 16px 28px rgba(36, 77, 136, 0.22);
}

.ghost-btn {
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink);
    border: 1px solid var(--line);
}

.primary-btn:hover,
.ghost-btn:hover {
    transform: translateY(-1px);
}

.search-meta {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(36, 77, 136, 0.06);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.6;
}

.result-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.result-item {
    width: 100%;
    border: 1px solid rgba(36, 77, 136, 0.1);
    background: #fff;
    border-radius: 20px;
    padding: 16px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.result-item:hover {
    transform: translateY(-1px);
    border-color: rgba(36, 77, 136, 0.24);
    box-shadow: 0 14px 26px rgba(23, 43, 77, 0.08);
}

.result-item strong {
    display: block;
    font-size: 16px;
    margin-bottom: 6px;
    color: var(--ink);
}

.result-item span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.preview-stage {
    margin-top: 22px;
}

.empty-state {
    min-height: 320px;
    border-radius: 28px;
    border: 1.5px dashed rgba(36, 77, 136, 0.22);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 247, 234, 0.94)),
        radial-gradient(circle at top right, rgba(247, 148, 29, 0.14), transparent 26%);
    display: grid;
    place-items: center;
    text-align: center;
    padding: 28px;
    color: var(--muted);
}

.empty-state strong {
    display: block;
    margin-bottom: 10px;
    font-size: 22px;
    color: var(--ink);
}

.certificate-wrap {
    width: 100%;
}

.certificate-stage {
    position: relative;
    width: 100%;
    height: calc(var(--certificate-height) * var(--preview-scale));
    overflow: hidden;
}

.certificate-artboard {
    position: absolute;
    top: 0;
    left: 50%;
    width: var(--certificate-width);
    height: var(--certificate-height);
    /* Default template; JS akan override via style.backgroundImage */
    background: url("Sertifikat_PreReg.jpg") center/cover no-repeat;
    transform: translateX(-50%) scale(var(--preview-scale));
    transform-origin: top center;
    box-shadow: 0 26px 56px rgba(23, 43, 77, 0.16);
}

/* ── Certificate fields ──────────────────────────────────────────────────── */

.certificate-field {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: #2d2627;
    text-align: center;
    white-space: nowrap;
}

/* Nomor sertifikat */
.certificate-number {
    top: 520px;
    width: 1900px;
    font-size: 92px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

/* Nama peserta */
.certificate-name {
    top: 710px;
    width: 2300px;
    min-height: 190px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 150px;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 0.98;
    white-space: normal;
    text-transform: uppercase;
}

/* Sekolah */
.certificate-school {
    top: 900px;
    width: 2200px;
    min-height: 112px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 82px;
    font-weight: 700;
    line-height: 1;
    white-space: normal;
    text-transform: uppercase;
}

.certificate-kegiatan {
    top: 1100px;
    width: 2200px;
    min-height: 112px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 65px;
    font-weight: 600;
    white-space: normal;
}

.is-hidden {
    display: none !important;
    visibility: hidden !important;
}

@media print {
    .is-hidden {
        display: none !important;
        visibility: hidden !important;
    }
}

/* Deskripsi: "Sebagai Juara 1 ..." / "Sebagai peserta GRAND FINAL ..."
   Posisi di bawah sekolah, italic sesuai desain sertifikat             */
.certificate-desc {
    top: 1020px;
    width: 2600px;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 72px;
    font-weight: 600;
    /* font-style: italic; */
    line-height: 1.1;
    white-space: normal;
    color: #2d2627;
}

.is-loading {
    opacity: 0.72;
    pointer-events: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
    body {
        padding: 20px;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .header-actions {
        justify-content: flex-start;
    }

    :root {
        --preview-scale: 0.22;
    }
}

@media (max-width: 720px) {
    body {
        padding: 14px;
    }

    .search-panel,
    .preview-panel {
        padding: 18px;
        border-radius: 22px;
    }

    .header-actions,
    .form-actions {
        flex-direction: column;
    }

    .primary-btn,
    .ghost-btn {
        width: 100%;
        text-align: center;
    }

    :root {
        --preview-scale: 0.14;
    }
}

/* ── Print ───────────────────────────────────────────────────────────────── */

@media print {
    @page {
        size: 3514px 2490px;
        margin: 0;
    }

    html,
    body {
        width: 3514px;
        height: 2490px;
        margin: 0;
        padding: 0;
        background: #fff;
        overflow: hidden;
    }

    .page-header,
    .search-panel,
    .preview-head,
    .empty-state {
        display: none !important;
    }

    .page-shell,
    .content-grid,
    .preview-panel,
    .preview-stage,
    .certificate-wrap,
    .certificate-stage {
        display: block;
        width: 3514px;
        height: 2490px;
        margin: 0;
        padding: 0;
        max-width: none;
        min-height: auto;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        overflow: hidden;
    }

    .certificate-artboard {
        position: relative;
        top: 0;
        left: 0;
        width: 3514px !important;
        height: 2490px !important;
        transform: none !important;
        box-shadow: none;
        margin: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}