:root {
    --bg-dark: #020617;
    --card-bg: rgba(15, 23, 42, 0.6);
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.5);
    --secondary: #a855f7;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-bright: rgba(255, 255, 255, 0.15);
    --error: #f43f5e;
    --success: #10b981;
    --ease-squish: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.6s var(--ease-squish);
    --transition-med: 0.3s var(--ease-squish);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Background Accents */
.bg-blob {
    position: fixed;
    width: 700px;
    height: 700px;
    border-radius: 50%;
    z-index: -1;
    opacity: 0.15;
    pointer-events: none;
    filter: blur(100px);
    /* Extra safety for smooth edges */
}

.blob-1 {
    top: -150px;
    right: -150px;
    background: radial-gradient(circle at center, var(--primary) 0%, rgba(99, 102, 241, 0) 70%);
    animation: pulse 12s infinite alternate;
}

.blob-2 {
    bottom: -150px;
    left: -150px;
    background: radial-gradient(circle at center, var(--secondary) 0%, rgba(168, 85, 247, 0) 70%);
    animation: pulse 10s infinite alternate-reverse;
}

@keyframes pulse {
    from {
        transform: scale(1) translate(0, 0);
    }

    to {
        transform: scale(1.2) translate(50px, 50px);
    }
}

.container {
    width: 100%;
    max-width: 1000px;
    min-height: 100vh;
    padding: 4rem 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    animation: slideUpFade 0.8s var(--ease-squish);
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 0.25rem;
}

.logo-image {
    width: 3.5rem;
    height: 3.5rem;
    filter: drop-shadow(0 0 10px var(--primary-glow));
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-5px);
    }

    100% {
        transform: translateY(0px);
    }
}

header h1 {
    font-size: clamp(2rem, 8vw, 4rem);
    font-weight: 800;
    letter-spacing: -3px;
    line-height: 1;
}

header h1 span {
    background: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-dim);
    font-size: 1.2rem;
    font-weight: 300;
}

/* Top Nav / Extension Area */
.top-nav {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    z-index: 100;
}

.ext-download-btn {
    display: inline-block;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.3);
    color: #c084fc;
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    transition: var(--transition-med);
    backdrop-filter: blur(10px);
}

.ext-download-btn:hover {
    background: rgba(168, 85, 247, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.2);
}

.text-link {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.85rem;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.3s;
    font-family: inherit;
}

.text-link:hover {
    color: var(--text-main);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
    display: flex !important;
    /* Override standard .hidden so transition works */
    visibility: hidden;
}

.modal-content {
    position: relative;
    max-width: 600px;
    width: 100%;
    padding: 2.5rem;
    transform: translateY(0) scale(1);
    transition: transform 0.4s var(--ease-squish);
}

.modal-backdrop.hidden .modal-content {
    transform: translateY(20px) scale(0.95);
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 25px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.3s, transform 0.3s;
    line-height: 1;
}

.close-btn:hover {
    color: var(--error);
    transform: rotate(90deg);
}

.modal-content h2 {
    margin-bottom: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.instructions-steps {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    background: rgba(255, 255, 255, 0.03);
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
}

.step-num {
    background: var(--primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.step p {
    color: var(--text-dim);
    line-height: 1.5;
    font-size: 1rem;
}

.step p strong {
    color: var(--text-main);
}

.step p code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--secondary);
    font-family: monospace;
    font-size: 0.9rem;
}

/* Tabs */
.tabs {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.4rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    display: flex;
    gap: 0.25rem;
    margin-bottom: 2rem;
    backdrop-filter: blur(10px);
    animation: slideUpFade 0.8s var(--ease-squish) 0.1s both;
    width: fit-content;
    margin: 0 auto;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.75rem 2.5rem;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition-med);
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-main);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.tab-btn:hover:not(.active) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

/* Card */
.card {
    width: 100%;
    background: var(--card-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 2rem;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
    animation: slideUpFade 0.8s var(--ease-squish) 0.2s both;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--glass-border-bright), transparent);
}

.tab-content {
    display: none;
    flex: 1;
    min-height: 0;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    animation: contentReveal 0.5s var(--ease-squish);
}

@keyframes contentReveal {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

label {
    display: block;
    margin-bottom: 1.25rem;
    font-weight: 500;
    color: var(--text-dim);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
}

textarea,
input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: white;
    padding: 1.25rem;
    font-family: inherit;
    font-size: 1.05rem;
    line-height: 1.6;
    transition: var(--transition-med);
}

textarea:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 1px var(--primary), 0 0 30px rgba(99, 102, 241, 0.15);
}

textarea {
    flex: 1;
    min-height: 150px;
    resize: none;
}

input {
    height: 72px;
}

.input-group {
    margin-bottom: 2rem;
}

.input-group:last-child {
    margin-bottom: 0;
}

.cookie-group textarea {
    min-height: 100px;
    font-size: 0.9rem;
    font-family: monospace;
    opacity: 0.8;
}

.cookie-group textarea:focus {
    opacity: 1;
}

#convert-btn,
#convert-png-btn {
    height: 64px;
    padding: 0 2.5rem;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-med);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#convert-btn {
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

#convert-btn:not(:disabled):hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px -10px var(--primary-glow);
    background: #7376ff;
}

#convert-png-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

#convert-png-btn:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--glass-border-bright);
    transform: translateY(-4px);
    box-shadow: 0 20px 40px -10px rgba(255, 255, 255, 0.05);
}

#convert-btn:not(:disabled):active,
#convert-png-btn:not(:disabled):active {
    transform: translateY(-1px);
}

#convert-btn:disabled,
#convert-png-btn:disabled {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    color: #475569;
    cursor: not-allowed;
    opacity: 0.5;
}

.actions {
    margin-top: 2.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    display: none;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#convert-btn.loading .spinner {
    display: block;
}

/* Toasts */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 1.25rem 2rem;
    border-radius: 20px;
    color: white;
    font-weight: 600;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 15px;
    min-width: 340px;
    animation: toastIn 0.5s var(--ease-squish);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(50px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.toast.success {
    border-left: 5px solid var(--success);
}

.toast.error {
    border-left: 5px solid var(--error);
}

.toast.info {
    border-left: 5px solid var(--primary);
}

.toast-exit {
    animation: toastExit 0.4s forwards var(--ease-squish);
}

@keyframes toastExit {
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* Footer */
footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    opacity: 0.5;
    animation: slideUpFade 0.8s var(--ease-squish) 0.4s both;
    flex-shrink: 0;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
        .top-nav {
        display: none !important;
    }

    .tab-btn[data-tab="url-mode"] {
        display: none !important;
    }

    .ext-download-btn {
        background: none;
        border: none;
        padding: 0;
        color: var(--secondary);
        font-size: 0.85rem;
        text-decoration: underline;
    }

    .text-link {
        font-size: 0.85rem;
    }

    .container {
        padding: 1rem;
        justify-content: flex-start;
        height: auto;
        min-height: 100vh;
    }

        header {
        margin-bottom: 1rem;
        margin-top: 0.5rem;
    }

    header h1 {
        font-size: 1.6rem;
        letter-spacing: -1px;
    }

    .logo-image {
        width: 2rem;
        height: 2rem;
    }

    .logo-container {
        gap: 8px;
    }

    .card {
        padding: 1.25rem;
        border-radius: 24px;
        flex: none;
        margin-bottom: 2rem;
    }

    textarea {
        height: 220px;
        padding: 1rem;
        font-size: 0.95rem;
    }

    input {
        height: 60px;
        padding: 1rem;
        font-size: 0.95rem;
    }

    .tabs {
        width: 100%;
        margin-bottom: 1.5rem;
        padding: 0.3rem;
        overflow: hidden;
    }

    .tab-btn {
        padding: 0.6rem 0.5rem;
        font-size: 0.8rem;
        flex: 1;
        border-radius: 12px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
        width: 100%;
        margin-top: 1.5rem;
    }

    #convert-btn,
    #convert-png-btn {
        width: 100%;
        height: 56px;
        font-size: 1rem;
        padding: 0;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8rem;
    }

    .ext-download-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}

@media (max-height: 750px) {
    .container {
        padding-top: 2rem;
    }

    .card {
        flex: none;
    }
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Review Studio */
.review-studio {
    width: 100%;
    background: var(--card-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 2rem;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    height: 80vh;
    /* Fixed height so we can scroll inside */
    animation: slideUpFade 0.7s var(--ease-squish);
}

.review-header {
    text-align: center;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.review-header p {
    color: var(--text-dim);
    margin-top: 5px;
}

.gallery {
    flex: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 16px;
    border: 1px inset var(--glass-border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    /* Pages touch each other linearly */
}

/* Hide scrollbar for aesthetics */
.gallery::-webkit-scrollbar {
    display: none;
}

.page-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    background: white;
    /* PDF simulation */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.page-container img {
    width: 100%;
    height: auto;
    display: block;
    -webkit-user-drag: none;
    pointer-events: none;
    /* Let drag events pass through to canvas or overlay */
}

/* The Crop Overlay */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    /* Dim out the cropped part */
    pointer-events: none;
    /* Only the handle is interactable */
    clip-path: inset(100% 0 0 0);
    /* Cropped part starts hidden at the bottom */
}

.crop-handle {
    position: absolute;
    bottom: -10px;
    /* Start at the bottom of the image */
    left: 0;
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: ns-resize;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crop-line {
    width: 100%;
    height: 3px;
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
    transition: background 0.2s;
}

.crop-handle:hover .crop-line {
    background: white;
    box-shadow: 0 0 15px white, 0 0 5px var(--error);
}

.page-number {
    position: absolute;
    top: 10px;
    left: -40px;
    color: var(--text-dim);
    font-weight: bold;
    font-size: 1.2rem;
}

.review-footer {
    padding-top: 1.5rem;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

#build-pdf-btn {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
    color: white;
    border: none;
    padding: 1.25rem 4rem;
    border-radius: 20px;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-med);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

#build-pdf-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px -10px rgba(99, 102, 241, 0.6);
}

#build-pdf-btn.loading .spinner {
    display: block;
}