:root {
    --primary-color: #232323;
    --background-color: rgb(220, 220, 220);
    --accent-color: #ff3700;
    --box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Press Start 2P", monospace;
    background-color: var(--background-color);
    padding: 20px;
    color: var(--primary-color);
}
body.fullscreen-active {
    overflow: hidden;
}

button,
input,
textarea {
    font-family: "Press Start 2P", monospace;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--background-color);
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
}

.title-container {
    display: flex;
    align-items: center;
    gap: 30px;
    flex-wrap: wrap;
}

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

h1 {
    font-size: 2rem;
    text-transform: uppercase;
    color: var(--primary-color);
}

.keypress-legend {
    display: flex;
    gap: 15px;
    background-color: var(--primary-color);
    color: var(--background-color);
    padding: 8px 12px;
    font-size: 0.7rem;
    flex-wrap: wrap;
}

.keypress-legend span {
    white-space: nowrap;
}

h2 {
    font-size: 1.5rem;
    text-transform: uppercase;
    margin-bottom: 20px;
}

h3 {
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--primary-color);
    margin-bottom: 15px;
}

button {
    background-color: var(--background-color);
    border: 3px solid var(--primary-color);
    padding: 10px 15px;
    font-weight: bold;
    color: var(--primary-color);
    cursor: pointer;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.8);
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
}

button:hover {
    background-color: rgb(200, 200, 200);
}

button:active {
    transform: translate(3px, 3px);
    box-shadow: none;
}

.session-code {
    background: var(--primary-color);
    color: var(--background-color);
    padding: 10px 20px;
    font-size: 0.8rem;
    letter-spacing: 2px;
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.sync-indicator {
    width: 10px;
    height: 10px;
    background: #666;
    border: 2px solid var(--primary-color);
}

.sync-indicator.connected {
    background: #4caf50;
}
.sync-indicator.syncing {
    background: #ff9800;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

.summary-filter-container {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
}

.stats,
.filter-section {
    background: var(--background-color);
    padding: 20px;
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
    font-size: 0.7rem;
    flex: 1;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 2px solid var(--primary-color);
    font-weight: bold;
}
.stat-item:last-child {
    border-bottom: none;
}

.active-users {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 3px solid var(--primary-color);
}

.user-avatar {
    display: inline-block;
    width: 40px;
    height: 30px;
    background: var(--primary-color);
    color: var(--background-color);
    margin-right: 8px;
    text-align: center;
    line-height: 30px;
    font-size: 0.8rem;
    border: 2px solid var(--primary-color);
}

.sub-filter-container {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 3px dashed var(--primary-color);
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.sub-filter-button {
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    border: 3px solid transparent;
}
.sub-filter-button.active {
    border-color: var(--accent-color);
    box-shadow: 3px 3px 0px var(--accent-color);
}
.sub-filter-button:active {
    transform: translate(2px, 2px);
    box-shadow: none !important;
}

.upload-area {
    border: 3px dashed var(--primary-color);
    padding: 30px;
    margin-bottom: 30px;
    text-align: center;
    background-color: #d0d0d0;
    transition: background-color 0.2s, border-color 0.2s;
    position: relative;
}
.upload-area.drag-over {
    background-color: #c0c0c0;
    border-color: var(--accent-color);
}
.upload-area .upload-area-content p {
    font-size: 0.8rem;
    margin-top: 15px;
}
.upload-progress-container {
    font-size: 0.7rem;
}
#uploadProgressLabel {
    margin-bottom: 10px;
    word-break: break-all;
}
.progress-bar {
    width: 100%;
    height: 20px;
    background: var(--primary-color);
    border: 2px solid var(--primary-color);
}
.progress-bar-fill {
    width: 0%;
    height: 100%;
    background: var(--accent-color);
    transition: width 0.2s ease-out;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
    margin-bottom: 50px;
}

.photo-wrapper {
    position: relative;
    cursor: pointer;
    border: 5px solid transparent;
    transition: border-color 0.2s;
}

.photo-wrapper img {
    display: block;
    width: 100%;
    height: auto;
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
}

.photo-actions {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none; /* Pass clicks through the container's background */
}

/* Children of the container can still be interactive */
.photo-actions > * {
    pointer-events: all;
}

/* Hide the rating bars by default, show on hover */
.photo-actions .rating {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
}

.photo-wrapper:hover .photo-actions .rating,
.photo-actions .rating.is-rated {
    opacity: 1;
    visibility: visible;
}

/* --- Like Button Styles & Logic --- */
.like-button {
    background: transparent;
    border: none;
    box-shadow: none;
    width: 30px;
    height: 30px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

/* Show the button on hover */
.photo-wrapper:hover .like-button {
    opacity: 1;
    visibility: visible;
}

/* On hover, IF NOT LIKED, show the unliked.png */
.photo-wrapper:hover .like-button:not(.liked) {
    background-image: url("unliked.png");
}

/* --- Liked State --- */
/* ALWAYS show the button if it's liked (regardless of hover) */
.like-button.liked {
    opacity: 1;
    visibility: visible;
    transform: scale(1.1); /* Add a little pop */
    background-image: url("liked.png");
}

/* ALWAYS use the red heart content if it's liked (regardless of hover) */
.like-button.liked::before {
    background-image: url("liked.png");
}

/* --- Fullscreen Styles --- */
.fullscreen-actions .like-button::before {
    background-image: url("unliked.png");
}

.fullscreen-actions .like-button.liked::before {
    background-image: url("liked.png");
}

.rating {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding-bottom: 2px;
}

.rating {
    display: flex;
    align-items: flex-end;
    /* gap: 4px; // REMOVED to fix hover bug */
    padding-bottom: 2px;
}

.rating-bar {
    width: 12px; /* INCREASED for accessibility */
    margin-right: 4px; /* ADDED to replace gap and fix bug */
    background-color: #888;
    border: 2px solid var(--primary-color);
    cursor: pointer;
    transition: all 0.15s ease-out;
    height: 10px;
}
.rating-bar:last-child {
    margin-right: 0; /* No margin on the final bar */
}

.rating-bar:nth-child(2) {
    height: 14px;
}
.rating-bar:nth-child(3) {
    height: 18px;
}
.rating-bar:nth-child(4) {
    height: 22px;
}
.rating-bar:nth-child(5) {
    height: 26px;
}

.rating-bar.active {
    background-color: var(--accent-color);
}

/* Interactive hover-to-fill effect (Bug Fixed) */
/* When hovering the container, color all bars up to the hovered one */
.rating:hover .rating-bar {
    background-color: var(--accent-color);
}
/* Then, reset the color for all bars that come AFTER the one being hovered */
.rating .rating-bar:hover ~ .rating-bar {
    background-color: #888;
}

.fullscreen-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    overflow: hidden;
}

/* Desktop: Use Flexbox for side-by-side layout */
.fullscreen-overlay.active {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 20px;
    gap: 20px;
}

.fullscreen-content {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
    min-width: 0;
    height: 100%;
}

.fullscreen-image#fullscreenImageDesktop {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.fullscreen-comment-section {
    flex-shrink: 0;
    width: 25%;
    max-width: 350px;
    height: 90%;
    max-height: 800px;
    background: var(--background-color);
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.fullscreen-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--primary-color);
}

.rating-overviews-container {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 3px dashed var(--primary-color);
}
.rating-overview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}
.rating-overview-item .user-avatar {
    margin-right: 0;
    flex-shrink: 0;
}
.rating-overview-item .rating {
    padding-bottom: 0;
}

#fullscreenCommentInput {
    width: 100%;
    border: 3px solid var(--primary-color);
    padding: 10px;
    font-size: 0.7rem;
    margin: 15px 0;
    resize: none;
    overflow-y: auto;
    min-height: 30px;
    max-height: 200px;
}

#fullscreenCommentDisplay {
    overflow-y: auto;
    flex-grow: 1;
}

.comment-display {
    margin-top: 10px;
    padding: 10px;
    background: var(--primary-color);
    color: var(--background-color);
    font-size: 0.5rem;
    word-break: break-word;
}

.comment-display strong {
    color: var(--accent-color);
}

.close-button {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    z-index: 10;
}

.navigation-arrows {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-color);
    color: white;
    border: 3px solid white;
    font-size: 20px;
    padding: 10px 15px;
    cursor: pointer;
    box-shadow: 3px 3px 0px rgba(255, 255, 255, 0.3);
}
.prev-arrow {
    left: 20px;
}
.next-arrow {
    right: 20px;
}

.swipe-up-indicator {
    display: none;
}

.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.login-content {
    position: relative;
    background: var(--background-color);
    padding: 40px;
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
    text-align: center;
    max-width: 500px;
    width: 90%;
}
.modal-close-button {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.2rem;
}
.login-input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 3px solid var(--primary-color);
    font-size: 0.7rem;
    background: #fff;
}
.login-button {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: var(--background-color);
    border: none;
    font-size: 0.7rem;
    cursor: pointer;
    margin-top: 10px;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.8);
}
.login-button:hover {
    background: #333;
}
.login-button.secondary {
    background: #666;
}
.login-button.secondary:hover {
    background: #888;
}
.divider {
    margin: 20px 0;
    position: relative;
    text-align: center;
}
.divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}
.divider span {
    background: var(--background-color);
    padding: 0 15px;
    position: relative;
    font-weight: 700;
    text-transform: uppercase;
}
.generated-code {
    font-size: 2rem;
    letter-spacing: 4px;
    color: var(--background-color);
    background: var(--primary-color);
    margin: 20px 0;
    padding: 20px;
    border: 3px solid var(--primary-color);
    box-shadow: var(--box-shadow);
}
.share-link {
    margin-top: 20px;
    padding: 15px;
    background: #fff;
    border: 3px solid var(--primary-color);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.8);
}
.share-link input {
    width: 100%;
    padding: 10px;
    border: 3px solid var(--primary-color);
    font-size: 0.9rem;
    margin-top: 10px;
}
.copy-button {
    margin-top: 10px;
    padding: 8px 16px;
    background: var(--accent-color);
    color: #fff;
    border: 3px solid var(--accent-color);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.8);
}
.copy-button:hover {
    background: #ff5722;
}
.sessions-list {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 20px;
    text-align: left;
}
.session-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 10px;
    border-bottom: 3px solid var(--primary-color);
    font-size: 0.7rem;
}
.session-list-item:last-child {
    border-bottom: none;
}
.session-list-item strong {
    font-size: 1rem;
    letter-spacing: 2px;
}
.session-list-item .copy-button {
    font-size: 0.7rem;
    padding: 8px 12px;
    margin: 0;
}
.manage-button,
.logout-button {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--primary-color);
}

@media (max-width: 900px) {
    .summary-filter-container {
        flex-direction: column;
    }
}

/* Hide all mobile-specific elements by default */
.fullscreen-header-mobile,
.like-animation-heart,
.mobile-rating-overlay,
.fullscreen-carousel-container,
.swipe-up-indicator,
.close-button.mobile {
    display: none;
}

/* === Mobile and Touch Devices Overrides === */
@media (pointer: coarse), (max-width: 768px) {
    /* --- Gallery --- */
    .gallery {
        /* Adjust grid for smaller screens */
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    /* Hide like/rating actions on grid view for a cleaner look */
    .photo-actions .like-button,
    .photo-actions .rating {
        display: none !important;
    }

    /* Keep the heart icon as an indicator if liked, but make it non-interactive */
    .photo-actions .like-button.liked {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: none;
        width: 24px;
        height: 24px;
        bottom: 8px;
        left: 8px;
        background-image: url("liked.png");
    }

    /* --- Fullscreen Overlay Structure --- */
    .fullscreen-overlay {
        padding: 0;
    }
    .fullscreen-overlay.active {
        display: grid;
        grid-template-rows: auto 1fr auto;
        grid-template-columns: 100%;
    }

    /* Hide desktop elements */
    .fullscreen-content,
    .navigation-arrows,
    .close-button.desktop {
        display: none !important;
    }

    /* Show mobile elements */
    .fullscreen-header-mobile,
    .swipe-up-indicator,
    .fullscreen-carousel-container,
    .close-button.mobile,
    .like-animation-heart {
        display: block;
    }

    /* --- Mobile Header --- */
    .fullscreen-header-mobile {
        display: flex;
        grid-row: 1 / 2;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        z-index: 10;
    }
    .close-button.mobile {
        position: static;
        font-size: 2rem;
        padding: 5px;
    }
    .mobile-like-indicator {
        width: 28px;
        height: 28px;
        background-image: url("liked.png");
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        opacity: 0;
        transform: scale(0.8);
        transition: opacity 0.2s, transform 0.2s;
    }
    .mobile-like-indicator.is-liked {
        opacity: 1;
        transform: scale(1);
    }

    /* --- Mobile Carousel --- */
    .fullscreen-carousel-container {
        grid-row: 2 / 3;
        position: relative;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    .fullscreen-image-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        will-change: transform;
    }
    .fullscreen-image-wrapper img {
        max-height: 100%;
        width: 100%;
        object-fit: contain;
        user-select: none;
        pointer-events: none;
    }
    .fullscreen-image-wrapper.prev {
        transform: translateX(-100%);
    }
    .fullscreen-image-wrapper.current {
        transform: translateX(0);
    }
    .fullscreen-image-wrapper.next {
        transform: translateX(100%);
    }

    /* --- Mobile Comment Drawer --- */
    .fullscreen-comment-section {
        display: flex !important; /* Override inline styles */
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 85%;
        max-height: none;
        max-width: none;
        border-top: 3px solid var(--primary-color);
        border-left: none;
        border-right: none;
        border-bottom: none;
        transform: translateY(100%);
        transition: transform 0.4s ease-in-out;
        z-index: 15;
    }
    .fullscreen-overlay.drawer-visible .fullscreen-comment-section {
        transform: translateY(0);
    }
    #fullscreenCommentInput {
        font-size: 0.8rem;
        min-height: 40px;
        max-height: 150px;
        background: white;
    }
    #fullscreenCommentDisplay {
        padding-right: 10px;
    }

    /* --- Swipe Up Indicator --- */
    .swipe-up-indicator {
        grid-row: 3 / 4;
        position: static;
        transform: none;
        text-align: center;
        color: #fff;
        background: transparent;
        padding: 15px;
        font-size: 0.7rem;
        border: none;
        z-index: 6;
        transition: opacity 0.3s;
    }
    .swipe-up-indicator span {
        display: inline-block;
        animation: bounce 1.5s infinite;
    }
    .fullscreen-overlay.drawer-visible .swipe-up-indicator {
        opacity: 0;
        pointer-events: none;
    }
    @keyframes bounce {
        0%,
        20%,
        50%,
        80%,
        100% {
            transform: translateY(0);
        }
        40% {
            transform: translateY(-8px);
        }
        60% {
            transform: translateY(-4px);
        }
    }

    /* --- Mobile Gesture Animations --- */
    .like-animation-heart {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0);
        width: 100px;
        height: 100px;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        opacity: 0;
        pointer-events: none;
        z-index: 20;
    }
    .like-animation-heart.red {
        background-image: url("liked.png");
    }
    .like-animation-heart.white {
        background-image: url("unliked.png");
    }
    .like-animation-heart.animate {
        animation: heart-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }
    @keyframes heart-pop {
        0% {
            transform: translate(-50%, -50%) scale(0);
            opacity: 0;
        }
        50% {
            transform: translate(-50%, -50%) scale(1.2);
            opacity: 1;
        }
        100% {
            transform: translate(-50%, -50%) scale(1.5);
            opacity: 0;
        }
    }

    /* --- Mobile Rating UI --- */
    .mobile-rating-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.6);
        z-index: 25;
        display: flex;
        justify-content: center;
        align-items: center;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s, visibility 0.2s;
        pointer-events: none;
    }
    .mobile-rating-overlay.visible {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }
    .mobile-rating-bar-container {
        display: flex;
        align-items: flex-end;
        gap: 10px;
        padding: 20px;
    }
    .mobile-rating-bar {
        width: 40px;
        background-color: #888;
        border: 3px solid var(--background-color);
        transition: background-color 0.1s;
        height: 40px;
    }
    .mobile-rating-bar:nth-child(2) {
        height: 50px;
    }
    .mobile-rating-bar:nth-child(3) {
        height: 60px;
    }
    .mobile-rating-bar:nth-child(4) {
        height: 70px;
    }
    .mobile-rating-bar:nth-child(5) {
        height: 80px;
    }
    .mobile-rating-bar.active {
        background-color: var(--accent-color);
    }
}

/* === Desktop-Specific Styles === */
@media (pointer: fine) and (min-width: 769px) {
    /* Hide all mobile-only elements on desktop */
    .fullscreen-header-mobile,
    .like-animation-heart,
    .mobile-rating-overlay,
    .fullscreen-carousel-container,
    .swipe-up-indicator,
    .close-button.mobile {
        display: none !important;
    }
}
