/* Game Canvas */
#gameCanvas {
    border: 2px solid var(--bs-border-color);
    border-radius: 0.375rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

[data-bs-theme="dark"] #gameCanvas {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Hold & Next Canvas */
#holdCanvas,
#nextCanvas {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
    background: var(--bs-body-bg);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Game Container */
#gameContainer {
    position: relative;
}

/* Game Overlays */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(5px);
    border-radius: 0.375rem;
}

.overlay-content {
    color: white;
    text-align: center;
    padding: 2rem;
    animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Stat Cards */
.card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card h4 {
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.card small {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Mobile Control Buttons */
.btn-control {
    width: 60px;
    height: 60px;
    padding: 0;
    font-size: 1.5rem;
    border-radius: 50%;
    border-width: 2px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-control:active {
    transform: scale(0.95);
    box-shadow: 0 0 10px rgba(13, 110, 253, 0.5);
}

/* Keyboard Key Styling */
kbd {
    background-color: var(--bs-secondary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

[data-bs-theme="dark"] kbd {
    background-color: var(--bs-tertiary-bg);
    box-shadow: 0 2px 0 rgba(255, 255, 255, 0.05);
}

/* Button Animations */
.btn {
    transition: all 0.2s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Statistics Styling */
.card-body .d-flex {
    padding: 0.25rem 0;
}

.card-body .d-flex:not(:last-child) {
    border-bottom: 1px solid var(--bs-border-color);
}

/* Hold & Next Piece Titles */
.card-header h6 {
    font-weight: 600;
    color: var(--bs-emphasis-color);
}

/* Canvas Container Responsiveness */
@media (max-width: 768px) {
    #gameCanvas {
        width: 100%;
        height: auto;
    }

    .btn-control {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    .overlay-content {
        padding: 1rem;
    }

    .overlay-content h2 {
        font-size: 1.5rem;
    }

    .overlay-content p {
        font-size: 0.9rem;
    }

    .overlay-content .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 576px) {
    .btn-control {
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }

    .card h4 {
        font-size: 1.25rem;
    }

    .card small {
        font-size: 0.7rem;
    }
}

/* Game Instructions Alert */
.alert ul {
    margin-bottom: 0;
    padding-left: 1.5rem;
}

.alert ul li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.alert ul li:last-child {
    margin-bottom: 0;
}

/* Form Controls */
.form-select,
.form-check-input {
    transition: all 0.2s ease;
}

.form-check-input:checked {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

/* Focus States */
button:focus,
select:focus,
.form-check-input:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Score Animation */
@keyframes scoreUpdate {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        color: var(--bs-success);
    }
}

.score-update {
    animation: scoreUpdate 0.3s ease-in-out;
}

/* Line Clear Flash */
@keyframes lineClearFlash {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
        background-color: rgba(255, 255, 255, 0.8);
    }
}

.line-clear-flash {
    animation: lineClearFlash 0.5s ease-in-out 3;
}

/* Tetris Effect (4 lines) */
@keyframes tetrisEffect {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(255, 0, 0, 0);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
    }
}

.tetris-effect {
    animation: tetrisEffect 0.5s ease-in-out 2;
}

/* Prevent text selection on game elements */
#gameCanvas,
#holdCanvas,
#nextCanvas,
.btn-control {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Card Header Icons */
.card-header img.fsvg {
    filter: var(--bs-body-color);
}

/* Touch Feedback for Mobile */
@media (hover: none) {
    .btn-control:active {
        background-color: var(--bs-primary);
        color: white;
        border-color: var(--bs-primary);
    }

    .btn:active:not(:disabled) {
        background-color: var(--bs-primary);
        color: white;
    }
}

/* Ghost Piece Indicator */
.ghost-indicator {
    opacity: 0.3;
    border: 2px dashed var(--bs-secondary);
}

/* High Score Celebration */
@keyframes celebrate {
    0%, 100% {
        transform: scale(1) rotate(0deg);
    }
    25% {
        transform: scale(1.1) rotate(-5deg);
    }
    75% {
        transform: scale(1.1) rotate(5deg);
    }
}

.high-score-celebration {
    animation: celebrate 0.5s ease-in-out 3;
}

/* Game Over Effect */
@keyframes gameOverShake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-10px);
    }
    75% {
        transform: translateX(10px);
    }
}

.game-over-shake {
    animation: gameOverShake 0.5s ease-in-out 2;
}

/* Level Up Effect */
@keyframes levelUp {
    0% {
        transform: scale(1);
        color: inherit;
    }
    50% {
        transform: scale(1.3);
        color: var(--bs-warning);
    }
    100% {
        transform: scale(1);
        color: inherit;
    }
}

.level-up {
    animation: levelUp 0.6s ease-in-out;
}

/* Statistics Highlight */
.stat-highlight {
    background: linear-gradient(90deg, transparent, var(--bs-primary-bg-subtle), transparent);
    animation: statHighlight 1s ease-in-out;
}

@keyframes statHighlight {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
}

/* Dark Mode Specific */
[data-bs-theme="dark"] .card {
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .alert-info {
    background-color: var(--bs-info-bg-subtle);
    border-color: var(--bs-info-border-subtle);
    color: var(--bs-info-text-emphasis);
}

/* Smooth Transitions */
* {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

button,
select,
input,
canvas {
    transition: all 0.2s ease;
}

/* Accessibility - High Contrast Mode */
@media (prefers-contrast: high) {
    kbd {
        border: 2px solid currentColor;
    }

    #gameCanvas,
    #holdCanvas,
    #nextCanvas {
        border: 3px solid currentColor;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
