* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 20px;
    overflow-x: hidden;
    position: fixed;
    width: 100%;
}


    .hide-all {
        display: none !important;
    }
    

/* Native app environment detection - JavaScript-based */
.native-app,
.native-app body {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.native-app body {
    padding: 0 !important;
}

.native-app .hide-on-native {
    display: none !important;
}

/* .native-app .container {
    height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    height: calc(100% - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.native-app .play-row {
    flex: 1;
    overflow: hidden;
} */

/* Fallback: Keep media query for browsers that support it */
@media (display-mode: standalone), (display-mode: fullscreen) {
    html, body {
        height: 100%;
        height: -webkit-fill-available;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    body {
        padding: 0 !important;
    }

    .hide-on-native {
        display: none !important;
    }

    /* .container {
        height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        height: calc(100% - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overflow: hidden;
        display: flex;
        flex-direction: column;
    } */

    .play-row {
        flex: 1;
        overflow: hidden;
    }
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 900px;
    margin: 0 auto;
}

/* Header - Compact */
header.compact-header {
    margin-bottom: 15px;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.back-btn {
    text-decoration: none;
    color: #F59E0B;
    font-size: 0.85em;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.3s;
    background: #FEF3C7;
    white-space: nowrap;
}

.back-btn:hover {
    background: #FDE68A;
    transform: translateX(-2px);
}

h1 {
    text-align: center;
    color: #F59E0B;
    margin: 0;
    font-size: 1.6em;
    flex: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

/* Icon buttons */
.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: #FEF3C7;
    border: none;
    color: #F59E0B;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: #FDE68A;
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.3s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    border: 3px solid #F59E0B;
    animation: modalSlideIn 0.3s ease-out;
    position: relative;
}

/* Safe area for modal content on iOS */
@supports (padding: max(0px)) {
    .modal-content {
        padding-top: max(30px, env(safe-area-inset-top));
        padding-bottom: max(30px, env(safe-area-inset-bottom));
        padding-left: max(30px, env(safe-area-inset-left));
        padding-right: max(30px, env(safe-area-inset-right));
    }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #F59E0B;
    margin: 0 0 20px 0;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #F59E0B;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.8em;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    font-weight: bold;
    padding: 0;
}

.close-btn:hover {
    background: #D97706;
    transform: rotate(90deg);
}

/* Leaderboard */
.leaderboard-list {
    margin-top: 20px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

.leaderboard-item .rank {
    font-size: 1.5em;
    font-weight: bold;
    color: #F59E0B;
    min-width: 50px;
}

.leaderboard-item .name {
    flex: 1;
    font-weight: 600;
    color: #4a5568;
}

.leaderboard-item .score-val {
    font-size: 1.2em;
    font-weight: bold;
    color: #F59E0B;
}

.coming-soon {
    text-align: center;
    padding: 30px 20px;
    color: #9ca3af;
    font-style: italic;
}

/* Instructions Content */
.instructions-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.mobile-controls {
    padding: 15px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 10px;
    border: 2px solid #F59E0B;
}

.mobile-controls p {
    margin: 8px 0;
    color: #4a5568;
    font-size: 1em;
}

/* Game Info */
.game-info {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 15px;
    padding: 12px;
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    flex-shrink: 0;
}

.game-info.compact {
    padding: 8px;
    grid-template-columns: 1fr;
    gap: 6px;
}

.game-info.compact .info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    transition: all 0.3s;
}

.info-item {
    text-align: center;
    color: white;
}

.info-item .label {
    display: block;
    font-size: 0.7em;
    opacity: 0.9;
    margin-bottom: 2px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item .value {
    display: block;
    font-size: 1.1em;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

/* Game Layout */
.play-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 15px;
    flex: 1;
    overflow: hidden;
}

.info-side {
    flex: 0 0 22%;
    max-width: 22%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.side-panel.small {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-board {
    flex: 1 1 78%;
    max-width: 78%;
    position: relative;
                display: grid;
        place-items: center;  /* ← Add this */
    overflow: hidden;
}

.next-piece-panel,
.hold-piece-panel {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    width: 100%;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

.next-piece-panel h3,
.hold-piece-panel h3 {
    color: #F59E0B;
    margin-bottom: 6px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.key-hint {
    font-size: 0.7em;
    opacity: 0.7;
    font-weight: normal;
    background: rgba(245, 158, 11, 0.2);
    padding: 2px 4px;
    border-radius: 4px;
    margin-left: 2px;
}

#nextCanvas,
#holdCanvas {
    display: block;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    border: 2px solid #F59E0B;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* Game Control Panel (Start/Pause Button) */
.game-control-panel {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    width: 100%;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
    margin-top: 8px;
}

.control-btn {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn.start-btn {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
}

.control-btn.pause-btn {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
}

.control-btn.resume-btn {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.game-board {
    background: white;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

/* Canvas */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    border: 3px solid #F59E0B;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4),
                inset 0 0 20px rgba(0,0,0,0.3);
}

/* Pause Overlay */
.pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    animation: fadeIn 0.3s ease-out;
    backdrop-filter: blur(4px);
}

.pause-overlay.hidden {
    display: none;
}

.pause-content {
    text-align: center;
    animation: modalSlideIn 0.3s ease-out;
    padding: 20px;
}

/* Safe area for pause overlay on iOS */
@supports (padding: max(0px)) {
    .pause-content {
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

.pause-content h2 {
    color: #F59E0B;
    font-size: 3em;
    margin: 0 0 15px 0;
    text-shadow: 0 0 20px rgba(245, 158, 11, 0.8),
                 2px 2px 4px rgba(0,0,0,0.5);
    animation: pulse 2s ease-in-out infinite;
}

.pause-content p {
    color: white;
    font-size: 1.2em;
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    opacity: 0.9;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.9;
    }
}

/* Game Over Modal */
.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 25px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 260px;
    border: 3px solid #F59E0B;
    animation: modalSlideIn 0.3s ease-out;
    z-index: 1000;
}

/* Safe area for game over modal on iOS */
@supports (padding: max(0px)) {
    .game-over {
        padding-top: max(25px, env(safe-area-inset-top));
        padding-bottom: max(25px, env(safe-area-inset-bottom));
        padding-left: max(25px, env(safe-area-inset-left));
        padding-right: max(25px, env(safe-area-inset-right));
    }
}

.game-over.hidden {
    display: none;
}

.game-over h2 {
    margin-top: 0;
    color: #F59E0B;
    margin-bottom: 15px;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.final-stats {
    text-align: left;
    margin: 15px 0;
    padding: 15px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 10px;
    border: 2px solid #F59E0B;
}

.final-stats p {
    margin: 8px 0;
    color: #4a5568;
    font-size: 1em;
    display: flex;
    justify-content: space-between;
}

.final-stats strong {
    color: #F59E0B;
    font-weight: 700;
}

.btn {
    padding: 12px 30px;
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.5);
}

.btn:active {
    transform: translateY(-1px);
}

/* Instructions for web */
.instructions {
    padding: 20px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-radius: 12px;
    border-left: 4px solid #F59E0B;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
    margin-bottom: 15px;
}

.instructions h3 {
    color: #F59E0B;
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: 700;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px;
    background: white;
    border-radius: 8px;
    font-size: 0.85em;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.key {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-weight: bold;
    font-size: 0.85em;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
    min-width: 35px;
    text-align: center;
}

.mobile-text {
    display: none;
}

.tip {
    color: #4a5568;
    font-size: 0.9em;
    line-height: 1.5;
    padding: 10px;
    background: white;
    border-radius: 8px;
    margin-top: 8px;
}

/* Ad Placeholders */
.ad-placeholder {
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    margin: 20px auto;
    max-width: 728px;
}

/* Animations */
.score-popup {
    position: absolute;
    color: #F59E0B;
    font-weight: bold;
    font-size: 1.5em;
    pointer-events: none;
    animation: scorePopup 1s ease-out forwards;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

@keyframes scorePopup {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-30px) scale(1.5);
        opacity: 0;
    }
}

/* Mobile & Native App */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .ad-placeholder,
    .ad-top,
    .ad-bottom {
        display: none !important;
    }

    .container {
        padding: 8px;
        padding-top: max(8px,  0px);
        border-radius: 0;
        height: 100vh;
        height: -webkit-fill-available;
        display: flex;
        flex-direction: column;
    }

    header.compact-header {
        margin-bottom: 8px;
    }

    h1 {
        font-size: 1.2em;
    }

    .icon-btn {
        width: 44px;  /* ✅ Apple HIG minimum touch target */
        height: 44px;
    }

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .game-info.compact {
        /* flex: 0 0 40%; 
        display: flex;
        flex-direction: column; */
                display: grid;
        place-items: center;  /* ← Add this */
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
        padding: 6px;
        margin-bottom: 8px;
    }
    
    .game-info.compact .info-item {
        flex-direction: column;
        text-align: center;
        padding: 6px 4px;
    }
    
    .info-item .label {
        font-size: 0.6em;
        margin-bottom: 1px;
    }
    
    .info-item .value {
        font-size: 0.95em;
    }
    
    .play-row {
        flex-direction: column;
        gap: 8px;
        margin-bottom: 0;
    }
    
    .info-side {
        display: flex;
        flex-direction: row;
        gap: 5px;
        flex: 0 0 100%; /* Make info-side full width */
        max-width: 100%; /* Make info-side full width */
    }
    
    .game-board {
        flex: 1;
        max-width: 100%;
        width: 100%;
        padding: 8px;
        min-height: 0;
                display: grid;
        place-items: center;  /* ← Add this */
    }
    
    .side-panel.small {
        flex: 1; /* Next + Hold chiếm 60% */
        display: flex;
        flex-direction: row;
        gap: 5px;
    }
    
    .next-piece-panel,
    .hold-piece-panel {
        flex: 1;
    }
    
    .game-control-panel {
        flex: 1;
        margin-top: 0;
    }
    
    .control-btn {
        padding: 10px 12px;
        font-size: 0.9em;
    }
    
    .next-piece-panel h3,
    .hold-piece-panel h3 {
        font-size: 0.7em;
        margin-bottom: 4px;
    }
    
    #nextCanvas,
    #holdCanvas {
        width: 70px;
        height: 70px;
    }

    #gameCanvas {
        border-width: 2px;
    }
    
    .modal-content {
        padding: 20px;
        padding-top: 50px;
        max-width: 95%;
    }
    
    .modal-content h2 {
        font-size: 1.5em;
    }
    
    .controls-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .control-item {
        padding: 8px;
    }
    
    .desktop-text {
        display: none;
    }

    .mobile-text {
        display: block;
    }

    /* Hide instructions on mobile - they're in modal instead */
    .instructions.hide-on-native {
        display: none !important;
    }
}

/* Prevent text selection */
#gameCanvas,
button,
.game-board,
.icon-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
