@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;800&display=swap');

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'JetBrains Mono', monospace;
    background-color: #F0F4F8;
    color: #334155;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Main Body */
.main-body {
    background-color: #F0F4F8;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    margin: 0;
    position: relative;
    box-sizing: border-box;
}

/* Menu Screen - Pop-up Modal */
.menu-screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.menu-screen.show {
    display: flex;
}

.menu-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.menu-modal {
    position: relative;
    z-index: 51;
    background-image: 
        linear-gradient(rgba(203, 213, 225, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(203, 213, 225, 0.3) 1px, transparent 1px),
        linear-gradient(to bottom right, #F0F4F8 0%, #E2E8F0 30%, #F0F4F8 70%, #E2E8F0 100%);
    background-size: 40px 40px, 40px 40px, 100% 100%;
    display: flex;
    flex-direction: column;
    max-width: 95vw;
    max-height: 95vh;
    width: 800px;
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s;
}

.menu-screen.show .menu-modal {
    transform: scale(1);
}

.menu-screen.translate-y-full {
    display: none;
}

/* Menu Header */
.menu-header {
    position: relative;
    background-color: #0f172a;
    color: white;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 10;
    flex-shrink: 0;
    border-bottom: 1px solid #1e293b;
}

.header-pattern-bg {
    position: absolute;
    inset: 0;
    opacity: 0.1;
    pointer-events: none;
    background-image: radial-gradient(#9ca3af 1px, transparent 1px);
    background-size: 4px 4px;
}

.header-left {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.header-title {
    font-size: 1.875rem;
    font-weight: 900;
    letter-spacing: -0.025em;
    line-height: 1;
    user-select: none;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .header-title {
        font-size: 1.25rem;
    }
    
    .menu-header {
        padding: 0.875rem 1rem;
    }
    
    .menu-modal {
        max-width: 98vw;
        max-height: 98vh;
        border-radius: 0.375rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .header-title {
        font-size: 1.5rem;
    }
    
    .menu-header {
        padding: 1rem 1.25rem;
    }
}

.title-separator {
    color: #3b82f6;
    font-weight: 300;
    margin: 0 0.125rem;
}

/* Level Grid Container */
.level-grid-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    max-height: 60vh;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .level-grid-container {
        padding: 0.75rem;
        max-height: 65vh;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .level-grid-container {
        padding: 1rem;
        max-height: 62vh;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .level-grid-container {
        padding: 1.5rem;
        max-height: 60vh;
    }
}

/* Tablet Landscape & Desktop (≥769px) */
@media (min-width: 769px) {
    .level-grid-container {
        padding: 2rem;
    }
}

.level-grid-container::-webkit-scrollbar {
    width: 6px;
}

.level-grid-container::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.level-grid-container::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
}

.level-grid-container::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.level-grid-wrapper {
    max-width: 80rem;
    margin: 0 auto;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    align-content: start;
    padding-bottom: 3rem;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .level-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.5rem;
        padding-bottom: 2rem;
    }
}

/* Mobile (≤640px) */
@media (min-width: 481px) and (max-width: 640px) {
    .level-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.75rem;
        padding-bottom: 3rem;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .level-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0.875rem;
        padding-bottom: 4rem;
    }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .level-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 1rem;
        padding-bottom: 4.5rem;
    }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
    .level-grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
        gap: 1rem;
        padding-bottom: 5rem;
    }
}

/* Game Header */
.game-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    width: 100%;
    padding: 0;
    margin: 0;
    background-color: #F0F4F8;
    pointer-events: none;
    box-sizing: border-box;
}

.game-header > * {
    pointer-events: auto;
}

.game-header-content {
    width: 100%;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .game-header-content {
        padding: 0.5rem 0.5rem;
        gap: 0.375rem;
        flex-wrap: wrap;
        justify-content: space-between;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .game-header-content {
        padding: 0.625rem 0.625rem;
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: space-between;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .game-header-content {
        padding: 0.75rem 0.875rem;
    }
}

/* Tablet Landscape & Desktop (≥769px) */
@media (min-width: 769px) {
    .game-header-content {
        padding: 0.75rem 1rem;
    }
}

/* Game Header Left */
.game-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .game-header-left {
        gap: 0.375rem;
        width: 100%;
        justify-content: center;
        order: 1;
        flex-basis: 100%;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .game-header-left {
        gap: 0.5rem;
        width: 100%;
        justify-content: center;
        order: 1;
        flex-basis: 100%;
    }
}

/* Game Header Right */
.game-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    flex-wrap: nowrap;
}

/* Mobile: Center buttons in new row */
@media (max-width: 640px) {
    .game-header-content {
        flex-direction: row;
    }
    
    .game-header-right {
        width: 100%;
        justify-content: center;
        order: 2;
        margin-top: 0.5rem;
        flex-basis: 100%;
    }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .game-header-right {
        gap: 0.375rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .game-header-right {
        gap: 0.5rem;
    }
}

/* Home Button */
.home-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem;
    min-width: 2.5rem;
    color: #ffffff;
    background-color: #2563EB;
    border: none;
    border-radius: 0.375rem;
    transition: all 0.2s;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
    touch-action: manipulation;
}

/* How to Play Button - Icon Only on All Screens */
.how-to-play-button {
    font-size: 0.75rem;
    font-weight: 700;
    color: #ffffff;
    padding: 0.625rem;
    width: 2.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem;
    border-radius: 0.375rem;
    border: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    background-color: #10B981;
}

.how-to-play-text {
    display: none;
}

.how-to-play-icon {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 2.5;
}

.how-to-play-button:hover {
    background-color: #059669;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.how-to-play-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.how-to-play-icon {
    width: 1rem;
    height: 1rem;
    stroke-width: 2.5;
}

.home-button:hover {
    background-color: #1d4ed8;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.home-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.home-button-icon {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 2.5;
}

/* Small Mobile (≤480px) - All buttons same height */
@media (max-width: 480px) {
    .home-button {
        width: 2.5rem;
        height: 2.5rem;
        min-height: 2.5rem;
        min-width: 2.5rem;
        border-radius: 0.25rem;
    }
    
    .home-button-icon {
        width: 1.125rem;
        height: 1.125rem;
        stroke-width: 2.5;
    }
}

/* Mobile (≤640px) - All buttons same height */
@media (max-width: 640px) {
    .home-button {
        width: 2.5rem;
        height: 2.5rem;
        min-height: 2.5rem;
        min-width: 2.5rem;
    }
    
    .home-button-icon {
        width: 1.1875rem;
        height: 1.1875rem;
    }
}

/* Level Display */
.level-display {
    font-size: 0.875rem;
    font-weight: 700;
    color: #64748B;
    background-color: transparent;
    padding: 0;
    height: auto;
    min-height: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
    white-space: nowrap;
    box-sizing: border-box;
    letter-spacing: 0.05em;
}

/* Small Mobile (≤480px) - Match button height */
@media (max-width: 480px) {
    .level-display {
        font-size: 0.6875rem;
        padding: 0;
        gap: 0.375rem;
        height: auto;
        min-height: auto;
    }
}

/* Mobile (≤640px) - Match button height */
@media (max-width: 640px) {
    .level-display {
        font-size: 0.75rem;
        padding: 0;
        gap: 0.4375rem;
        height: auto;
        min-height: auto;
    }
}

.level-number {
    color: #2563EB;
    font-weight: 800;
    font-family: monospace;
    font-size: 0.875rem;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .level-number {
        font-size: 0.6875rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .level-number {
        font-size: 0.75rem;
    }
}


.header-reset-button,
.header-rescramble-button {
    font-size: 0.75rem;
    font-weight: 700;
    color: #ffffff;
    padding: 0.625rem 1rem;
    height: 2.5rem;
    min-height: 2.5rem;
    border-radius: 0.375rem;
    border: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

/* RESET Button - Orange */
.header-reset-button {
    background-color: #F97316;
}

.header-reset-button:hover {
    background-color: #EA580C;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.header-reset-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* RE-SCRAMBLE Button - Solid Red */
.header-rescramble-button {
    background-color: #EF4444;
}

.header-rescramble-button:hover {
    background-color: #DC2626;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.header-rescramble-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* Small Mobile (≤480px) - All buttons same height (2.5rem) */
@media (max-width: 480px) {
    .header-reset-button,
    .header-rescramble-button {
        padding: 0.5rem 0.625rem;
        font-size: 0.625rem;
        height: 2.5rem;
        min-height: 2.5rem;
        gap: 0.25rem;
        border-radius: 0.25rem;
    }
    
    .how-to-play-button {
        padding: 0.5rem;
        width: 2.5rem;
        min-width: 2.5rem;
        height: 2.5rem;
        min-height: 2.5rem;
        border-radius: 0.25rem;
    }
    
    .reset-icon,
    .rescramble-icon {
        width: 0.75rem;
        height: 0.75rem;
    }
    
    .how-to-play-icon {
        width: 1.125rem;
        height: 1.125rem;
        stroke-width: 2.5;
    }
}

/* Mobile (≤640px) - All buttons same height (2.5rem) */
@media (max-width: 640px) {
    .header-reset-button,
    .header-rescramble-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.6875rem;
        height: 2.5rem;
        min-height: 2.5rem;
        gap: 0.375rem;
    }
    
    .how-to-play-button {
        padding: 0.625rem;
        width: 2.5rem;
        min-width: 2.5rem;
        height: 2.5rem;
        min-height: 2.5rem;
    }
    
    .reset-icon,
    .rescramble-icon {
        width: 0.875rem;
        height: 0.875rem;
    }
    
    .how-to-play-icon {
        width: 1.1875rem;
        height: 1.1875rem;
        stroke-width: 2.5;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .header-reset-button,
    .header-rescramble-button {
        padding: 0.5625rem 0.875rem;
        font-size: 0.71875rem;
    }
    
    .how-to-play-button {
        padding: 0.625rem;
        width: 2.5rem;
        min-width: 2.5rem;
    }
    
    .how-to-play-icon {
        width: 1.25rem;
        height: 1.25rem;
        stroke-width: 2.5;
    }
}

.reset-icon,
.rescramble-icon {
    width: 1rem;
    height: 1rem;
    stroke-width: 2.5;
}

/* Canvas Container */
.canvas-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 40rem;
    padding: 0;
    padding-top: 4.5rem;
    margin-top: 0;
    box-sizing: border-box;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .canvas-container {
        padding: 0;
        padding-top: 3.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        max-width: 100%;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .canvas-container {
        padding: 0;
        padding-top: 4rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        max-width: 100%;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .canvas-container {
        padding-top: 4.5rem;
        padding-left: 1rem;
        padding-right: 1rem;
        max-width: 38rem;
    }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .canvas-container {
        padding-top: 4.5rem;
        max-width: 40rem;
    }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
    .canvas-container {
        padding-top: 4.5rem;
        max-width: 40rem;
    }
}

.game-canvas {
    background-color: #FFFFFF;
    background-image: 
        linear-gradient(rgba(203, 213, 225, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(203, 213, 225, 0.3) 1px, transparent 1px);
    background-size: 40px 40px;
    border: 2px solid #CBD5E1;
    box-shadow: none;
    border-radius: 1rem;
    backdrop-filter: none;
    cursor: move;
    touch-action: none;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .game-canvas {
        border-radius: 0.75rem;
        border-width: 1.5px;
        background-size: 30px 30px;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .game-canvas {
        border-radius: 0.875rem;
        border-width: 1.75px;
        background-size: 35px 35px;
    }
}

#gameCanvas {
    width: var(--canvas-width, 400px);
    height: var(--canvas-height, 400px);
    max-width: 100%;
    max-height: calc(100vh - 5rem);
}

/* Victory Modal */
.victory-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.5s;
}

.victory-modal.flex {
    display: flex;
}

.victory-overlay {
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.victory-modal-content {
    position: relative;
    z-index: 2;
    width: 60%;
    max-width: 20rem;
    min-width: 16rem;
    background-color: #FFFFFF;
    border-radius: 0.75rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 1.25rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
    display: flex;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .victory-modal-content {
        width: 85%;
        max-width: none;
        min-width: 12rem;
        padding: 0.75rem 0.875rem;
        border-radius: 0.5rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .victory-modal-content {
        width: 80%;
        max-width: none;
        min-width: 14rem;
        padding: 0.875rem 1rem;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .victory-modal-content {
        width: 65%;
        max-width: 18rem;
        min-width: 15rem;
    }
}

.victory-icon {
    background-color: #2563EB;
    color: #FFFFFF;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    font-size: 2.25rem;
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
    line-height: 1;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .victory-icon {
        width: 3rem;
        height: 3rem;
        font-size: 1.875rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .victory-icon {
        width: 3.25rem;
        height: 3.25rem;
        font-size: 2rem;
    }
}

.victory-title {
    font-size: 1.875rem;
    font-weight: 900;
    color: #1E293B;
    margin-top:  10px;
    margin-bottom: 0px;
    letter-spacing: -0.025em;
    text-align: center;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .victory-title {
        font-size: 1.25rem;
        margin-top: 8px;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .victory-title {
        font-size: 1.5rem;
    }
}

.victory-subtitle {
    color: #2563EB;
    background-color: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.2);
    padding: 0.375rem 0.875rem;
    border-radius: 0.375rem;
    font-weight: 700;
    font-size: 0.75rem;
    margin-top: 0.45rem;
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
    font-family: monospace;
    text-align: center;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .victory-subtitle {
        font-size: 0.625rem;
        padding: 0.3125rem 0.75rem;
        margin-top: 0.375rem;
        margin-bottom: 0.625rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .victory-subtitle {
        font-size: 0.6875rem;
        padding: 0.34375rem 0.8125rem;
    }
}

.victory-buttons {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .victory-buttons {
        gap: 0.375rem;
        margin-top: 0.375rem;
    }
}

.home-modal-button {
    background-color: #E2E8F0;
    color: #475569;
    border: none;
    outline: none;
    font-weight: 700;
    padding: 0.75rem 1.25rem;
    border-radius: 0.375rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    flex: 1;
    max-width: 8rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-sizing: border-box;
    touch-action: manipulation;
    min-height: 2.75rem;
}

.home-modal-button:hover {
    background-color: #CBD5E1;
}

.home-modal-button:active {
    transform: scale(0.95);
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .home-modal-button {
        padding: 0.625rem 1rem;
        font-size: 0.6875rem;
        max-width: 7rem;
        min-height: 2.5rem;
        border-radius: 0.25rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .home-modal-button {
        padding: 0.6875rem 1.125rem;
        font-size: 0.71875rem;
        min-height: 2.625rem;
    }
}

.next-level-button {
    background-color: #2563EB;
    color: #FFFFFF;
    border: none;
    outline: none;
    font-weight: 700;
    padding: 0.75rem 1.5rem;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
    transform: none;
    transition: all 0.2s;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    text-align: center;
    flex: 1;
    max-width: 10rem;
    line-height: 1;
    box-sizing: border-box;
    touch-action: manipulation;
    min-height: 2.75rem;
}

.next-level-button:hover {
    background-color: #1d4ed8;
}

.next-level-button:active {
    transform: scale(0.95);
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .next-level-button {
        padding: 0.625rem 1.25rem;
        font-size: 0.6875rem;
        max-width: 8.5rem;
        min-height: 2.5rem;
        border-radius: 0.25rem;
        gap: 0.375rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .next-level-button {
        padding: 0.6875rem 1.375rem;
        font-size: 0.71875rem;
        min-height: 2.625rem;
    }
}

/* Tech Card Styles for Levels */
.tech-card {
    position: relative;
    background: rgba(255, 255, 255, 0.8);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    border: 1px solid #cbd5e1;
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 0.125rem;
    touch-action: manipulation;
    cursor: pointer;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .tech-card {
        border-radius: 0.1rem;
    }
}

/* Corner Accent */
.tech-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 8px 8px;
    border-color: transparent transparent #cbd5e1 transparent;
    transition: all 0.2s;
    z-index: 11;
}

/* Hover State */
.tech-card:not(:disabled):hover {
    transform: translateY(-2px);
    background: #ffffff;
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.tech-card:not(:disabled):hover::after {
    border-color: transparent transparent #3b82f6 transparent;
}

/* Active Level (Current Challenge) */
.tech-card.active-level {
    background: #ffffff;
    border-color: #3b82f6;
    border-width: 2px;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
    color: #2563eb;
    font-weight: 900;
}

.tech-card.active-level::after {
    border-color: transparent transparent #3b82f6 transparent;
}

/* Locked State */
.tech-card.locked {
    background: #f1f5f9;
    border-style: dashed;
    opacity: 0.9;
    color: #cbd5e1;
}

/* Cleared State (Green accent) */
.tech-card.cleared {
    color: #475569;
    font-weight: 700;
}

.tech-card.cleared .status-indicator {
    background-color: #10b981;
}

/* Staggered Entrance Animation */
@keyframes cardEnter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Pulse Animation for Active Status Indicator */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.animate-card {
    animation: cardEnter 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    animation-delay: var(--card-delay, 0s);
}

/* Level Card Content */
.level-number {
    font-size: 1.125rem;
    font-family: monospace;
    position: relative;
    z-index: 10;
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .level-number {
        font-size: 0.875rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .level-number {
        font-size: 1rem;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .level-number {
        font-size: 1.0625rem;
    }
}

.level-number-locked {
    color: #cbd5e1;
    z-index: 0;
}

.lock-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background-color: rgba(241, 245, 249, 0.1);
    backdrop-filter: blur(1px);
}

.lock-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: #94a3b8;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.status-indicator {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    z-index: 10;
}

.status-indicator-active {
    background-color: #3b82f6;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.status-indicator-cleared {
    background-color: #10b981;
}

.status-indicator-default {
    background-color: #cbd5e1;
}

/* ============================================
   LANDSCAPE MOBILE ORIENTATION
   ============================================ */

@media (max-width: 1024px) and (orientation: landscape) {
    /* Menu Modal - Landscape */
    .menu-modal {
        max-width: 95vw;
        max-height: 95vh;
        width: auto;
    }
    
    .menu-header {
        padding: 0.75rem 1rem;
    }
    
    .header-title {
        font-size: 1.25rem;
    }
    
    .level-grid-container {
        max-height: 50vh;
        padding: 0.75rem;
    }
    
    /* Level Grid - Landscape */
    @media (max-width: 640px) and (orientation: landscape) {
        .level-grid {
            grid-template-columns: repeat(6, minmax(0, 1fr));
            gap: 0.5rem;
            padding-bottom: 2rem;
        }
    }
    
    @media (min-width: 641px) and (max-width: 1024px) and (orientation: landscape) {
        .level-grid {
            grid-template-columns: repeat(8, minmax(0, 1fr));
            gap: 0.75rem;
            padding-bottom: 2.5rem;
        }
    }
    
    /* Game Header - Landscape */
    .game-header-content {
        padding: 0.5rem 0.75rem;
    }
    
    /* Canvas Container - Landscape */
    .canvas-container {
        padding-top: 3.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        max-width: 100%;
    }
    
    @media (max-width: 640px) and (orientation: landscape) {
        .canvas-container {
            padding-top: 3rem;
            padding-left: 0.375rem;
            padding-right: 0.375rem;
        }
    }
    
    /* Victory Modal - Landscape */
    .victory-modal-content {
        width: 70%;
        max-width: 18rem;
        min-width: 14rem;
        padding: 0.875rem 1rem;
    }
    
    @media (max-width: 640px) and (orientation: landscape) {
        .victory-modal-content {
            width: 75%;
            max-width: 16rem;
            min-width: 12rem;
            padding: 0.75rem 0.875rem;
        }
        
        .victory-icon {
            width: 2.75rem;
            height: 2.75rem;
            font-size: 1.75rem;
        }
        
        .victory-title {
            font-size: 1.125rem;
            margin-top: 6px;
        }
        
        .victory-subtitle {
            font-size: 0.625rem;
            padding: 0.25rem 0.625rem;
            margin-top: 0.25rem;
            margin-bottom: 0.5rem;
        }
        
        .victory-buttons {
            gap: 0.375rem;
            margin-top: 0.375rem;
        }
        
        .home-modal-button,
        .next-level-button {
            padding: 0.5rem 0.875rem;
            font-size: 0.625rem;
            min-height: 2.25rem;
        }
    }
}

/* ============================================
   ADDITIONAL RESPONSIVE ENHANCEMENTS
   ============================================ */

/* Ensure touch targets are at least 44x44px on mobile */
@media (max-width: 640px) {
    .home-button,
    .header-reset-button,
    .header-rescramble-button,
    .how-to-play-button,
    .home-modal-button,
    .next-level-button {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Prevent text size adjustment on iOS */
@media (max-width: 640px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* Optimize for high DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .game-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* How to Play Modal */
.how-to-play-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 30;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.how-to-play-modal.show {
    display: flex;
}

.how-to-play-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1;
}

.how-to-play-content {
    position: relative;
    z-index: 2;
    width: 90%;
    max-width: 28rem;
    min-width: 18rem;
    background-color: #FFFFFF;
    border-radius: 0.75rem;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s;
}

.how-to-play-modal.show .how-to-play-content {
    transform: scale(1);
}

.how-to-play-header {
    background-color: #0f172a;
    color: white;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1e293b;
}

.how-to-play-title {
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: -0.025em;
    margin: 0;
}

.close-how-to-play-button {
    background: transparent;
    border: none;
    color: white;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: all 0.2s;
    padding: 0;
}

.close-how-to-play-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.close-how-to-play-button svg {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 2.5;
}

.how-to-play-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.instruction-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #F0F4F8;
    border-radius: 0.5rem;
}

.instruction-text {
    flex: 1;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: #334155;
}

.instruction-text strong {
    color: #1E293B;
    font-weight: 700;
}


/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .how-to-play-content {
        width: 95%;
        min-width: 16rem;
        border-radius: 0.5rem;
    }
    
    .how-to-play-header {
        padding: 1rem 1.25rem;
    }
    
    .how-to-play-title {
        font-size: 1.25rem;
    }
    
    .how-to-play-body {
        padding: 1.25rem;
        gap: 1rem;
    }
    
    .instruction-icon {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.25rem;
    }
    
    .instruction-text {
        font-size: 0.875rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .how-to-play-content {
        width: 88%;
        min-width: 17rem;
    }
    
    .how-to-play-header {
        padding: 1.125rem 1.375rem;
    }
    
    .how-to-play-title {
        font-size: 1.375rem;
    }
    
    .how-to-play-body {
        padding: 1.375rem;
        gap: 1.125rem;
    }
    
    .instruction-text {
        font-size: 0.90625rem;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .how-to-play-content {
        max-width: 26rem;
        min-width: 19rem;
    }
}

/* Landscape Mobile */
@media (max-width: 1024px) and (orientation: landscape) {
    .how-to-play-content {
        max-width: 24rem;
        min-width: 16rem;
    }
    
    .how-to-play-body {
        padding: 1.25rem;
        gap: 1rem;
    }
    
    @media (max-width: 640px) and (orientation: landscape) {
        .how-to-play-content {
            max-width: 22rem;
            min-width: 14rem;
        }
        
        .how-to-play-header {
            padding: 0.875rem 1rem;
        }
        
        .how-to-play-title {
            font-size: 1.125rem;
        }
        
        .how-to-play-body {
            padding: 1rem;
            gap: 0.875rem;
        }
        
        .instruction-icon {
            width: 2rem;
            height: 2rem;
            font-size: 1.125rem;
        }
        
        .instruction-text {
            font-size: 0.8125rem;
        }
    }
}
