/* Discover Grid (Unified Board) */
.discover-grid-wrapper {
    position: relative;
}

/* Parent grid with seamless pattern */
.discover-grid-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    aspect-ratio: 1/1;
    position: relative;
    padding: 12px;
    /* allow 3D-transformed notes to render outside the grid bounds when flipping */
    overflow: visible;
    background-image: linear-gradient(rgba(49, 84, 114, .2) 1px, transparent 1px), linear-gradient(90deg, rgba(49, 84, 114, .2) 1px, transparent 1px);
    background-size: 30px 30px;
}

@media (min-width:768px) {
    .discover-grid-layout {
        background-size: 40px 40px;
    }
}

@media (min-width:1024px) {
    .discover-grid-layout {
        background-size: 50px 50px;
    }
}

@media (min-width:1024px) {
    .discover-grid-layout {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: 1fr;
        aspect-ratio: auto;
        max-width: none;
    }
}

/* Cells (transparent to show board) */
.dg-cell {
    position: relative;
    overflow: visible;
    /* border-radius: var(--radius-lg); */
    aspect-ratio: 1/1;
}

/* Image base */
.dg-cell .dg-image {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + var(--dg-img-off-x, 0)), calc(-50% + var(--dg-img-off-y, 0))) rotate(var(--dg-img-rot, 0deg));
    width: 100%;
    height: auto;
    object-fit: cover;
    z-index: 1;
    /* border-width: 2px; */
    /* border-radius: var(--radius-lg); */
}

/* Floating notes */
.dg-note-floater {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + var(--dg-off-x, 0)), calc(-50% + var(--dg-off-y, 0))) scale(1) rotate(var(--dg-rot, 0deg));
    width: var(--dg-width, 85%);
    height: var(--dg-height, 85%);
    max-width: 310px;
    max-height: 310px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    /* border-radius: var(--radius-lg); */
    box-shadow: none;
    /* border: 2px solid rgba(0, 0, 0, 1); */
    /* border-width: 2px; */
    padding: 7px 8px;
    cursor: pointer;
    transition: transform .5s cubic-bezier(.4, .0, .2, 1), box-shadow .45s, filter .45s;
    transform-origin: center center;
    will-change: transform;
    font-size: 6px;
    line-height: 1.3;
    font-weight: 400;
    z-index: 2;
    background: #ffe08a;
    overflow: hidden;
}

/* Post-it specific layout: justify content between and right-align author */
.dg-note-floater.dg-postit {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
}

.dg-note-floater.dg-postit .dg-author {
    align-self: flex-end;
    text-align: right;
}

.dg-note-floater.dg-flip {
    background: transparent;
}

.dg-note-floater.dg-flip .dg-flip-front,
.dg-note-floater.dg-flip .dg-flip-back {
    background: var(--dg-flip-bg, #ffe08a);
}

.dg-note-floater .dg-quote-icon {
    margin: -4px 0 4px;
    color: #000;
    opacity: .9;
    line-height: 0;
}

.dg-note-floater .dg-quote-icon svg {
    width: 18px;
    height: 18px;
}

.dg-note-floater .dg-text {
    margin: 0;
    font-size: inherit;
}

.dg-note-floater .dg-author {
    margin-top: 6px;
    font-size: 0.95em;
    font-weight: 400;
}

@media (min-width:500px) {
    .dg-note-floater {
        font-size: 8px;
        padding: 14px 16px;
    }
}

@media (min-width:1024px) {
    .dg-note-floater {
        font-size: 14px;
    }
}

/* Post-it-like treatment for flip frame: padding, subtle shadow and consistent corner clipping */
.dg-note-floater.dg-flip .dg-flip-frame {
    /* give inner faces some breathing room so content matches post-it spacing */
    padding: 8px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    background-clip: padding-box;
}

/* Rotation + offset seeds */
.discover-grid-layout .dg-cell:nth-child(1) .dg-note-floater {
    --dg-rot: -2.5deg;
    --dg-off-x: -8%;
    --dg-off-y: -6%;
}

.discover-grid-layout .dg-cell:nth-child(2) .dg-note-floater {
    --dg-rot: 1.5deg;
    --dg-off-x: 10%;
    --dg-off-y: -4%;
}

.discover-grid-layout .dg-cell:nth-child(3) .dg-note-floater {
    --dg-rot: -1.2deg;
    --dg-off-x: -6%;
    --dg-off-y: 8%;
}

.discover-grid-layout .dg-cell:nth-child(4) .dg-note-floater {
    --dg-rot: 2deg;
    --dg-off-x: 9%;
    --dg-off-y: 6%;
}

/* Image rotation + offset seeds (subtle) */
.discover-grid-layout .dg-cell:nth-child(1) .dg-image {
    --dg-img-rot: -1.2deg;
    --dg-img-off-x: -3%;
    --dg-img-off-y: -2%;
}

.discover-grid-layout .dg-cell:nth-child(2) .dg-image {
    --dg-img-rot: 1deg;
    --dg-img-off-x: 3%;
    --dg-img-off-y: -2%;
}

.discover-grid-layout .dg-cell:nth-child(3) .dg-image {
    --dg-img-rot: -0.8deg;
    --dg-img-off-x: -2%;
    --dg-img-off-y: 3%;
}

.discover-grid-layout .dg-cell:nth-child(4) .dg-image {
    --dg-img-rot: 1.1deg;
    --dg-img-off-x: 3%;
    --dg-img-off-y: 2.5%;
}

/* Active state */
.dg-note-floater.dg-active {
    transform: translate(calc(-50% + var(--dg-move-x, 0px)), calc(-50% + var(--dg-move-y, 0px))) scale(var(--dg-scale, 1)) rotate(0deg);
    z-index: 5;
    box-shadow: none;
}

.dg-note-floater.dg-active .dg-text {
    font-size: inherit;
}

.dg-note-floater.dg-active .dg-author {
    font-size: 0.95em;
}

/* Flip structure */
.dg-note-floater.dg-flip {
    padding: 0;
    background: transparent;
    /* allow the flipping element to escape its container during 3D rotation */
    overflow: visible;
    perspective: 1000px;
    isolation: isolate;
}

.dg-note-floater.dg-flip {
    border: none;
    box-shadow: none;
}

.dg-note-floater.dg-flip .dg-flip-frame {
    position: relative;
    width: 100%;
    height: 100%;
    /* border-radius: var(--radius-lg); */
    box-shadow: none;
    overflow: hidden;
    /* mask faces with rounded corners */
}

.dg-note-floater.dg-flip .dg-flip-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform .65s cubic-bezier(.65, .05, .36, 1);
    will-change: transform;
}

.dg-note-floater.dg-flip .dg-flip-front,
.dg-note-floater.dg-flip .dg-flip-back {
    position: absolute;
    inset: 0;
    padding: 16px;
    /* border-radius: var(--radius-lg); */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* border: 2px solid rgba(0, 0, 0, 1); */
}

/* @media (min-width: 768px) {

    .dg-note-floater.dg-flip .dg-flip-front,
    .dg-note-floater.dg-flip .dg-flip-back {
        border: 4px solid rgba(0, 0, 0, 1);
    }
} */

/* when there is a front image, space content between so title sits at top and image at bottom */
.dg-note-floater.dg-flip .dg-flip-inner.has-front-image .dg-flip-front,
.dg-note-floater.dg-flip .dg-flip-inner.has-front-image .dg-flip-back {
    align-items: stretch;
    justify-content: space-between;
}

/* front face starts facing forward */
.dg-note-floater.dg-flip .dg-flip-front {
    transform: rotateY(0deg);
}

/* back face starts facing away */
.dg-note-floater.dg-flip .dg-flip-back {
    transform: rotateY(180deg);
}

.dg-note-floater.dg-flip .dg-title {
    margin: 0 0 8px;
    font-size: 1.2em;
    line-height: 1.2;
    font-weight: 500;
    text-align: center;
    width: 100%;
    white-space: nowrap;
    /* single-line */
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.dg-note-floater.dg-flip .dg-front-image {
    margin: auto;
    max-height: 75%;
    width: 100%;
    object-fit: contain;
}

.dg-note-floater.dg-flip.dg-active .dg-flip-inner {
    transform: rotateY(180deg);
    box-shadow: none;
}

.dg-note-floater.dg-flip .dg-title {
    /* ensure the title doesn't change size or rasterize during 3D flip */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    will-change: transform, opacity;
    -webkit-font-smoothing: antialiased;
}

.dg-note-floater.dg-flip.dg-active .dg-description {
    font-size: 1em;
}

.dg-description {
    margin: 0;
    font-size: 12px;
    line-height: 1.3;
}

/* Smooth text resize: fade during recompute to avoid visible jumps */
.dg-text,
.dg-description {
    transition: font-size .5s cubic-bezier(.4, .0, .2, 1), opacity .2s ease;
}

.dg-resizing .dg-text,
.dg-resizing .dg-description {
    opacity: .05;
}

/* Sibling dimming */
.discover-grid-layout.dg-has-active .dg-note-floater:not(.dg-active) {
    filter: blur(2px);
    opacity: 1;
}

.discover-grid-layout.dg-has-active .dg-cell:not(:has(.dg-note-floater.dg-active)) .dg-image {
    filter: blur(2px);
}

/* Hover */
@media (hover:hover) {
    .dg-note-floater:not(.dg-active):hover {
        transform: translate(calc(-50% + var(--dg-off-x, 0)), calc(-50% + var(--dg-off-y, 0))) scale(1.03) rotate(var(--dg-rot, 0deg));
    }
}

/* Mobile: make flip front title significantly larger (~3x) */
@media (max-width: 1920px) {
    .dg-note-floater.dg-flip .dg-title {
        font-size: 22px;
    }
}