/* Projects hub: patchwork grid of polaroid cards. */


/* Patchwork */

.projects-patchwork {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 40px;
    padding: 20px 0 60px;
    max-width: 1400px;
    margin: 0 auto;
}

.projects-patchwork--flush { padding-top: 0; }

.patchwork-item {
    position: relative;
    cursor: pointer;
    transition: transform var(--dur-base) var(--ease-back);
}

.patchwork-item:hover {
    transform: scale(1.02) rotate(-1deg);
    z-index: 10;
}

@media (min-width: 992px) {
    /* Desktop: a 12-column grid where each item spans a block sized by its importance. */
    .projects-patchwork {
        grid-template-columns: repeat(12, 1fr);
        grid-auto-rows: 100px;
        grid-auto-flow: dense;
    }

    .patchwork-item--large {
        --span: 6;

        grid-row: span 5;
    }

    .patchwork-item--medium {
        --span: 5;

        grid-row: span 4;
    }

    .patchwork-item--small {
        --span: 4;

        grid-row: span 3;
    }

    /* Every card leans on the central axis of the page, whatever its size: on the left it ends
       there, on the right it starts there, and the gap between the two halves stays centred. */
    .patchwork-item { grid-column: span var(--span, 4); }
    .patchwork-item--left { grid-column: span var(--span, 4) / 7; }
    .patchwork-item--right { grid-column: 7 / span var(--span, 4); }
}


/* Polaroid */

.polaroid-card {
    background: var(--polaroid);
    padding: 12px 12px 60px;
    border-radius: 2px;
    box-shadow: 0 10px 30px rgb(0 0 0 / 30%), 0 2px 10px rgb(0 0 0 / 10%);
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.patchwork-item--large .polaroid-card { transform: rotate(-1deg); }
.patchwork-item--medium .polaroid-card { transform: rotate(2deg); }
.patchwork-item--small .polaroid-card { transform: rotate(-1.5deg); }

.polaroid-card .sketch-rect-svg {
    z-index: 20;
    width: 106%;
    height: 106%;
    left: -3%;
    top: -3%;
}

/* Hovering anywhere on the item draws its red rectangle. */
.patchwork-item:hover .sketch-rect-svg { opacity: 1; }
.patchwork-item:hover .sketch-rect-svg .sketch-rect-path { stroke-dashoffset: 0; }

.polaroid-img-wrap {
    flex: 1;
    overflow: hidden;
    background: var(--bg-deep);
    position: relative;
    border-radius: 2px;
}

.patchwork-item--large .polaroid-img-wrap { background: var(--black); }
.polaroid-img { transition: transform 0.6s ease; }
.patchwork-item:hover .polaroid-img { transform: scale(1.05); }

/* The first photo is shown whole inside its frame. Same weight as the hover zoom above and
   declared after it, so it does not zoom. */
.patchwork-item--large .polaroid-card .polaroid-img { transform: scale(0.92); }

/* Card without a photo: a spinning mark and a pulsing note stand in for it. */
.patchwork-item--small .polaroid-img-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.patchwork-item--small .polaroid-img-wrap > svg { animation: spin-slow 3s linear infinite; }
.patchwork-item--small .polaroid-img-wrap > svg path { animation: pulse-opacity 2s ease-in-out infinite; }

.patchwork-item--small .polaroid-img-wrap .font-sketch {
    color: var(--white);
    font-size: 2.2rem;
    animation: pulse-opacity 2s ease-in-out infinite;
    letter-spacing: 2px;
}

/* Small card that has its photo: it fills the frame like the photo of the other cards. */
.patchwork-item--small .polaroid-img-wrap--photo { display: block; }

/* backdrop-filter is unprefixed only: Safari before 18 ignores it and shows the tape without blur. */
.polaroid-tape {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%) rotate(-2deg);
    width: 120px;
    height: 40px;
    background: rgb(255 255 255 / 15%);
    box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
    backdrop-filter: blur(4px);
    z-index: 5;
    border: 1px solid rgb(255 255 255 / 5%);
}

.patchwork-item:nth-child(even) .polaroid-tape {
    transform: translateX(-50%) rotate(3deg);
    top: -10px;
}

.polaroid-label {
    position: absolute;
    bottom: 5px;
    left: 0;
    width: 100%;
    text-align: center;
    color: var(--ink);

    /* Mark and title on one row, the title wrapping beside the mark if it must; the date, when
       there is one, sits on its own line below, outside that row, so it never widens the room
       of the mark. */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 10px;
}

.polaroid-label-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}

.polaroid-label-mark {
    color: var(--red);
    font-size: 2.8rem;
    line-height: 1;
    transform: rotate(-8deg) translateY(-2px);
}

.polaroid-label-text {
    font-size: 1.8rem;
    line-height: 1;
    letter-spacing: 0.05em;
}

.patchwork-item--large .polaroid-label-mark { font-size: 3.5rem; }
.patchwork-item--large .polaroid-label-text { font-size: 2.5rem; }

/* The date sits on its own line under the title: one year, or the span of a collection with a
   drawn arrow (the sketch font has no arrow). The card keeps more room under its photo for it,
   where the label sits over the card; on phones the label is in the flow and needs none. */
.polaroid-label-date {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-size: 1.3rem;
    line-height: 1;
    letter-spacing: 0.04em;
    color: var(--red);
}

.patchwork-item--large .polaroid-label-date { font-size: 1.6rem; }

.polaroid-label-arrow {
    width: 30px;
    height: 11px;
    fill: none;
    stroke: currentcolor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (min-width: 769px) {
    .polaroid-card--dated { padding-bottom: 90px; }
    .patchwork-item--large .polaroid-card--dated { padding-bottom: 102px; }
}

/* A title that takes two lines in its card: the label returns to the flow, as on phones, and
   the photo yields the room it needs instead of being covered. */
.polaroid-card--label-flow { padding-bottom: 14px; }

.polaroid-card--label-flow .polaroid-label {
    position: static;
    margin-top: 10px;
}

@media (max-width: 768px) {
    /* Phones: the label returns to the flow. Absolutely positioned over a flex:1 image, a two-
       line title would overflow the 60px reserved for it and run onto the photo; in the flow,
       the image yields exactly the room needed. */
    .polaroid-card { padding-bottom: 14px; }

    .polaroid-label {
        position: static;
        margin-top: 10px;
        padding: 0 4px;
    }

    .polaroid-label-mark,
    .patchwork-item--large .polaroid-label-mark {
        font-size: 2.2rem;
    }

    .polaroid-label-text,
    .patchwork-item--large .polaroid-label-text {
        font-size: 1.55rem;
        line-height: 1.05;
    }

    /* The card without a photo would size to its content alone (126px on phones) and the tape
       would cut the mark. It gets a height close to its neighbours; 34px at the top clear the
       tape, which ends at 20px. */
    .patchwork-item--small .polaroid-img-wrap {
        min-height: 190px;
        padding: 34px 12px 16px;
    }

    /* A photo needs neither: it has its own height and the tape may overlap it. */
    .patchwork-item--small .polaroid-img-wrap--photo {
        min-height: 0;
        padding: 0;
    }
}

@keyframes spin-slow {
    100% { transform: rotate(360deg); }
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}
