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

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: #ffffff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    overflow-x: hidden;
}

.top-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 20px;
}

header {
    flex-shrink: 0;
    align-self: flex-start;
}

h1 {
    color: #333;
    font-size: 2.5rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    margin: 0;
}

.controls {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 15px 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    max-width: 800px;
    border: 1px solid #e9ecef;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-weight: 600;
    color: #495057;
    font-size: 0.8rem;
}

.control-group input[type="file"] {
    padding: 6px;
    border: 2px dashed #007bff;
    border-radius: 6px;
    cursor: pointer;
    background: #ffffff;
    font-size: 0.8rem;
    transition: all 0.3s ease;
}

.control-group input[type="file"]:hover {
    border-color: #0056b3;
    background: #f0f8ff;
}

.control-group input[type="number"] {
    padding: 8px 12px;
    border: 2px solid #ced4da;
    border-radius: 6px;
    font-size: 0.9rem;
    width: 70px;
    transition: all 0.3s ease;
}

.control-group input[type="number"]:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: #007bff;
    color: #fff;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    background: #0069d9;
    box-shadow: 0 6px 15px rgba(0, 123, 255, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: #fff;
    box-shadow: 0 4px 10px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    background: #5a6268;
    box-shadow: 0 6px 15px rgba(108, 117, 125, 0.4);
}

.btn-success {
    background: #28a745;
    color: #fff;
    box-shadow: 0 4px 10px rgba(40, 167, 69, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    background: #218838;
    box-shadow: 0 6px 15px rgba(40, 167, 69, 0.4);
}

.game-info {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    display: flex;
    gap: 30px;
    align-items: center;
    max-width: 1200px;
    width: 100%;
    border: 1px solid #e9ecef;
    box-sizing: border-box;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.info-item .label {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 5px;
}

.info-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #007bff;
}

.info-item.rotation-control {
    margin-left: auto;
}

#toggleRotationBtn {
    background: #17a2b8 !important;
    color: #fff !important;
    box-shadow: 0 4px 10px rgba(23, 162, 184, 0.3) !important;
}

#toggleRotationBtn:hover {
    background: #138496 !important;
    box-shadow: 0 6px 15px rgba(23, 162, 184, 0.4) !important;
}

.game-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.main-game-wrapper {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    background: #f8f9fa;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 1200px;
    border: 1px solid #e9ecef;
    box-sizing: border-box;
}

.puzzle-area {
    background: #ffffff;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
}

.puzzle-grid {
    display: grid;
    gap: 2px;
    background: #dee2e6;
    padding: 2px;
    border-radius: 8px;
    position: relative;
    overflow: visible;
}

.puzzle-cell {
    background: #ffffff;
    border: 1px solid #ced4da;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #6c757d;
}

.puzzle-piece {
    position: absolute;
    cursor: grab;
    transition: all 0.3s ease;
    user-select: none;
    border: 2px solid #ffffff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.puzzle-piece:hover {
    z-index: 100;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    transform: translateY(-2px);
}

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 1000;
    opacity: 0.9;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    transform: translateY(-4px);
}

.preview-area {
    background: #ffffff;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    text-align: center;
    border: 1px solid #e9ecef;
}

.preview-area h3 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.preview-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.preview-image:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
}

.hint {
    margin-top: 15px;
    padding: 15px;
    background: #e7f3ff;
    border-radius: 8px;
    color: #004085;
    font-size: 0.9rem;
    border-left: 4px solid #007bff;
}

.complete-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.complete-overlay.show {
    display: flex;
}

.complete-modal {
    background: #ffffff;
    border-radius: 20px;
    padding: 50px;
    text-align: center;
    color: #495057;
    animation: popIn 0.5s ease;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
    border: 1px solid #e9ecef;
}

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

.complete-modal h2 {
    font-size: 3rem;
    margin-bottom: 20px;
    color: #28a745;
}

.backend-status {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    z-index: 1000;
    max-width: 300px;
    text-align: center;
    transition: opacity 0.5s;
}

.backend-status.success {
    background-color: #4caf50;
    color: white;
}

.backend-status.error {
    background-color: #f44336;
    color: white;
}

.ai-assistant-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: all 0.3s ease;
}

.ai-assistant-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.complete-modal p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #6c757d;
}

.rotate-hint {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    color: #333;
    pointer-events: none;
    display: none;
}

@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    h1 {
        font-size: 1.8rem;
    }

    .controls {
        padding: 15px;
    }

    .game-info {
        flex-wrap: wrap;
        justify-content: center;
    }
}

.footer-text {
    margin-top: 20px;
    padding: 15px;
    text-align: center;
    font-size: 0.9rem;
    color: #6c757d;
    background: #f8f9fa;
    border-radius: 15px;
    max-width: 1200px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 15px;
}
