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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background-color: #f0f8ff;
    color: #333;
    overflow-x: hidden;
    touch-action: manipulation;
}

.container {
    max-width: 100vw;
    min-height: 100vh;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Language Selector */
.language-selector {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 100;
}

.lang-btn {
    padding: 5px 10px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.lang-btn:hover {
    background: #f0f0f0;
}

.lang-btn.active {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
}

/* Step Container */
.step {
    display: none;
    width: 100%;
    max-width: 500px;
    animation: fadeIn 0.3s ease-in;
}

.step.active {
    display: block;
}

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

.step-title {
    font-size: 18px;
    margin: 20px 0 10px;
    text-align: center;
    color: #2c3e50;
}

.step-description {
    font-size: 14px;
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 20px;
}

/* Canvas Container */
.canvas-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 auto 20px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#mapCanvas, #mapCanvas2, #finalMapCanvas {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    touch-action: none;
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.3;
}

/* Controls */
.controls, .object-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.mode-btn, .object-btn {
    padding: 10px 20px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.mode-btn:hover, .object-btn:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.mode-btn.active, .object-btn.active {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
}

.object-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    min-width: 60px;
}

.object-preview {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    margin-bottom: 4px;
}

.erase-icon {
    font-size: 24px;
    line-height: 32px;
    display: block;
    width: 32px;
    height: 32px;
    text-align: center;
    margin-bottom: 4px;
}

.erase-btn {
    background: #ff6b6b;
    color: white;
    border-color: #ff6b6b;
}

.erase-btn:hover {
    background: #ff5252;
}

/* Buttons */
.next-btn, .complete-btn, .download-btn, .close-btn, .back-btn {
    display: block;
    margin: 5px auto;
    padding: 12px 30px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.next-btn:hover, .complete-btn:hover {
    background: #229954;
    transform: translateY(-2px);
}

.back-btn {
    background: #95a5a6;
}

.back-btn:hover {
    background: #7f8c8d;
    transform: translateY(-2px);
}

.step2-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.step2-buttons button {
    margin: 10px 5px;
}

.download-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

.download-btn {
    background: #3498db;
}

.download-btn:hover {
    background: #2980b9;
}

.download-btn.image-btn {
    background: #8BC34A;
}

.download-btn.image-btn:hover {
    background: #8BC34A;
}

.download-btn.tilesheet-btn {
    background: #3498db;
}

.download-btn.tilesheet-btn:hover {
    background: #2980b9;
}

.close-btn {
    background: #95a5a6;
}

.close-btn:hover {
    background: #7f8c8d;
}

/* Dialog */
.dialog-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.dialog-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialog {
    background: white;
    border-radius: 12px;
    padding: 30px 20px;
    max-width: 90%;
    width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s;
}

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

.dialog-title {
    font-size: 20px;
    margin-bottom: 20px;
    text-align: center;
    color: #2c3e50;
}

.dialog-description {
    font-size: 14px;
    text-align: center;
    color: #7f8c8d;
    margin: 20px 0;
}

.final-map-container {
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    margin: 20px auto;
    max-width: 360px;
}

#finalMapCanvas {
    max-width: 100%;
}

/* Tile highlighting for step 2 */
.tile-unavailable {
    opacity: 0.5;
    filter: brightness(0.7);
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }
    
    .step-title {
        font-size: 16px;
    }
    
    .step-description {
        font-size: 13px;
    }
    
    .mode-btn, .object-btn {
        font-size: 14px;
        padding: 8px 16px;
    }
    
    .object-btn {
        min-width: 50px;
    }
    
    .next-btn, .complete-btn {
        font-size: 16px;
        padding: 10px 24px;
    }
    
    .language-selector {
        top: 5px;
        right: 5px;
    }
    
    .lang-btn {
        font-size: 12px;
        padding: 4px 8px;
    }
}

/* Prevent text selection */
* {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Share Section */
.share-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.share-message {
    font-size: 14px;
    color: #555;
    margin-bottom: 10px;
    text-align: center;
}

.share-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    color: #333;
}

.share-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.share-btn svg {
    width: 20px;
    height: 20px;
}

.taittsuu-btn:hover {
    background: #1da1f2;
    color: white;
    border-color: #1da1f2;
}

.x-btn:hover {
    background: #000;
    color: white;
    border-color: #000;
}

.copy-btn:hover {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
}

.copy-btn .copy-text {
    font-size: 14px;
}

.copy-success {
    text-align: center;
    color: #27ae60;
    font-size: 14px;
    margin-top: 5px;
}

/* Footer */
.tool-footer {
    margin-top: 60px;
    padding: 30px 20px;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #4a90e2;
    text-decoration: none;
    font-size: 16px;
    padding: 10px 20px;
    border-radius: 8px;
    transition: all 0.3s;
    margin-bottom: 20px;
}

.back-link:hover {
    background: #f0f8ff;
    transform: translateX(-5px);
}

.back-arrow {
    font-size: 20px;
    transition: transform 0.3s;
}

.back-link:hover .back-arrow {
    transform: translateX(-3px);
}

.copyright {
    color: #7f8c8d;
    font-size: 14px;
    margin-top: 20px;
}

@media (max-width: 480px) {
    .tool-footer {
        margin-top: 40px;
        padding: 20px 15px;
    }
    
    .back-link {
        font-size: 14px;
        padding: 8px 16px;
    }
    
    .copyright {
        font-size: 12px;
    }
    
    .share-message {
        font-size: 13px;
    }
    
    .share-btn {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .share-btn svg {
        width: 18px;
        height: 18px;
    }
    
    .copy-btn .copy-text {
        font-size: 13px;
    }
}