* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    background: #1a1a2e;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #1a1a2e;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #ffffff;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px;
    padding-top: env(safe-area-inset-top, 10px);
    padding-bottom: env(safe-area-inset-bottom, 10px);
}

header {
    flex-shrink: 0;
    padding: 10px 0;
}

.score-section {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 25px;
    border-radius: 12px;
    min-width: 100px;
}

.score-box .label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 4px;
}

.score-box span:last-child {
    font-size: 28px;
    font-weight: bold;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    padding: 10px 0;
}

#board-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    margin: 0 auto;
}

#game-board, #preview-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

#board-container {
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 8px;
}

#preview-layer {
    pointer-events: none;
}

#pieces-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 20px 10px;
    gap: 10px;
}

.piece-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 90px;
    height: 90px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: grab;
    transition: transform 0.15s ease, background 0.15s ease;
}

.piece-slot:hover {
    background: rgba(255, 255, 255, 0.1);
}

.piece-slot.dragging {
    transform: scale(1.1);
    opacity: 0.7;
    cursor: grabbing;
}

.piece-slot.empty {
    cursor: default;
    background: rgba(255, 255, 255, 0.02);
}

.piece-slot canvas {
    pointer-events: none;
}

/* Game Over Overlay */
#game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

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

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

.game-over-content {
    text-align: center;
    padding: 40px;
    background: linear-gradient(135deg, #2d2d4a 0%, #1a1a2e 100%);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

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

.game-over-content h2 {
    font-size: 32px;
    margin-bottom: 20px;
    color: #FF6B6B;
}

.game-over-content p {
    font-size: 20px;
    margin-bottom: 10px;
}

.game-over-content .new-high-score {
    color: #FFEAA7;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 20px;
}

.game-over-content .new-high-score.hidden {
    display: none;
}

#play-again-btn {
    margin-top: 20px;
    padding: 15px 40px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #4ECDC4 0%, #45B7D1 100%);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#play-again-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(78, 205, 196, 0.4);
}

#play-again-btn:active {
    transform: scale(0.98);
}

/* Responsive adjustments */
@media (max-height: 700px) {
    .score-box {
        padding: 8px 20px;
    }

    .score-box span:last-child {
        font-size: 24px;
    }

    .piece-slot {
        width: 75px;
        height: 75px;
    }

    #pieces-container {
        padding: 15px 10px;
    }
}

@media (max-height: 600px) {
    .score-box {
        padding: 6px 15px;
        min-width: 80px;
    }

    .score-box .label {
        font-size: 10px;
    }

    .score-box span:last-child {
        font-size: 20px;
    }

    .piece-slot {
        width: 65px;
        height: 65px;
    }

    #pieces-container {
        padding: 10px;
    }
}

/* Desktop adjustments */
@media (min-width: 600px) {
    #game-container {
        padding: 20px;
        justify-content: center;
    }

    header {
        padding: 20px 0;
    }

    .score-box {
        padding: 15px 35px;
        min-width: 120px;
    }

    .score-box span:last-child {
        font-size: 36px;
    }

    .piece-slot {
        width: 100px;
        height: 100px;
    }

    #pieces-container {
        padding: 30px 10px;
    }
}

/* iPhone notch support */
@supports (padding-top: env(safe-area-inset-top)) {
    #game-container {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}
