/* -----------------------------------------------------------
           BASE VARIABLES & RESET
           ----------------------------------------------------------- */


body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: var(--body-font);
    overflow-x: hidden;
    padding: 20px;
    margin: 0;
}

/* -----------------------------------------------------------
           CERTIFICATE CONTAINER (Desktop/Print Default)
           ----------------------------------------------------------- */
.cert-wrapper {
    width: 297mm;
    height: 210mm;
    background-color: var(--graphite);
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    /* Ensure it doesn't shrink on small screens initially */
    flex-shrink: 0;
}

/* Circular Watermark */
.watermark-img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40rem;
    height: 40rem;
    border-radius: 50%;
    object-fit: contain;
    opacity: 0.05;
    z-index: 2;
    pointer-events: none;
}

/* Dark Overlay */
.overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(21, 21, 21, 0.9) 0%, rgba(11, 11, 13, 0.98) 100%);
    z-index: 1;
}

/* Content Layer */
.content-layer {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px 60px;
}

/* --- Borders & Ornaments --- */
.border-frame {
    position: absolute;
    inset: 5mm;
    border: 2px solid var(--liquid-gold);
    z-index: 5;
    pointer-events: none;
}

.border-frame::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid var(--molten-orange);
    opacity: 0.6;
}

.corner-decor {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--liquid-gold);
    z-index: 6;
}

.c-tl {
    top: 14mm;
    left: 14mm;
    border-right: none;
    border-bottom: none;
}

.c-tr {
    top: 14mm;
    right: 14mm;
    border-left: none;
    border-bottom: none;
}

.c-bl {
    bottom: 14mm;
    left: 14mm;
    border-right: none;
    border-top: none;
}

.c-br {
    bottom: 14mm;
    right: 14mm;
    border-left: none;
    border-top: none;
}

/* Header Section */
.header-section {
    position: absolute;
    top: 25mm;
    left: 25mm;
    right: 25mm;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 20;
}

.logo-container {
    width: 6rem;
    height: 6rem;
    border-radius: 50%;
    border: 3px solid var(--liquid-gold);
    padding: 4px;
    background: rgba(11, 11, 13, 0.8);
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.3);
    flex-shrink: 0;
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.qr-block {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#qrcode {
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#qrcode img,
#qrcode canvas {
    background: transparent !important;
    filter: invert(1) brightness(1.2);
}

/* Center Content */
.center-content {
    text-align: center;
    flex-grow: 1;
    display: flex;
    margin-top: 3rem;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

h1.cert-title {
    font-family: 'Cinzel', serif;
    font-size: 3.2rem;
    letter-spacing: 5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    margin: 0;
}

.subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.2rem;
    color: var(--soft-white);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 5px;
}

.presented-text {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.3rem;
    color: var(--soft-white);
    margin-top: 20px;
}

.recipient-name {
    font-family: 'Cinzel', serif;
    font-size: 3.8rem;
    margin: 10px 0 20px 0;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    border-bottom: 2px solid var(--molten-orange);
    display: inline-block;
    padding-bottom: 10px;
    min-width: 50%;
    line-height: 1.2;
}

.description {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.1rem;
    color: var(--soft-white);
    max-width: 75%;
    margin: 0 auto 25px auto;
    line-height: 1.6;
}

.score-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--liquid-gold);
    padding: 10px 30px;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--heading-font);
    font-weight: 700;
    color: var(--liquid-gold);
    font-size: 1.4rem;
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.1);
}

/* Footer Section */
.footer-section {
    position: absolute;
    bottom: 25mm;
    left: 25mm;
    right: 25mm;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 20;
}

.sig-block {
    text-align: center;
    width: 250px;
}

.sig-line {
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--ashen-silver), transparent);
    margin-bottom: 10px;
}

.sig-name {
    font-family: 'Great Vibes', cursive;
    font-size: 2.2rem;
    color: var(--molten-orange);
    margin-bottom: 5px;
    transform: rotate(-5deg);
    text-shadow: 0 0 10px rgba(255, 106, 0, 0.3);
}

.sig-title {
    font-size: 0.8rem;
    color: var(--steel-gray);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.meta-info {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}

.reg-badge {
    font-family: monospace;
    font-size: 1rem;
    color: var(--electric-blue);
    background: rgba(0, 191, 255, 0.1);
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px dashed var(--electric-blue);
    letter-spacing: 1px;
    white-space: nowrap;
}

.date-badge {
    font-family: var(--body-font);
    font-size: 0.85rem;
    color: var(--ashen-silver);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Floating Button */
.fab-download {
    position: fixed !important;
    bottom: 30px;
    right: 30px;
    z-index: 100;
}

/* -----------------------------------------------------------
           RESPONSIVE DESIGN (Mobile & Tablet)
           ----------------------------------------------------------- */

/* Target screens smaller than A4 Landscape width (approx 11 inches) */
@media screen and (max-width: 1100px) {
    body {
        padding: 10px;
        align-items: flex-start;
        /* Allow scrolling if needed */
    }

    .cert-wrapper {
        /* Switch from fixed mm to percentage/max-width */
        width: 100%;
        max-width: 800px;
        /* Max width for tablet view */
        height: auto;
        /* Let height grow naturally */
        min-height: 500px;
        aspect-ratio: 297/210;
        /* Maintain rough A4 ratio visually */
        padding: 20px;
    }

    /* Adjust Padding inside wrapper */
    .content-layer {
        padding: 30px 20px;
    }

    /* Adjust Absolute Positions to be Relative/Flexible */
    .header-section {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        margin-bottom: 20px;
        justify-content: space-between;
    }

    .center-content {
        margin-top: 10px;
        padding: 20px 0;
    }

    .footer-section {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        margin-top: 20px;
        flex-direction: row;
        /* Keep side-by-side on tablet */
        justify-content: space-between;
    }

    /* Scale Down Fonts */
    h1.cert-title {
        font-size: 2rem;
        letter-spacing: 2px;
    }

    .recipient-name {
        font-size: 2.2rem;
        min-width: 80%;
    }

    .subtitle {
        font-size: 1rem;
    }

    .description {
        font-size: 1rem;
        max-width: 95%;
    }

    .score-badge {
        font-size: 1.1rem;
        padding: 8px 20px;
    }

    /* Adjust Logo & QR size */
    .logo-container {
        width: 4rem;
        height: 4rem;
    }

    #qrcode {
        width: 70px;
        height: 70px;
    }

    /* Adjust Watermark */
    .watermark-img {
        width: 25rem;
        height: 25rem;
    }

    /* Adjust Borders */
    .border-frame {
        inset: 10px;
    }

    .corner-decor {
        width: 15px;
        height: 15px;
    }

    .c-tl,
    .c-tr,
    .c-bl,
    .c-br {
        top: 10px;
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
}

/* Target Phones specifically */
@media screen and (max-width: 600px) {
    .cert-wrapper {
        aspect-ratio: auto;
        /* Remove aspect ratio constraint on phones */
        min-height: auto;
    }

    .footer-section {
        flex-direction: column-reverse;
        /* Stack signature and date */
        align-items: center;
        gap: 30px;
    }

    .meta-info {
        align-items: center;
        text-align: center;
    }

    .sig-block {
        width: 100%;
    }

    h1.cert-title {
        font-size: 1.5rem;
    }

    .recipient-name {
        font-size: 1.8rem;
    }

    .description {
        font-size: 0.9rem;
    }

    /* Hide decorative corners on very small screens to save space/clutter */
    .corner-decor {
        display: none;
    }
}

/* -----------------------------------------------------------
           PRINT OPTIMIZATION
           ----------------------------------------------------------- */
@media print {
    @page {
        size: 297mm 210mm;
        margin: 0 !important;
    }

    body {
        background: none !important;
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
        width: 297mm !important;
        height: 210mm !important;
        overflow: hidden !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .cert-wrapper {
        box-shadow: none !important;
        width: 297mm !important;
        height: 210mm !important;
        margin: 0 !important;
        padding: 0 !important;
        position: relative !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        scale: 1 !important;
        background-color: var(--graphite) !important;
        /* Reset responsive changes for print */
        max-width: none !important;
        aspect-ratio: auto !important;
    }

    /* Reset positions for print */
    .header-section {
        position: absolute !important;
        top: 25mm !important;
        left: 25mm !important;
        right: 25mm !important;
        margin: 0 !important;
    }

    .footer-section {
        position: absolute !important;
        bottom: 25mm !important;
        left: 25mm !important;
        right: 25mm !important;
        margin: 0 !important;
    }

    .center-content {
        margin-top: 3rem !important;
    }

    /* Ensure colors print correctly */
    h1.cert-title,
    .recipient-name {
        background: none !important;
        -webkit-background-clip: initial !important;
        background-clip: initial !important;
        -webkit-text-fill-color: var(--liquid-gold) !important;
        color: var(--liquid-gold) !important;
    }

    .no-print,
    .fab-download {
        display: none !important;
    }
}