/* Shared bento card styles (index.html, pages/deepdish.html).
   Pair with js/bento.js, which adds the CRT/glow/specular layers,
   per-card --accent from data-accent, tilt, and entrance reveal. */

/* Bento Grid */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    gap: clamp(0.6rem, 1.6vw, 1.5rem);
    position: relative;
    flex: 1 1 auto;
    /* Fill leftover vertical space, but stay usable on short screens (page scrolls) */
    min-height: 340px;
}

@property --border-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

@keyframes rotateBorder {
    to { --border-angle: 360deg; }
}

/* Bento Items - Dark Glass (deepdish style) */
.bento-item {
    --border-angle: 0deg;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(139, 233, 253, 0.25);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    perspective: 800px;
    box-shadow: 
        0 4px 24px rgba(0, 0, 0, 0.3),
        0 8px 32px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 0 20px rgba(139, 233, 253, 0.03);
}

/* Holographic shimmer overlay */
.bento-item::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(
        from var(--border-angle),
        transparent 0%,
        rgba(139, 233, 253, 0.03) 10%,
        transparent 20%,
        rgba(189, 147, 249, 0.03) 30%,
        transparent 40%,
        rgba(80, 250, 123, 0.03) 50%,
        transparent 60%
    );
    animation: rotateBorder 8s linear infinite;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* Sweep light effect */
.bento-item::after {
    content: '';
    position: absolute;
    top: -100%;
    left: -75%;
    width: 50%;
    height: 300%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(139, 233, 253, 0.04) 45%,
        rgba(139, 233, 253, 0.08) 50%,
        rgba(139, 233, 253, 0.04) 55%,
        transparent 100%
    );
    transform: rotate(25deg);
    transition: left 0.7s ease;
    pointer-events: none;
    z-index: 1;
}

.bento-item:hover::after {
    left: 125%;
}

.bento-item:hover {
    border-color: rgba(139, 233, 253, 0.5);
    border-top-color: rgba(255, 255, 255, 0.2);
    border-left-color: rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.4);
    transform: translateY(-8px) scale(1.03);
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.4),
        0 0 40px rgba(139, 233, 253, 0.15),
        0 0 80px rgba(139, 233, 253, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        inset 0 0 30px rgba(139, 233, 253, 0.05);
}

.bento-item:hover::before {
    opacity: 1;
}



/* Featured sizes */
.bento-item.featured {
    grid-column: span 2;
    grid-row: span 2;
}

.bento-item.wide {
    grid-column: span 2;
}

.bento-item.tall {
    grid-row: span 2;
}

/* Bento Image */
.bento-image {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    z-index: 3;
    background: transparent;
}

/* CRT scanline overlay - covers entire card */
.bento-item .crt-overlay {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.12) 2px,
        rgba(0, 0, 0, 0.12) 4px
    );
    pointer-events: none;
    z-index: 20;
    opacity: 0.55;
    transition: opacity 0.4s ease;
    mix-blend-mode: multiply;
    border-radius: 16px;
    animation: crtFlicker 4s ease-in-out infinite;
}

.bento-item:hover .crt-overlay {
    opacity: 0.25;
}

/* CRT vignette + edge glow - covers entire card */
.bento-item .crt-vignette {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(
        ellipse at center,
        transparent 40%,
        rgba(0, 0, 0, 0.25) 75%,
        rgba(0, 0, 0, 0.55) 100%
    );
    pointer-events: none;
    z-index: 21;
    opacity: 0.65;
    transition: opacity 0.4s ease;
    border-radius: 16px;
}

.bento-item:hover .crt-vignette {
    opacity: 0.35;
    background: radial-gradient(
        ellipse at center,
        rgba(139, 233, 253, 0.02) 20%,
        transparent 45%,
        rgba(0, 0, 0, 0.18) 75%,
        rgba(0, 0, 0, 0.45) 100%
    );
}

.bento-image img {
    max-width: 85%;
    max-height: 85%;
    object-fit: contain;
    filter: brightness(0.95) contrast(1.05) saturate(0.9) drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
    transition: all 0.4s ease;
    image-rendering: auto;
}

.bento-item:hover .bento-image img {
    filter: brightness(1.15) contrast(1.1) saturate(1.1) drop-shadow(0 4px 16px rgba(139, 233, 253, 0.25)) drop-shadow(0 0 8px rgba(139, 233, 253, 0.15));
    transform: scale(1.08) translateY(-2px);
}

/* CRT flicker animation */
@keyframes crtFlicker {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 0.5; }
    92% { opacity: 0.55; }
    93% { opacity: 0.35; }
    94% { opacity: 0.55; }
}

/* Bento Content */
.bento-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    z-index: 4;
    text-align: center;
    min-height: 55px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.bento-content h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #eaeaea;
    margin-bottom: 0.25rem;
    text-transform: lowercase;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    transition: color 0.3s ease;
}

.bento-item:hover .bento-content h3 {
    color: #fff;
    text-shadow: 0 0 20px rgba(139, 233, 253, 0.4);
}

.bento-content p {
    font-size: 0.7rem;
    color: #888;
    text-transform: lowercase;
    letter-spacing: 0.05em;
    line-height: 1.3;
    transition: color 0.3s ease;
}

.bento-item:hover .bento-content p {
    color: #aaa;
}

/* External link indicator */
.bento-item[target="_blank"] .bento-content::before {
    content: '↗';
    position: absolute;
    top: -85px;
    right: 8px;
    font-size: 0.8rem;
    color: rgba(139, 233, 253, 0.3);
    transition: all 0.3s;
}

.bento-item[target="_blank"]:hover .bento-content::before {
    color: #8be9fd;
    transform: translate(2px, -2px);
}

/* Glow layer that appears on tilt */
.bento-item .tilt-glow {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 16px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 0;
}

.bento-item:hover .tilt-glow {
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
    /* Revert to natural scrolling flow on smaller screens */
    .bento-container {
        display: block;
        flex: none;
    }
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: auto;
        flex: none;
        min-height: 0;
    }
    .bento-item {
        aspect-ratio: 3 / 2;
    }
    
    /* Ensure transparency on mobile */
    .bento-item {
        background: rgba(0, 0, 0, 0.45) !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
    }
    
    /* Reduce 3D effect on mobile for performance */
    .bento-item .bento-image {
        transform: translateZ(20px);
    }
    .bento-item:hover .bento-image {
        transform: translateZ(30px);
    }
}

@media (max-width: 500px) {
    .bento-item {
        background: rgba(0, 0, 0, 0.4) !important;
        backdrop-filter: blur(8px) !important;
        -webkit-backdrop-filter: blur(8px) !important;
    }
}

/* On phones: single column, but compact (flat, banner-height) cards to match the installer */
@media (max-width: 600px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }
    .bento-item {
        aspect-ratio: 2.8 / 1;
    }
}

/* ---------- Bento card polish ----------
   Cards are size containers so each one picks its own layout from its shape:
   stacked (icon over text) when roomy, horizontal row when short and wide.
   --accent is an "r,g,b" triplet set per card from data-accent (js/index.js). */
.bento-item {
    --accent: 139, 233, 253;
    container-type: size;
    background:
        linear-gradient(160deg, rgba(var(--accent), 0.08) 0%, rgba(var(--accent), 0.015) 40%, transparent 70%),
        rgba(0, 0, 0, 0.35);
    border-color: rgba(var(--accent), 0.22);
    border-top-color: rgba(255, 255, 255, 0.14);
    border-left-color: rgba(255, 255, 255, 0.08);
}

.bento-item:focus-visible {
    outline: 2px solid rgba(var(--accent), 0.85);
    outline-offset: 3px;
}

/* Icon area: in normal flow, fills the space above the text */
.bento-image {
    position: relative;
    inset: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding: clamp(0.5rem, 9cqh, 1.4rem) 1rem 0;
}

/* Soft accent halo behind the icon */
.bento-image::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 55%;
    width: min(70cqh, 70%);
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(var(--accent), 0.16) 0%, rgba(var(--accent), 0.05) 45%, transparent 70%);
    pointer-events: none;
    z-index: -1;
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0.8;
}

.bento-item:hover .bento-image::before {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
}

.bento-content {
    position: relative;
    flex: none;
    min-height: 0;
    padding: 0.6rem 1rem clamp(0.75rem, 8cqh, 1.1rem);
    background: none;
}

.bento-content h3 {
    font-size: clamp(0.9rem, 0.5rem + 3.2cqw, 1.05rem);
    letter-spacing: 0.02em;
    margin-bottom: 0.2rem;
}

.bento-item:hover .bento-content h3 {
    color: rgb(var(--accent));
    text-shadow: 0 0 18px rgba(var(--accent), 0.45);
}

.bento-content p {
    color: #8a8f98;
}

.bento-item:hover .bento-content p {
    color: #b4b9c2;
}

/* Replaced by .bento-ext (the old pseudo-element sat outside the card) */
.bento-item[target="_blank"] .bento-content::before {
    content: none;
}

.bento-ext {
    position: absolute;
    top: 0.55rem;
    right: 0.7rem;
    z-index: 22;
    font-size: 0.95rem;
    line-height: 1;
    color: rgba(var(--accent), 0.6);
    pointer-events: none;
    transition: color 0.3s ease, transform 0.3s ease;
}

.bento-item:hover .bento-ext {
    color: rgb(var(--accent));
    transform: translate(2px, -2px);
}

/* Short, wide cards (desktop grid filling the viewport, phones): icon left, text right.
   Absolute positioning (not transforms) because js/index.js writes inline transforms
   on .bento-image / .bento-content for the hover parallax. */
@container (min-aspect-ratio: 21 / 10) {
    .bento-item > .bento-image {
        --icon: min(64cqh, 92px);
        position: absolute;
        left: clamp(0.9rem, 6cqw, 1.5rem);
        top: calc((100cqh - var(--icon)) / 2);
        width: var(--icon);
        height: var(--icon);
        padding: 0;
    }
    .bento-image img {
        max-width: 100%;
        max-height: 100%;
    }
    .bento-image::before {
        top: 50%;
        width: 150%;
    }
    .bento-item > .bento-content {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        left: calc(clamp(0.9rem, 6cqw, 1.5rem) + min(64cqh, 92px));
        justify-content: center;
        text-align: left;
        padding: 0 1.75rem 0 clamp(0.8rem, 4cqw, 1.25rem);
    }
}
/* Staggered entrance animations */
.bento-item {
    opacity: 0;
}
.bento-item.visible {
    animation: bentoReveal 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    animation-delay: var(--reveal-delay, 0s);
}
@keyframes bentoReveal {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Touch feedback on mobile */
@media (hover: none) and (pointer: coarse) {
    .bento-item:active {
        transform: scale(0.96) !important;
        transition: transform 0.1s ease !important;
        border-color: rgba(139, 233, 253, 0.5);
    }
}

/* ---------- #5 Glass refraction layer ----------
   A dedicated layer with backdrop-filter that gets an SVG
   displacement map on hover. Falls back gracefully if the
   browser doesn't support backdrop-filter: url(). */
.bento-refract {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    pointer-events: none;
    z-index: 2;
    backdrop-filter: blur(0px) saturate(110%);
    -webkit-backdrop-filter: blur(0px) saturate(110%);
    transition: backdrop-filter 0.4s ease, -webkit-backdrop-filter 0.4s ease, opacity 0.4s ease;
    opacity: 0;
}
@supports (backdrop-filter: url(#bento-refract)) or (-webkit-backdrop-filter: url(#bento-refract)) {
    .bento-item:hover .bento-refract {
        opacity: 1;
        backdrop-filter: blur(2px) saturate(140%) url(#bento-refract);
        -webkit-backdrop-filter: blur(2px) saturate(140%) url(#bento-refract);
    }
}
/* Mobile / touch devices: hover never fires, and the always-on
   backdrop-filter on this layer can paint over card images on
   iOS Safari (preserve-3d + backdrop-filter stacking bug).
   Disable the layer entirely on hover-less devices. */
@media (hover: none), (max-width: 768px) {
    .bento-refract {
        display: none !important;
    }
}

/* ---------- #6 Parallax depth layers ----------
   The image, content, and a specular highlight move
   independently for a real-feeling 3D effect. */
.bento-item .bento-image,
.bento-item .bento-content {
    will-change: transform;
}
.bento-item .spec-highlight {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.35s ease;
    mix-blend-mode: screen;
}
.bento-item:hover .spec-highlight {
    opacity: 1;
}

/* ---------- #11 Idle shuffle glitch ---------- */
.bento-grid.idle-pulse::before {
    content: '';
    position: absolute;
    inset: -8px;
    border: 1px dashed rgba(139, 233, 253, 0.15);
    border-radius: 20px;
    pointer-events: none;
    animation: idleFrame 2s ease-in-out infinite;
    z-index: -1;
}
@keyframes idleFrame {
    0%, 100% { opacity: 0.2; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.005); }
}
.bento-item.shuffle-out {
    animation: shuffleGlitchOut 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.bento-item.shuffle-in {
    animation: shuffleGlitchIn 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes shuffleGlitchOut {
    0%   { clip-path: inset(0 0 0 0); filter: none; transform: translate(0,0); }
    20%  { clip-path: inset(10% 0 40% 0); filter: hue-rotate(40deg) saturate(1.5); transform: translate(-4px, 2px); }
    40%  { clip-path: inset(45% 0 5% 0); filter: hue-rotate(-30deg) saturate(2); transform: translate(5px, -3px); }
    60%  { clip-path: inset(20% 0 60% 0); filter: hue-rotate(80deg) brightness(1.3); transform: translate(-3px, 4px); }
    80%  { clip-path: inset(0 0 80% 0); filter: brightness(1.6); transform: translate(2px, 0); opacity: 0.6; }
    100% { clip-path: inset(0 0 100% 0); opacity: 0; transform: translate(0, 0); }
}
@keyframes shuffleGlitchIn {
    0%   { clip-path: inset(100% 0 0 0); opacity: 0; transform: translate(0, 0); filter: brightness(1.6); }
    25%  { clip-path: inset(60% 0 0 0); opacity: 0.8; transform: translate(-4px, 2px); filter: hue-rotate(-60deg) saturate(1.8); }
    50%  { clip-path: inset(20% 0 30% 0); opacity: 1; transform: translate(5px, -2px); filter: hue-rotate(40deg) saturate(1.4); }
    75%  { clip-path: inset(5% 0 60% 0); transform: translate(-2px, 3px); filter: hue-rotate(-20deg); }
    100% { clip-path: inset(0 0 0 0); transform: translate(0, 0); filter: none; }
}

@media (prefers-reduced-motion: reduce) {
    .bento-item.shuffle-out,
    .bento-item.shuffle-in { animation: none !important; }
    .bento-grid.idle-pulse::before { animation: none; }
}
