/* ========== GLOBAL STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3498DB;
    --primary-dark: #2980B9;
    --success: #27AE60;
    --success-light: #2ECC71;
    --danger: #E74C3C;
    --warning: #F39C12;
    --purple: #9B59B6;
    --dark: #2C3E50;
    --darker: #1a252f;
    --light: #ECF0F1;
    --white: #FFFFFF;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Comic Sans MS', 'Arial Rounded MT Bold', 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, #1a2332 0%, #2C3E50 100%);
    min-height: 100vh;
    color: var(--dark);
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* ========== SPLASH SCREEN ========== */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a2332 0%, #2C3E50 50%, #1a2332 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.splash-content {
    text-align: center;
    animation: fadeIn 1s ease-in;
}

.splash-logo {
    max-width: 300px;
    max-height: 200px;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 20px rgba(52, 152, 219, 0.5));
}

.tagline {
    font-size: 24px;
    color: var(--light);
    font-weight: bold;
    padding: 20px;
    background: rgba(52, 152, 219, 0.3);
    border-radius: 10px;
    margin: 20px;
}

.loading {
    color: var(--primary);
    font-size: 16px;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.modal-content {
    background: var(--white);
    border-radius: 15px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    color: var(--dark);
    margin-bottom: 20px;
    text-align: center;
}

.student-list {
    max-height: 300px;
    overflow-y: auto;
    border: 2px solid var(--primary);
    border-radius: 10px;
    margin-bottom: 20px;
}

.student-item {
    padding: 15px;
    border-bottom: 1px solid #E5E8E8;
    cursor: pointer;
    transition: all 0.2s;
}

.student-item:hover {
    background: #ABEBC6;
}

.student-item.selected {
    background: var(--primary);
    color: white;
}

.student-item h4 {
    margin-bottom: 5px;
}

.student-item p {
    font-size: 14px;
    opacity: 0.8;
}

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--dark);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #BDC3C7;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ========== BUTTONS ========== */
.btn-primary {
    background: var(--success);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary:hover:not(:disabled) {
    background: var(--success-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.4);
}

.btn-primary:disabled {
    background: #95A5A6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-danger:hover:not(:disabled) {
    background: #C0392B;
    transform: translateY(-2px);
}

.btn-large {
    padding: 15px 30px;
    font-size: 16px;
}

.student-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* ========== APP CONTAINER ========== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== HEADER ========== */
.app-header {
    background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary);
}

.current-student {
    color: var(--light);
    font-size: 14px;
}

.header-nav {
    display: flex;
    gap: 10px;
}

.nav-btn {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--light);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s;
}

.nav-btn:hover, .nav-btn.active {
    background: var(--primary);
    color: white;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.score {
    color: #F1C40F;
    font-weight: bold;
    font-size: 16px;
}

.energy-bar {
    display: flex;
    align-items: center;
    gap: 5px;
}

.energy-fill {
    width: 100px;
    height: 20px;
    background: #34495E;
    border-radius: 10px;
    overflow: hidden;
}

.energy-fill div {
    height: 100%;
    background: linear-gradient(90deg, var(--success) 0%, var(--success-light) 100%);
    transition: width 0.3s;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.view {
    display: none;
    height: 100%;
}

.view.active {
    display: block;
}

/* ========== COMMAND HUB ========== */
.hub-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 140px);
}

.phase-panel {
    width: 280px;
    background: linear-gradient(180deg, var(--dark) 0%, var(--darker) 100%);
    border-radius: 15px;
    padding: 20px;
    border: 2px solid #34495E;
}

.phase-panel h3 {
    color: var(--light);
    text-align: center;
    margin-bottom: 20px;
}

.phase-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.phase-item {
    padding: 15px;
    border-radius: 10px;
    color: var(--light);
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.1);
}

.phase-item:hover:not(.locked) {
    background: var(--primary);
}

.phase-item.selected {
    background: var(--primary);
    font-weight: bold;
}

.phase-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.mission-panel {
    flex: 1;
    background: linear-gradient(180deg, var(--light) 0%, #D5DBDB 100%);
    border-radius: 15px;
    padding: 20px;
    border: 2px solid #BDC3C7;
    display: flex;
    flex-direction: column;
}

.mission-panel h3 {
    color: var(--dark);
    text-align: center;
    margin-bottom: 10px;
}

.completion-status {
    text-align: center;
    padding: 10px;
    background: rgba(39, 174, 96, 0.1);
    border-radius: 8px;
    margin-bottom: 15px;
    color: var(--success);
    font-weight: bold;
}

.mission-list {
    flex: 1;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    padding: 10px;
    border: 1px solid #BDC3C7;
}

.mission-item {
    padding: 15px;
    border-bottom: 1px solid #E5E8E8;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
}

.mission-item:hover {
    background: #ABEBC6;
}

.mission-item.selected {
    background: #58D68D;
    color: #145A32;
    font-weight: bold;
}

.mission-item.completed {
    background: rgba(39, 174, 96, 0.2);
}

.mission-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #BDC3C7;
}

/* ========== CODE EDITOR ========== */
.code-editor {
    border: 2px solid var(--primary);
    border-radius: 10px;
    overflow: hidden;
}

.code-editor .monaco-editor {
    height: 100%;
}

.monaco-editor {
    border-radius: 8px;
}

/* ========== SANDBOX VIEW ========== */
.sandbox-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 140px);
}

.editor-panel {
    flex: 1.5;
    display: flex;
    flex-direction: column;
    background: var(--white);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px var(--shadow);
}

.panel-header {
    margin-bottom: 15px;
}

.panel-header h3 {
    color: var(--dark);
    font-size: 24px;
}

.panel-header p {
    color: #7f8c8d;
    font-size: 14px;
}

#sandbox-editor {
    flex: 1;
    min-height: 300px;
}

.editor-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.output-panel {
    flex: 1;
    background: var(--dark);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.output-panel h3 {
    color: var(--light);
    margin-bottom: 15px;
}

.output-console {
    flex: 1;
    background: #2C3E50;
    color: #00FF00;
    padding: 15px;
    border-radius: 10px;
    font-family: 'Consolas', monospace;
    font-size: 14px;
    overflow-y: auto;
    white-space: pre-wrap;
    border: 2px solid #34495E;
}

.output-console.error {
    color: var(--danger);
}

/* ========== TERMINAL VIEW ========== */
.terminal-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 140px);
}

.terminal-left {
    flex: 1;
    background: linear-gradient(135deg, #32CD32 0%, #7FFF33 100%);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.mission-info {
    margin-bottom: 15px;
}

.mission-info h3 {
    color: #FF6B35;
    font-size: 20px;
}

#terminal-editor {
    flex: 1;
    min-height: 275px;
    margin-bottom: 15px;
}

.terminal-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.terminal-output {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #FF6B35;
    border-radius: 8px;
    padding: 15px;
    min-height: 100px;
    max-height: 150px;
    overflow-y: auto;
    font-family: 'Consolas', monospace;
    font-size: 14px;
}

.terminal-center {
    width: 250px;
    background: linear-gradient(135deg, #0f141b 0%, #1a2332 50%, #0f141b 100%);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    border: 1px solid #223040;
}

.terminal-right-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.terminal-right {
    width: 430px;
    height: 340px;
    background: linear-gradient(135deg, #0f141b 0%, #1a2332 50%, #0f141b 100%);
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    border: 1px solid #223040;
    gap: 15px;
}

.terminal-output {
    width: 430px;
    min-height: 250px;
    max-height: 350px;
}

.instructions-box {
    background: linear-gradient(135deg, #0f141b 0%, #1a2332 50%, #0f141b 100%);
    border: 2px solid #223040;
    border-radius: 8px;
    padding: 12px;
    color: #6cf3ff;
    font-family: 'Comic Sans MS', Arial, sans-serif;
    font-size: 14px;
    font-weight: bold;
    width: 200px;
    height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.waibot-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px;
}

.waibot-label {
    color: var(--light);
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
}

.waibot-display {
    width: 200px;
    height: 300px;
    background: #2C3E50;
    border: 3px solid #34495E;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

#waibot-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.waibot-display.neutral { background: linear-gradient(180deg, #3498DB 0%, #2980B9 100%); }
.waibot-display.displeasure { background: linear-gradient(180deg, #F39C12 0%, #E67E22 100%); }
.waibot-display.anger { background: linear-gradient(180deg, #E74C3C 0%, #C0392B 100%); }
.waibot-display.smug { background: linear-gradient(180deg, #9B59B6 0%, #8E44AD 100%); }

/* ========== TRAINING GROUND ========== */
.training-container {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.training-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--white);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px var(--shadow);
}

#training-editor {
    flex: 1;
    min-height: 350px;
    max-height: 400px;
    margin-bottom: 15px;
}

.training-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.training-settings {
    display: flex;
    gap: 15px;
    align-items: center;
    padding: 15px;
    background: var(--light);
    border-radius: 8px;
}

.training-settings label {
    font-weight: bold;
}

.training-settings select {
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #BDC3C7;
}

.training-settings input[type="range"] {
    width: 100px;
}

.training-right {
    width: 700px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.telemetry-bar {
    background: #34495E;
    border-radius: 8px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-around;
    color: #00FF00;
    font-family: 'Consolas', monospace;
    font-weight: bold;
    font-size: 14px;
}

.sensor-display {
    background: #2C3E50;
    color: var(--danger);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
}

.training-status {
    background: var(--success);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
}

.training-status.success {
    background: var(--success);
    font-size: 18px;
}

.training-status.running {
    background: var(--warning);
}

#simulation-canvas {
    background: #ECF0F1;
    border: 3px solid #BDC3C7;
    border-radius: 10px;
    max-width: 100%;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
    .hub-container,
    .sandbox-container,
    .terminal-container,
    .training-container {
        flex-direction: column;
        height: auto;
    }
    
    .phase-panel,
    .terminal-center,
    .terminal-right,
    .training-right {
        width: 100%;
    }
    
    .header-nav {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ========== ANIMATIONS ========== */
.waibot-emoji.neutral::after { content: "🤖"; }
.waibot-emoji.displeasure::after { content: "😤"; }
.waibot-emoji.anger::after { content: "😠"; }
.waibot-emoji.smug::after { content: "😏"; }

.success-animation {
    animation: successPulse 0.5s ease-in-out 3;
}

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

/* ========== CONSOLE TOOLBAR & XTERM ========== */
.terminal-console-wrapper {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.console-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #1a2332 0%, #2C3E50 100%);
    border-radius: 8px 8px 0 0;
    border: 2px solid #34495E;
    border-bottom: none;
}

.output-panel .console-toolbar {
    background: transparent;
    border: none;
    padding: 0 0 10px 0;
    border-radius: 0;
    justify-content: space-between;
}

.output-panel .console-toolbar h3 {
    margin: 0;
}

.toolbar-actions {
    display: flex;
    gap: 5px;
}

.console-btn {
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid var(--primary);
    color: var(--light);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.console-btn:hover {
    background: var(--primary);
    color: white;
}

.console-status {
    color: #00FF00;
    font-size: 12px;
    font-weight: bold;
    margin-left: auto;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* XTerm terminal styling */
.terminal-output {
    background: #0d1117;
    border: 2px solid #FF6B35;
    border-radius: 0 0 8px 8px;
    padding: 0;
    min-height: 250px;
    max-height: 350px;
    overflow: hidden;
}

.terminal-output .xterm {
    padding: 10px;
}

.output-console {
    flex: 1;
    background: #0d1117;
    color: #00FF00;
    padding: 0;
    border-radius: 0 0 10px 10px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
    overflow: hidden;
    border: 2px solid #34495E;
}

.output-console .xterm {
    padding: 15px;
}

/* Input prompt for interactive input */
.input-prompt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: linear-gradient(135deg, #1a2332 0%, #2C3E50 100%);
    border: 2px solid #FF6B35;
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.input-prompt.hidden {
    display: none;
}

.input-label {
    color: var(--primary);
    font-weight: bold;
    font-size: 14px;
}

.console-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--primary);
    border-radius: 5px;
    padding: 8px 12px;
    color: var(--light);
    font-family: 'Consolas', monospace;
    font-size: 14px;
}

.console-input:focus {
    outline: none;
    border-color: var(--success);
    box-shadow: 0 0 10px rgba(39, 174, 96, 0.3);
}

/* Error decoration in Monaco */
.monaco-editor .squiggly-error {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' enable-background='new 0 0 6 3' height='3' width='6'%3E%3Cg fill='%23E74C3C'%3E%3Cellipse cx='2.5' cy='1.5' rx='2' ry='1'/%3E%3Cellipse cx='5.5' cy='1.5' rx='2' ry='1'/%3E%3C/g%3E%3C/svg%3E") repeat-x bottom left;
}

/* Error line highlight */
.error-line {
    background-color: rgba(231, 76, 60, 0.15) !important;
}

/* Editor decorations */
.monaco-editor .margin-view-overlays .error-glyph {
    background-color: var(--danger);
    border-radius: 50%;
    width: 8px;
    height: 8px;
    margin: 6px;
}

/* XTerm cursor styles */
.xterm .xterm-viewport {
    scrollbar-width: thin;
    scrollbar-color: var(--primary) #1a2332;
    overflow-x: hidden !important;
}

.xterm .xterm-screen {
    overflow-x: hidden !important;
}

.xterm {
    overflow-x: hidden !important;
}

.xterm .xterm-viewport::-webkit-scrollbar {
    width: 8px;
}

.xterm .xterm-viewport::-webkit-scrollbar-track {
    background: #1a2332;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ========== ROBOTC OUTPUT STYLES ========== */
.output-normal { color: #00FF00; font-family: 'Consolas', monospace; font-size: 13px; }
.output-info   { color: #3498DB; font-family: 'Consolas', monospace; font-size: 13px; }
.output-success{ color: #2ECC71; font-family: 'Consolas', monospace; font-size: 13px; font-weight: bold; }
.output-error  { color: #E74C3C; font-family: 'Consolas', monospace; font-size: 13px; }

/* Terminal output used by RobotC (div-based, not xterm) */
#terminal-output:not(:has(.xterm)),
#sandbox-output:not(:has(.xterm)) {
    background: #0d1117;
    color: #00FF00;
    font-family: 'Consolas', monospace;
    font-size: 13px;
    padding: 12px;
    overflow-y: auto;
    white-space: pre-wrap;
}
