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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    color: #fff;
    overflow: hidden;
}

#app {
    width: 100vw;
    height: 100vh;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
}

.screen.active {
    display: flex;
}

/* Start Screen */
#start-screen {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    overflow-y: auto;
}

#start-screen h1 {
    font-size: 3rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.start-options {
    background: rgba(255,255,255,0.1);
    padding: 30px;
    border-radius: 20px;
    max-width: 100%;
    width: 100%;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.image-selection, .difficulty-selection {
    margin-bottom: 30px;
}

.image-selection h3, .difficulty-selection h3 {
    margin-bottom: 15px;
    font-size: 1.2rem;
    color: #a0a0ff;
}

.image-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}

.image-option {
    border: 3px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    aspect-ratio: 3/2;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
}

.image-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-option:hover {
    border-color: rgba(100, 150, 255, 0.5);
    transform: scale(1.05);
}

.image-option.selected {
    border-color: #6496ff;
    box-shadow: 0 0 20px rgba(100, 150, 255, 0.4);
}

.image-option.solved {
    position: relative;
}

.solved-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.4);
    border: 2px solid rgba(255,255,255,0.3);
}

.solved-time {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    color: #fff;
    font-size: 0.75rem;
    font-family: 'Courier New', monospace;
    padding: 15px 8px 6px;
    text-align: center;
}

.loading-images, .no-images {
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px;
    color: #888;
    font-size: 0.95rem;
}

.no-images small {
    display: block;
    margin-top: 8px;
    color: #666;
    font-size: 0.8rem;
}

/* Dialog Overlay */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

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

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

.dialog {
    background: linear-gradient(135deg, #1e1e3f 0%, #2a2a5a 100%);
    border-radius: 20px;
    padding: 30px;
    max-width: 700px;
    width: 90%;
    position: relative;
    animation: slideIn 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.dialog-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.dialog-close:hover {
    background: rgba(255,100,100,0.3);
    transform: scale(1.1);
}

#dialog-preview {
    width: 100%;
    height: 250px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px solid rgba(255,255,255,0.1);
}

.dialog h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #a0a0ff;
    font-size: 1.1rem;
}

.dialog .difficulty-options {
    margin-bottom: 20px;
}

.dialog .difficulty-btn {
    min-width: 80px;
    padding: 12px 8px;
    font-size: 0.9rem;
}

.dialog .primary-btn {
    margin-top: 5px;
}

.difficulty-options {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
}

.difficulty-btn {
    flex: 1;
    min-width: 0;
    padding: 15px 10px;
    border: 2px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.05);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.difficulty-btn small {
    font-size: 0.75rem;
    color: #aaa;
}

.difficulty-btn:hover {
    border-color: rgba(100, 150, 255, 0.5);
    background: rgba(100, 150, 255, 0.1);
}

.difficulty-btn.selected {
    border-color: #6496ff;
    background: rgba(100, 150, 255, 0.2);
}

.primary-btn {
    width: 100%;
    padding: 20px;
    font-size: 1.3rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #6496ff 0%, #4a7adb 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(100, 150, 255, 0.4);
}

/* Game Screen */
#game-screen {
    flex-direction: column;
}

#toolbar {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 20px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-wrap: wrap;
}

#toolbar button {
    padding: 8px 15px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

#toolbar button:hover {
    background: rgba(255,255,255,0.2);
}

#timer {
    font-size: 1.2rem;
    font-family: 'Courier New', monospace;
    background: rgba(0,0,0,0.3);
    padding: 8px 15px;
    border-radius: 5px;
}

#progress {
    font-size: 0.9rem;
    color: #aaa;
}

#bg-color {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: none;
    padding: 0;
}

#bg-color::-webkit-color-swatch-wrapper {
    padding: 2px;
}

#bg-color::-webkit-color-swatch {
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.3);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
}

.zoom-controls button {
    width: 35px;
    height: 35px;
    padding: 0;
    font-size: 1.2rem;
}

#zoom-level {
    min-width: 50px;
    text-align: center;
    font-size: 0.9rem;
}

#puzzle-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

#puzzle-container:active {
    cursor: grabbing;
}

#puzzle-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

#preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#preview-overlay.hidden {
    display: none;
}

#preview-image {
    max-width: 90%;
    max-height: 90%;
    border-radius: 10px;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
}

/* Win Screen */
#win-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(10,10,30,0.95) 0%, rgba(20,20,50,0.95) 100%);
}

.win-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: popIn 0.5s ease;
    max-width: 90vw;
    max-height: 90vh;
}

#win-image {
    max-width: 70vw;
    max-height: 55vh;
    border-radius: 12px;
    box-shadow: 0 10px 50px rgba(0,0,0,0.5), 0 0 100px rgba(100,150,255,0.2);
    border: 3px solid rgba(255,255,255,0.2);
}

.win-info {
    text-align: center;
    background: rgba(255,255,255,0.1);
    padding: 25px 50px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

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

.win-info h1 {
    font-size: 2rem;
    margin-bottom: 10px;
    color: #fff;
}

.win-info p {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: #aaa;
}

#final-time {
    font-size: 1.8rem !important;
    font-family: 'Courier New', monospace;
    color: #6496ff !important;
    margin-bottom: 5px !important;
}

#final-pieces {
    font-size: 1rem !important;
    color: #888 !important;
}

.win-info .primary-btn {
    margin-top: 15px;
    width: auto;
    padding: 12px 35px;
}

/* Responsive */
@media (max-width: 600px) {
    #start-screen h1 {
        font-size: 2rem;
    }

    .start-options {
        padding: 20px;
    }

    .difficulty-btn {
        min-width: 80px;
        padding: 10px 5px;
    }

    #toolbar {
        gap: 8px;
        padding: 8px 10px;
    }

    #toolbar button {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}
