
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden; /* Prevent scrollbars from appearing */
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            color: white;
            overflow: hidden;
            user-select: none;
            /* Truly dynamic viewport - no fixed heights */
            height: 100vh;
            height: 100dvh; /* Dynamic viewport height */
            height: -webkit-fill-available;
            margin: 0;
            padding: 0;
        }

        /* Hide audio elements */
        .game-audio {
            display: none;
        }

        .game-container {
            display: flex;
            flex-direction: column;
            /* Use full available height */
            height: 100vh;
            height: 100dvh;
            height: -webkit-fill-available;
            width: 100%;
            padding: 10px;
            box-sizing: border-box;
            /* Safe area insets for mobile devices */
            padding-bottom: max(10px, env(safe-area-inset-bottom));
            padding-top: max(10px, env(safe-area-inset-top));
            padding-left: max(10px, env(safe-area-inset-left));
            padding-right: max(10px, env(safe-area-inset-right));
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 20px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            margin-bottom: 20px; /* Add some space below the header */
        }

        .score-display {
            font-size: 24px;
            font-weight: bold;
        }

        .high-score {
            font-size: 16px;
            opacity: 0.8;
        }

        .pause-btn {
            background: transparent;
            border: none;
            color: #ff6b6b;
            padding: 10px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 32px;
            width: 44px;
            height: 44px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: none;
            outline: none;
        }
        
        .button-group {
            display: flex;
            gap: 10px;
        }
        
        #sound-btn {
            background: transparent;
            min-width: 50px;
            box-shadow: none;
            outline: none;
        }
        
        #sound-btn.muted {
            background: transparent;
        }

        #reload-btn {
            background: transparent;
            min-width: 50px;
            box-shadow: none;
            outline: none;
        }

        .game-board-container {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-grow: 1;
            /* Center the game board in available space */
            min-height: 0;
            overflow: hidden;
        }

        .game-board {
            display: grid;
            grid-template-columns: repeat(8, 40px);
            grid-template-rows: repeat(8, 40px);
            gap: 2px;
            background: rgba(255, 255, 255, 0.1);
            padding: 10px;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        }

        .cell {
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 3px;
            transition: all 0.2s ease;
        }

        .cell.filled {
            border: 2px solid rgba(255, 255, 255, 0.3);
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
            background: var(--cell-color, #ff6b6b) !important;
        }

        .cell.valid-drop {
            background: rgba(0, 255, 0, 0.3);
            border-color: #00ff00;
        }

        .cell.invalid-drop {
            background: rgba(255, 0, 0, 0.3);
            border-color: #ff0000;
        }

        .cell.magnetic-snap {
            background: rgba(0, 255, 255, 0.4);
            border-color: #00ffff;
            animation: magneticPulse 0.8s ease-in-out infinite alternate;
            box-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
        }

        @keyframes magneticPulse {
            0% {
                background: rgba(0, 255, 255, 0.3);
                box-shadow: 0 0 5px rgba(0, 255, 255, 0.4);
            }
            100% {
                background: rgba(0, 255, 255, 0.5);
                box-shadow: 0 0 12px rgba(0, 255, 255, 0.8);
            }
        }

        .pieces-tray {
            display: flex;
            justify-content: center;
            gap: 15px;
            padding: 20px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            margin-top: 20px; /* Add some space above the tray */
        }

        .piece-container {
            display: grid;
            gap: 2px;
            cursor: grab;
            transition: transform 0.2s ease;
            padding: 10px;
            border-radius: 5px;
            background: rgba(255, 255, 255, 0.05);
        }

        .piece-container.no-moves {
            opacity: 0.5;
            cursor: not-allowed;
            background: rgba(255, 0, 0, 0.1);
            border: 2px solid rgba(255, 0, 0, 0.3);
        }

        .piece-container.no-moves:hover {
            transform: none;
        }

        .piece-container:hover {
            transform: scale(1.05);
        }

        .piece-container.dragging {
            cursor: grabbing;
            transform: scale(1.1);
            z-index: 1000;
            position: fixed;
            pointer-events: none;
        }
        
        .piece-container.dragging {
            gap: 2px;
        }
        
        .piece-container.dragging .piece-block {
            width: 40px;
            height: 40px;
        }
        
        .piece-container.dragging .piece-block-empty {
            width: 40px;
            height: 40px;
        }


        .piece-block {
            width: 25px;
            height: 25px;
            border-radius: 3px;
            border: 1px solid rgba(255, 255, 255, 0.3);
        }
        
        /* Instructions Modal */
        .instructions-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 2000;
        }
        
        .instructions-content {
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            border: 2px solid rgba(255, 255, 255, 0.2);
            border-radius: 15px;
            padding: 30px;
            max-width: 500px;
            width: 90%;
            text-align: center;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
        }
        
        .instructions-content h2 {
            color: #4ecdc4;
            margin-bottom: 20px;
            font-size: 28px;
        }
        
        .instructions-content p {
            margin-bottom: 15px;
            line-height: 1.6;
            font-size: 16px;
        }
        
        .instructions-content .highlight {
            color: #feca57;
            font-weight: bold;
        }
        
        .got-it-btn {
            background: linear-gradient(45deg, #4ecdc4, #45b7d1);
            border: none;
            color: white;
            padding: 15px 30px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 18px;
            font-weight: bold;
            margin-top: 20px;
            transition: transform 0.2s ease;
        }
        
        .got-it-btn:hover {
            transform: scale(1.05);
        }
        
        .piece-block-empty {
            width: 25px;
            height: 25px;
            border-radius: 3px;
            border: none;
            background: transparent !important;
        }

        .combo-indicator {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 48px;
            font-weight: bold;
            color: #ffff00;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
            pointer-events: none;
            z-index: 2000;
            animation: comboAnimation 1s ease-out;
        }

        @keyframes comboAnimation {
            0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
            50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
        }

        .score-popup {
            position: fixed;
            font-size: 24px;
            font-weight: bold;
            color: #00ff00;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
            pointer-events: none;
            z-index: 2000;
            animation: scorePopup 1.5s ease-out forwards;
        }

        @keyframes scorePopup {
            0% { transform: scale(0.8); opacity: 1; }
            50% { transform: scale(1.2); opacity: 1; }
            100% { transform: scale(1) translateY(-50px); opacity: 0; }
        }

        .achievement-text {
            position: fixed;
            top: 40%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 36px;
            font-weight: bold;
            color: #ff6b6b;
            text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.7);
            pointer-events: none;
            z-index: 2000;
            animation: achievementAnimation 2s ease-out;
        }

        @keyframes achievementAnimation {
            0% { transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); opacity: 0; }
            30% { transform: translate(-50%, -50%) scale(1.3) rotate(5deg); opacity: 1; }
            60% { transform: translate(-50%, -50%) scale(1.1) rotate(-2deg); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 0; }
        }

        .particle {
            position: fixed;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            pointer-events: none;
            z-index: 1500;
        }

        @keyframes particleExplosion {
            0% { transform: scale(1); opacity: 1; }
            100% { transform: scale(0); opacity: 0; }
        }

        .line-glow {
            position: absolute;
            pointer-events: none;
            z-index: 1000;
            animation: lineGlowEffect 0.8s ease-out;
        }

        @keyframes lineGlowEffect {
            0% { box-shadow: 0 0 0px var(--glow-color); opacity: 1; }
            50% { box-shadow: 0 0 20px var(--glow-color), 0 0 40px var(--glow-color); opacity: 1; }
            100% { box-shadow: 0 0 0px var(--glow-color); opacity: 0; }
        }

        .high-score-celebration {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 2500;
        }

        .confetti {
            position: absolute;
            width: 10px;
            height: 10px;
            background: var(--confetti-color);
            animation: confettiFall 3s linear forwards;
        }

        @keyframes confettiFall {
            0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
            100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
        }

        .record-breaking-text {
            position: fixed;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 48px;
            font-weight: bold;
            color: #ffd700;
            text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.8);
            pointer-events: none;
            z-index: 3000;
            animation: recordBreakingAnimation 3s ease-out;
        }

        @keyframes recordBreakingAnimation {
            0% { transform: translate(-50%, -50%) scale(0.1); opacity: 0; }
            20% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
            40% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
            60% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
            80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
        }

        /* All Clear Styles */
        .all-clear-text {
            position: fixed;
            top: 35%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 64px;
            font-weight: bold;
            color: #ffffff;
            text-shadow: 0 0 20px #ff00ff, 0 0 40px #00ffff, 0 0 60px #ffff00;
            pointer-events: none;
            z-index: 3000;
            animation: allClearTextAnimation 4s ease-out;
        }

        @keyframes allClearTextAnimation {
            0% { transform: translate(-50%, -50%) scale(0.1) rotate(-180deg); opacity: 0; }
            25% { transform: translate(-50%, -50%) scale(1.5) rotate(0deg); opacity: 1; }
            50% { transform: translate(-50%, -50%) scale(1.2) rotate(5deg); opacity: 1; }
            75% { transform: translate(-50%, -50%) scale(1.3) rotate(-3deg); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 0; }
        }

        .all-clear-particle {
            position: fixed;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            pointer-events: none;
            z-index: 2000;
        }

        @keyframes allClearExplosion {
            0% { transform: scale(1); opacity: 1; }
            50% { transform: scale(1.5); opacity: 0.8; }
            100% { transform: scale(0.2); opacity: 0; }
        }

        .all-clear-glow {
            animation: boardGlowEffect 4s ease-in-out;
        }

        @keyframes boardGlowEffect {
            0% { box-shadow: 0 0 0px #ffffff; }
            25% { box-shadow: 0 0 30px #ff00ff, 0 0 60px #00ffff; }
            50% { box-shadow: 0 0 40px #ffff00, 0 0 80px #ff0080; }
            75% { box-shadow: 0 0 30px #00ff00, 0 0 60px #ff4000; }
            100% { box-shadow: 0 0 0px #ffffff; }
        }

        .all-clear-score {
            color: #ff00ff !important;
            text-shadow: 0 0 10px #ff00ff, 0 0 20px #00ffff !important;
            font-size: 32px !important;
        }

        .all-clear-bonus {
            font-size: 18px;
            color: #ffff00;
            text-shadow: 0 0 8px #ffff00;
        }

        .all-clear-achievement {
            color: #ffffff !important;
            text-shadow: 0 0 15px #ff00ff, 0 0 30px #00ffff, 0 0 45px #ffff00 !important;
            font-size: 48px !important;
        }

        .game-over-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 3000;
        }

        .modal-content {
            background: linear-gradient(135deg, #2c2c54, #40407a);
            padding: 40px;
            border-radius: 20px;
            text-align: center;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
        }

        .modal-content h2 {
            font-size: 36px;
            margin-bottom: 20px;
            color: #ff6b6b;
        }

        .modal-content p {
            font-size: 18px;
            margin-bottom: 30px;
        }

        .restart-btn {
            background: #4ecdc4;
            border: none;
            color: white;
            padding: 15px 30px;
            border-radius: 10px;
            cursor: pointer;
            font-size: 18px;
            font-weight: bold;
        }

        .restart-btn:hover {
            background: #45b7aa;
        }

        /* Mobile-specific styles */
         @media screen and (max-width: 768px) {
              .game-container {
                  padding: 5px;
                  padding-bottom: max(20px, env(safe-area-inset-bottom)); /* Increased bottom padding */
                  /* Fully responsive height */
                  height: 100vh;
                  height: 100dvh;
                  height: -webkit-fill-available;
              }
            
            .header {
                  padding: 8px 15px;
                  margin-bottom: 10px;
              }
            
            .score-display {
                font-size: 20px;
            }
            
            .high-score {
                font-size: 14px;
            }
            
            .pause-btn {
                padding: 8px;
                font-size: 28px;
                width: 38px;
                height: 38px;
            }
            
            .game-board {
                grid-template-columns: repeat(8, 35px);
                grid-template-rows: repeat(8, 35px);
                gap: 1px;
                padding: 8px;
            }
            
            .cell {
                width: 35px;
                height: 35px;
            }
            
            .pieces-tray {
                  padding: 15px 10px;
                  margin-top: 10px;
                  gap: 12px;
                  /* Ensure tray stays above mobile toolbar */
                  margin-bottom: max(15px, env(safe-area-inset-bottom)); /* Added margin for toolbar */
              }
            
            .piece-block {
                width: 22px;
                height: 22px;
            }
            
            .piece-block-empty {
                width: 22px;
                height: 22px;
            }
        }
        
        /* Extra small mobile devices */
         @media screen and (max-height: 600px) {
              .game-container {
                  padding: 3px;
                  /* Fully adaptive height for small screens */
                  height: 100vh;
                  height: 100dvh;
                  height: -webkit-fill-available;
              }
            
            .header {
                  padding: 5px 10px;
                  margin-bottom: 10px;
              }
            
            .score-display {
                font-size: 18px;
            }
            
            .high-score {
                font-size: 12px;
            }
            
            .pause-btn {
                padding: 6px;
                font-size: 24px;
                width: 32px;
                height: 32px;
            }
            
            .game-board {
                grid-template-columns: repeat(8, 30px);
                grid-template-rows: repeat(8, 30px);
                padding: 5px;
            }
            
            .cell {
                width: 30px;
                height: 30px;
            }
            
            .pieces-tray {
                   padding: 10px 5px;
                   gap: 8px;
                   margin-top: 10px;
               }
            
            .piece-block {
                width: 20px;
                height: 20px;
            }
            
            .piece-block-empty {
                width: 20px;
                height: 20px;
            }
        }
    
:root{--tc-piece:22px;--tc-cell:clamp(18px,min(calc((100vw - 48px)/8 - 2px),calc((100dvh - 300px)/8 - 2px)),48px)}
html,body{height:100%;margin:0;background:#273f78;color:#fff;font-family:Arial,Helvetica,sans-serif}body{height:100dvh;min-height:450px;overflow:auto;touch-action:manipulation}button{cursor:pointer;font:inherit}button:focus-visible,[tabindex]:focus-visible{outline:3px solid #ffe17e;outline-offset:3px}[hidden]{display:none!important}
.game-container{width:min(100%,520px);height:100%;min-height:450px;margin:auto;padding:10px 12px;gap:8px;display:flex;flex-direction:column;justify-content:center;background:none}
.header{width:100%;max-width:450px;align-self:center;display:flex;align-items:center;justify-content:space-between;padding:0 2px;flex:0 0 58px;background:none;border:none;gap:8px}.score-display{font-size:28px;font-weight:800;line-height:1.1}.high-score{font-size:13px;opacity:1;color:#e6cd83}.tc-name{font-size:12px;color:#d7e3ff;font-weight:600;margin-bottom:3px}.button-group{gap:6px;display:flex}.header button{width:38px;height:38px;padding:7px;border:1px solid #829dd1;border-radius:10px;background:#314e89;color:#f4f7ff;display:grid;place-items:center}.header button:hover{background:#42629f}
.game-board-container{flex:0 0 auto;min-height:0;overflow:visible}.game-board{grid-template-columns:repeat(8,var(--tc-cell));grid-template-rows:repeat(8,var(--tc-cell));gap:2px;padding:8px;background:#142750;border:1px solid #6582ba;border-radius:10px;box-shadow:none}.cell{width:var(--tc-cell);height:var(--tc-cell);border:1px solid #32466c;background:#1d315a;border-radius:3px;transition:background-color .12s}.cell.filled{box-shadow:inset 0 3px 0 #ffffff30,inset 0 -3px 0 #00000025}.cell.valid-drop{background:#83d8c0!important;border-color:#effff9}
.pieces-tray{padding:8px 2px;gap:10px;margin:0;background:none;border:none;display:flex;align-items:center;justify-content:center;min-height:128px;flex:0 0 128px}.piece-container{touch-action:none;flex:0 1 auto;margin:0;padding:5px;display:grid;gap:2px;grid-auto-flow:row;border:2px solid transparent;border-radius:7px;box-shadow:none;background:none;transform:none!important;cursor:grab}.piece-block,.piece-block-empty{width:var(--tc-piece)!important;height:var(--tc-piece)!important;border-radius:3px;box-shadow:inset 0 2px 0 #ffffff38,inset 0 -2px 0 #00000026}.piece-block-empty{box-shadow:none}.piece-container.tc-selected{border-color:#ffe17e;background:#ffffff12}.piece-container.no-moves{opacity:.35}.tc-drag{position:fixed;left:0;top:0;z-index:1000;pointer-events:none;display:grid;gap:2px;opacity:.95}.tc-drag>.piece-block,.tc-drag>.piece-block-empty{width:100%!important;height:100%!important}
#tc-status{min-height:16px;text-align:center;font-size:12px;color:#dae5ff}.tc-footer{font-size:11px;color:#c3d3f4;display:flex;gap:12px;justify-content:center;align-items:center;min-height:18px}.tc-footer a{color:inherit;text-decoration:none}.tc-footer a:hover{text-decoration:underline}
dialog{color:#f4f7ff;background:#1d315a;border:1px solid #829dd1;border-radius:14px;width:min(320px,calc(100vw - 32px));padding:24px;box-shadow:0 20px 70px #0009}dialog::backdrop{background:#07142abf}dialog h2{font-size:22px;margin:0 0 14px}dialog p{line-height:1.5;margin-bottom:20px}dialog button{border:1px solid #829dd1;border-radius:8px;background:#3b5d9d;color:white;padding:10px 16px}dialog .tc-actions{display:flex;gap:10px;justify-content:flex-end}#tc-final-score{font-size:36px;font-weight:800;color:#ffe17e}
@media(max-width:420px){:root{--tc-piece:18px}.pieces-tray{gap:3px;min-height:104px;flex-basis:104px}.piece-container{padding:3px}.header{padding:0}.score-display{font-size:25px}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
