/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* 内存条区域 */
.memory-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.memory-section h3 {
    margin-bottom: 10px;
    color: #4a5568;
    font-size: 1.2em;
}

.memory-container {
    position: relative;
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    padding: 10px;
    overflow-x: auto;
}

.memory-scroll {
    min-width: 100%;
    display: inline-block;
}

.memory-cells {
    display: flex;
    gap: 2px;
    min-height: 30px;
}

.memory-cell {
    width: 30px;
    height: 30px;
    background: #edf2f7;
    border: 1px solid #cbd5e0;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.memory-cell.active {
    background: #4299e1;
    color: white;
    transform: scale(1.1);
}

.memory-pointer {
    position: absolute;
    top: -20px;
    font-size: 16px;
    font-weight: bold;
    color: #e53e3e;
    transition: left 0.3s ease;
}

/* 主内容区域 */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    min-height: 500px;
    height: calc(100vh - 200px);
    max-height: 800px;
}

.editor-section, .maze-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-section h3, .maze-section h3 {
    margin-bottom: 15px;
    color: #4a5568;
    font-size: 1.2em;
    flex-shrink: 0;
}

/* 代码编辑器样式 */
#codeEditor {
    width: 100%;
    height: calc(100% - 40px);
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: none;
}

/* CodeMirror自定义样式 */
.CodeMirror {
    height: calc(100% - 40px) !important;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
    flex: 1;
    min-height: 300px;
}

/* 当前执行指令高亮 */
.cm-current-instruction {
    background: #ffeb3b !important;
    color: #000 !important;
    font-weight: bold;
    border-radius: 2px;
}

/* 控制按钮区域 */
.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
}

/* 前方方块信息显示 */
.front-cell-info {
    margin-left: auto;
    padding: 8px 12px;
    background: #edf2f7;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    color: #2d3748;
    white-space: nowrap;
}

.front-cell-info span {
    color: #4299e1;
    font-weight: bold;
}

.control-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    background: #4299e1;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #3182ce;
    transform: translateY(-1px);
}

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

.control-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.speed-select {
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    background: white;
    font-size: 14px;
}

/* 迷宫画布容器 */
.maze-container {
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    max-height: 60vh;
    overflow: auto;
    flex: 1;
}

#mazeCanvas {
    background: #f7fafc; /* 与容器背景颜色一致 */
    border: none; /* 取消边框 */
    border-radius: 8px;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.1), /* 内阴影边框 */
        0 8px 30px rgba(0, 0, 0, 0.3); /* 外阴影效果 */
    transition: box-shadow 0.3s ease;
}

/* 鼠标悬停时增强阴影效果 */
#mazeCanvas:hover {
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.15),
        0 12px 40px rgba(0, 0, 0, 0.4);
}

/* 状态信息区域 */
.status-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: #edf2f7;
    padding: 15px;
    border-radius: 5px;
    font-size: 14px;
}

.status-info div {
    display: flex;
    justify-content: space-between;
}

.status-info span {
    font-weight: bold;
    color: #2d3748;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .container {
        max-width: 95%;
        padding: 15px;
    }
    
    .main-content {
        gap: 15px;
        max-height: 700px;
    }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
    }
    
    .editor-section, .maze-section {
        min-height: 400px;
        max-height: 50vh;
    }
    
    .maze-container {
        max-height: 50vh;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        max-width: 100%;
    }
    
    .controls {
        justify-content: center;
        gap: 8px;
    }
    
    .control-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .speed-select {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .status-info {
        grid-template-columns: 1fr;
        font-size: 12px;
        padding: 10px;
    }
    
    .editor-section, .maze-section {
        padding: 15px;
        min-height: 350px;
        max-height: 45vh;
    }
    
    .maze-container {
        max-height: 40vh;
        min-height: 150px;
    }
    
    .CodeMirror {
        font-size: 12px;
        min-height: 250px;
    }
    
    .memory-cell {
        width: 25px;
        height: 25px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    .main-content {
        gap: 10px;
    }
    
    .editor-section, .maze-section {
        padding: 10px;
        min-height: 300px;
        max-height: 40vh;
    }
    
    .maze-container {
        max-height: 35vh;
        min-height: 120px;
        padding: 5px;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .control-btn, .speed-select {
        width: 100%;
        text-align: center;
    }
    
    .status-info {
        padding: 8px;
        font-size: 11px;
    }
    
    h3 {
        font-size: 1.1em;
    }
}

/* 动画效果 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

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

/* 成功和错误状态 */
.success {
    color: #38a169;
}

.error {
    color: #e53e3e;
}

.warning {
    color: #d69e2e;
}

/* 迷宫单元格样式 */
.cell-wall {
    background: #2d3748;
}

.cell-path {
    background: #f7fafc;
}

.cell-start {
    background: #48bb78;
}

.cell-end {
    background: #ed8936;
}

.cell-robot {
    background: #4299e1;
}

/* 胜利页面样式 */
.victory-overlay {
    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: 1000;
    animation: fadeIn 0.3s ease-in-out;
}

.victory-modal {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
}

.victory-modal h2 {
    color: #4299e1;
    margin-bottom: 15px;
    font-size: 2em;
}

.victory-modal p {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 1.2em;
}

.victory-stats {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    border: 2px solid #e2e8f0;
}

.victory-stats p {
    margin: 5px 0;
    font-weight: bold;
    color: #2d3748;
}

.victory-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.victory-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    background: #4299e1;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.victory-btn:hover {
    background: #3182ce;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.3);
}

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

/* 胜利页面动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 排行榜页面样式 */
.navigation-section {
    padding: 0px;
    margin-bottom: 0px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.navigation-section h1 {
    color: #4a5568;
    font-size: 1.8em;
    margin: 0;
}

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

.scoreboard-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.scoreboard-section h2 {
    color: #4a5568;
    margin-bottom: 10px;
    font-size: 1.5em;
}

.scoreboard-description {
    color: #718096;
    margin-bottom: 20px;
    font-size: 0.95em;
}

.scoreboard-container {
    position: relative;
    min-height: 200px;
}

.scoreboard-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.scoreboard-table th {
    background: #4299e1;
    color: white;
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
}

.scoreboard-table td {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
}

.scoreboard-table tr:last-child td {
    border-bottom: none;
}

.scoreboard-table tr:hover {
    background: #f7fafc;
}

/* 排名样式 */
.rank-cell {
    font-weight: bold;
    text-align: center;
    width: 80px;
}

.rank-number {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    border-radius: 50%;
    background: #edf2f7;
    color: #4a5568;
    font-weight: bold;
}

.rank-1 .rank-number {
    background: linear-gradient(135deg, #ffd700, #ffed4a);
    color: #744210;
}

.rank-2 .rank-number {
    background: linear-gradient(135deg, #c0c0c0, #e2e8f0);
    color: #4a5568;
}

.rank-3 .rank-number {
    background: linear-gradient(135deg, #cd7f32, #ed8936);
    color: white;
}

.rank-icon {
    margin-left: 5px;
    font-size: 16px;
}

/* 昵称单元格 */
.nickname-cell {
    font-weight: 500;
    color: #2d3748;
}

/* 代码长度单元格 */
.length-cell {
    font-weight: bold;
    color: #4299e1;
    text-align: center;
    width: 100px;
}

/* 时间单元格 */
.time-cell {
    color: #718096;
    font-size: 13px;
    width: 180px;
}

/* 加载和空状态 */
.loading-message, .empty-message {
    text-align: center;
    padding: 40px 20px;
    color: #718096;
    font-size: 16px;
}

.loading-message p, .empty-message p {
    margin: 0;
}

.empty-message .error {
    color: #e53e3e;
}

/* 统计信息区域 */
.stats-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.stats-section h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat-item {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    text-align: center;
}

.stat-label {
    display: block;
    color: #718096;
    font-size: 14px;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    color: #2d3748;
    font-size: 24px;
    font-weight: bold;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navigation-section, .scoreboard-navigation-section{
        flex-direction: column;
        text-align: center;
    }
    
    .navigation-section h1, .scoreboard-navigation-section h1 {
        font-size: 1.5em;
    }
    
    .scoreboard-table {
        font-size: 12px;
    }
    
    .scoreboard-table th,
    .scoreboard-table td {
        padding: 8px 6px;
    }
    
    .rank-cell {
        width: 60px;
    }
    
    .length-cell {
        width: 80px;
    }
    
    .time-cell {
        width: 140px;
        font-size: 11px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-value {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .scoreboard-table {
        display: block;
        overflow-x: auto;
    }
    
    .nav-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .nav-buttons .control-btn {
        width: 100%;
    }
}

.scoreboard-navigation-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.scoreboard-navigation-section h1 {
    color: #4a5568;
    font-size: 1.8em;
    margin: 0;
}