/* ====================================================
   MERGED FLASK SHELF SYSTEM CSS
   Your existing styles + Flask integration + Responsive grid
   ==================================================== */

:root {
  /* Hover Effect Variables */
  --hover-duration: 0.4s;
  --hover-easing: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --hover-delay: 0s;
  --hover-scale: 1.05;
  --hover-translateY: -8px;
  --hover-rotation: 2deg;
  --hover-glow-intensity: 1.5;
  --hover-shadow-spread: 20px;
  --hover-brightness: 1.1;

  /* Special Effects Toggles */
  --shine-enabled: 1;
  --pulse-enabled: 1;
  --float-enabled: 0;
  --ripple-enabled: 0;

  /* Shelf Variables */
  --shelf-primary-color: linear-gradient(135deg, #8B4513 0%, #A0522D 50%, #CD853F 100%);
  --shelf-secondary-color: linear-gradient(135deg, #A0522D 0%, #CD853F 50%, #DEB887 100%);
  --shelf-accent-color: #654321;
  --shelf-highlight-color: rgba(255, 255, 255, 0.1);
  --shelf-height: 80px;
  --shelf-depth: 16px;
  --shelf-border-radius: 12px;
  --shelf-gap: 60px;
  --shelf-shadow-color: rgba(0, 0, 0, 0.4);
  --shelf-shadow-blur: 35px;
  --shelf-shadow-spread: 0px;
  --shelf-shadow-offset: 15px;

  /* Background Variables */
  --bg-brightness: 0.4;
  --bg-contrast: 0.6;
  --bg-hue: 220;
  --bg-saturation: 0.7;
  --adaptive-overlay-opacity: calc(0.3 + (var(--bg-contrast) * 0.4));
  --adaptive-blur: calc(2px + (var(--bg-contrast) * 8px));
  --adaptive-shadow-opacity: calc(0.2 + (var(--bg-brightness) * 0.3));

  /* NEW: Responsive Variables */

  --container-max-width: 1000px;
}

/* ====================================================
   FLASK INTEGRATION CONTAINER
   ==================================================== */

/* Main results container - adapted from your original */
#results_container.shelf-system {
    position: relative;
    width: 100%;
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 20px;
}

/* Alternative: Keep your original container styling */
#results_container.bgc {
    /* Your existing .bgc styles can stay here */
}

/* ====================================================
   SHELF STRUCTURE (Your existing + enhancements)
   ==================================================== */
/* Dynamic Shelf System Override */
.shelf-system.dynamic-shelves .toys-container {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--calculated-gap, 15px);
    justify-content: center;
    align-items: flex-end;
    padding: 0 20px;
    min-height: 140px;
}

.shelf-system.dynamic-shelves .shelf {
    --shelf-toy-count: 5; /* default, overridden by JS */
}

.shelf {
    position: relative;
    width: 100%;
    max-width: var(--container-max-width);
    margin: 0 auto var(--shelf-gap) auto;
    min-height: 200px;
    overflow: visible; /* Allow effects to extend beyond shelf */
}

.shelf:hover {
    z-index: 5;
}

.shelf-surface {
    position: absolute;
    bottom: 2px; /* Anchor to bottom */
    left: 0;
    right: 0;
    width: 100%;
    height: var(--shelf-height);
    background: var(--shelf-primary-color);
    border-radius: var(--shelf-border-radius);
    box-shadow:
        0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color),
        0 calc(var(--shelf-shadow-offset) * 0.3) calc(var(--shelf-shadow-blur) * 0.5) rgba(0, 0, 0, 0.2),
        inset 0 2px 0 var(--shelf-highlight-color);
    z-index: 1; /* Below toys */
}

.shelf-surface::before {
    content: '';
    position: absolute;
    top: calc(var(--shelf-depth) * -0.5);
    left: 0;
    right: 0;
    height: var(--shelf-depth);
    background: var(--shelf-secondary-color);
    border-radius: var(--shelf-border-radius) var(--shelf-border-radius) calc(var(--shelf-border-radius) * 0.7) calc(var(--shelf-border-radius) * 0.7);
    box-shadow: 0 calc(var(--shelf-depth) * -0.2) calc(var(--shelf-depth) * 0.5) rgba(0, 0, 0, 0.2);
}

/* ====================================================
   TOYS CONTAINER - Enhanced with responsive grid
   ==================================================== */

.toys-container {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    gap: var(--calculated-gap, 15px);
    padding: 0 40px;
    min-height: 140px;
    justify-content: center;
    align-items: flex-end;
    z-index: 2;
    margin-bottom: calc(var(--shelf-height) * 0.07);
    overflow: visible; /* Allow effects to extend */
}

/* ====================================================
   TOY STYLING - Your existing + Flask integration
   ==================================================== */

.toy {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all var(--hover-duration) var(--hover-easing) var(--hover-delay);
    transform-origin: center bottom;
    /* Remove overflow hidden to allow effects to extend */
    overflow: visible;
    z-index: 1;
}



/* ====================================================
   TOY CONTENT - Adapted for Flask data structure
   ==================================================== */

/* Your existing toy-mock styling preserved */
.toy-mock {
    width: 60px;
    height: 80px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 24px;
    text-align: center;
    transition: all var(--hover-duration) var(--hover-easing);
    filter:
        brightness(calc(0.95 + (var(--bg-brightness) * 0.1)))
        contrast(calc(0.9 + (var(--bg-contrast) * 0.2)))
        saturate(calc(0.9 + (var(--bg-saturation) * 0.2)));
}

/* NEW: Real image styling for Flask integration */
.toy-link {
    display: flex;
    align-items: flex-end; /* Align toys to bottom like on a shelf */
    justify-content: center;
    text-decoration: none;
    color: inherit;
    width: 100%;
    min-height: 140px; /* Ensure consistent container height */
    padding-bottom: 10px; /* Small padding so toys don't touch the shelf */
    overflow:visible;
}

.toy-image,
.thumb {
    position: relative; /* For pseudo-elements */
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    z-index: 3;
    transition: all var(--hover-duration) var(--hover-easing);
    filter:
        brightness(calc(0.95 + (var(--bg-brightness) * 0.1)))
        contrast(calc(0.9 + (var(--bg-contrast) * 0.2)))
        saturate(calc(0.9 + (var(--bg-saturation) * 0.2)));
}

/* NEW: Toy information overlay for Flask data */
.toy-info-overlay {
    position: absolute;
    top: 100%; /* Always positioned below the toy */
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all var(--hover-duration) var(--hover-easing);
    width: auto;
    min-width: 100px;
    max-width: 100px;
    z-index: 1;
}

/* Hide details by default */
.toy-details {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all var(--hover-duration) var(--hover-easing);
    margin-top: 0;
}

/* Detail items styling */
.toy-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    line-height: 1.4;
    margin: 2px 0;
    white-space: nowrap;
}

.detail-label {
    color: rgba(255, 255, 255, 0.6);
    font-weight: normal;
    margin-right: 8px;
}

.detail-value {
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    text-align: right;
}


.toy-maker {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.7);
    display: block;
    margin-bottom: 2px;
}

.toy-name {
    font-size: 11px;
    color: white;
    margin: 0;
    font-weight: bold;
    line-height: 1.2;
    margin-bottom: 4px;
}

.toy-price {
    font-size: 10px;
    color: #4CAF50;
    font-weight: bold;
}

/* Your existing toy category styles preserved */
.toy.robot .toy-mock { background: linear-gradient(135deg, #ff6b6b, #ee5a52); }
.toy.teddy .toy-mock { background: linear-gradient(135deg, #8B4513, #D2691E); border-radius: 50% 50% 40% 40%; }
.toy.car .toy-mock { background: linear-gradient(135deg, #4ecdc4, #44a08d); border-radius: 20px 20px 8px 8px; height: 40px; width: 80px; }
.toy.doll .toy-mock { background: linear-gradient(135deg, #ffeaa7, #fdcb6e); border-radius: 50% 50% 30% 30%; }
.toy.block .toy-mock { background: linear-gradient(135deg, #a8e6cf, #88d8a3); border-radius: 4px; width: 50px; height: 50px; }

/* NEW: Empty slots for incomplete shelves */
.toy-slot.empty {
    width: 80px;
    height: 100px;
    opacity: 0.3;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 12px;
}

.toy-slot.empty::after {
    content: "Empty";
}

/* ====================================================
   HOVER EFFECTS - Your existing preserved
   ==================================================== */

.toy:hover {
    transform:
        translateY(var(--hover-translateY))
        scale(var(--hover-scale))
        rotate(var(--hover-rotation));
    z-index: 101;
    filter: drop-shadow(0 var(--toy-shadow-intensity) var(--hover-shadow-spread) rgba(0, 0, 0, calc(var(--adaptive-shadow-opacity) + 0.2)));
}

.toy:hover .toy-mock,
.toy:hover .toy-image,
.toy:hover .thumb {
    transform-origin: bottom center;
    transform: scale(1.05);
    z-index:99;
    filter:
        brightness(var(--hover-brightness))
        contrast(calc(1.0 + (var(--bg-contrast) * 0.3)))
        saturate(calc(1.1 + (var(--bg-saturation) * 0.3)))
        drop-shadow(0 0 calc(var(--toy-shadow-intensity) * var(--hover-glow-intensity)) var(--toy-glow-color));
}

/* NEW: Enhanced hover for info overlay */
.toy:hover .toy-info-overlay {
    position: absolute;
    top: 100%; /* Position below the toy image */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(15px);
    border-color: rgba(255, 255, 255, 0.3);
    max-width: 140px;
    z-index: 100; /* High z-index to appear above everything */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.toy:hover .toy-details {
    max-height: 150px;
    opacity: 1;
    margin-top: 8px;
}


/* Your existing glow effect preserved */
.toy::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    transform: translate(-50%, -50%) scale(0.8);
    border-radius: 50%;
    background: radial-gradient(
        circle,
        transparent 60%,
        var(--toy-glow-color) 70%,
        transparent 80%
    );
    opacity: 0;
    transition: all var(--hover-duration) var(--hover-easing);
    pointer-events: none;
    z-index: -1;
}

.toy:hover::before {
    opacity: calc(var(--toy-highlight-opacity) * var(--pulse-enabled));
    transform: translate(-50%, -50%) scale(1.2);
    animation: pulseGlow calc(var(--hover-duration) * 5) ease-in-out infinite;
}

/* Your existing shine effect preserved */
.toy::after {
    content: '';
    position: absolute;
    top: 10%;
    left: -20%;
    width: 40%;
    height: 80%;
    background: linear-gradient(
        45deg,
        transparent,
        rgba(255, 255, 255, calc(var(--toy-highlight-opacity) + 0.1)),
        transparent
    );
    transform: skewX(-20deg) translateX(-200%);
    transition: transform 0.6s var(--hover-easing);
    pointer-events: none;
    border-radius: 4px;
    opacity: var(--shine-enabled);
}

.toy:hover::after {
    transform: skewX(-20deg) translateX(calc(500% * var(--shine-enabled)));
}

/* ====================================================
   PRESET SELECTOR - Your existing preserved
   ==================================================== */

.preset-selector {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 300px;
}

.preset-controls {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    border-radius: 15px;
    padding: 25px;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.preset-controls h3 {
    margin-bottom: 20px;
    text-align: center;
    color: #fff;
    font-size: 18px;
}

.preset-group {
    margin-bottom: 18px;
}

.preset-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    font-size: 14px;
    color: #ccc;
}

.preset-group select {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.preset-group select:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
}

.preset-actions {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.preset-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    font-weight: bold;
}

.preset-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

/* ====================================================
   MATERIAL PRESETS - Your existing preserved
   ==================================================== */

.shelf-preset-wooden .shelf-surface {
    background-image:
        var(--shelf-primary-color),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0, 0, 0, 0.05) 2px, rgba(0, 0, 0, 0.05) 4px);
}

.shelf-preset-metal .shelf-surface {
    background-image:
        var(--shelf-primary-color),
        repeating-linear-gradient(45deg, transparent, transparent 1px, rgba(255, 255, 255, 0.1) 1px, rgba(255, 255, 255, 0.1) 2px);
    box-shadow:
        0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}

.shelf-preset-glass .shelf-surface {
    backdrop-filter: blur(20px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow:
        0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.shelf-preset-neon .shelf-surface {
    box-shadow:
        0 0 20px var(--shelf-accent-color),
        0 0 40px var(--shelf-accent-color),
        0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color),
        inset 0 0 20px rgba(255, 255, 255, 0.1);
    animation: neonPulse 3s ease-in-out infinite alternate;
}

/* ====================================================
   HOVER PRESET EFFECTS - Your existing preserved
   ==================================================== */

.hover-preset-magical .toy:hover {
    animation: magicalFloat 2s ease-in-out infinite;
}

.hover-preset-gentle .toy:hover {
    animation: gentleFloat 4s ease-in-out infinite;
}

.hover-preset-dramatic .toy:hover {
    animation: dramaticShake 0.3s ease-in-out;
}

.hover-preset-bouncy .toy:hover {
    animation: bouncySpring 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ====================================================
   RESPONSIVE DESIGN SYSTEM - NEW
   ==================================================== */

/* Large Screens (Desktop) */
@media (min-width: 1600px) {
    :root {
        --container-max-width: 1600px;
    }
}

/* Large Screens (Desktop) */
@media (min-width: 1200px) {
    :root {
        --shelf-gap: 80px;
        --shelf-height: 90px;
        --container-max-width: 1400px;
    }

    .toys-container {
        padding: 0 50px;
        gap: 20px;
        align-items: flex-end;
    }

    .toy-image,
    .thumb {

    }

    .toy-info-overlay {
        max-width: 110px;
    }
}

/* Medium Screens (Tablets) */
@media (min-width: 768px) and (max-width: 1199px) {
    :root {

        --shelf-gap: 60px;
        --shelf-height: 80px;
        --container-max-width: 900px;
    }

    .toys-container {
        bottom: calc(var(--shelf-height) - 55px);
        padding: 0 30px;
        gap: 15px;
    }

    .toy:hover .toy-info-overlay {
        max-width: 130px;
    }

    .toy-image,
    .thumb {

    }
}

/* Small Screens (Mobile) */
@media (max-width: 767px) {
    :root {

        --shelf-gap: 40px;
        --shelf-height: 60px;
        --shelf-depth: 12px;
        --hover-scale: 1.03;
        --hover-translateY: -4px;
        --container-max-width: 100%;
    }

    #results_container.shelf-system {
        padding: 15px;
        overflow:hidden;
    }

    .toys-container {
        bottom: calc(var(--shelf-height) - 110px);
        padding: 0 15px;
        gap: 10px;
    }

    .toy-image,
    .thumb {

    }

    .toy:hover .toy-info-overlay {
        max-width: 120px;
    }

    .toy-detail {
        font-size: 8px;
    }

    .toy-info-overlay {
        max-width: 80px;
        padding: 4px 6px;
        margin-top: 6px;
    }

    .toy-maker {
        font-size: 8px;
    }

    .toy-name {
        font-size: 10px;
    }

    .toy-price {
        font-size: 9px;
    }

    .shelf {
        padding-bottom: var(--shelf-height);
        min-height: 180px;
    }

    .shelf-surface {
        margin-top: -15px; /* Adjust for smaller screens */
        bottom: 15px;
    }
}

/* Extra Small Screens */
@media (max-width: 480px) {
    :root {

        --shelf-gap: 30px;
        --shelf-height: 50px;
    }

    .toys-container {
        bottom: calc(var(--shelf-height) - 120px);
        gap: 8px;
        padding: 0 10px;
    }

    .toy-image,
    .thumb {

    }

    .toy:hover .toy-info-overlay {
        max-width: 110px;
    }

    .toy-detail {
        font-size: 7px;
    }

    .toy-info-overlay {
        max-width: 70px;
        padding: 4px;
    }

    .toy-name {
        font-size: 9px;
    }

    .toy-maker {
        font-size: 7px;
    }

    .preset-selector {
        position: relative;
        top: auto;
        right: auto;
        max-width: 100%;
        margin: 20px 0;
    }

    .preset-controls {
        padding: 20px 15px;
    }

    .shelf-surface {
        margin-top: -10px; /* Adjust for smaller screens */
    }

    .shelf {
        min-height: 160px;
    }
}

/* ====================================================
   ENHANCED INTERACTION STATES - NEW
   ==================================================== */

/* Focus state for keyboard navigation */
.toy:focus-within {
    outline: none;
    transform: translateY(-4px) scale(1.02);
}

.toy:focus-within .toy-image,
.toy:focus-within .thumb {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5);
}

/* Active/clicked state */
.toy:active {
    transform: translateY(-2px) scale(0.98);
    transition: all 0.1s ease-out;
}

/* Selected state */
.toy.selected {
    transform: translateY(-4px) scale(1.02);
}

.toy.selected::before {
    opacity: calc(var(--toy-highlight-opacity) * 1.5);
    transform: translate(-50%, -50%) scale(1.1);
    animation: selectedPulse 3s ease-in-out infinite;
}

.toy.selected .toy-info-overlay {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

/* Loading state */
.toy.loading .toy-image,
.toy.loading .thumb {
    opacity: 0.5;
    filter: blur(2px);
}

.toy.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: spin 1s linear infinite;
    z-index: 10;
}

/* ====================================================
   ANIMATIONS - Your existing preserved + new ones
   ==================================================== */

@keyframes pulseGlow {
    0%, 100% {
        opacity: var(--toy-highlight-opacity);
        transform: translate(-50%, -50%) scale(1.2);
    }
    50% {
        opacity: calc(var(--toy-highlight-opacity) * 1.5);
        transform: translate(-50%, -50%) scale(1.3);
    }
}

@keyframes magicalFloat {
    0%, 100% { transform: translateY(var(--hover-translateY)) scale(var(--hover-scale)) rotate(var(--hover-rotation)); }
    50% { transform: translateY(calc(var(--hover-translateY) - 4px)) scale(calc(var(--hover-scale) + 0.02)) rotate(calc(var(--hover-rotation) * -0.5)); }
}

@keyframes gentleFloat {
    0%, 100% { transform: translateY(var(--hover-translateY)) scale(var(--hover-scale)); }
    50% { transform: translateY(calc(var(--hover-translateY) - 2px)) scale(calc(var(--hover-scale) + 0.01)); }
}

@keyframes dramaticShake {
    0%, 100% { transform: translateY(var(--hover-translateY)) scale(var(--hover-scale)) rotate(var(--hover-rotation)); }
    25% { transform: translateY(calc(var(--hover-translateY) - 3px)) scale(calc(var(--hover-scale) + 0.03)) rotate(calc(var(--hover-rotation) + 2deg)); }
    75% { transform: translateY(calc(var(--hover-translateY) + 1px)) scale(calc(var(--hover-scale) - 0.01)) rotate(calc(var(--hover-rotation) - 1deg)); }
}

@keyframes bouncySpring {
    0% { transform: translateY(var(--hover-translateY)) scale(var(--hover-scale)); }
    30% { transform: translateY(calc(var(--hover-translateY) - 6px)) scale(calc(var(--hover-scale) + 0.05)); }
    60% { transform: translateY(calc(var(--hover-translateY) + 2px)) scale(calc(var(--hover-scale) - 0.02)); }
    100% { transform: translateY(var(--hover-translateY)) scale(var(--hover-scale)); }
}

@keyframes neonPulse {
    0% {
        box-shadow:
            0 0 20px var(--shelf-accent-color),
            0 0 40px var(--shelf-accent-color),
            0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color);
    }
    100% {
        box-shadow:
            0 0 30px var(--shelf-accent-color),
            0 0 60px var(--shelf-accent-color),
            0 var(--shelf-shadow-offset) var(--shelf-shadow-blur) var(--shelf-shadow-spread) var(--shelf-shadow-color);
    }
}

/* NEW: Additional animations */
@keyframes selectedPulse {
    0%, 100% {
        opacity: calc(var(--toy-highlight-opacity) * 1.5);
    }
    50% {
        opacity: calc(var(--toy-highlight-opacity) * 2);
    }
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ====================================================
   ACCESSIBILITY & PERFORMANCE
   ==================================================== */

/* High contrast mode */
@media (prefers-contrast: high) {
    .toy-info-overlay {
        background: rgba(0, 0, 0, 0.8);
        border: 2px solid white;
    }

    .toy-name, .toy-maker, .toy-price {
        color: white;
        text-shadow: 1px 1px 2px black;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .toy,
    .toy *,
    .shelf-surface {
        transition: none !important;
        animation: none !important;
    }

    .toy:hover {
        transform: scale(1.02);
    }

    :root {
        --shine-enabled: 0;
        --pulse-enabled: 0;
        --float-enabled: 0;
        --ripple-enabled: 0;
    }
}

/* ====================================================
   FLASK INTEGRATION UTILITIES
   ==================================================== */

/* Hide elements during loading */
.toys-loading .toy {
    opacity: 0.5;
    pointer-events: none;
}

/* Error state */
.toy.error .toy-image,
.toy.error .thumb {
    opacity: 0.3;
    filter: grayscale(100%);
}

.toy.error::after {
    content: '❌';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    z-index: 10;
}

/* Search highlight */
.toy.highlighted {
    animation: highlightPulse 2s ease-in-out 3;
}

@keyframes highlightPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7);
    }
    50% {
        box-shadow: 0 0 0 20px rgba(255, 215, 0, 0);
    }
}

/* ====================================================
   DYNAMIC RESPONSIVE SHELF SYSTEM
   ==================================================== */

/* Base responsive adjustments */
.shelf-system.dynamic-shelves {
    --responsive-toy-width: 120px;
    --responsive-toy-height: 160px;
    --responsive-gap: 15px;
}

/* Ensure toys don't shrink too much */
.dynamic-shelves .toy {
    width: var(--responsive-toy-width);
    max-width: var(--responsive-toy-width);
    min-width: var(--responsive-toy-width);
    flex: 0 0 var(--responsive-toy-width);
}

.dynamic-shelves .toy-image,
.dynamic-shelves .thumb {
    width: calc(var(--responsive-toy-width) - 20px);
    height: auto;
    object-fit: contain;
}

.dynamic-shelves .toys-container {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--responsive-gap);
    justify-content: center;
    padding: 0 20px;
}

/* 6 toys per shelf (large screens) */
@media (min-width: 1400px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="7"] {
        --responsive-toy-width: 140px;
        --responsive-toy-height: 180px;
        --responsive-gap: 20px;
    }
}

/* 6 toys per shelf (large screens) */
@media (min-width: 1200px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="6"] {
        --responsive-toy-width: 140px;
        --responsive-toy-height: 180px;
        --responsive-gap: 20px;
    }
}

/* 5 toys per shelf */
@media (min-width: 992px) and (max-width: 1199px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="5"] {
        --responsive-toy-width: 130px;
        --responsive-toy-height: 170px;
        --responsive-gap: 18px;
    }
}

/* 4 toys per shelf (tablets) */
@media (min-width: 768px) and (max-width: 991px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="4"] {
        --responsive-toy-width: 120px;
        --responsive-toy-height: 160px;
        --responsive-gap: 15px;
    }

    .dynamic-shelves .toys-container {
        padding: 0 30px;
    }
}

/* 3 toys per shelf (large phones) */
@media (min-width: 576px) and (max-width: 767px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="3"] {
        --responsive-toy-width: 110px;
        --responsive-toy-height: 150px;
        --responsive-gap: 12px;
        --shelf-height: 70px;
    }

    .dynamic-shelves .toys-container {
        padding: 0 20px;
    }

    .dynamic-shelves .toy-info-overlay {
        font-size: 10px;
        padding: 4px 6px;
    }
}

/* 2 toys per shelf (phones) */
@media (max-width: 575px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="2"] {
        --responsive-toy-width: 140px;
        --responsive-toy-height: 180px;
        --responsive-gap: 20px;
        --shelf-height: 60px;
        --shelf-gap: 50px;
    }

    .dynamic-shelves .toys-container {
        padding: 0 15px;
    }

    .dynamic-shelves .toy-info-overlay {
        max-width: 120px;
    }

    /* Adjust shelf appearance for mobile */
    .dynamic-shelves .shelf {
        margin-bottom: var(--shelf-gap);
    }

    .dynamic-shelves .shelf-surface {
        height: var(--shelf-height);
    }
}

/* Extra small screens - ensure toys are still visible */
@media (max-width: 400px) {
    .shelf-system.dynamic-shelves[data-toys-per-shelf="2"] {
        --responsive-toy-width: 120px;
        --responsive-toy-height: 160px;
        --responsive-gap: 15px;
    }

    .dynamic-shelves .toys-container {
        padding: 0 10px;
    }
}

/* Prevent hover effects from breaking layout on mobile */
@media (max-width: 767px) {
    .dynamic-shelves .toy:hover {
        transform: translateY(-4px) scale(1.02);
        --hover-rotation: 0deg;
    }
}

/* Ensure toy info is readable on all sizes */
.dynamic-shelves .toy-name {
    font-size: clamp(10px, 2vw, 13px);
    line-height: 1.2;
}

.dynamic-shelves .toy-price {
    font-size: clamp(10px, 2vw, 12px);
}

.dynamic-shelves .toy-maker {
    font-size: clamp(8px, 1.5vw, 10px);
}

/* Dynamic toy sizing based on calculated values */
.shelf-system.dynamic-shelves .toy {
    transition: all 0.3s ease;
}

.shelf-system.dynamic-shelves .toys-container {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--calculated-gap, 15px);
    justify-content: center;
    padding: 0 20px;
}

/* Ensure images scale proportionally */
.shelf-system.dynamic-shelves .toy-image,
.shelf-system.dynamic-shelves .thumb {
    width: auto;
    max-width: none;
    height: auto;
}

/* Adjust info overlay to match */
.shelf-system.dynamic-shelves .toy-info-overlay {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}

/* In effects.css */
@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.8); }
}





/* ====================================================
   LOADING SCREEN STYLES
   ==================================================== */

/* Loading overlay that covers everything */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: all;
}

/* Canvas for animated background matching WebGL shader */
#loading-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

/* Loading content container */
.loading-content {
    position: relative;
    z-index: 10;
    text-align: center;
    color: white;
}

/* Animated shelf loader */
.shelf-loader {
    width: 200px;
    height: 120px;
    margin: 0 auto 30px;
    position: relative;
}

/* Animated shelf base */
.loader-shelf {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    height: 12px;
    background: var(--shelf-primary-color, linear-gradient(135deg, #8B4513 0%, #A0522D 50%, #CD853F 100%));
    border-radius: 6px;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: shelfGlow 2s ease-in-out infinite;
}

/* Animated toy placeholders */
.loader-toy {
    position: absolute;
    bottom: 32px;
    width: 30px;
    height: 40px;
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    border-radius: 8px;
    opacity: 0;
    animation: toyLoad 2s ease-in-out infinite;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.loader-toy:nth-child(1) {
    left: 20px;
    animation-delay: 0s;
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
}

.loader-toy:nth-child(2) {
    left: 60px;
    animation-delay: 0.2s;
    background: linear-gradient(135deg, #8B4513, #D2691E);
}

.loader-toy:nth-child(3) {
    left: 100px;
    animation-delay: 0.4s;
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
}

.loader-toy:nth-child(4) {
    left: 140px;
    animation-delay: 0.6s;
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
}

/* Loading text */
.loading-text {
    font-size: 24px;
    font-weight: 300;
    letter-spacing: 2px;
    opacity: 0.9;
    margin-bottom: 10px;
}

/* Progress dots */
.loading-dots {
    display: inline-flex;
    gap: 8px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

/* Status text */
.loading-status {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 20px;
    min-height: 20px;
    transition: opacity 0.3s ease;
}

/* Animations */
@keyframes shelfGlow {
    0%, 100% {
        box-shadow:
            0 4px 20px rgba(0, 0, 0, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }
    50% {
        box-shadow:
            0 4px 30px rgba(0, 0, 0, 0.6),
            0 0 40px rgba(205, 133, 63, 0.3),
            inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }
}

@keyframes toyLoad {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.8);
    }
    50% {
        opacity: 1;
        transform: translateY(-5px) scale(1.05);
    }
    100% {
        opacity: 0.6;
        transform: translateY(0) scale(1);
    }
}

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    40% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* Fade out when loaded */
#loading-screen.loaded {
    opacity: 0;
    pointer-events: none;
}

/* Hide main content initially */
body.loading #main_horizontal,
body.loading #main_vertical,
body.loading #results_container,
body.loading #search_options {
    opacity: 0;
    visibility: hidden;
}

/* Smooth reveal */
body:not(.loading) #main_horizontal,
body:not(.loading) #main_vertical,
body:not(.loading) #results_container,
body:not(.loading) #search_options {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.6s ease-out 0.3s, visibility 0s 0.3s;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .shelf-loader {
        width: 160px;
        height: 100px;
    }

    .loader-toy {
        width: 24px;
        height: 32px;
    }

    .loader-toy:nth-child(1) { left: 16px; }
    .loader-toy:nth-child(2) { left: 48px; }
    .loader-toy:nth-child(3) { left: 80px; }
    .loader-toy:nth-child(4) { left: 112px; }

    .loading-text {
        font-size: 20px;
    }

    .loading-status {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .shelf-loader {
        width: 140px;
        height: 80px;
    }

    .loader-toy {
        width: 20px;
        height: 26px;
        bottom: 28px;
    }

    .loader-shelf {
        height: 10px;
    }

    .loading-text {
        font-size: 18px;
    }
}