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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #E3F2FD;
    height: 100vh;
    overflow: hidden;
    color: #1565C0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.container {
    width: 100%;
    height: 100vh;
    max-width: 100%;
    margin: 0;
    background: white;
    box-shadow: 0 10px 40px rgba(33, 150, 243, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.header {
    background: #2196F3;
    color: white;
    padding: 20px 30px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
}

.header h1 {
    font-size: 2rem;
    margin: 0;
    font-weight: 700;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    letter-spacing: -0.5px;
    text-align: center;
}

.twitter-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    color: white;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    z-index: 2;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.twitter-link:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-50%) translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.twitter-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.twitter-link:hover .twitter-icon {
    transform: scale(1.1) rotate(-5deg);
}

.header p {
    font-size: 0.95rem;
    opacity: 0.95;
    position: relative;
    z-index: 1;
    font-weight: 400;
}

.main-content {
    display: flex;
    gap: 20px;
    padding: 20px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: transparent;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(33, 150, 243, 0.05);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #64B5F6, #42A5F5);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #42A5F5, #2196F3);
}

.control-panel {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 0;
    border: 2px solid rgba(33, 150, 243, 0.15);
    box-shadow: 0 4px 16px rgba(33, 150, 243, 0.08);
    transition: all 0.3s ease;
}

.control-panel:hover {
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.12);
    border-color: rgba(33, 150, 243, 0.25);
}

.upload-area {
    border: 3px dashed #2196F3;
    border-radius: 16px;
    padding: 30px 20px;
    text-align: center;
    background: #E3F2FD;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}

.upload-area::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(33, 150, 243, 0.08);
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.upload-area:hover::before {
    width: 300px;
    height: 300px;
}

.upload-area:hover {
    border-color: #1976D2;
    background: #BBDEFB;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(33, 150, 243, 0.2);
}

.upload-area.dragover {
    border-color: #0D47A1;
    background: #90CAF9;
    box-shadow: 0 10px 30px rgba(33, 150, 243, 0.3);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    color: #2196F3;
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 2px 4px rgba(33, 150, 243, 0.3));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
}

.upload-text {
    font-size: 1rem;
    color: #1565C0;
    margin-bottom: 6px;
    font-weight: 600;
    position: relative;
    z-index: 1;
}

.upload-hint {
    font-size: 0.85rem;
    color: #64B5F6;
    position: relative;
    z-index: 1;
    font-weight: 500;
}

#file-input {
    display: none;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

label {
    font-weight: 600;
    color: #1565C0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select, button {
    padding: 12px 16px;
    border: 2px solid rgba(33, 150, 243, 0.2);
    border-radius: 10px;
    font-size: 0.9rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
}

select {
    color: #1565C0;
    font-weight: 600;
    cursor: pointer;
}

select:hover {
    border-color: #42A5F5;
    box-shadow: 0 3px 10px rgba(33, 150, 243, 0.12);
}

select:focus, button:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

button {
    background: #2196F3;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
    font-size: 0.85rem;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    transform: translate(-50%, -50%);
    transition: width 0.5s ease, height 0.5s ease;
}

button:hover::before {
    width: 300px;
    height: 300px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.35);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 3px 10px rgba(33, 150, 243, 0.25);
}

button:disabled {
    background: #B0BEC5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.5;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.stat-card {
    background: #E3F2FD;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 2px solid #2196F3;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.08);
}

.stat-card:hover {
    border-color: #1976D2;
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(33, 150, 243, 0.15);
    background: #BBDEFB;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2196F3;
    margin-bottom: 6px;
}

.stat-label {
    font-size: 0.75rem;
    color: #1565C0;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.puzzle-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    min-width: 0;
    min-height: 0;
    padding: 10px;
}

.puzzle-board {
    border: 3px solid #2196F3;
    border-radius: 20px;
    background: white;
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    max-width: min(calc(100vh - 200px), calc(100vw - 400px));
    max-height: min(calc(100vh - 200px), calc(100vw - 400px));
    box-shadow: 0 10px 40px rgba(33, 150, 243, 0.25);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.puzzle-board:hover {
    box-shadow: 0 15px 50px rgba(33, 150, 243, 0.35);
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FAFAFA;
}

#puzzleCanvas {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    cursor: grab;
    display: block;
    object-fit: contain;
}

#puzzleCanvas.dragging {
    cursor: grabbing;
}

.preview-image {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(33, 150, 243, 0.2);
    margin-top: 16px;
    border: 2px solid rgba(33, 150, 243, 0.2);
}

.message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2196F3;
    color: white;
    padding: 28px 50px;
    border-radius: 20px;
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 20px 60px rgba(33, 150, 243, 0.5);
    z-index: 1000;
    animation: successPulse 1s ease-in-out;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

@keyframes successPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.05);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.hint-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(33, 150, 243, 0.08);
    pointer-events: none;
    border-radius: 12px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #2196F3;
}

.loading p {
    font-size: 1rem;
    font-weight: 600;
    color: #1565C0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(33, 150, 243, 0.2);
    border-top: 4px solid #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
    box-shadow: 0 3px 12px rgba(33, 150, 243, 0.15);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(33, 150, 243, 0.15);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 12px;
    box-shadow: inset 0 2px 4px rgba(33, 150, 243, 0.1);
}

.progress-fill {
    height: 100%;
    background: #2196F3;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.4);
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: transparent;
}

.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 14px;
    margin-top: 20px;
}

.mobile-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    background: #2196F3;
    color: white;
    border: none;
    padding: 16px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 5px 16px rgba(33, 150, 243, 0.35);
    transition: all 0.3s ease;
}

.mobile-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(33, 150, 243, 0.45);
}

/* Tablet and medium screens */
@media (max-width: 1024px) and (min-width: 769px) {
    .header h1 {
        font-size: 1.8rem;
        padding-right: 200px;
    }
}

/* Small tablets */
@media (max-width: 900px) and (min-width: 769px) {
    .header h1 {
        font-size: 1.6rem;
    }

    .twitter-link {
        font-size: 0.85rem;
        padding: 8px 14px;
    }
}

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

    .container {
        border-radius: 0;
        height: 100vh;
    }

    .header {
        padding: 16px 20px;
        min-height: 70px;
    }

    .header h1 {
        font-size: 1.4rem;
        padding-right: 60px;
    }

    .twitter-link {
        right: 16px;
        padding: 10px;
        gap: 0;
    }

    .twitter-link span {
        display: none;
    }

    .twitter-icon {
        width: 22px;
        height: 22px;
    }

    .header p {
        font-size: 0.85rem;
    }

    .main-content {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .sidebar {
        width: 100%;
        order: 2;
        max-height: none;
        flex-shrink: 0;
    }

    .puzzle-area {
        order: 1;
        flex: 1;
        min-height: 0;
        padding: 5px;
    }

    .puzzle-board {
        max-width: 100%;
        max-height: calc(100vh - 500px);
        min-height: 300px;
    }

    .mobile-toggle {
        display: block;
    }

    .sidebar.mobile-hidden {
        display: none;
    }

    .canvas-container {
        max-width: 100%;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .control-panel {
        padding: 16px;
    }

    .upload-area {
        padding: 24px 16px;
    }

    .upload-icon {
        font-size: 2rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }
}

/* Very small mobile screens */
@media (max-width: 480px) {
    .header {
        padding: 14px 16px;
        min-height: 60px;
    }

    .header h1 {
        font-size: 1.2rem;
        padding-right: 50px;
        letter-spacing: -0.3px;
    }

    .twitter-link {
        right: 12px;
        padding: 8px;
    }

    .twitter-icon {
        width: 20px;
        height: 20px;
    }
}

.piece-preview {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 2px solid rgba(33, 150, 243, 0.2);
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.12);
}

.piece-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.control-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* Input file styling */
#fileInput {
    display: none;
}

/* Smooth transitions for all interactive elements */
* {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Custom focus styles for accessibility */
*:focus-visible {
    outline: 2px solid #2196F3;
    outline-offset: 2px;
}

/* Ensure canvas scales properly */
.puzzle-board canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
