/* ===== 基础变量 ===== */
:root {
    --primary: #5b6abf;
    --primary-light: #7c8ae0;
    --primary-dark: #4350a0;
    --green: #34c78b;
    --green-bg: #eefbf5;
    --red: #e85d5d;
    --red-bg: #fef2f2;
    --orange: #eda145;
    --orange-bg: #fffbf0;
    --bg: #f9fafb;
    --card: #ffffff;
    --border: #e5e7eb;
    --border-light: #f0f0f0;
    --text-primary: #1a1a1a;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.04), 0 0 0 1px rgba(0,0,0,.03);
    --font-sans: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* ===== 全局重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* ===== 顶部标题栏 ===== */
.header {
    background: linear-gradient(135deg, #667eea 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 0 20px;
    height: 48px;
    flex-shrink: 0;
}

.header-inner {
    max-width: 1800px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon {
    font-size: 18px;
    opacity: .85;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: .3px;
}

.header-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 10px;
    background: rgba(255,255,255,.18);
    border-radius: 20px;
    letter-spacing: .5px;
}

/* ===== 题目选项卡 ===== */
.tab-bar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    flex-shrink: 0;
}

.tab-bar-inner {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    gap: 0;
}

.tab-btn {
    position: relative;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: color .2s;
    font-family: var(--font-sans);
}

.tab-btn:hover { color: var(--text-primary); }

.tab-btn.active {
    color: var(--primary);
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 12px;
    right: 12px;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

/* ===== 主体布局 ===== */
.main-container {
    flex: 1;
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    min-height: 0;
    overflow: hidden;
}

/* ===== 面板通用 ===== */
.panel {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.panel-left { flex: 0 0 40%; max-width: 40%; }
.panel-right { flex: 1; }

.panel-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    background: var(--bg);
}

.panel-icon { font-size: 15px; }

/* ===== 左侧：题目描述 ===== */
.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    line-height: 1.6;
}

.problem-section {
    margin-bottom: 14px;
}

.problem-section:last-child { margin-bottom: 0; }

.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 14px;
    background: var(--primary);
    border-radius: 2px;
}

.problem-text {
    font-size: 15px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    line-height: 1.7;
}

.code-block {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--text-primary);
    overflow-x: auto;
}

.code-block .copy-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity .15s;
    line-height: 1;
}

.code-block:hover .copy-btn { opacity: 1; }
.code-block .copy-btn:hover { color: var(--primary); border-color: var(--primary); }
.code-block .copy-btn.copied { color: var(--green); border-color: var(--green); }

.sample-group {
    margin-bottom: 10px;
}

.sample-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: .3px;
    margin-bottom: 3px;
}

.explanation {
    margin-top: 6px;
    padding: 8px 12px;
    background: #f0f4ff;
    border-radius: 6px;
    font-size: 13.5px;
    color: var(--text-secondary);
    border-left: 3px solid var(--primary-light);
}

.explanation pre {
    font-family: var(--font-mono);
    font-size: 13px;
    white-space: pre;
    margin: 0;
}

.hint-box {
    padding: 8px 12px;
    background: #fffbe6;
    border-radius: 6px;
    font-size: 14px;
    color: #7c5a1e;
    border-left: 3px solid #f0c040;
}

/* ===== 右侧：编辑器 ===== */
.btn-reset {
    margin-left: auto;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 3px 8px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all .15s;
}

.btn-reset:hover {
    color: var(--red);
    border-color: var(--red);
}

.editor-wrapper {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.CodeMirror {
    height: 100% !important;
    font-family: var(--font-mono) !important;
    font-size: 14.5px !important;
    line-height: 1.55 !important;
}

/* ===== 操作栏 ===== */
.action-bar {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    gap: 10px;
    flex-shrink: 0;
    background: var(--bg);
}

.action-left { flex: 1; }

.status-text {
    font-size: 13px;
    color: var(--text-muted);
}

.action-right {
    display: flex;
    gap: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 18px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font-sans);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-icon { font-size: 11px; }

.btn-run {
    background: var(--text-primary);
    color: #fff;
}

.btn-run:hover:not(:disabled) {
    background: #000;
}

.btn-submit {
    background: var(--primary);
    color: #fff;
}

.btn-submit:hover:not(:disabled) {
    background: var(--primary-dark);
}

/* ===== 结果面板 ===== */
.result-panel {
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    max-height: 240px;
    overflow-y: auto;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    background: var(--card);
}

.btn-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover { color: var(--text-secondary); }

.result-body {
    padding: 8px 12px;
}

/* 错误信息 */
.error-message {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--red);
    background: var(--red-bg);
    padding: 10px 12px;
    border-radius: 6px;
}

/* 提交结果 */
.submit-summary {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.submit-summary.all-pass {
    background: var(--green-bg);
    color: #157a52;
}

.submit-summary.has-fail {
    background: var(--red-bg);
    color: #b33b3b;
}

.test-case-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}

.test-case-item:last-child { border-bottom: none; }

.tc-badge {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 3px;
    letter-spacing: .3px;
}

.tc-badge.pass { background: var(--green-bg); color: #157a52; }
.tc-badge.fail { background: var(--red-bg); color: #b33b3b; }

.tc-detail {
    flex: 1;
    min-width: 0;
}

.tc-row {
    display: flex;
    gap: 6px;
    margin-bottom: 2px;
}

.tc-label {
    flex-shrink: 0;
    font-weight: 600;
    color: var(--text-muted);
    width: 48px;
    text-align: right;
    font-size: 12px;
}

.tc-value {
    font-family: var(--font-mono);
    font-size: 12.5px;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
}

/* ===== Loading 动画 ===== */
.loading {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 底部 ===== */
.footer {
    padding: 5px 20px;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ===== 滚动条美化 ===== */
.panel-body::-webkit-scrollbar,
.result-panel::-webkit-scrollbar {
    width: 4px;
}

.panel-body::-webkit-scrollbar-track,
.result-panel::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb,
.result-panel::-webkit-scrollbar-thumb {
    background: #d4d4d4;
    border-radius: 2px;
}

.panel-body::-webkit-scrollbar-thumb:hover,
.result-panel::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ===== 响应式 ===== */
@media (max-width: 900px) {
    html, body { overflow: auto; }
    .main-container {
        flex-direction: column;
        padding: 8px;
        overflow: visible;
    }
    .panel-left {
        flex: none;
        max-width: 100%;
        max-height: 45vh;
    }
    .panel-right { flex: none; min-height: 50vh; }
    .header { padding: 0 12px; }
    .tab-bar { padding: 0 12px; }
}
