/* Can You Sort It? Game Styles */

/* ============================================================================
   GAME MENU CUSTOMIZATION (Can You Sort It)
   ============================================================================ */
:root {
    --game-primary: #FF8C00;  /* Dark orange */
    --game-primary-dark: #FF7700;
    --game-secondary: #FFD700; /* Gold */
}

body.game-menu-active {
    --menu-bg-image: url('/interactive/shared/backgrounds/canyousortit.png');
}

body {
    position: relative;
    background: #121212;
    min-height: 100vh;
    color: #fff;
}

/* Allow scrolling on menu screen */
body.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

/* Prevent scrolling only when game screen is active (not menu) */
body:not(.game-menu-active) #game-screen.active {
    max-height: 100vh;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

html {
    height: 100%;
}

/* Prevent scrolling on html when game screen is active (not menu) */
html:not(.menu-active) {
    overflow: hidden;
}

/* Allow scrolling on html when menu is active */
html.menu-active {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100% !important;
}

body.game-menu-active {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* Hide game header on menu screen */
body.game-menu-active #game-header {
    display: none !important;
}

/* Hide game header and shelf on mobile devices */
@media (max-width: 768px), (max-height: 667px) {
    #game-header {
        display: none !important;
    }
    
    body.with-game-header {
        padding-top: 0 !important;
    }
    
    /* Hide shelf background on mobile */
    .game-area::before {
        display: none !important;
    }
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        rgba(201, 12, 15, 0.1) 0%, 
        rgba(29, 78, 216, 0.1) 100%);
    opacity: 0.5;
    z-index: -2;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(18, 18, 18, 0.4) 0%, rgba(18, 18, 18, 0.85) 100%);
    z-index: -1;
}

/* ============================================================================
   GAME-SPECIFIC STYLES
   ============================================================================ */

/* Hide game screen by default */
#game-screen {
    display: none;
}

#game-screen.active {
    display: block;
}

/* Ensure game-shell doesn't constrain width */
#game-screen .game-shell {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

.canyousortit-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 1.5rem 2rem;
    font-family: 'Rockwell', serif;
}

.canyousortit-container h3 {
    color: var(--game-primary);
    margin-bottom: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.game-area {
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    overflow: visible; /* Allow visibility of fixed children */
    overflow-x: hidden;
    overflow-y: hidden;
}

/* Latest Guess Stats - Display at top of screen */
.latest-guess-stats {
    position: fixed;
    top: 80px; /* Below header if present */
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--game-primary);
    border-radius: 12px;
    padding: 1rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    text-align: center;
}

.stats-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: white;
    font-size: 1.1rem;
}

.stats-label {
    font-weight: 600;
    color: var(--game-secondary);
}

.stats-value {
    font-weight: 700;
    color: var(--game-primary);
}

/* Shelf background - centered on screen */
.game-area::before {
    content: '';
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 95vw;
    height: auto;
    aspect-ratio: 2816 / 1536; /* Maintain shelf aspect ratio */
    background-image: url('assets/images/shelf.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
    pointer-events: none;
}

/* Drop Zones Section - Positioned at 75% up the shelf */
.drop-zones-section {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    /* Shelf is centered at 50vh, width 95vw, aspect ratio 2816/1536 */
    /* Shelf height = 95vw * (1536/2816) ≈ 51.8vw */
    /* 75% up from bottom = 25% from top = 51.8vw * 0.25 = 12.95vw from shelf top */
    /* Shelf top = 50vh - 25.9vw, so position = 50vh - 25.9vw + 12.95vw = 50vh - 12.95vw */
    top: calc(50vh - 12.95vw);
    z-index: 10; /* Higher than shelf (z-index: 1) */
    width: 95vw;
    max-width: 95vw;
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 0;
    pointer-events: none; /* Allow clicks through to drop zones */
}

.drop-zones-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: nowrap;
    width: 100%;
    padding: 0;
    position: relative;
    pointer-events: auto; /* Allow interaction with drop zones */
}

.drop-zone {
    width: 160px;
    height: 240px;
    min-width: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px dashed rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    background: transparent;
    transition: all 0.3s ease;
    position: relative;
    flex-shrink: 0;
    pointer-events: auto;
    z-index: 11;
}

/* Mystery can placeholder inside drop zone */
.drop-zone::before {
    content: '';
    position: absolute;
    width: 140px;
    height: 210px;
    background-image: url('assets/images/mystery.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.6;
    z-index: 9;
    pointer-events: none;
}

/* Hide placeholder when drop zone is filled */
.drop-zone.filled::before {
    display: none;
}

.drop-zone.drag-over,
.drop-zone.touch-drag-over {
    border-color: var(--game-primary);
    border-style: solid;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 140, 0, 0.5);
    background: rgba(255, 140, 0, 0.1);
}

/* Enhanced touch drag-over state */
.drop-zone.touch-drag-over {
    animation: pulse-drop-zone 0.6s ease-in-out infinite;
}

@keyframes pulse-drop-zone {
    0%, 100% {
        box-shadow: 0 0 20px rgba(255, 140, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 30px rgba(255, 140, 0, 0.8);
    }
}

.drop-zone.filled {
    border-color: rgba(255, 255, 255, 0.6);
    border-style: solid;
}

.drop-zone .can-item {
    width: 140px;
    height: 210px;
    cursor: grab;
    position: relative;
    z-index: 12;
}

.drop-zone .can-item:active {
    cursor: grabbing;
}

/* Check Guess Button Section - Positioned above drop zones */
.check-guess-section {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    /* Position above drop zones (drop zones are at calc(50vh - 12.95vw)) */
    top: calc(50vh - 12.95vw - 80px); /* 80px above drop zones */
    z-index: 10;
    display: flex;
    justify-content: center;
    gap: 1rem;
    width: 95vw;
    max-width: 95vw;
    margin: 0;
    padding: 0.5rem 0;
}

/* Initial Cans Section - Positioned directly underneath shelf, no gap */
.initial-cans-section {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    /* Keep bottom fixed, extend upward */
    bottom: 20px; /* Fixed bottom position */
    z-index: 15; /* Higher z-index to ensure visibility */
    width: 95vw;
    max-width: 95vw;
    margin: 0;
    padding: 0;
    pointer-events: auto; /* Ensure it's interactive */
    display: block !important; /* Force display */
    visibility: visible !important; /* Force visibility */
}

.initial-cans-section h3 {
    display: none; /* Hide heading to remove all spacing */
}

.initial-cans-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.5rem; /* Padding on all sides */
    margin: 0;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 140, 0, 0.3);
    border-radius: 16px; /* Rounded corners on all sides */
    max-height: none; /* No max height - show all cans without cropping */
    overflow: visible; /* No scrolling - show all content */
    overflow-x: hidden;
    min-height: 120px; /* Minimum height */
    pointer-events: auto; /* Ensure it's interactive */
}

.initial-cans-grid .can-item {
    cursor: grab;
    opacity: 1;
}

.initial-cans-grid .can-item:active {
    cursor: grabbing;
}

.initial-cans-grid .can-item.dragging,
.can-item.touch-dragging {
    opacity: 0.8;
    transform: scale(1.15) rotate(5deg);
    filter: drop-shadow(0 12px 24px rgba(255, 140, 0, 0.8));
    z-index: 1000;
    transition: transform 0.1s ease;
}

/* Can Items */
.can-item {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 8px;
    overflow: visible;
    width: 140px;
    height: 210px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.can-item img {
    width: 140px;
    height: 210px;
    object-fit: contain;
    display: block;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    transition: transform 0.2s ease;
    max-width: 100%;
    max-height: 100%;
}

.can-item:hover {
    transform: translateY(-8px) scale(1.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.can-item.mystery-can {
    cursor: default;
}

.can-item.mystery-can:hover {
    transform: none;
}

/* Bin Icon - Fixed in bottom right corner */
.bin-icon-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 80px;
    height: 80px;
    background: rgba(15, 23, 42, 0.95);
    border: 3px solid var(--game-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.bin-icon-container:hover {
    transform: scale(1.1);
    border-color: var(--game-secondary);
    box-shadow: 0 6px 30px rgba(255, 140, 0, 0.5);
}

.bin-icon-container.drag-over,
.bin-icon-container.touch-drag-over {
    background: rgba(255, 140, 0, 0.3);
    border-color: var(--game-secondary);
    transform: scale(1.15);
    animation: pulse-bin 0.6s ease-in-out infinite;
}

@keyframes pulse-bin {
    0%, 100% {
        box-shadow: 0 6px 30px rgba(255, 140, 0, 0.5);
    }
    50% {
        box-shadow: 0 8px 40px rgba(255, 140, 0, 0.8);
    }
}

.bin-icon-container i {
    font-size: 2rem;
    color: var(--game-primary);
    pointer-events: none;
}

.bin-icon-container.drag-over i {
    color: var(--game-secondary);
}

/* Game Controls - Removed, now using check-guess-section */
.game-controls {
    display: none;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--game-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--game-primary-dark);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Feedback Section - Fixed positioned, no scrolling */
.feedback-section {
    position: fixed;
    top: 120px; /* Below latest guess stats */
    left: 50%;
    transform: translateX(-50%);
    padding: 1.5rem;
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--game-primary);
    border-radius: 12px;
    z-index: 100;
    max-width: 600px;
    width: 90%;
    display: none;
}

.feedback-message {
    color: white;
    font-size: 1.1rem;
}

/* Previous Guesses - Fixed positioned, no scrolling */
.guesses-history {
    position: fixed;
    bottom: 100px; /* Above bin icon */
    left: 2rem;
    right: 100px; /* Leave space for bin icon */
    z-index: 10;
    max-width: 500px;
    background: rgba(15, 23, 42, 0.9);
    border: 2px solid var(--game-primary);
    border-radius: 12px;
    padding: 1rem;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.guesses-history h3 {
    text-align: center;
    color: var(--game-primary);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.guesses-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.previous-guess {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.guess-row-small {
    display: flex;
    gap: 0.5rem;
}

.guess-row-small .can-item {
    width: 60px;
    height: 90px;
}

.guess-row-small .can-item img {
    width: 60px;
    height: 90px;
}

/* Statistics Modal */
.stats-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.stats-modal-content {
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--game-primary);
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.stats-header h3 {
    margin: 0;
    color: var(--game-primary);
    font-size: 1.5rem;
    flex: 1;
}

.stats-close-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
}

.stats-close-btn:hover {
    background: rgba(255, 140, 0, 0.2);
    border-color: var(--game-primary);
    transform: rotate(90deg);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.stat-item {
    text-align: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--game-primary);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-item {
    text-align: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.stat-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--game-primary);
}

/* Landscape Orientation Overlay */
.landscape-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.landscape-overlay.show {
    display: flex;
}

.landscape-overlay-content {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.landscape-icon {
    font-size: 5rem;
    color: var(--game-primary);
    margin-bottom: 2rem;
    animation: rotate 2s ease-in-out infinite;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.landscape-overlay-content h2 {
    color: var(--game-primary);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.landscape-overlay-content p {
    color: #fff;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.landscape-hint {
    color: var(--game-secondary);
    font-size: 1rem;
    font-style: italic;
    margin-top: 1rem;
}

/* Mobile Landscape Optimizations */
@media (max-height: 667px) and (orientation: landscape) {
    /* Reduce shelf size for mobile landscape */
    .game-area::before {
        width: 90vw;
        top: 50%;
        transform: translate(-50%, -50%);
    }
    
    /* Adjust drop zones for smaller screens */
    .drop-zones-section {
        top: calc(50vh - 10vw);
        gap: 0.8rem;
    }
    
    .drop-zone {
        width: 100px;
        height: 150px;
        min-width: 100px;
    }
    
    .drop-zone::before {
        width: 90px;
        height: 135px;
    }
    
    .drop-zone .can-item {
        width: 90px;
        height: 135px;
    }
    
    .drop-zone .can-item img {
        width: 90px;
        height: 135px;
    }
    
    /* Adjust check guess button section */
    .check-guess-section {
        top: calc(50vh - 10vw - 60px);
        gap: 0.5rem;
        padding: 0.3rem 0;
    }
    
    .check-guess-section .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Adjust selectable cans section */
    .initial-cans-section {
        bottom: 10px;
    }
    
    .initial-cans-grid {
        max-height: none; /* Show all cans without cropping */
        min-height: 80px;
        padding: 0.3rem;
        gap: 0.5rem;
        overflow: visible; /* No scrolling */
    }
    
    .initial-cans-grid .can-item {
        width: 70px;
        height: 105px;
    }
    
    .initial-cans-grid .can-item img {
        width: 70px;
        height: 105px;
    }
    
    /* Adjust latest guess stats */
    .latest-guess-stats {
        top: 60px;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-width: 250px;
    }
    
    /* Adjust bin icon */
    .bin-icon-container {
        width: 60px;
        height: 60px;
        bottom: 10px;
        right: 10px;
    }
    
    .bin-icon-container i {
        font-size: 1.5rem;
    }
    
    /* Hide heading in initial cans section on very small screens */
    .initial-cans-section h3 {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
    }
}

/* Very small mobile landscape (e.g., iPhone SE) */
@media (max-height: 568px) and (orientation: landscape) {
    .game-area::before {
        width: 85vw;
    }
    
    .drop-zones-section {
        top: calc(50vh - 8vw);
        gap: 0.5rem;
    }
    
    .drop-zone {
        width: 80px;
        height: 120px;
        min-width: 80px;
    }
    
    .drop-zone::before {
        width: 70px;
        height: 105px;
    }
    
    .drop-zone .can-item {
        width: 70px;
        height: 105px;
    }
    
    .drop-zone .can-item img {
        width: 70px;
        height: 105px;
    }
    
    .check-guess-section {
        top: calc(50vh - 8vw - 50px);
    }
    
    .check-guess-section .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .initial-cans-grid {
        max-height: none; /* Show all cans without cropping */
        min-height: 60px;
        overflow: visible; /* No scrolling */
    }
    
    .initial-cans-grid .can-item {
        width: 60px;
        height: 90px;
    }
    
    .initial-cans-grid .can-item img {
        width: 60px;
        height: 90px;
    }
    
    .latest-guess-stats {
        top: 50px;
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* Menu buttons */
#canyousortit-menu .game-menu-button,
#canyousortit-menu .difficulty-pill {
    pointer-events: auto !important;
    cursor: pointer !important;
    position: relative;
    z-index: 10;
}

/* Hide pattern section - we're using drop zone placeholders instead */
.pattern-section {
    display: none;
}

/* ============================================================================
   MOBILE TOUCH ENHANCEMENTS
   ============================================================================ */

/* Improve touch targets for mobile */
@media (max-width: 768px) {
    .can-item {
        min-width: 60px;
        min-height: 90px;
        touch-action: none; /* Prevent default touch behaviors */
    }
    
    .drop-zone {
        min-width: 120px;
        min-height: 180px;
        touch-action: none;
    }
    
    /* Larger touch area for bin */
    .bin-icon-container {
        min-width: 60px;
        min-height: 60px;
        touch-action: manipulation;
    }
    
    /* Prevent text selection during drag */
    .can-item.touch-dragging,
    .drop-zone.touch-drag-over {
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* Enhanced visual feedback for touch interactions */
    .can-item:active {
        transform: scale(1.05);
        transition: transform 0.1s ease;
    }
    
    /* Better spacing for touch */
    .initial-cans-grid {
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .drop-zones-row {
        gap: 1rem;
    }
}

/* Prevent accidental scrolling during drag */
body.touch-dragging-active {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Smooth transitions for touch interactions */
.can-item {
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.drop-zone {
    -webkit-tap-highlight-color: transparent;
}
