/* Game-specific styles for Uncrossy player */

/* CSS Variables */
body {
    --cell-size: 51px; /* Global cell size CSS variable */
    height: 100vh;
    height: 100svh; /* Dynamic viewport height when supported on mobile */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent scrolling */
}

/* Container override for game page */
.container {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

.puzzle-navigation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 600px;
}

.current-puzzle-info {
    text-align: center;
}

.current-puzzle-info h2 {
    margin: 0 0 5px 0;
    color: #333;
    font-size: 20px;
    font-weight: bold;
}

.puzzle-status {
    color: #666;
    font-size: 14px;
    margin: 0;
}

.puzzle-selector {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
    justify-content: center;
}

.puzzle-selector label {
    font-weight: bold;
    color: #555;
}

.game-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
}

/* Undo/Redo specific button styles */
.undo-button {
    background: #3498db;
}

.undo-button:hover {
    background: #2b7fb7;
}

.redo-button {
    background: #7383ca;
}

.redo-button:hover {
    background: #5c69a2;
}

.hint-button {
    background: #8371be;
}

.hint-button:hover {
    background: #6c5d9c;
}

.reset-button {
    background: #824a98;
}

.reset-button:hover {
    background: #663a78;
}

/* Select dropdown styles */
select {
    padding: 12px 20px;
    margin: 5px;
    border: none;
    border-radius: 6px;
    background: #2196F3;
    color: white;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    min-width: 120px;
}

select option {
    background: white;
    color: #333;
}

/* Game Area */
.game-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex: 1;
    overflow: hidden;
    min-height: 0; /* Important for flexbox children */
}

/* Grid Container */
.grid-container {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: 100%;
    height: 100%;
    max-width: 600px;
    display: flex;
    cursor: grab;
    overflow: hidden;
    touch-action: none; /* Prevent default touch behaviors */
}

.grid-container.dragging {
    cursor: grabbing;
}

.grid {
    position: relative;
    display: inline-block;
}

/* Cell Styles */
.cell {
    width: 50px;
    height: 50px;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 500;
    position: absolute;
    background: transparent;
    user-select: none;
    transition: none;
    z-index: 10;  /* Letters on top */
    cursor: pointer;
    pointer-events: none; /* Let touch events pass through to grid */
    transform: translate(1px, 2px); /* Slight offset for better visual centering */
}

.cell.empty {
    background: #fafafa;
    border: 1px solid #ddd;
    z-index: 1;  /* Empty cells at bottom */
    cursor: default;
}

.cell.dragging {
    z-index: 20;  /* Dragging letters even higher */
    /* Add text shadow for better visibility when dragging */
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.8), 
                 0 0 6px rgba(255, 255, 255, 0.6);
}

.cell.falling {
    z-index: 100;
}

/* Word Outline Styles */
.word-outline {
    position: absolute;
    border: 2px solid #333;
    border-radius: calc(var(--cell-size, 51px) * 0.39); /* Half of 78% height for fully rounded ends */
    pointer-events: none;
    z-index: 5;  /* Behind letters (z-index: 10) but above empty cells (z-index: 1) */
    opacity: 0.9;
    /* CSS transition removed - all animations now handled by JavaScript AnimationManager */
}

.word-outline.horizontal {
    height: calc(var(--cell-size, 51px) * 0.78);  /* 78% of cell size */
    top: calc(var(--cell-size, 51px) * 0.11);  /* 11% offset for centering */
    --word-color: #3498db; /* Blue for horizontal */
    border-color: var(--word-color);
}

.word-outline.vertical {
    width: calc(var(--cell-size, 51px) * 0.78);  /* 78% of cell size */
    left: calc(var(--cell-size, 51px) * 0.11);  /* 11% offset for centering */
    --word-color: #9b59b6; /* Purple for vertical */
    border-color: var(--word-color);
}

.word-outline.dragging {
    opacity: 0.4;
    border-width: 3px;
}

.word-outline.flash-valid {
    background-color: rgba(76, 175, 80, 0.3); 
    border-color: #4CAF50;
    border-width: 4px;
}

.word-outline.flash-invalid {
    background-color: rgba(244, 67, 54, 0.3); 
    border-color: #f44336;
    border-width: 4px;
}

/* Status Bar */
#status {
    padding: 10px;
    margin: 10px 0;
    border-radius: 6px;
    text-align: center;
    min-height: 20px;
    max-width: 500px;
    margin: 10px auto;
}

.success { background: #d4edda; color: #155724; }
.error { background: #f8d7da; color: #721c24; }
.info { background: #d1ecf1; color: #0c5460; }
.warning { background: #fff3cd; color: #856404; }

/* Win Message */
.win-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    text-align: center;
    z-index: 1000;
}

.win-message h2 {
    color: #4CAF50;
    margin-top: 0;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* Ghost Word */
.ghost-word {
    position: absolute;
    pointer-events: none;
    opacity: 0.5;
    z-index: 10;
}

/* Version Info */
.version-info {
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    z-index: 100;
}

/* Debug Panel */
#debugPanel {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.85);
    color: #0f0;
    padding: 10px;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    z-index: 1000;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    pointer-events: none; /* Don't interfere with game */
}

#debugPanel div {
    margin: 2px 0;
}

#debugPanel .touch-event { color: #ff0; }
#debugPanel .drag-event { color: #0ff; }
#debugPanel .error-event { color: #f00; }

/* Tutorial Overlay */
.tutorial-overlay {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    background: transparent;
    padding: 20px;
    display: none; /* Hidden by default */
    z-index: 50; /* Above game elements but below modals */
    text-align: center;
    pointer-events: none; /* Allow clicks to pass through to game elements */
}

.tutorial-overlay.active {
    display: block;
}

.tutorial-overlay h3 {
    margin-top: 0;
    color: #4CAF50;
    font-size: 20px;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.tutorial-overlay p {
    margin: 10px 0;
    line-height: 1.5;
    color: #555;
}

/* Hint Modal Styles */
.hint-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

.hint-modal.show {
    display: block;
}

.hint-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
}

.hint-dialog {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    min-width: 320px;
    max-width: 90%;
    animation: hintSlideDown 0.3s ease-out;
}

@keyframes hintSlideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.hint-content {
    padding: 20px;
}

.hint-text {
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    margin-bottom: 20px;
    min-height: 60px;
    text-align: left;
}

.hint-text div {
    margin-bottom: 4px;
}

.hint-text div:last-child {
    margin-bottom: 0;
}

.hint-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.hint-buttons button {
    min-width: 100px;
    margin: 0;
}

/* Game button responsive layout */
@media (max-width: 480px) {
    .game-buttons {
        gap: 6px;
    }
    
    .game-buttons button.compact-button {
        min-width: 65px;
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .game-buttons button.icon-button {
        min-width: 45px;
        padding: 10px;
    }
}

@media (max-width: 360px) {
    .game-buttons {
        gap: 4px;
    }
    
    .game-buttons button.compact-button {
        min-width: 60px;
        padding: 10px 8px;
        font-size: 13px;
    }
    
    .game-buttons button.icon-button {
        min-width: 40px;
        padding: 8px;
    }
}

/* Hint modal responsive */
@media (max-width: 480px) {
    .hint-dialog {
        top: 10px;
        max-width: 95%;
        min-width: 280px;
    }
    
    .hint-content {
        padding: 15px;
    }
    
    .hint-text {
        font-size: 14px;
        min-height: 50px;
    }
    
    .hint-buttons {
        flex-direction: column;
    }
    
    .hint-buttons button {
        width: 100%;
    }
}

.tutorial-overlay strong {
    color: #333;
}

.tutorial-image {
    width: 100%;
    max-width: 120px;
    height: auto;
    margin: 10px auto;
    display: block;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .controls-section {
        gap: 10px;
        margin-bottom: 10px;
    }
    
    /* Remove container padding on game page for tighter mobile layout */
    .container {
        padding: 0;
    }
    
    /* Fix horizontal overflow issue */
    .grid-container {
        max-width: calc(100vw - 10px); /* Only body padding: 5px each side = 10px total */
        margin: 0 auto;
    }
    
    /* Fix vertical centering */
    .game-area {
        align-items: center; /* Change from flex-start to center */
        justify-content: center;
        padding: 0; /* Remove redundant padding - container already has padding */
    }
    
    /* Ensure grid doesn't overflow */
    .grid {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Make win dialog wider on mobile */
    .win-message {
        width: 80%;  /* Use most of screen width */
        max-width: 350px;  /* But cap at reasonable size */
        padding: 30px 20px;  /* Reduce padding for more content space */
    }
}