body {
    background-color: #333;
    color: #fff;
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    transition: padding-top 0.3s ease-in-out;
}

/* This creates the necessary space to prevent content from jumping when the header becomes fixed */
body.scrolled {
    padding-top: 150px;
}

#header-wrapper {
    transition: all 0.3s ease-in-out;
    position: relative;
    z-index: 10;
    padding: 20px;
    background: #000;
    max-width: 900px;
    margin: auto;
}

/* New styling for the IP message and directory form */
.header-local-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
    margin-bottom: 20px;
    gap: 10px;
}

.ip-message {
    margin: 0;
    font-size: 1.1em;
    font-weight: bold;
}

.dir-form {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dir-form input[type="text"] {
    background: #1a1a1a;
    border: 1px solid #555;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
}

.dir-form button {
    background: #a00;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}

.dir-form button:hover {
    background: #c00;
}

/* Styles for the message boxes */
.message {
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 5px;
    font-weight: bold;
    text-align: center;
}

.message.success {
    background-color: #4CAF50;
    color: white;
}

.message.error {
    background-color: #f44336;
    color: white;
}

/* Styles for the new breadcrumb trail */
.breadcrumb {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
}

.breadcrumb-item {
    color: #aaa;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1em;
}

.breadcrumb-item:hover {
    color: #fff;
    text-decoration: underline;
}

/* Base styles for the headers - initial header is visible by default */
.initial-header-content {
    display: block;
}

.fixed-header-content {
    display: none; /* Fixed header is hidden by default */
}

/* When the body has the 'scrolled' class, hide the initial header and show the fixed header */
body.scrolled .initial-header-content {
    display: none;
}

body.scrolled .fixed-header-content {
    display: block;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 900px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

/* New flexbox layout for the fixed header */
.fixed-header-content .fixed-header-top-row {
    display: flex;
    flex-wrap: nowrap; /* Prevent wrapping by default on desktop */
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
}

.fixed-header-content .mj-shooting-logo {
    width: 10%;
    max-height: 52.5px;
    height: auto;
    margin: 0;
    flex-shrink: 0;
}

.fixed-header-content .mj-shooting-shop-button {
    height: 52.5px;
    font-size: 0.9em;
    padding: 0 5px;
    margin: 0;
    line-height: 52.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    /* Make all buttons in the fixed header equal size */
    flex-grow: 1;
    flex-basis: 0; /* Allow flex-grow to distribute space equally */
}

.fixed-header-content .fixed-button-container {
    display: flex;
    justify-content: flex-end; /* Align to the right */
    align-items: center;
    gap: 5px;
    width: auto;
    /* Make buttons inside this container also grow equally */
    flex-grow: 1;
    flex-basis: 0; /* Allow flex-grow to distribute space equally */
}

.fixed-header-content .up-button, .fixed-header-content .targets-home-sub-button {
    height: 52.5px;
    font-size: 0.9em;
    line-height: 52.5px;
    margin: 0;
    padding: 0 5px;
    white-space: nowrap;
    /* Make these buttons equal size to each other and the shop button */
    flex-grow: 1;
    flex-basis: 0; /* Allow flex-grow to distribute space equally */
}

.fixed-header-content .breadcrumb {
    text-align: center;
    font-size: 0.8em;
    width: 100%;
    margin-top: 5px;
    margin-bottom: 0;
}

/* Original header elements */
.mj-shooting-logo {
    display: block;
    margin: 0 auto 20px auto;
    max-width: 300px;
    height: auto;
    transition: all 0.3s ease-in-out;
    max-height: 250px;
}

.mj-shooting-shop-button {
    width: 100%;
    height: 70px;
    background: #a00;
    color: #fff;
    text-align: center;
    font-size: 1.5em;
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease-in-out;
}

.targets-home-button, .up-button, .targets-home-sub-button {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #fff;
    background: #a00;
    height: 50px;
    font-size: 1.2em;
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease-in-out;
    margin-top: 5px;
}

.targets-home-button {
    width: 100%;
}

.button-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    transition: margin 0.3s ease-in-out;
}

.up-button, .targets-home-sub-button {
    width: calc(50% - 5px); /* Makes both buttons the same width */
}

.targets-home-button:hover, .up-button:hover, .targets-home-sub-button:hover,
.mj-shooting-shop-button:hover {
    background: #c00;
}

/* Fix for the REBUILD INDEX button's hover effect due to inline styles */
a.dir-form.button:hover {
    background: #c00 !important;
}

/* New styles for the REBUILD INDEX button to make it smaller */
a.dir-form.button {
    font-size: 0.7em;
    padding: 3px 6px;
    height: auto;
}

.content-container {
    width: 90%;
    max-width: 900px;
    margin: auto;
    padding: 20px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
}

.pdf-cell {
    background: #1a1a1a;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    box-sizing: border-box;
    min-height: 280px;
}

.pdf-thumb-wrapper {
    width: 100%;
    max-height: 280px;
    text-align: center;
}

.pdf-thumb-wrapper img {
    max-width: 100%;
    max-height: 280px;
    display: inline-block;
    border: 1px solid #333;
    border-radius: 4px;
    background: #222;
    object-fit: contain;
}

.no-preview {
    color: #888;
}

.pdf-name {
    margin-top: 10px;
    font-size: 1.1em;
    word-wrap: break-word;
    color: #fff;
}

.print-button {
    display: block;
    width: 100%;
    margin-top: 15px;
    padding: 10px 0;
    background: #000;
    color: #ff0000;
    border: 2px solid #ff0000;
    border-radius: 5px;
    text-align: center;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.9em;
    box-sizing: border-box;
    cursor: pointer;
}

.print-button:hover {
    background: #ff0000;
    color: #000;
}

.version {
    font-size: 10px;
    font-style: italic;
    text-align: center;
    margin-top: 20px;
    color: #ccc;
}

.error-msg {
    color: #f33;
    font-weight: bold;
    margin-top: 20px;
    text-align: center;
}

.dir-thumb {
    border: 1px solid #333;
    border-radius: 4px;
    background: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

.dir-name-box {
    text-align: center;
    color: #fff;
    font-weight: bold;
    word-wrap: break-word;
}

.full-width-heading {
    grid-column: 1 / -1;
    text-align: center;
    margin-top: 20px;
    margin-bottom: 10px;
    color: #fff;
}

.incognito-button {
    display: inline-block;
    width: auto;
    height: 50px;
    background: #444; /* Changed background color */
    color: #aaa;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    margin-top: 30px;
    padding: 0 20px;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.incognito-button:hover {
    background: #555;
    color: #fff;
    border: 2px solid #fff;
}

/* Spacer at the bottom of the page */
.spacer-bottom {
    height: 500px;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .content-container {
        width: 100%;
        padding: 10px;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .mj-shooting-logo {
        width: 80%;
    }

    .mj-shooting-shop-button {
        height: 70px;
        font-size: 1.5em;
        line-height: 70px;
    }
    
    .targets-home-button, .up-button, .targets-home-sub-button {
        height: 50px;
        font-size: 1.2em;
        line-height: 50px;
    }

    body.scrolled {
        padding-top: 100px;
    }

    body.scrolled #header-wrapper {
        padding-left: 10px;
        padding-right: 10px;
    }

    body.scrolled #header-wrapper .mj-shooting-logo {
        max-height: 60px;
        width: 30%;
    }

    /* Fixed header for mobile: image above buttons, and all buttons equal size */
    body.scrolled .fixed-header-content .fixed-header-top-row {
        flex-direction: column; /* Stack items vertically */
        align-items: center; /* Center items horizontally */
    }

    body.scrolled .fixed-header-content .mj-shooting-logo {
        width: 100%; /* Make logo take full width */
        max-height: 80px; /* Adjust logo size */
        margin-bottom: 10px; /* Space below logo */
        order: -1; /* Place image above */
    }

    body.scrolled .fixed-header-content .mj-shooting-shop-button,
    body.scrolled .fixed-header-content .fixed-button-container {
        width: 100%; /* Make buttons take full width */
        max-width: 300px; /* Optional: cap max width for aesthetic */
        margin-bottom: 5px; /* Space between buttons */
    }

    body.scrolled .fixed-header-content .mj-shooting-shop-button,
    body.scrolled .fixed-header-content .up-button,
    body.scrolled .fixed-header-content .targets-home-sub-button {
        height: 52.5px;
        line-height: 52.5px;
        font-size: 0.9em;
        flex-grow: 1; /* Ensure buttons grow equally */
        flex-basis: 0; /* Important for equal distribution */
    }

    body.scrolled .fixed-header-content .fixed-button-container {
        display: flex; /* Ensure inner container is also flex */
        justify-content: space-around; /* Distribute space more evenly */
        width: 100%; /* Take full width of its parent */
        gap: 5px; /* Keep gap */
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: 1fr;
    }
    
    .up-button, .targets-home-sub-button {
        width: calc(50% - 5px);
        font-size: 1.0em;
    }

    /* Mobile styles for scrolled header */
    body.scrolled #header-wrapper .mj-shooting-logo {
        width: 60%; /* Adjust logo size for very small screens */
        margin-right: 0; /* Remove right margin */
        margin-bottom: 10px;
    }

    body.scrolled #header-wrapper .mj-shooting-shop-button {
        padding: 0 8px; /* Reduce padding for smaller screens */
    }

    body.scrolled #header-wrapper .mj-shooting-shop-button,
    body.scrolled #header-wrapper .targets-home-button,
    body.scrolled #header-wrapper .up-button,
    body.scrolled #header-wrapper .targets-home-sub-button {
        height: 52.5px;
        line-height: 52.5px;
        font-size: 0.7em; /* Smaller font size for very small screens */
        flex-grow: 1; /* Ensure buttons grow equally */
        flex-basis: 0; /* Important for equal distribution */
    }

    body.scrolled #header-wrapper .fixed-button-container {
        width: 100%; /* Ensure inner container is also flex */
        justify-content: space-around; /* Distribute space more evenly */
        gap: 5px; /* Keep gap */
    }

    .fixed-header-table .fixed-button-container {
        gap: 5px; /* Reduce gap between items on very small screens */
    }
}