* {
    box-sizing: border-box;
}

/* Base page styles */
body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

/* Gallery top bar */
.gallery-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "title actions"
        "filters filters";
    align-items: start;
    gap: 0.85rem 1rem;
    padding: 1.5rem 1.5rem;
    background-color: var(--gallery-bar-bg);
}

.gallery-bar h1 {
    grid-area: title;
    margin: 0;
    font-size: 1.75rem;
    line-height: 1.2;
    color: var(--text-primary);
}

#delete-all-button {
    grid-area: actions;
    justify-self: end;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--text-secondary);
    background-color: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 600;
}

/* Gallery filter controls */
.filter-controls {
    grid-area: filters;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 0.85rem;
    margin-left: 0;
    width: 100%;
}

.filter-controls label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.filter-controls select,
.filter-controls input[type="text"],
.filter-controls input[type="date"] {
    padding: 0.4rem 0.6rem;
    min-height: 2.1rem;
    min-width: 8.8rem;
    border-radius: 6px;
    border: 1px solid var(--filter-input-border);
    background: var(--filter-input-bg);
    color: var(--text-primary);
}

.filter-controls select:focus,
.filter-controls input[type="text"]:focus,
.filter-controls input[type="date"]:focus {
    outline: 3px solid var(--filter-input-focus);
    outline-offset: 2px;
    border-color: var(--filter-input-focus);
}

.filter-controls input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--filter-input-focus);
}

.filter-controls input[type="checkbox"]:focus {
    outline: 3px solid var(--filter-input-focus);
    outline-offset: 2px;
}

/* Card layout */
.gallery-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    padding: 1.5rem;
    width: 100%;
}

.gallery-card {
    background-color: var(--bg-card);
    border-radius: 8px;
    box-shadow: 4px 4px 6px var(--shadow-card);
    padding: 1rem;
    width: 450px;
    height: 770px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card-scroll-content {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.2rem;
}

.gallery-card:hover {
    transform: translateY(-2px);
    box-shadow: 6px 8px 14px var(--shadow-card);
}

/* Card media and metadata */
.gallery-image {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    background-color: #ffffff;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.image-container {
    width: 90%;
    position: relative;
}

.gallery-info {
    width: 100%;
    text-align: left;
    padding: 0.2rem 0;
}

.gallery-info p {
    margin: 0;
    line-height: 1.45;
}

.gallery-timestamp {
    font-size: 0.9rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
    margin-bottom: 0.5rem;
}

.gallery-word {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    padding-bottom: 0.45rem;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.18);
    margin-bottom: 0.6rem;
}

.mode-stats {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.mode-stats p {
    margin: 0;
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 999px;
    padding: 0.18rem 0.6rem;
    font-size: 0.83rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.gallery-draw-type.mode-challenge {
    background-color: #e9f2ff;
    border-color: #0b3d91;
    color: #0b3d91;
}

.gallery-draw-type.mode-sandbox {
    background-color: #eafaf2;
    border-color: #1c7c54;
    color: #1c7c54;
}

.gallery-difficulty.difficulty-easy {
    background-color: #ecf9ef;
    border-color: #166534;
    color: #166534;
}

.gallery-difficulty.difficulty-medium {
    background-color: #fff6e5;
    border-color: #92400e;
    color: #92400e;
}

.gallery-difficulty.difficulty-hard {
    background-color: #ffecec;
    border-color: #c53030;
    color: #c53030;
}

.gallery-guess-time {
    margin: 1rem 0 0.5rem;
    color: #ffffff;
    font-weight: 600;
    display: block;
    width: fit-content;
    background-color: #6f42c1;
    border: 1px solid #57309b;
    border-radius: 999px;
    padding: 0.2rem 0.75rem;
}

.gallery-top-guesses {
    margin-top: 0.35rem;
    padding-top: 0.45rem;
    border-top: 1px dashed rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    text-align: center;
}

.top-guesses-label {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.top-guesses-list {
    margin: 0;
    padding-left: 0;
    list-style-position: inside;
    display: grid;
    gap: 0.2rem;
}

.top-guesses-item {
    font-size: 0.9rem;
    line-height: 1.35;
    word-break: break-word;
}

.top-guesses-empty {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Tags */
.tag-section {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 0.55rem;
}

.tags-container {
    width: 100%;
    min-height: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag {
    border: none;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    color: #ffffff;
    font-size: 0.8rem;
    cursor: pointer;
}

.tag-input {
    flex: 1;
    min-width: 10rem;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background: #ffffff;
}

.tag-color-input {
    width: 2rem;
    height: 2rem;
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.add-tag-button {
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    border: 1px solid #0b3d91;
    color: #0b3d91;
    background-color: #e9f2ff;
    cursor: pointer;
    font-weight: 700;
}

.add-tag-button:hover {
    background-color: #dbe9ff;
}

/* Card actions */
.gallery-actions {
    width: 100%;
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 0.55rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    background-color: var(--bg-card);
}

.download-button,
.delete-button {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.download-button {
    color: #0b3d91;
    background-color: #e9f2ff;
    border: 2px solid #0b3d91;
}

.delete-button {
    color: #b22222;
    background-color: #ffecec;
    border: 2px solid #b22222;
}

/* Favorite icon behavior */
.favorite-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 999px;
    background-color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    color: #6b5200;
    font-size: 1.35rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.gallery-card:hover .favorite-button {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.favorite-button.is-favorite {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Card scrollbar */
.card-scroll-content::-webkit-scrollbar {
    width: 8px;
}

/* Load more button */
#load-more-button {
    display: block;
    margin: 2rem auto 3rem;
    padding: 0.75rem 2rem;
    border-radius: 6px;
    border: 1px solid var(--text-secondary);
    background-color: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 600;
}

/* Responsive layout */
@media (max-width: 1100px) {
    .gallery-bar {
        grid-template-columns: 1fr;
        grid-template-areas:
            "title"
            "actions"
            "filters";
    }

    #delete-all-button {
        justify-self: start;
    }
}

@media (max-width: 1000px) {
    .gallery-bar {
        padding: 1rem;
        gap: 0.7rem;
    }

    .gallery-bar h1 {
        font-size: 1.25rem;
    }

    .filter-controls {
        gap: 0.45rem 0.6rem;
    }

    .filter-controls label {
        font-size: 0.86rem;
    }

    .filter-controls select,
    .filter-controls input[type="text"],
    .filter-controls input[type="date"] {
        min-width: 100%;
        width: 100%;
    }

    .gallery-card {
        width: min(100%, 340px);
    }

    .gallery-actions {
        flex-direction: column;
    }
}