:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --primary: #3b82f6;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --font-main: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.main-header {
    height: 60px;
    /* Reduced from 70px */
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    /* Reduced padding */
    z-index: 10;
}

.logo h1 {
    font-size: 1.3rem;
    /* Reduced from 1.5rem */
    font-weight: 800;
    letter-spacing: -0.5px;
}

.highlight {
    color: var(--accent);
}

.level-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    /* Reduced gap */
    background: rgba(15, 23, 42, 0.5);
    padding: 0.4rem 0.8rem;
    /* Reduced padding */
    border-radius: 99px;
    border: 1px solid var(--border);
}

.level-badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    /* Reduced */
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

.mission-text {
    font-weight: 600;
    font-size: 0.9rem;
    /* Added size */
    color: var(--accent);
}

/* Stats Bar */
.stats-bar {
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
    /* Reduced from 0.75rem 2rem */
    display: flex;
    align-items: center;
    gap: 1.5rem;
    /* Reduced */
    backdrop-filter: blur(10px);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent);
    min-width: 60px;
    text-align: right;
}


/* Layout */
#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.workspace-container {
    flex: 1;
    display: flex;
    min-height: 0;
    /* Important: allows flex children to shrink */
    height: calc(100vh - 150px);
    /* 60px header + 40px stats + 50px margin */
}

/* Game Panel (Left) */
.game-panel {
    flex: 0 0 min(400px, 30vw);
    /* Responsive width */
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
    overflow-y: auto;
    /* Allow scroll if needed */
}

.game-window {
    width: 100%;
    aspect-ratio: 1;
    max-height: min(350px, 40vh);
    /* Limit height */
    background: #020617;
    border-radius: 16px;
    border: 2px solid var(--border);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    /* Don't shrink the game window */
}

.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    width: 100%;
    height: 100%;
}

.cell {
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.character {
    position: absolute;
    width: 20%;
    /* 1/5 of grid */
    height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.5));
}

/* Direction Arrow */
.character::after {
    content: '➤';
    position: absolute;
    font-size: 1rem;
    color: #00f2ff;
    bottom: 5px;
    right: 5px;
    text-shadow: 0 0 5px black;
}

.target {
    position: absolute;
    width: 20%;
    height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    z-index: 5;
    animation: bounce 2s infinite;
}

@keyframes bounce {

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

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

/* Console/Log */
.console-panel {
    flex: 1;
    min-height: 150px;
    /* Minimum height */
    max-height: 250px;
    /* Maximum height */
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.console-header {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    /* Don't shrink header */
}

.log-content {
    padding: 0.75rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--accent);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    /* Allow flex to work */
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    color: white;
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-shrink: 0;
    /* Don't let button shrink */
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--text-main);
}

/* Editor Panel (Right) */
.editor-panel {
    flex: 1;
    position: relative;
    background: #e2e8f0;
    /* Light bg for blockly contrast */
}

.blockly-workspace {
    width: 100%;
    height: 100%;
}

/* Blockly Customization Overrides */
.blocklyToolboxDiv {
    background-color: #f8fafc !important;
    border-right: 1px solid #cbd5e1;
}

.blocklyTreeLabel {
    font-family: var(--font-main) !important;
    font-weight: 600;
    color: #475569;
}

.obstacle {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(239, 68, 68, 0.2);
    /* Red tint */
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(239, 68, 68, 0.5);
    animation: pulse-obstacle 2s infinite;
}

@keyframes pulse-obstacle {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }

    50% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Adjust blockly flyout to look cleaner */
.blocklyFlyoutBackground {
    fill: #f1f5f9 !important;
    fill-opacity: 0.9 !important;
}

/* Success Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: block;
}

.modal-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, var(--bg-panel), #2d3748);
    border: 2px solid var(--accent);
    border-radius: 24px;
    padding: 3rem;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.trophy {
    font-size: 5rem;
    animation: bounce 1s infinite;
    margin-bottom: 1rem;
}

.modal-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(6, 182, 212, 0.5);
}

.modal-message {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-secondary,
.btn-success {
    padding: 1rem 2rem;
    border-radius: 12px;
    border: none;
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #14b8a6);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
}

/* Confetti Animation */
.confetti-container {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent);
    top: -10px;
    animation: confettiFall 3s linear infinite;
}

@keyframes confettiFall {
    to {
        transform: translateY(600px) rotate(360deg);
        opacity: 0;
    }
}