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

/* 基础样式 */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    transition: all 0.3s ease;
}

/* 暗色模式 */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

/* 容器 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 头部导航 */
header {
    background-color: #4CAF50;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

nav {
    padding: 1rem 0;
}

nav .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

nav ul {
    display: flex;
    list-style: none;
    gap: 1.5rem;
}

nav ul li a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

nav ul li a:hover {
    color: #e0e0e0;
}

.theme-toggle button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: white;
}

/* 英雄区域 */
.hero {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    padding: 4rem 0;
    text-align: center;
}

.hero h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.hero p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* 按钮样式 */
.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn.primary {
    background-color: #2196F3;
    color: white;
}

.btn.primary:hover {
    background-color: #0b7dda;
}

.btn.secondary {
    background-color: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

body.dark-mode .btn.secondary {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}

.btn.secondary:hover {
    background-color: #e0e0e0;
}

body.dark-mode .btn.secondary:hover {
    background-color: #444;
}

/* 特性区域 */
.features {
    padding: 4rem 0;
}

.features h3 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 2rem;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.feature-item {
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

body.dark-mode .feature-item {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.feature-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

body.dark-mode .feature-item:hover {
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

.feature-item h4 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #4CAF50;
}

/* 题库页面 */
.problems {
    padding: 2rem 0;
}

.problems h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
}

.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 500;
}

.filter-group select,
.filter-group input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    color: #333;
}

body.dark-mode .filter-group select,
body.dark-mode .filter-group input {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}

.problem-list {
    margin-bottom: 2rem;
}

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

body.dark-mode .problem-list table {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.problem-list th,
.problem-list td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

body.dark-mode .problem-list th,
body.dark-mode .problem-list td {
    border-bottom-color: #555;
}

.problem-list th {
    background-color: #f5f5f5;
    font-weight: 600;
}

body.dark-mode .problem-list th {
    background-color: #3d3d3d;
}

.problem-list tr:hover {
    background-color: #f9f9f9;
}

body.dark-mode .problem-list tr:hover {
    background-color: #3d3d3d;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.dark-mode .pagination button {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}

.pagination button:hover:not(:disabled) {
    background-color: #f5f5f5;
}

body.dark-mode .pagination button:hover:not(:disabled) {
    background-color: #444;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 题目详情页面 - 新布局 */
.problem-detail {
    padding: 1.5rem 0;
}

.detail-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    min-height: calc(100vh - 200px);
    transition: grid-template-columns 0.3s ease;
}

/* 侧边栏折叠状态 */
.detail-layout.sidebar-collapsed {
    grid-template-columns: 60px 1fr;
}

/* 侧边栏 - 题目信息 */
.problem-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.problem-sidebar.collapsed {
    overflow: hidden;
}

.problem-sidebar.collapsed .problem-header,
.problem-sidebar.collapsed .problem-info-sections {
    opacity: 0;
    transform: translateX(-100%);
    pointer-events: none;
}

/* 侧边栏头部 */
.sidebar-header {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
}

.collapse-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.3s ease;
}

body.dark-mode .collapse-btn {
    background-color: rgba(50, 50, 50, 0.8);
    color: #e0e0e0;
}

.collapse-btn:hover {
    background-color: white;
    transform: scale(1.05);
}

body.dark-mode .collapse-btn:hover {
    background-color: #444;
}

.problem-sidebar.collapsed .collapse-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    right: auto;
}

/* 调整宽度的handle */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    background-color: transparent;
    transition: background-color 0.3s ease;
}

.resize-handle:hover {
    background-color: rgba(76, 175, 80, 0.3);
}

/* 右侧工作区最小宽度 */
.editor-workspace {
    min-width: 400px;
}

.problem-sidebar .problem-header {
    margin-bottom: 0;
    padding: 1rem;
    border-bottom: none;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.dark-mode .problem-sidebar .problem-header {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.problem-sidebar .problem-header h2 {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
    line-height: 1.4;
}

.problem-sidebar .problem-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: #666;
}

body.dark-mode .problem-sidebar .problem-meta {
    color: #aaa;
}

.problem-sidebar .problem-meta .chapter {
    background-color: #f0f0f0;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
}

body.dark-mode .problem-sidebar .problem-meta .chapter {
    background-color: #3d3d3d;
}

.problem-sidebar .problem-meta .difficulty {
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-weight: 500;
}

.problem-sidebar .problem-meta .difficulty.easy {
    background-color: #e8f5e9;
    color: #2e7d32;
}

.problem-sidebar .problem-meta .difficulty.medium {
    background-color: #fff3e0;
    color: #ef6c00;
}

.problem-sidebar .problem-meta .difficulty.hard {
    background-color: #ffebee;
    color: #c62828;
}

body.dark-mode .problem-sidebar .problem-meta .difficulty.easy {
    background-color: #1b5e20;
    color: #a5d6a7;
}

body.dark-mode .problem-sidebar .problem-meta .difficulty.medium {
    background-color: #e65100;
    color: #ffcc80;
}

body.dark-mode .problem-sidebar .problem-meta .difficulty.hard {
    background-color: #b71c1c;
    color: #ffcdd2;
}

.problem-info-sections {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    overflow-y: auto;
    flex: 1;
}

.info-section {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

body.dark-mode .info-section {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.info-section .section-title {
    padding: 0.7rem 1rem;
    background-color: #f5f5f5;
    font-size: 0.9rem;
    font-weight: 600;
    color: #4CAF50;
    border-bottom: 1px solid #eee;
}

body.dark-mode .info-section .section-title {
    background-color: #3d3d3d;
    border-bottom-color: #444;
}

.info-section .section-title.toggleable {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.info-section .section-title.toggleable:hover {
    background-color: #e8e8e8;
}

body.dark-mode .info-section .section-title.toggleable:hover {
    background-color: #444;
}

.info-section .section-title .toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.info-section.collapsed .section-content {
    display: none;
}

.info-section > div:not(.section-title) {
    padding: 0.8rem 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.info-section pre {
    margin: 0;
    padding: 0.6rem;
    background-color: #f9f9f9;
    border-radius: 4px;
    font-size: 0.85rem;
    overflow-x: auto;
}

body.dark-mode .info-section pre {
    background-color: #1e1e1e;
}

.info-section .table-definition {
    margin-bottom: 0.8rem;
}

.info-section .table-definition:last-child {
    margin-bottom: 0;
}

.info-section .table-definition h4 {
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: #666;
}

body.dark-mode .info-section .table-definition h4 {
    color: #aaa;
}

/* 编辑工作区 */
.editor-workspace {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.editor-workspace .sql-editor {
    margin-bottom: 0;
}

.editor-workspace .editor-header {
    padding: 0.8rem 1rem;
}

.editor-workspace .editor-header h3 {
    display: none;
}

.editor-workspace .editor-buttons button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.editor-workspace .editor-buttons button.primary {
    background-color: #2196F3;
    color: white;
    border-color: #2196F3;
}

.editor-workspace .editor-buttons button.primary:hover {
    background-color: #0b7dda;
}

.editor-workspace .editor-buttons button.success {
    background-color: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.editor-workspace .editor-buttons button.success:hover {
    background-color: #45a049;
}

.editor-workspace .editor-body {
    padding: 0.8rem;
}

.editor-workspace #sql-input {
    min-height: 250px;
    font-size: 0.95rem;
}

.editor-workspace .editor-footer {
    padding: 0.6rem 1rem;
}

.editor-workspace .result-section {
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-workspace .result-section h3 {
    display: none;
}

.editor-workspace .result-section .section-title {
    padding: 0.7rem 1rem;
    background-color: #f5f5f5;
    font-size: 0.9rem;
    font-weight: 600;
    color: #4CAF50;
    border-bottom: 1px solid #eee;
}

body.dark-mode .editor-workspace .result-section .section-title {
    background-color: #3d3d3d;
    border-bottom-color: #444;
}

.editor-workspace #result-container {
    flex: 1;
    min-height: 150px;
    padding: 0.8rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .detail-layout {
        grid-template-columns: 1fr;
    }
    
    .problem-sidebar {
        max-height: none;
    }
    
    .problem-info-sections {
        overflow-y: visible;
    }
}

.sql-editor {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

body.dark-mode .sql-editor {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
}

body.dark-mode .editor-header {
    background-color: #3d3d3d;
    border-bottom-color: #555;
}

.editor-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.editor-buttons {
    display: flex;
    gap: 0.5rem;
}

.editor-buttons button {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.dark-mode .editor-buttons button {
    background-color: #444;
    color: #e0e0e0;
    border-color: #555;
}

.editor-buttons button:hover {
    background-color: #f5f5f5;
}

body.dark-mode .editor-buttons button:hover {
    background-color: #555;
}

.editor-body {
    padding: 1rem;
}

#sql-input {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    line-height: 1.5;
    resize: vertical;
    background-color: #f9f9f9;
}

body.dark-mode #sql-input {
    background-color: #1e1e1e;
    color: #e0e0e0;
    border-color: #555;
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #f5f5f5;
    border-top: 1px solid #ddd;
}

body.dark-mode .editor-footer {
    background-color: #3d3d3d;
    border-top-color: #555;
}

#judge-result {
    font-weight: 500;
}

.result-section {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.dark-mode .result-section {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* 用户中心页面 */
.user-center {
    padding: 2rem 0;
}

.auth-section {
    max-width: 500px;
    margin: 0 auto;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 2rem;
}

body.dark-mode .auth-section {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.auth-section h2 {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.8rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    background-color: white;
    color: #333;
}

body.dark-mode .form-group input {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}

.auth-section button {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 1rem;
}

.auth-switch {
    text-align: center;
}

.auth-switch a {
    color: #4CAF50;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.user-info {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 2rem;
}

body.dark-mode .user-info {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #ddd;
}

body.dark-mode .user-header {
    border-bottom-color: #555;
}

.user-header h2 {
    margin: 0;
    font-size: 1.8rem;
}

.user-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-item {
    text-align: center;
    padding: 1.5rem;
    background-color: #f5f5f5;
    border-radius: 8px;
}

body.dark-mode .stat-item {
    background-color: #3d3d3d;
}

.stat-item h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #666;
}

body.dark-mode .stat-item h3 {
    color: #aaa;
}

.stat-item p {
    font-size: 1.8rem;
    font-weight: 600;
    color: #4CAF50;
}

.submission-history h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #4CAF50;
}

#submission-table {
    width: 100%;
    border-collapse: collapse;
}

#submission-table th,
#submission-table td {
    padding: 0.8rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

body.dark-mode #submission-table th,
body.dark-mode #submission-table td {
    border-bottom-color: #555;
}

#submission-table th {
    background-color: #f5f5f5;
    font-weight: 600;
}

body.dark-mode #submission-table th {
    background-color: #3d3d3d;
}

/* 关于页面 */
.about {
    padding: 2rem 0;
}

.about h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
}

.about-content {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 2rem;
}

body.dark-mode .about-content {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.about-content h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: #4CAF50;
}

.about-content p {
    margin-bottom: 1rem;
}

.about-content ul,
.about-content ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

.about-content li {
    margin-bottom: 0.5rem;
}

/* 页脚 */
footer {
    background-color: #333;
    color: white;
    padding: 2rem 0;
    margin-top: 2rem;
}

footer p {
    text-align: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
    nav .container {
        flex-direction: column;
        gap: 1rem;
    }
    
    nav ul {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .hero h2 {
        font-size: 2rem;
    }
    
    .hero p {
        font-size: 1rem;
    }
    
    .buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .problem-list table {
        font-size: 0.9rem;
    }
    
    .problem-list th,
    .problem-list td {
        padding: 0.5rem;
    }
    
    .user-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .user-stats {
        grid-template-columns: 1fr;
    }
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero,
.features,
.problems,
.problem-detail,
.user-center,
.about {
    animation: fadeIn 0.5s ease-in-out;
}

/* 判题结果样式 */
.wa {
    color: #f44336;
}

.ac {
    color: #4CAF50;
}

.ce {
    color: #ff9800;
}

.re {
    color: #9c27b0;
}

/* SQL 编辑器语法高亮 */
.syntax-highlight-overlay {
    overflow: hidden;
}

.syntax-highlight-overlay .keyword {
    color: #0000ff;
    font-weight: bold;
}

.syntax-highlight-overlay .string {
    color: #008000;
}

.syntax-highlight-overlay .number {
    color: #ff0000;
}

.syntax-highlight-overlay .comment {
    color: #808080;
    font-style: italic;
}

/* 结果表格样式 */
.result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.result-table th,
.result-table td {
    padding: 0.5rem;
    border: 1px solid #ddd;
    text-align: left;
}

body.dark-mode .result-table th,
body.dark-mode .result-table td {
    border-color: #555;
}

.result-table th {
    background-color: #f5f5f5;
    font-weight: 600;
}

body.dark-mode .result-table th {
    background-color: #3d3d3d;
}