:root {
    --primary-color: #4CAF50;
    /* Green */
    --secondary-color: #FF9800;
    /* Orange */
    --bg-color: #E0F7FA;
    /* Light Blue */
    --text-color: #333;
    --card-bg: rgba(255, 255, 255, 0.8);
    --grid-bg: rgba(255, 255, 255, 0.9);
    --grid-line: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    perspective: 1000px;
}

h1,
h2,
h3 {
    font-family: 'Fredoka One', cursive;
    margin: 0;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

/* Screens */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.hidden {
    display: none !important;
}

/* Landing Screen */
#landing-screen h1 {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-20px);
    }

    100% {
        transform: translateY(0px);
    }
}

.mode-selection {
    display: flex;
    gap: 3rem;
    margin-top: 2rem;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.18);
    cursor: pointer;
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
    width: 220px;
}

.card:hover {
    transform: translateY(-10px) scale(1.05);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}

.card .icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* Game Screen */
#game-screen header {
    width: 100%;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.back-btn {
    background: #fff;
    border: 2px solid #ccc;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.back-btn:hover {
    background: #f0f0f0;
    transform: scale(1.05);
}

#instruction-box {
    background: #FFF3E0;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    border: 2px solid var(--secondary-color);
    font-weight: bold;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

main {
    display: flex;
    flex: 1;
    width: 100%;
    padding: 2rem;
    gap: 3rem;
    box-sizing: border-box;
    overflow: hidden;
    align-items: center;
}

/* 3D Scene */
#scene-3d {
    flex: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1200px;
    height: 100%;
}

/* Grid */
#grid-container {
    background: var(--grid-bg);
    border-radius: 15px;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.3),
        0 0 0 10px rgba(255, 255, 255, 0.5);
    /* Rim */
    display: grid;
    /* grid-template-columns set by JS */
    padding: 15px;
    gap: 5px;
    max-height: 70vh;
    aspect-ratio: 1;
    transform: rotateX(20deg) rotateY(0deg);
    /* The 3D Tilt */
    transform-style: preserve-3d;
    transition: transform 0.5s;
    position: relative;
    /* Anchor for absolute turtle */
}

.cell {
    background: #f9f9f9;
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    position: relative;
    transform-style: preserve-3d;
}

/* Objects */
.rock {
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.4));
    transform: translateZ(20px);
}

.flag {
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.4));
    transform: translateZ(20px);
    animation: wave 1s infinite alternate;
}

@keyframes wave {
    from {
        transform: translateZ(20px) rotate(0deg);
    }

    to {
        transform: translateZ(20px) rotate(10deg);
    }
}

/* Turtle */
.turtle {
    position: absolute;
    z-index: 50;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.3));
    transform-origin: center center;
    width: var(--cell-size, 50px);
    /* Will be set by JS or calculated */
    height: var(--cell-size, 50px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    /* Let clicks pass through to grid */
    transition: none;
    /* GSAP handles this */
}

/* 
   Turtle Orientation Logic:
   Standard 🐢 faces LEFT.
   We want "East" (Right) to be the default forward direction visually?
   Or just make it match the direction.
   
   If dir = 0 (North/Up): Rotate 90deg clockwise from Left? No.
   Let's define transforms based on the emoji facing LEFT.
*/

/* 
   FIX: The user wants the turtle to look to the RIGHT (East) by default.
   If the emoji faces Left, we scaleX(-1) to face Right.
*/

.turtle-sprite {
    display: block;
    font-size: 2.5rem;
    /* 
       User wants default to look RIGHT. 
       Standard Turtle 🐢 looks LEFT.
       So we flip it horizontally.
    */
    transform: scaleX(-1);
}

/* Controls */
#controls-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
    display: flex;
    flex-direction: column;
    height: 80%;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.control-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Level 0 Tools */
.toolbox {
    display: flex;
    gap: 15px;
    margin-bottom: 1.5rem;
}

.tool-btn {
    background: linear-gradient(to bottom, #E1F5FE, #B3E5FC);
    border: none;
    box-shadow: 0 4px 0 #0288D1;
    color: #01579B;
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    flex: 1;
    transition: all 0.1s;
    font-size: 1.2rem;
}

.tool-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #0288D1;
}

#sequence-bar {
    background: rgba(0, 0, 0, 0.05);
    border: 2px dashed #ccc;
    border-radius: 12px;
    padding: 15px;
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-content: flex-start;
    overflow-y: auto;
    max-height: 250px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
}

.seq-block {
    background: #FFF9C4;
    border-bottom: 3px solid #FBC02D;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

    to {
        transform: scale(1);
    }
}

/* Level 1 Editor */
.editor-wrapper {
    display: flex;
    border: 2px solid #ccc;
    border-radius: 12px;
    height: 350px;
    font-family: 'Fira Code', monospace;
    background: #fff;
    overflow: hidden;
}

.line-numbers {
    background: #f5f5f5;
    padding: 15px 10px;
    text-align: right;
    color: #aaa;
    border-right: 1px solid #eee;
    user-select: none;
    line-height: 1.5;
    font-size: 1rem;
}

#code-editor {
    border: none;
    padding: 15px;
    flex: 1;
    resize: none;
    outline: none;
    font-family: 'Fira Code', monospace;
    font-size: 1rem;
    line-height: 1.5;
    color: #333;
}

.help-text {
    font-size: 0.9rem;
    color: #555;
    margin-top: 10px;
    font-style: italic;
}

/* Actions */
.actions {
    margin-top: auto;
    display: flex;
    gap: 15px;
    padding-top: 1.5rem;
}

.action-btn {
    flex: 1;
    padding: 18px;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    transition: transform 0.1s, filter 0.2s;
    color: white;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.clear {
    background: linear-gradient(to bottom, #FFCCBC, #FFAB91);
    box-shadow: 0 4px 0 #D84315;
    color: #D84315;
}

.run {
    background: linear-gradient(to bottom, #C8E6C9, #81C784);
    box-shadow: 0 4px 0 #388E3C;
    color: #1B5E20;
}

.action-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

/* Status Bar */
#status-bar {
    background: rgba(51, 51, 51, 0.9);
    backdrop-filter: blur(5px);
    color: #fff;
    padding: 12px;
    text-align: center;
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 1px;
}