:root {
    --bg-color: #e0e5ec;
    --text-main: #4a4a4a;
    --text-light: #8e9aaf;
    --accent: #6d5dfc;
    /* Vibrant purple-blue for active states */
    --shadow-light: #ffffff;
    --shadow-dark: #a3b1c6;
    --radius-main: 30px;
    --radius-btn: 50px;
    --font-main: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    transition: all 0.5s ease;
}

body.has-results {
    justify-content: flex-start;
    padding-top: 60px;
}

/* Typography & Layout */
.container {
    width: 90%;
    max-width: 900px;
    text-align: center;
}

.header {
    margin-bottom: 3rem;
}

.header h1 {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-main);
    text-shadow: 2px 2px 4px var(--shadow-dark), -2px -2px 4px var(--shadow-light);
    margin-bottom: 0.5rem;
}

.header p {
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Neumorphic Card (The Search Box) */
.search-box {
    background: var(--bg-color);
    padding: 3rem 3rem 1.5rem 3rem;
    border-radius: var(--radius-main);
    box-shadow:
        9px 9px 16px var(--shadow-dark),
        -9px -9px 16px var(--shadow-light);
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 650px;
    margin: 0 auto;
    transition: all 0.3s ease;
}

/* Drag & Drop Visual Feedback */
.search-box.drag-over {
    border: 2px dashed var(--accent);
    background: rgba(109, 93, 252, 0.05);
    transform: scale(1.02);
}

.input-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* Neumorphic Input (Inset) */
input[type="text"] {
    flex: 1;
    border: none;
    background: var(--bg-color);
    padding: 1.2rem 1.5rem;
    border-radius: var(--radius-btn);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    outline: none;
    box-shadow: inset 6px 6px 10px var(--shadow-dark),
        inset -6px -6px 10px var(--shadow-light);
    transition: all 0.3s ease;
}

input[type="text"]:focus {
    box-shadow: inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
    color: var(--accent);
}

input::placeholder {
    color: var(--text-light);
}

/* Neumorphic Button (Convex/Extruded) - Main Extract Button */
button {
    border: none;
    background-color: var(--bg-color);
    color: var(--accent);
    font-weight: 600;
    padding: 1.2rem 2.5rem;
    border-radius: var(--radius-btn);
    font-size: 1rem;
    cursor: pointer;
    box-shadow:
        6px 6px 10px var(--shadow-dark),
        -6px -6px 10px var(--shadow-light);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow:
        8px 8px 14px var(--shadow-dark),
        -8px -8px 14px var(--shadow-light);
}

button:active {
    transform: translateY(1px);
    box-shadow: inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
}

button:disabled {
    color: var(--text-light);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* --- Action Buttons (Upload & Coffee) --- */
.action-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 2rem;
    width: 100%;
}

.neumorphic-btn {
    text-decoration: none;
    font-size: 0.9rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.8rem 1.8rem;
    border-radius: 50px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    background: var(--bg-color);
    box-shadow:
        5px 5px 10px var(--shadow-dark),
        -5px -5px 10px var(--shadow-light);
}

.neumorphic-btn:hover {
    transform: translateY(-2px);
    color: var(--accent);
    box-shadow:
        7px 7px 14px var(--shadow-dark),
        -7px -7px 14px var(--shadow-light);
}

.neumorphic-btn:active {
    transform: translateY(1px);
    box-shadow: inset 3px 3px 6px var(--shadow-dark),
        inset -3px -3px 6px var(--shadow-light);
}

.neumorphic-btn.coffee:hover {
    color: #FF813F;
}

/* --- Rescue Box (Styled Error Notification) --- */
.status-msg {
    margin: 0;
    transition: all 0.3s ease;
}

.rescue-box {
    margin-top: 2rem;
    padding: 1.5rem;
    border-radius: 20px;
    background: var(--bg-color);
    box-shadow: inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
    text-align: center;
    animation: fadeIn 0.5s ease;
    width: 100%;
    box-sizing: border-box;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.rescue-text {
    color: #ff6b6b;
    font-weight: 600;
    margin-bottom: 1rem;
    display: block;
    font-size: 0.95rem;
}

.rescue-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.8rem 1.5rem;
    border-radius: 30px;
    background: var(--bg-color);
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 5px 5px 10px var(--shadow-dark),
        -5px -5px 10px var(--shadow-light);
    transition: all 0.3s ease;
}

.rescue-link-btn:hover {
    transform: translateY(-2px);
    box-shadow: 7px 7px 14px var(--shadow-dark),
        -7px -7px 14px var(--shadow-light);
}

.rescue-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 1rem;
}

/* NEW: Enhanced Upload Link Styling */
.upload-area {
    margin-top: 2rem;
    /* Clear separation from input */
    text-align: center;
}

.upload-link {
    color: var(--accent);
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 4px;
    transition: all 0.2s ease;
}

.upload-link:hover {
    color: #4834d4;
    text-shadow: 0 0 10px rgba(109, 93, 252, 0.3);
}


/* Paper Metadata Card */
.paper-meta-card {
    text-align: left;
    margin-bottom: 2rem;
    padding: 1.5rem 2rem;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
    border-left: 5px solid var(--accent);
}

.paper-meta-card h2 {
    font-size: 1.5rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-main);
    line-height: 1.3;
}

.paper-meta-card p {
    margin: 0;
    color: var(--text-light);
    font-size: 1rem;
    font-weight: 500;
}


/* Gallery Section */
.result-section {
    margin-top: 4rem;
    width: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.5s;
}

.result-section.visible {
    display: block;
    opacity: 1;
}

/* Result Header Layout */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 0 1rem;
    flex-wrap: wrap;
    gap: 15px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.result-header h2 {
    color: var(--text-main);
    text-shadow: 1px 1px 2px var(--shadow-light);
    margin: 0;
    white-space: nowrap;
}

/* --- Filter Controls (Slider Only) --- */
.filter-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 5px;
}

/* Slider Style Updates (No Toggle opacity) */
.slider-wrapper {
    display: flex;
    align-items: center;
    position: relative;
    opacity: 1;
    pointer-events: auto;
    transition: all 0.3s ease;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 140px;
    background: transparent;
}

/* Slider Track (Inset) */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 12px;
    cursor: pointer;
    background: var(--bg-color);
    border-radius: 10px;
    box-shadow: inset 2px 2px 5px var(--shadow-dark),
        inset -2px -2px 5px var(--shadow-light);
}

/* Slider Thumb (Popping Out - iOS Style) */
input[type=range]::-webkit-slider-thumb {
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin-top: -6px;
    /* Soft premium shadow */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

input[type=range]:active::-webkit-slider-thumb {
    transform: scale(1.1);
}

/* Tooltip for value (iOS Glassmorphism) */
.slider-tooltip {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 6px 12px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    font-weight: 600;
}

.slider-wrapper:hover .slider-tooltip,
.slider-wrapper:active .slider-tooltip {
    opacity: 1;
}

/* Icon Button (for Sort, etc.) */
.neumorphic-icon-btn {
    width: 45px;
    height: 45px;
    border-radius: 15px;
    /* Softer corners */
    padding: 0;
    min-width: unset;
    /* Override default button min-width */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--text-light);
    background: var(--bg-color);
    border: none;
    cursor: pointer;
    box-shadow:
        5px 5px 10px var(--shadow-dark),
        -5px -5px 10px var(--shadow-light);
    transition: all 0.2s ease;
}

.neumorphic-icon-btn:hover {
    transform: translateY(-2px);
    color: var(--accent);
    box-shadow:
        7px 7px 12px var(--shadow-dark),
        -7px -7px 12px var(--shadow-light);
}

.neumorphic-icon-btn:active {
    transform: translateY(1px);
    box-shadow: inset 3px 3px 6px var(--shadow-dark),
        inset -3px -3px 6px var(--shadow-light);
}


/* Download Button */
.download-all-btn {
    background: var(--bg-color);
    color: var(--accent);
    border: none;
    border-radius: var(--radius-btn);
    padding: 0.8rem 1.5rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow:
        5px 5px 10px var(--shadow-dark),
        -5px -5px 10px var(--shadow-light);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.download-all-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        7px 7px 12px var(--shadow-dark),
        -7px -7px 12px var(--shadow-light);
}

.download-all-btn:active {
    transform: translateY(1px);
    box-shadow: inset 3px 3px 6px var(--shadow-dark),
        inset -3px -3px 6px var(--shadow-light);
}

.download-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    position: relative;
}

/* Trash Button */
.trash-btn {
    color: var(--text-light);
    margin-left: 5px;
    /* Slight separation */
}

.trash-btn:hover {
    color: #ff4757;
    /* Red Warning Color */
    transform: translateY(-2px);
    box-shadow:
        7px 7px 12px var(--shadow-dark),
        -7px -7px 12px var(--shadow-light);
}

.trash-btn:active {
    transform: scale(0.92);
    /* Deep Press */
    box-shadow: inset 4px 4px 8px rgba(163, 177, 198, 0.6),
        inset -4px -4px 8px rgba(255, 255, 255, 0.8);
    color: #e84118;
}

/* Apple-style Deletion Animation (Poof) */
.img-card.deleting {
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform: scale(0.1);
    opacity: 0;
    pointer-events: none;
}


/* Checkbox for selection */
.img-card {
    position: relative;
    /* For positioning checkbox */
}

.checkbox-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: var(--bg-color);
    border-radius: 50%;
    box-shadow:
        3px 3px 6px var(--shadow-dark),
        -3px -3px 6px var(--shadow-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
}

.checkbox-overlay.checked {
    background: var(--accent);
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.2);
}

.checkbox-overlay i {
    font-size: 12px;
    color: white;
    opacity: 0;
    transition: opacity 0.2s;
}

.checkbox-overlay.checked i {
    opacity: 1;
}

.img-card.selected {
    box-shadow: inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
    border: 1px solid var(--accent);
}


.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 30px;
}

/* Neumorphic Image Card (Floating Display Card) */
.img-card {
    background: var(--bg-color);
    border-radius: 20px;
    padding: 15px;
    box-shadow:
        9px 9px 16px var(--shadow-dark),
        -9px -9px 16px var(--shadow-light);
    transition: transform 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.img-card:hover {
    transform: translateY(-5px);
}

/* Wrapper */
.img-wrapper {
    border-radius: 15px;
    overflow: hidden;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Optional: Inner shadow for image container */
    box-shadow: inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
    padding: 10px;
    background: var(--bg-color);
}

.img-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    mix-blend-mode: multiply;
}

.img-info {
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    padding: 0 5px;
}

/* Neumorphic Loader */
.spinner {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-color);
    position: relative;
    box-shadow: inset 2px 2px 4px var(--shadow-dark),
        inset -2px -2px 4px var(--shadow-light);
    display: none;
}

/* Rotating Bead */
.spinner::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 1px 1px 2px var(--shadow-dark),
        -1px -1px 2px var(--shadow-light);

    /* Position at top center */
    top: 3px;
    left: 9px;
    /* (24 - 6) / 2 = 9px to center horizontally */

    /* Origin is center of container relative to bead */
    /* Container center is at (12, 12). Bead center is at (12, 6). Distance is 6px. */
    /* Transform origin y = 6px (distance) + 3px (half height) = 9px. */
    transform-origin: 50% 9px;

    animation: orbit 1s linear infinite;
}

@keyframes orbit {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Ensure Button Layout accommodates spinner */
#btnSpinner {
    display: none;
    /* Controlled by JS */
}

/* Responseiveness */
@media (max-width: 600px) {
    .header h1 {
        font-size: 2rem;
    }

    .search-box {
        padding: 2rem 1.5rem;
        width: auto;
    }

    .input-group {
        flex-direction: column;
        width: 100%;
    }

    input[type="text"] {
        width: 100%;
        box-sizing: border-box;
    }

    button {
        width: 100%;
    }

    /* Stack buttons on mobile */
    .action-buttons {
        flex-direction: column;
        gap: 15px;
    }

    .neumorphic-btn {
        width: 100%;
        justify-content: center;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .download-all-btn {
        width: 100%;
        justify-content: center;
    }

    .filter-controls {
        width: 100%;
        justify-content: space-between;
    }
}

/* --- Chat Widget (Global Paper War) --- */
/* --- Chat Widget (Global Paper War) --- */
.chat-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    min-width: 50px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    background: var(--bg-color);
    border: none;
    color: var(--accent);
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
}

.chat-toggle.hidden {
    transform: scale(0) !important;
    opacity: 0;
    pointer-events: none;
}

.chat-toggle:hover {
    transform: scale(1.1);
    color: #5a4bcf;
}

/* ... (Active state remains same) ... */

/* ... (Badge remains same) ... */

/* Header & Close Button */
.chat-header {
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(163, 177, 198, 0.3);
}

.close-chat {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    box-shadow: none !important;
    color: var(--text-light);
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-chat:hover {
    color: #ff4757;
    background: rgba(255, 71, 87, 0.1);
    transform: rotate(90deg);
}

/* Leaderboard Area */
.chat-rank {
    padding: 10px;
    background: rgba(109, 93, 252, 0.05);
    display: flex;
    gap: 10px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    /* Firefox */
}

.chat-rank::-webkit-scrollbar {
    display: none;
}

.rank-item {
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--bg-color);
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    color: var(--text-main);
    font-weight: 600;
}

.rank-item.top {
    color: var(--accent);
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -2px -2px 4px var(--shadow-light);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.system-msg {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-light);
    margin: 10px 0;
    font-style: italic;
}

.msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.msg-row.mine {
    flex-direction: row-reverse;
}

.msg-flag {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.msg-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg-row .msg-bubble {
    background: var(--bg-color);
    color: var(--text-main);
    box-shadow:
        5px 5px 10px var(--shadow-dark),
        -5px -5px 10px var(--shadow-light);
    border-bottom-left-radius: 2px;
}

.msg-row.mine .msg-bubble {
    background: var(--accent);
    color: white;
    box-shadow:
        5px 5px 10px rgba(109, 93, 252, 0.4),
        -5px -5px 10px var(--shadow-light);
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 2px;
}

/* Input Area */
.chat-input-area {
    padding: 15px;
    display: flex;
    gap: 10px;
    border-top: 1px solid rgba(163, 177, 198, 0.3);
}

#chatInput {
    padding: 10px 15px;
    /* Smaller than main input */
    font-size: 0.9rem;
}

#sendChatBtn {
    min-width: 45px;
    width: 45px;
    height: 45px;
    padding: 0;
    border-radius: 50%;
    /* Circle btn */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
    border: none;
    background: var(--bg-color);
    color: var(--accent);
    cursor: pointer;
    transition: all 0.2s;
}

#sendChatBtn:active {
    box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
}

/* Chat Container - FIXED POSITIONING */
.chat-container {
    position: fixed !important;
    bottom: 30px;
    /* SAME AS BUTTON */
    right: 30px;
    width: 320px;
    height: 500px;
    max-height: 70vh;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow: 10px 10px 20px var(--shadow-dark), -10px -10px 20px var(--shadow-light);
    display: flex;
    flex-direction: column;
    z-index: 9998;

    /* Animation: Grow from button */
    transform-origin: bottom right;

    /* Initially Hidden */
    transform: scale(0);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    /* Bouncy Animation */
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.1);

    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.chat-container.open {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Connection Status Dot */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
    margin-left: 8px;
    display: inline-block;
    vertical-align: middle;
    transition: background-color 0.3s;
}

.status-dot.connected {
    background-color: #2ecc71;
    box-shadow: 0 0 5px #2ecc71;
}

.status-dot.disconnected {
    background-color: #e74c3c;
}

/* Leaderboard 2.0 */
.rank-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    /* Glass feel */
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 8px;
    transition: transform 0.2s, background 0.2s;
    animation: slideIn 0.4s ease-out backwards;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.rank-card:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.rank-card.top-rank {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.2);
    /* Subtle Gold border */
    font-weight: 600;
}

.rank-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rank-num {
    font-size: 0.9rem;
    color: var(--text-light);
    width: 24px;
    text-align: center;
}

.medal {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.chat-rank {
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    margin: 10px 10px 0 10px;
    border-radius: 12px;
    /* Scroll support for many countries */
    max-height: 150px;
    /* Keep it compact above chat */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.chat-rank::-webkit-scrollbar {
    width: 4px;
}

.chat-rank::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.country-code {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
}

.rank-score {
    font-size: 1rem;
    background: -webkit-linear-gradient(45deg, #0984e3, #6c5ce7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.rank-empty {
    text-align: center;
    color: var(--text-light);
    padding: 20px;
    font-size: 0.9rem;
    line-height: 1.5;
    opacity: 0.7;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(10px);
    }

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

/* Empty State (Existing) */
.empty-state {
    grid-column: 1 / -1;
    /* Span full width grid */
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.empty-state i {
    font-size: 4rem;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.5rem;
    color: var(--text-main);
    margin: 0;
}

.empty-state p {
    font-size: 0.9rem;
    line-height: 1.5;
    opacity: 0.7;
}

/* PDF View Button (Icon Only) */
.pdf-view-btn {
    margin-right: 15px;
    /* Spacing */
    vertical-align: middle;
}

.pdf-view-btn i {
    font-size: 1.2rem;
    color: #6c5ce7 !important;
    /* Theme Purple */
    filter: drop-shadow(0 0 5px rgba(108, 92, 231, 0.3));
}

/* --- Mobile Responsiveness --- */

/* DOI Pill Style - Absolute Positioning over Image */
.doi-pill {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(109, 93, 252, 0.85);
    /* Slightly more opaque */
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.doi-pill:hover {
    background: #5f27cd;
    /* Solid color on hover */
    transform: scale(1.05);
}

.doi-pill i {
    font-size: 0.75rem;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    /* Search Box: Stack vertically */
    .search-box .input-group {
        flex-direction: column;
        gap: 15px;
        padding: 5px;
        /* Reduce internal padding */
    }

    .search-box input {
        width: 100%;
        text-align: center;
        margin-bottom: 5px;
    }

    .search-box button {
        width: 100%;
        justify-content: center;
        border-radius: 12px !important;
        /* Reset radius */
        margin-left: 0 !important;
    }

    /* Results Header */
    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
    }

    .header-right {
        display: flex;
        flex-wrap: wrap;
        width: 100%;
        gap: 10px;
    }

    /* Small Buttons: Share row equally */
    .header-right .neumorphic-icon-btn,
    .header-right .pdf-view-btn {
        flex: 1;
        min-width: 0;
        /* Prevent overflow */
        margin-right: 0 !important;
    }

    /* Download All: Full Width below */
    #downloadAllBtn {
        width: 100%;
        order: 10;
        margin-top: 5px;
    }

    /* Gallery: 2 Columns for Mobile */
    .gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* Chat Widget Mobile - Full Screen Overlay Pattern */
    .chat-container {
        /* Full Screen Override */
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;

        width: 100%;
        height: 100vh;
        /* Use vh or % */
        height: 100dvh;
        /* Dynamic viewport height for mobile browsers */
        max-height: none;
        margin: 0;
        border-radius: 0;

        display: flex;
        flex-direction: column;
        z-index: 20000;
        /* Ensure on top of everything */
    }

    /* Ensure input handles safe area (Home Bar) */
    .chat-container .chat-input-area {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
        background: var(--bg-color);
        /* Opaque background */
    }

    /* Compact Inner Elements for Mobile */
    .chat-container .chat-header {
        padding: 10px 15px;
    }

    .chat-container .social-tabs {
        padding: 5px 15px 0 15px;
    }

    .chat-container .chat-rank {
        padding: 6px 10px;
        min-height: auto;
    }

    .chat-container .rank-item {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    /* Ensure message list grows */
    .chat-container .chat-messages {
        flex: 1;
        min-height: 0;
        padding: 10px;
    }

    /* Helper for PDF/Sort buttons */
    .pdf-view-btn,
    .neumorphic-icon-btn {
        margin-right: 0;
        /* Let flex gap handle spacing */
    }

    button,
    a.neumorphic-btn {
        min-height: 44px;
    }
}

/* History Chips */
.search-history {
    margin-top: 15px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    align-items: stretch;
}

.history-chip {
    background: rgba(255, 255, 255, 0.05);
    /* Revert to faint */
    padding: 6px 14px;
    /* Restore padding */
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-light);
    /* Restore color */
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    backdrop-filter: blur(4px);
}

.history-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
    color: var(--text-main);
    /* Darker text */
    display: block;
    text-align: left;
    /* Alignment */
    font-weight: 500;
}

.history-text:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
}

.history-del-btn {
    background: transparent;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    font-size: 0.9rem;
    min-width: unset;
    height: auto;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.history-del-btn:hover {
    color: #ff4757;
    background: rgba(255, 71, 87, 0.1);
    transform: scale(1.1);
}

.history-chip:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.history-chip i {
    /* Generic i selector to catch clock */
    font-size: 0.9em;
    opacity: 0.7;
    flex-shrink: 0;
}


/* --- Version 2.0: Social Tabs & Trending Gallery --- */

/* Tab Navigation Bar */
.social-tabs {
    display: flex;
    padding: 10px 15px 0 15px;
    background: rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(163, 177, 198, 0.2);
    gap: 15px;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 8px 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    position: relative;
    box-shadow: none !important;
    /* Override default button shadow */
    min-width: unset;
    min-height: unset;
    transform: none !important;
    transition: color 0.3s;
}

.tab-btn:hover {
    color: var(--accent);
    transform: none;
}

.tab-btn.active {
    color: var(--accent);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    /* Overlap border */
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
}

/* Views Logic */
.social-view {
    display: none;
    flex-direction: column;
    height: 100%;
    /* Fill remaining space */
    overflow: hidden;
}

.social-view.active {
    display: flex;
    animation: fadeInView 0.3s ease;
}

@keyframes fadeInView {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

/* Trending View Styles */
.trending-filter {
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    overflow-x: auto;
    /* Hide scrollbar */
    scrollbar-width: none;
}

.trending-filter::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: 5px 12px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.4);
    font-size: 0.8rem;
    color: var(--text-light);
    cursor: pointer;
    border: 1px solid transparent;
    min-width: auto;
    box-shadow: none;
    /* Flat style for chips */
    transition: all 0.2s;
}

.filter-chip:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: translateY(-1px);
}

.filter-chip.active {
    background: var(--accent);
    color: white;
    box-shadow: 2px 2px 5px rgba(109, 93, 252, 0.3);
}

/* Trending Grid */
.trending-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px 15px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 2 Columns */
    gap: 10px;
    align-content: start;
}

.trending-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 1;
    /* Square thumbnails */
    background: #fff;
    box-shadow: 2px 2px 5px rgba(163, 177, 198, 0.3);
    cursor: pointer;
    transition: transform 0.2s;
}

.trending-item:hover {
    transform: translateY(-2px);
}

.trending-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Or cover? contain better for paper figures */
    padding: 5px;
    box-sizing: border-box;
}

/* Rank Badge */
.trending-rank {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 700;
    backdrop-filter: blur(2px);
}

.trending-rank.top-3 {
    background: linear-gradient(135deg, #ffd700, #f1c40f);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Like Heart Overlay */
.trending_like-btn {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    display: flex;
    /* Flex to center icon */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    font-size: 0.9rem;
    color: #ccc;
    /* Default grey */
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: unset;
    /* Override button generic */
    padding: 0;
}

.trending_like-btn:hover {
    transform: scale(1.1);
    background: white;
    color: #ff4757;
}

.trending_like-btn.liked {
    color: #ff4757;
    animation: heartPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes heartPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.4);
    }

    100% {
        transform: scale(1);
    }
}

.like-count {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.6);
    font-weight: 600;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 5px;
    border-radius: 4px;
}

/* Loading State */
.loading-state {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-light);
    margin-top: 50px;
}

/* Helper for Main Gallery Heart Button */
.img-card .heart-action {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 30px;
    /* Small clean button */
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ccc;
    /* Default grey */
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
    z-index: 10;
}

.img-card .heart-action:hover {
    transform: scale(1.1);
    background: white;
    color: #ff6b6b;
}

.img-card .heart-action.active {
    color: #ff4757;
    animation: heartPop 0.4s ease;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 0.9rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(20px);
    animation: toastIn 0.3s forwards;
    backdrop-filter: blur(5px);
}

.toast.toast-out {
    animation: toastOut 0.3s forwards;
}

.toast i {
    color: #00b894;
}

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

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* --- Mobile Optimizations --- */
/* --- Mobile Optimizations (Refined) --- */
@media (max-width: 600px) {

    /* 1. Global Container Fixes */
    body {
        overflow-x: hidden;
    }

    .container {
        padding: 15px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* 2. Header Compact */
    .header {
        margin-top: 10px;
        margin-bottom: 20px;
    }

    .header h1 {
        font-size: 2.2rem;
    }

    /* 3. Search Box Compact */
    .search-box {
        padding: 20px;
        width: 100%;
        box-sizing: border-box;
    }

    .input-group {
        flex-direction: column;
        width: 100%;
    }

    .input-group input {
        width: 100%;
        box-sizing: border-box;
    }

    #extractBtn {
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
    }

    /* 4. History Chips (Fix Visibility & Layout) */
    /* 4. History Chips (Force 2-per-row Layout) */
    .search-history {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
        gap: 8px;
        width: 100%;
        margin-top: 15px;
    }

    .history-chip {
        display: grid;
        grid-template-columns: max-content minmax(0, 1fr) auto;
        align-items: center;
        gap: 6px;
        width: 100%;
        min-width: 0;
        padding: 6px 10px;
        box-sizing: border-box;
        margin: 0;
    }

    .history-text {
        min-width: 0;
        width: 100%;
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;

        text-align: left;

        font-size: 0.8rem;
        color: var(--text-main);
    }

    .history-del-btn {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        padding: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }



    /* 5. Result Gallery (Prevent Overflow) */
    .result-section {
        padding: 0;
        margin-top: 30px;
    }

    .gallery {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        /* Force 2 columns */
        gap: 10px;
        width: 100%;
        padding: 5px;
        box-sizing: border-box;
    }

    .img-card {
        width: 100%;
        box-sizing: border-box;
        padding: 10px;
    }

    .img-wrapper {
        height: 140px;
    }

    /* Smaller images */
    .img-wrapper img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    /* 6. Footer Buttons (Stack Vertical & Fix Overflow) */
    .action-buttons {
        display: flex;
        /* Ensure it's flex */
        flex-direction: column;
        width: 100%;
        gap: 12px;
        margin-top: 20px;
        box-sizing: border-box;
        /* Important */
    }

    /* Target the specific buttons to ensure they don't overflow */
    .action-buttons .neumorphic-btn {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        /* Include padding in width */
        min-width: 0;
        margin: 0;
        display: flex;
        justify-content: center;
    }

    /* 7. Social / Trending Mobile */
    .chat-container {
        /* Full Screen Overlay - Final Override */
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: none !important;
        margin: 0;
        border-radius: 0 !important;
        display: flex;
        flex-direction: column;
        z-index: 20000;
        background: var(--bg-color);
    }

    .chat-container .chat-input-area {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }

    .trending-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }
}
