:root {
    --primary-color: #56CCF2;
    /* Light Sky Blue */
    --secondary-color: #2F80ED;
    /* Darker Blue */
    --accent-color: #FFE66D;
    --dark-bg: #2C3E50;
    --light-bg: #F7F9FC;
    --text-color: #2C3E50;
    --card-bg: #FFFFFF;
    --font-heading: 'Fredoka One', cursive;
    --font-body: 'Nunito', sans-serif;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--light-bg);
    color: var(--text-color);
    min-height: 100vh;
    /* Use min-height */
    overflow-y: auto;
    /* Allow scrolling */
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Use min-height */
    padding: 1rem;
    gap: 1rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.logo {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px var(--dark-bg);
}

.level-indicator {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    background: var(--accent-color);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    color: var(--dark-bg);
}

main {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-height: 0;
    /* Important for nested flex scrolling */
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.left-panel {
    flex: 0 0 40%;
}

.instructions-card {
    background: #E8F8F5;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 5px solid var(--primary-color);
}

.instructions-card h3 {
    font-family: var(--font-heading);
    color: var(--dark-bg);
    margin-bottom: 0.5rem;
}

.editor-container {
    flex: 1;
    border: 2px solid #ddd;
    border-radius: 0.5rem;
    overflow: hidden;
}

.CodeMirror {
    height: 100% !important;
    font-size: 16px;
}

.controls {
    display: flex;
    gap: 1rem;
}

.btn {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    flex: 1;
}

.btn:active {
    transform: translateY(2px);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 0 #3BAFDA;
    /* Darker shade of #56CCF2 */
}

.btn-primary:active {
    box-shadow: 0 2px 0 #3BAFDA;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 0 #1D6FA5;
    /* Darker shade of #2F80ED */
}

.btn-secondary:active {
    box-shadow: 0 2px 0 #1D6FA5;
}

.btn-success {
    background-color: #2ECC71;
    color: white;
    box-shadow: 0 4px 0 #27ae60;
}

.right-panel {
    background: #34495E;
    /* Dark background for canvas area */
    justify-content: center;
    align-items: center;
    position: relative;
    flex: 1;
    /* Grow to fill space */
    display: flex;
    min-height: 0;
    /* Important for flex child */
}

.canvas-wrapper {
    position: relative;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#alpaca-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Keep aspect ratio or cover */
}

#alpaca-sprite {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    pointer-events: none;
    transition: all 0.3s ease;
    /* Smooth movement */
    width: 40px;
    /* Default size matching font-size approx */
    height: 40px;
}

#turtle-sprite img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#console-output {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.8);
    color: #0f0;
    font-family: monospace;
    padding: 0.5rem;
    border-radius: 0.5rem;
    max-height: 100px;
    overflow-y: auto;
    display: none;
    /* Show only if there's output/error */
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 900px;
    /* Larger max width */
    width: 90%;
    /* Responsive width */
    max-height: 90vh;
    /* Prevent overflow */
    overflow-y: auto;
}

.modal-content h2 {
    font-family: var(--font-heading);
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Shop Styles */
.shop-tabs .tab-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    cursor: pointer;
    color: #95a5a6;
    border-bottom: 3px solid transparent;
}

.shop-tabs .tab-btn.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
}

.shop-item {
    border: 2px solid #eee;
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    transition: transform 0.2s;
    position: relative;
}

.shop-item:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
}

.shop-item .icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.shop-item .name {
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.shop-item .cost {
    background: #f1c40f;
    color: #333;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    display: inline-block;
    margin-bottom: 0.5rem;
}

.shop-item .btn-buy {
    width: 100%;
    padding: 0.5rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.shop-item .btn-equip {
    width: 100%;
    padding: 0.5rem;
    background: #2ecc71;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.shop-item.owned .cost {
    background: #2ecc71;
    color: white;
}

.shop-item.equipped {
    border-color: #2ecc71;
    background: #eafaf1;
}