/* --- Base & Layout --- */

:root {
    --gap: 12px
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    font: 16px/1.45 system-ui;
    background:
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.35), transparent 40%),
        radial-gradient(circle at 80% 30%, rgba(255, 255, 255, 0.25), transparent 45%),
        linear-gradient(180deg, #e5edf4, #d6e1ea);
}

.wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px
}

/* Header */

header {
    background: linear-gradient(180deg, #c9d6e2, #b8c7d6);
    color: #0f172a;
    padding: 2px 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}

header a {
    color: inherit;
}

/* Configure Button */
header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

header .wrap>div:first-child {
    min-width: 0;
    /* Allows text truncation to work */
    flex: 1;
}

header h1 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.configure-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: inherit;
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.2s, border-color 0.2s;
}

.configure-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.35);
}

.configure-btn svg {
    width: 16px;
    height: 16px;
}

/* Loading & Sentinel */

#sentinel {
    width: 100%;
    height: 100px;
    margin-top: 100px;
}

#loading-pill {
    display: none;
    text-align: center;
    padding: 12px 24px;
    margin: 20px auto;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 20px;
    font-size: 14px;
    width: fit-content;
}

#loading-pill.visible {
    display: block;
}

/* --- Grid & Masonry --- */

/* Masonry grid new CSS config,  with fallback */
/* not well supported, but let's give it a try */
/* not well supported = lolz not at all supported yet except under flags :( */
/* https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Masonry_layout#browser_compatibility */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    grid-template-rows: masonry;
    gap: var(--gap)
}

@supports not (grid-template-rows: masonry) {
    .grid {
        display: block;
        column-width: 240px;
        column-gap: var(--gap)
    }

    .item {
        break-inside: avoid;
        margin: 0 0 var(--gap)
    }
}

/* Cards */

.item {
    border-radius: 12px;
    overflow: hidden
}

.item a {
    display: block;
    line-height: 0
}

.item a:focus-visible {
    outline: 3px solid #6ab0f3;
    outline-offset: -3px;
    border-radius: 12px;
}

.item img {
    width: 100%;
    height: auto;
    display: block;

    color: transparent;
}

.item img::before {
    color: transparent;
}

.p-name {
    display: none;
}

.placeholder {
    background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    aspect-ratio: var(--aspect-ratio);
    width: 100%;
}

.load-failed {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    min-height: 150px;
    position: relative;
}

.load-failed::after {
    content: "View Remotely";
    color: #b0b0b0;
    font-size: 0.85rem;
    pointer-events: none;
}

.load-failed img {
    display: none;
}

.load-failed a {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Footer */

footer {
    text-align: center;
    padding: 2rem 0 1.5rem;
}

footer a {
    display: inline-block;
    font: 700 0.7rem/1 'Courier New', Courier, monospace;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    text-decoration: none;
    color: #d4e7d4;
    background: #1a3a2a;
    padding: 0.45rem 1.1rem;
    border-radius: 4px;
    border: 1px solid #2d5a3f;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 1px 2px rgba(0, 0, 0, 0.15);
    transform: rotate(-2.5deg);
    transition: transform 0.3s ease, background 0.2s;
}

.codeberg-icon {
    width: 14px;
    height: 14px;
    fill: currentColor;
    vertical-align: -2px;
    margin-right: 0.15em;
}

footer a:hover {
    background: #224832;
    transform: rotate(0deg);
}

/* --- Modal --- */

dialog#modal {
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

dialog#modal::backdrop {
    background: rgba(0, 0, 0, 0.93);

}

.modal-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.modal-close:focus-visible {
    outline: 2px solid #6ab0f3;
    outline-offset: 2px;
}

.modal-close svg {
    width: 28px;
    height: 28px;
}

.modal-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    padding-bottom: 80px;
}

.modal-image-container img {
    max-width: 95vw;
    max-height: calc(100vh - 100px);
    object-fit: contain;
    display: block;
}

.modal-caption {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 5;
}

.modal-author {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.modal-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.modal-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-avatar-placeholder.hidden {
    display: none;
}

.modal-avatar-initial {
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
}

.modal-avatar-image {
    display: none;
}

.modal-avatar-image.loaded {
    display: block;
}

.modal-author-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 0.8rem;
}

.modal-author-name {
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
}

.modal-author-handle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
    color: #ccc;
}

.modal-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: #ccc;
    flex-shrink: 0;
}

.modal-stats svg {
    width: 16px;
    height: 16px;
    margin-right: 0.25rem;
    vertical-align: middle;
}

.modal-source a {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
    min-height: 44px;
}

.modal-source a:hover {
    background: rgba(255, 255, 255, 0.25);
}

.modal-source a:focus-visible {
    outline: 2px solid #6ab0f3;
    outline-offset: 2px;
}

.modal-alt-section {
    position: fixed;
    text-align: center;
    bottom: 65px;
    left: 0;
    right: 0;
    z-index: 4;
}

.modal-alt-section details {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-alt-section summary {
    color: #ccc;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.8rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-alt-section summary:focus-visible {
    outline: 2px solid #6ab0f3;
    outline-offset: -2px;
}

.modal-alt-section p {
    color: #ddd;
    padding: 0.5rem 1rem 0.75rem;
    margin: 0;
    font-size: 0.85rem;
    max-height: 30vh;
    overflow-y: auto;
}

.modal-alt-section details:not([open]) p {
    display: none;
}

.modal-alt-section details[open] summary {
    display: none;
}

/* Media Queries */

@media (max-width: 480px) {
    header .wrap {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    header h1 {
        white-space: normal;
        /* Allow wrapping on mobile */
        font-size: 1.1rem;
    }

    .configure-btn {
        align-self: flex-end;
    }
}

@media (prefers-color-scheme: dark) {
    header {
        background: linear-gradient(180deg, #1e293b, #0f172a);
        color: #e5edf4;
        box-shadow: 0 1px 2px rgba(255, 255, 255, .08);
    }

    .configure-btn {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.15);
    }

    .configure-btn:hover {
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(255, 255, 255, 0.25);
    }

    footer a {
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.08),
            inset 0 -1px 0 rgba(0, 0, 0, 0.3),
            0 1px 2px rgba(0, 0, 0, 0.3);
    }
}

/* Modal: Stack on very small screens */
@media (max-width: 600px) {
    .modal-caption {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .modal-author {
        flex-basis: 100%;
    }

    .modal-stats {
        flex: 1;
    }

    .modal-image-container {
        padding-bottom: 120px;
    }

    .modal-image-container img {
        max-height: calc(100vh - 140px);
    }

    .modal-alt-section {
        bottom: 105px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .placeholder {
        animation: none;
    }

    #modal-image {
        animation: none !important;
    }

    footer a {
        transition: none;
    }
}
