:root {
    --bg-color: #f0f8ff;
    --primary-color: #4a90e2;
    --secondary-color: #50e3c2;
    --accent-color: #ffca3a;
    --danger-color: #ff5e57;
    --text-color: #333;
    --board-bg: #e0e0e0;
    --cell-bg: #ffffff;
    --cell-border: #cccccc;
    --code-bg: #282c34;
    --code-text: #abb2bf;
    --code-keyword: #c678dd;
    --code-function: #61afef;
    --code-string: #98c379;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 2px solid var(--board-bg);
}

.header-content {
    display: flex;
    flex-direction: column;
}

h1 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 0;
}

.branding {
    font-size: 1rem;
    color: #cc0000; /* CNA Red */
    font-weight: 800;
    margin-top: -2px;
    letter-spacing: 0.5px;
}

.level-indicator {
    background: var(--accent-color);
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 10px;
    overflow-y: auto;
}

/* --- Level Info --- */
.level-info {
    width: 100%;
    background: #fff0f0; /* Slight red tint for branding match */
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 5px solid #cc0000;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.level-info h3 {
    margin: 0;
    color: var(--primary-color);
}

.level-info p {
    margin: 5px 0 0;
    font-size: 0.9rem;
    color: #555;
}

/* --- Tabuleiro --- */
.game-board {
    display: grid;
    gap: 2px;
    background-color: var(--board-bg);
    border: 5px solid var(--primary-color);
    border-radius: 10px;
    margin-bottom: 15px;
    width: 90vw;
    height: 90vw;
    max-width: 350px;
    max-height: 350px;
    position: relative;
}

.cell {
    background-color: var(--cell-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    position: relative;
}

.robot {
    z-index: 10;
    transition: all 0.5s ease;
}

.star {
    animation: pulse 1.5s infinite;
}

.wall {
    background-color: #555;
    border-radius: 4px;
}

/* --- Área de Programação --- */
.program-area {
    width: 100%;
    background: #f9f9f9;
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100px;
    max-height: 300px;
}

.program-area h3 {
    font-size: 1rem;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.command-list {
    flex: 1;
    overflow-y: auto;
    background: var(--code-bg);
    border: 2px solid #ccc;
    border-radius: 8px;
    padding: 10px;
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--code-text);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.empty-msg {
    color: #5c6370;
    font-style: italic;
    font-size: 0.9rem;
}

/* Code Lines */
.code-line {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid #3e4451;
    padding-bottom: 4px;
    cursor: pointer;
}

.code-line:last-child {
    border-bottom: none;
}

.code-line:hover {
    background: rgba(255,255,255,0.05);
}

.code-text {
    font-size: 1rem;
}

.code-keyword { color: var(--code-keyword); }
.code-func { color: var(--code-function); }
.code-paren { color: #abb2bf; }

.code-translation {
    font-size: 0.75rem;
    color: #98c379; /* Greenish for comments/translation */
    margin-top: 2px;
    font-family: 'Nunito', sans-serif;
    font-style: italic;
}

.code-line.active {
    background: rgba(97, 175, 239, 0.2);
    border-left: 3px solid var(--code-function);
    padding-left: 5px;
}

/* --- Controles --- */
.controls {
    width: 100%;
    padding-bottom: 10px;
}

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

/* Grid layout for arrow buttons */
.grid-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 10px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto 10px auto;
}

@media (max-width: 400px) {
    .grid-controls {
        gap: 5px;
    }
    .btn-cmd {
        font-size: 0.8rem;
        padding: 5px;
        height: 60px;
    }
}

/* 
  Layout:
  . . Up . .
  Left Down Right
*/
.btn-cmd:nth-child(1) { grid-column: 2; grid-row: 1; } /* Up */
.btn-cmd:nth-child(2) { grid-column: 1; grid-row: 2; } /* Left */
.btn-cmd:nth-child(3) { grid-column: 2; grid-row: 2; } /* Down */
.btn-cmd:nth-child(4) { grid-column: 3; grid-row: 2; } /* Right */


.btn-cmd {
    padding: 10px 5px;
    border: none;
    border-radius: 10px;
    font-family: 'Fredoka One', cursive;
    font-size: 0.9rem;
    cursor: pointer;
    background: white;
    border-bottom: 4px solid #ddd;
    transition: transform 0.1s;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 70px;
}

.btn-cmd:active {
    transform: translateY(4px);
    border-bottom: 0;
}

.btn-cmd svg {
    margin-bottom: 2px;
}

/* Cores específicas para botões */
.btn-cmd:nth-child(1) { background: #e3f2fd; border-color: #bbdefb; } /* Up */
.btn-cmd:nth-child(2) { background: #e0f2f1; border-color: #b2dfdb; } /* Left */
.btn-cmd:nth-child(3) { background: #ffebee; border-color: #ffcdd2; } /* Down */
.btn-cmd:nth-child(4) { background: #fff8e1; border-color: #ffecb3; } /* Right */

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

.btn-run {
    flex: 2;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #2a70c2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn-run:disabled {
    background-color: #ccc;
    box-shadow: none;
    cursor: not-allowed;
}

.btn-reset {
    flex: 1;
    background-color: var(--danger-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #d1403b;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    animation: popIn 0.5s;
}

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.modal-content button {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 1.2rem;
    background: var(--accent-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

/* --- Animations --- */
@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    80% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); }
}

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