/* Estilos Generales */
body {
    font-family: 'Nunito', sans-serif;
    background-color: #f0f9ff;
    margin: 0;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 100vh;
    color: #333;
    box-sizing: border-box;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

/* Achievement Notification */
.achievement-notification {
    position: fixed;
    top: -100px;
    /* Start off-screen */
    left: 50%;
    transform: translateX(-50%);
    background-color: #ffd700;
    /* Gold */
    color: #333;
    padding: 10px 25px;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 1000;
    /* On top of everything */
    transition: top 0.5s ease-out, opacity 0.5s ease-out, visibility 0s linear 0.5s;
    /* Delay visibility change */
    opacity: 0;
    visibility: hidden;
    /* Start hidden */
}

.achievement-notification.visible {
    top: 20px;
    /* Slide down */
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
    /* Remove delay when showing */
}

.game-outer-container {
    width: 100%;
    max-width: 850px;
    /* Controls width of centered content */
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}


/* --- Logo --- */
.logo-link {
    display: block;
    width: fit-content;
    margin: 0 auto 10px auto;
}

.app-logo {
    height: 150px;
    width: auto;
    display: block;
}

.main-title {
    font-family: 'Luckiest Guy', cursive;
    color: #0056b3;
    text-align: center;
    font-size: 2.5rem;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.15);
}

/* Container for Difficulty and Options */
.options-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    background-color: #e7f3fe;
    padding: 15px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px solid #b3d7ff;
    width: 100%;
    max-width: 600px;
    box-sizing: border-box;
}

.difficulty-selector {
    text-align: center;
    width: 100%;
}

.difficulty-selector h2,
.advanced-options h2 {
    margin: 0 0 10px 0;
    color: #0056b3;
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
}

.difficulty-selector .button.difficulty-button {
    background-color: #ffffff;
    color: #007bff;
    border: 2px solid #007bff;
    margin: 5px;
    padding: 8px 15px;
    font-size: 1rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.difficulty-selector .button.difficulty-button:hover:not(.active) {
    background-color: #f0f8ff;
    transform: translateY(-1px);
}

.difficulty-selector .button.difficulty-button.active {
    background-color: #007bff;
    color: #ffffff;
    border-color: #0056b3;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
    cursor: default;
}

.advanced-options {
    text-align: center;
    width: 100%;
    border-top: 1px dashed #b3d7ff;
    padding-top: 15px;
}

.advanced-options .option-label {
    display: inline-block;
    margin: 5px 10px;
    font-size: 0.95rem;
    color: #333;
    cursor: pointer;
}

.advanced-options input[type="checkbox"] {
    margin-right: 5px;
    cursor: pointer;
    vertical-align: middle;
}

.advanced-options .option-label sup {
    font-size: 0.8em;
    vertical-align: baseline;
    position: relative;
    top: -0.3em;
}

/* Container for Game Area + Robot */
.game-area-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    max-width: 1100px;
    /* Wider to accommodate robot */
    margin-left: auto;
    margin-right: auto;
    justify-content: center;
}

.game-container {
    background-color: #ffffff;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border: 5px solid #ffd700;
    width: 100%;
    max-width: 800px;
    box-sizing: border-box;
    position: relative;
    margin-top: 10px;
    flex-grow: 1;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

.game-container.fade-out {
    opacity: 0;
}


/* Robot Guide Styles */
.robot-guide {
    width: 150px;
    min-width: 120px;
    margin-top: 120px;
    text-align: center;
    transition: transform 0.3s ease-out;
}

.robot-guide img {
    max-width: 100%;
    height: auto;
    transition: transform 0.3s ease-in-out;
}

.robot-guide.robot-happy img {
    transform: scale(1.05) rotate(5deg);
}

.robot-guide.robot-sad img {
    transform: scale(0.95) rotate(-5deg);
    filter: grayscale(50%);
}

.robot-guide.robot-thinking img {
    transform: scale(1) rotate(0deg) translateY(-5px);
}


/* Quick Rules Reference */
.quick-rules {
    position: absolute;
    top: 55px;
    right: 15px;
    font-size: 0.75rem;
    color: #777;
    background-color: rgba(255, 255, 255, 0.8);
    padding: 3px 6px;
    border-radius: 4px;
    z-index: 5;
    font-family: 'Nunito', sans-serif;
}

/* Sound Toggle Button */
.sound-toggle-button {
    position: absolute;
    top: 15px;
    right: 155px;
    background-color: #6c757d;
    color: white;
    border: 1px solid #5a6268;
    padding: 5px 9px;
    font-size: 0.9rem;
    z-index: 10;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sound-toggle-button:hover {
    background-color: #5a6268;
}

.sound-toggle-button i {
    line-height: 1;
}

/* Rules Toggle Button */
.rules-toggle-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background-color: #ffc107;
    color: #333;
    border: 1px solid #e0a800;
    padding: 5px 10px;
    font-size: 0.85rem;
    z-index: 10;
}

.rules-toggle-button:hover {
    background-color: #e0a800;
}

/* Rules Box Styling */
.rules-box {
    background-color: #e0f7fa;
    border: 2px dashed #4dd0e1;
    border-radius: 10px;
    padding: 20px 15px 15px 15px;
    margin-bottom: 20px;
    overflow: hidden;
    transition: max-height 0.5s ease-in-out, padding 0.5s ease-in-out, margin 0.5s ease-in-out, border-width 0.5s ease-in-out;
    max-height: 500px;
}

.rules-box.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-width: 0;
    overflow: hidden;
}

.rules-box h2 {
    color: #00796b;
    margin: 0 0 15px 0;
    font-size: 1.3rem;
    text-align: center;
    font-weight: 700;
}

.rules-box ol {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.rules-box li {
    margin-bottom: 10px;
    position: relative;
    padding-left: 35px;
    font-size: 1rem;
    line-height: 1.5;
}

.rules-box li .rule-step {
    position: absolute;
    left: 0;
    top: 0;
    background-color: #ffcc80;
    color: #e65100;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-weight: bold;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
}

.rules-box .highlight-parentheses {
    font-weight: bold;
    color: #d81b60;
}

.rules-box .highlight-exponent {
    font-weight: bold;
    color: #ff6f00;
}

.rules-box .highlight-multdiv {
    font-weight: bold;
    color: #009688;
}

.rules-box .highlight-addsub {
    font-weight: bold;
    color: #673ab7;
}

.rules-box .highlight-instruccion {
    font-weight: bold;
    color: #e0a800;
}

.rules-box sup {
    font-size: 0.8em;
    vertical-align: baseline;
    position: relative;
    top: -0.3em;
}

/* General Progress Styles */
.general-progress-container {
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.general-progress-container h3 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    color: #555;
    text-align: center;
    font-weight: normal;
}

.general-progress-bar {
    width: 100%;
    background-color: #e9ecef;
    border-radius: 5px;
    height: 18px;
    overflow: hidden;
    position: relative;
}

.general-progress-fill {
    width: 0%;
    height: 100%;
    background-color: #28a745;
    border-radius: 5px;
    transition: width 0.5s ease-out;
}

#general-progress-text {
    display: block;
    text-align: center;
    margin-top: 5px;
    font-size: 0.9rem;
    font-weight: bold;
    color: #495057;
}

/* Operation Indicator */
.operation-indicator {
    text-align: center;
    font-weight: bold;
    color: #0077cc;
    margin-bottom: 20px;
    font-size: 1.1rem;
    background-color: #f8f9fa;
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #dee2e6;
    display: inline-block;
}

#current-difficulty-display {
    font-style: italic;
    color: #555;
    font-weight: normal;
}

#options-display {
    font-size: 0.9em;
    color: #777;
    font-weight: normal;
    margin-left: 5px;
}

/* Operation Container */
.operation-container {
    background-color: #f1f8e9;
    padding: 20px;
    border-radius: 10px;
    border: 3px solid #aed581;
    margin-bottom: 25px;
}

.operation-expression {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.9rem;
    font-weight: bold;
    text-align: center;
    color: #33691e;
    margin-bottom: 25px;
    padding: 12px 18px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px dashed #c5e1a5;
    word-wrap: break-word;
    min-height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1.4;
}

.operation-expression sup {
    font-size: 0.65em;
    position: relative;
    top: -0.6em;
    line-height: 0;
    margin-left: 1px;
}

.highlight-op {
    background-color: #fff59d;
    padding: 0px 4px;
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(255, 235, 59, 0.5);
    font-weight: bold;
    display: inline-block;
}

.highlight-op sup {
    position: relative;
    top: -0.6em;
    font-size: 0.65em;
}

/* Step Area */
.step-area {
    margin-bottom: 5px;
}

.step-area h3 {
    color: #0077cc;
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.step-input-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.step-input {
    padding: 10px 12px;
    border: 2px solid #81d4fa;
    border-radius: 8px;
    font-size: 1.3rem;
    font-family: 'Courier New', Courier, monospace;
    flex-grow: 1;
    min-width: 150px;
}

.step-input:focus {
    outline: none;
    border-color: #0077cc;
    box-shadow: 0 0 5px rgba(0, 119, 204, 0.5);
}

.step-input::placeholder {
    font-size: 0.9rem;
    font-weight: normal;
    color: #999;
    font-family: 'Nunito', sans-serif;
}

/* Operator Keypad */
.operator-keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 15px;
    margin-bottom: 10px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.keypad-button {
    padding: 12px 5px;
    font-size: 1.2rem;
    font-weight: bold;
    border: 1px solid #ccc;
    border-radius: 6px;
    background-color: #f9f9f9;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-family: 'Nunito', sans-serif;
    text-align: center;
    color: #333;
    min-height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.keypad-button:hover {
    background-color: #e0e0e0;
}

.keypad-button:active {
    background-color: #c5c5c5;
    transform: translateY(1px);
}

.keypad-button.keypad-action {
    background-color: #ffecb3;
}

.keypad-button.keypad-action:hover {
    background-color: #ffe082;
}

.keypad-button.keypad-action i {
    font-size: 1.1rem;
}

.keypad-button.keypad-wide {
    grid-column: span 2;
}

/* General Button Styles */
.button {
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
    font-size: 1rem;
    white-space: nowrap;
    font-family: 'Nunito', sans-serif;
}

.button:active:not(:disabled) {
    transform: translateY(1px);
}

.button:disabled {
    background-color: #cccccc !important;
    color: #666666 !important;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.check-button {
    background-color: #4caf50;
    color: white;
}

.check-button:hover:not(:disabled) {
    background-color: #388e3c;
}

.hint-button {
    background-color: transparent;
    color: #0077cc;
    text-decoration: underline;
    padding: 10px 5px;
    border: none;
    font-weight: normal;
}

.hint-button:hover:not(:disabled) {
    color: #00558b;
    background-color: transparent;
}

#explain-error-button {
    color: #c62828;
    margin-left: auto;
    text-decoration: underline;
}

#explain-error-button:hover:not(:disabled) {
    color: #a31515;
}

/* Feedback & Explanation Boxes with Transitions */
.feedback,
.explanation-box,
.completion-message,
#operation-completed-message {
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    font-weight: bold;
    text-align: center;
    border: 1px solid transparent;
    font-size: 1rem;
    transition: opacity 0.4s ease, transform 0.4s ease, max-height 0.4s ease, padding 0.4s ease, margin 0.4s ease, visibility 0s linear 0.4s;
    opacity: 0;
    transform: translateY(10px);
    max-height: 0;
    overflow: hidden;
    visibility: hidden;
}

.feedback.visible,
.explanation-box:not(.hidden),
.completion-message:not(.hidden),
#operation-completed-message:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    max-height: 200px;
    margin-top: 10px;
    padding: 12px;
    visibility: visible;
    transition-delay: 0s;
}

.feedback.hidden,
.explanation-box.hidden,
.completion-message.hidden,
#operation-completed-message.hidden {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    visibility: hidden;
}

.feedback-correct {
    background-color: #c8e6c9;
    color: #2e7d32;
    border-color: #a5d6a7;
}

.feedback-incorrect {
    background-color: #ffcdd2;
    color: #c62828;
    border-color: #ef9a9a;
}

.feedback-info {
    background-color: #bbdefb;
    color: #0d47a1;
    border-color: #90caf9;
}

.feedback-completed {
    background-color: #fff9c4;
    color: #f57f17;
    border-color: #fff59d;
}

.explanation-box {
    background-color: #fffde7;
    color: #795548;
    border-color: #fff59d;
    border-style: dashed;
}

.completion-message {
    background-color: #c8e6c9;
    border: 3px solid #4caf50;
}

#operation-completed-message {
    background-color: #e1f5fe;
    color: #0277bd;
    border-color: #b3e5fc;
}

.feedback sup,
.explanation-box sup {
    font-size: 0.8em;
    vertical-align: super;
    line-height: 0;
}

.explanation-box p {
    margin: 0;
}

.explanation-box strong {
    font-style: normal;
    color: #5d4037;
}

/* Progress Tracker */
.progress-tracker {
    margin-top: 20px;
}

.progress-tracker h3 {
    color: #0077cc;
    margin-bottom: 10px;
    font-size: 1.1rem;
    text-align: center;
}

.progress-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-height: 40px;
}

.progress-step {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #555;
    background-color: #e0e0e0;
    border: 2px solid #bdbdbd;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.progress-step.current {
    border-color: #0077cc;
    color: #0077cc;
    background-color: #e3f2fd;
    transform: scale(1.1);
}

.progress-step.completed {
    background-color: #81c784;
    border-color: #4caf50;
    color: white;
    font-size: 1.2rem;
    transform: scale(1.1);
}

.progress-step.completed i {
    vertical-align: middle;
    line-height: 1;
    font-size: 0.9em;
    /* Adjust star size */
}

/* Navigation Buttons */
.navigation-buttons {
    display: flex;
    justify-content: space-between;
    margin: 25px 0;
}

.nav-button {
    background-color: #64b5f6;
    color: white;
    padding: 10px 20px;
}

.nav-button:hover:not(:disabled) {
    background-color: #2196f3;
}

/* Completion Message */
.completion-message h2 {
    color: #1b5e20;
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.8rem;
    margin: 0 0 15px 0;
}

.completion-message p {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 15px;
}

.completion-message .score {
    font-weight: bold;
    color: #0077cc;
}

.completion-message .final-text {
    font-style: italic;
    color: #555;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* Action Buttons */
.action-button {
    background-color: #ff9800;
    color: white;
    padding: 12px 25px;
    font-size: 1.1rem;
}

.action-button:hover:not(:disabled) {
    background-color: #f57c00;
}

.new-operations-button-container {
    text-align: center;
    margin-top: 20px;
}

/* Footer */
.footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 3px dashed #ffd700;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    width: 100%;
}

.footer-button {
    background-color: #0077cc;
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 20px;
    transition: background-color 0.3s, transform 0.2s;
    display: inline-block;
    font-size: 0.9rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.footer-button:hover {
    background-color: #00558b;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Shake Animation */
@keyframes shake {

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

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

/* Responsive Adjustments */
@media (max-width: 900px) {
    .game-area-container {
        flex-direction: column;
        align-items: center;
        max-width: 800px;
    }

    .robot-guide {
        width: 100px;
        margin-top: 20px;
        order: 2;
    }

    .game-container {
        order: 1;
        max-width: 100%;
    }

    .sound-toggle-button {
        right: auto;
        left: 15px;
    }

    .quick-rules {
        top: 15px;
        left: 55px;
        right: auto;
    }
}

@media (max-width: 400px) {
    .operator-keypad {
        max-width: none;
        gap: 5px;
    }

    .keypad-button {
        min-height: 45px;
        font-size: 1.1rem;
        padding: 10px 3px;
    }

    .main-title {
        font-size: 2rem;
    }

    .step-input {
        font-size: 1.1rem;
    }

    .operation-expression {
        font-size: 1.5rem;
    }
}