* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: 
        radial-gradient(circle at 20% 30%, rgba(139, 69, 19, 0.8) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(160, 82, 45, 0.8) 0%, transparent 50%),
        linear-gradient(135deg, #8B4513 0%, #A0522D 50%, #8B4513 100%);
    background-size: 100% 100%, 100% 100%, 100% 100%;
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.03) 2px,
            rgba(0, 0, 0, 0.03) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.03) 2px,
            rgba(0, 0, 0, 0.03) 4px
        );
    pointer-events: none;
    z-index: 0;
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100vw;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    position: relative;
    z-index: 1;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(139, 69, 19, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(160, 82, 45, 0.5);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.crown-icon {
    font-size: 24px;
}

.score-value {
    font-size: 20px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.current-score {
    font-size: 32px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
}

.combo-display {
    font-size: 14px;
    font-weight: bold;
    color: #FF6B6B;
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    margin-top: 4px;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
}

.combo-display.combo-active {
    opacity: 1;
    transform: scale(1);
    animation: comboPulse 0.5s ease-in-out infinite;
}

@keyframes comboPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 10px rgba(255, 107, 107, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    }
    50% {
        transform: scale(1.1);
        text-shadow: 0 0 20px rgba(255, 107, 107, 1), 0 2px 8px rgba(0, 0, 0, 0.7);
    }
}

.header-right {
    position: relative;
}

.settings-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    transition: transform 0.2s;
}

.settings-btn:active {
    transform: scale(0.9);
}

.settings-btn::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    border: 2px solid rgba(139, 69, 19, 0.9);
}

/* Game Area */
.game-area {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow: hidden;
}

#gameCanvas {
    max-width: 100%;
    max-height: 100%;
    border: 3px solid rgba(160, 82, 45, 0.9);
    border-radius: 12px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 215, 0, 0.3) inset,
        0 2px 8px rgba(255, 215, 0, 0.15),
        0 0 40px rgba(139, 69, 19, 0.3);
    background: #D2B48C;
    touch-action: none;
    position: relative;
    overflow: hidden;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 8px;
}

.game-overlay.active {
    display: flex;
}

.overlay-content {
    background: linear-gradient(135deg, #8B4513 0%, #A0522D 100%);
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(255, 215, 0, 0.5);
}

.overlay-content h2 {
    color: #FFD700;
    margin-bottom: 16px;
    font-size: 28px;
}

.overlay-content p {
    color: #FFF;
    margin-bottom: 24px;
    font-size: 18px;
}

.restart-btn {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border: none;
    padding: 12px 32px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    color: #8B4513;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

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

/* Pieces Container */
.pieces-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: rgba(139, 69, 19, 0.7);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.pieces-container::-webkit-scrollbar {
    display: none;
}

.piece {
    flex-shrink: 0;
    background: rgba(210, 180, 140, 0.9);
    border: 2px solid rgba(160, 82, 45, 0.8);
    border-radius: 8px;
    padding: 8px;
    cursor: grab;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.piece:active {
    cursor: grabbing;
}

.piece.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.piece.active {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.6);
    border-color: #FFD700;
}

.piece.can-place {
    animation: pulse 1s infinite;
}

.piece.cannot-place {
    opacity: 0.5;
    filter: grayscale(50%);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0 4px 16px rgba(255, 215, 0, 0.8);
    }
}

.piece-canvas {
    display: block;
    pointer-events: none;
}

/* Drag Ghost Element */
.drag-ghost {
    transition: none !important;
    will-change: transform;
}

.drag-ghost canvas {
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Game Controls */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 12px;
    background: rgba(139, 69, 19, 0.7);
}

.control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(160, 82, 45, 0.8);
    background: rgba(210, 180, 140, 0.9);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Settings Modal */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.settings-modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #8B4513 0%, #A0522D 100%);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(255, 215, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid rgba(160, 82, 45, 0.5);
}

.modal-header h3 {
    color: #FFD700;
    font-size: 24px;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 32px;
    color: #FFF;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid rgba(160, 82, 45, 0.3);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item label {
    color: #FFF;
    font-size: 18px;
}

.setting-item input[type="checkbox"] {
    width: 48px;
    height: 24px;
    appearance: none;
    background: rgba(160, 82, 45, 0.5);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.setting-item input[type="checkbox"]:checked {
    background: #FFD700;
}

.setting-item input[type="checkbox"]::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FFF;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.setting-item input[type="checkbox"]:checked::after {
    transform: translateX(24px);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .current-score {
        font-size: 24px;
    }
    
    .score-value {
        font-size: 18px;
    }
    
    .pieces-container {
        gap: 8px;
        padding: 8px;
    }
    
    .piece {
        padding: 6px;
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .game-header {
        padding: 8px 12px;
    }
    
    .current-score {
        font-size: 20px;
    }
    
    .pieces-container {
        padding: 6px;
    }
}

