:root {
    --primary-color: #4361ee;
    --secondary-color: #3a0ca3;
    --accent-color: #f72585;
    --success-color: #4cc9f0;
    --danger-color: #f94144;
    --warning-color: #f8961e;
    --info-color: #90be6d;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --water-color: #4cc9f0;
    --sky-color: #90e0ef;
    --cloud-color: #ffffff;
    --ground-color: #588157;
    --road-color: #495057;
}

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

body {
    font-family: 'Baloo 2', cursive;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #90e0ef 0%, #4cc9f0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: var(--dark-color);
}

.game-container {
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 25px;
    max-width: 950px;
    width: 95%;
    animation: fadeIn 0.5s ease-in-out;
}

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

.game-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 22px;
    font-weight: bold;
    padding: 0 10px;
    position: relative;
}

#budget {
    color: var(--accent-color);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

#level {
    color: var(--primary-color);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

#level-name {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: var(--secondary-color);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
    font-size: 24px;
}

.canvas-container {
    position: relative;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

canvas {
    display: block;
    margin: 0 auto;
    background: linear-gradient(180deg, var(--sky-color) 0%, var(--sky-color) 60%, var(--water-color) 60%, var(--water-color) 100%);
}

#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 10;
}

.loader {
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.game-controls {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.material-selection {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 15px;
    border-radius: 12px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    position: relative;
}

.material-selection::before {
    content: "Building Materials";
    position: absolute;
    top: -10px;
    left: 20px;
    background-color: white;
    padding: 0 10px;
    font-weight: bold;
    color: var(--primary-color);
    border-radius: 4px;
}

.build-mode-toggle {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.build-mode-btn {
    background-color: var(--success-color);
    font-size: 24px;
    padding: 15px 30px;
    border-radius: 12px;
    transition: all 0.3s;
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
}

.build-mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

.build-mode-btn.active {
    background-color: var(--success-color);
}

.build-mode-btn:not(.active) {
    background-color: var(--light-color);
    color: var(--dark-color);
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    border: none;
    color: white;
    padding: 12px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    font-family: 'Baloo 2', cursive;
    font-weight: bold;
    margin: 4px 2px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button.active {
    background-color: var(--secondary-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    transform: translateY(1px);
}

#steelBtn.active, #ropeBtn.active, #roadBtn.active {
    transform: translateY(2px);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

#steelBtn.active {
    background-color: #2563eb;
}

#ropeBtn.active {
    background-color: #f59e0b;
}

#roadBtn.active {
    background-color: #343a40;
}

#steelBtn, #ropeBtn, #roadBtn {
    position: relative;
    padding: 15px 25px;
    font-size: 18px;
    min-width: 180px;
    text-align: left;
    border-left: 8px solid;
    transition: all 0.3s;
}

#steelBtn {
    background-color: #3a86ff;
    border-left-color: #1d3557;
}

#ropeBtn {
    background-color: #ffbe0b;
    border-left-color: #fb8500;
    color: #333;
}

#roadBtn {
    background-color: #495057;
    border-left-color: #212529;
}

#steelBtn::before, #ropeBtn::before, #roadBtn::before {
    content: "";
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 6px;
    border-radius: 3px;
}

#steelBtn::before {
    background-color: #3a86ff;
    box-shadow: 0 0 0 2px #1d3557;
}

#ropeBtn::before {
    background-color: #ffbe0b;
    box-shadow: 0 0 0 2px #fb8500;
    border-top: 2px dashed #fb8500;
}

#roadBtn::before {
    background-color: #495057;
    box-shadow: 0 0 0 2px #212529;
    height: 10px;
}

.primary-btn {
    background-color: var(--primary-color);
}

.danger-btn {
    background-color: var(--danger-color);
}

.info-btn {
    background-color: var(--info-color);
}

.warning-btn {
    background-color: var(--warning-color);
}

.level-selector {
    margin-top: 20px;
    padding: 15px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.level-selector h3 {
    margin-bottom: 10px;
    color: var(--secondary-color);
    text-align: center;
}

#level-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.level-btn {
    background-color: var(--light-color);
    color: var(--dark-color);
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    font-weight: bold;
}

.level-btn.active {
    background-color: var(--accent-color);
    color: white;
}

.level-btn.completed {
    background-color: var(--success-color);
    color: white;
}

.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border: none;
    width: 80%;
    max-width: 600px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.4s ease-out;
}

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

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
}

.modal-content ul {
    margin-left: 20px;
    margin-bottom: 20px;
}

.modal-content li {
    margin-bottom: 10px;
    line-height: 1.5;
}

.modal-content button {
    display: block;
    margin: 20px auto 0;
    min-width: 150px;
}

.celebration {
    text-align: center;
}

.stars {
    color: var(--warning-color);
    font-size: 40px;
    margin: 20px 0;
    animation: starPulse 1.5s infinite alternate;
}

@keyframes starPulse {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}

.budget-remaining {
    margin: 15px 0;
    font-size: 18px;
}

#remaining-budget {
    color: var(--accent-color);
    font-weight: bold;
}

/* Tutorial overlay */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.tutorial-content {
    background-color: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.5s ease-out;
}

.tutorial-content h2 {
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 20px;
}

.tutorial-step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 15px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.tutorial-number {
    background-color: var(--primary-color);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    margin-right: 15px;
    flex-shrink: 0;
}

.tutorial-step p {
    margin: 0;
    line-height: 1.5;
}

#close-tutorial {
    display: block;
    margin: 25px auto 0;
    min-width: 150px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .game-container {
        padding: 15px;
        width: 100%;
        border-radius: 0;
    }

    canvas {
        width: 100%;
        height: auto;
    }

    .game-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .material-selection, .action-buttons {
        justify-content: center;
    }

    .modal-content {
        width: 95%;
        margin: 20% auto;
        padding: 20px;
    }
}
