/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.6;
    height: 100vh; /* 设置高度为视口高度 */
    margin: 0;
    overflow-x: hidden; /* 防止横向滚动 */
}

html {
    width: 100%;
    overflow-x: hidden; /* 强制不产生横向滚动 */
}

body.no-scroll {
    overflow: hidden; /* 防止页面滚动 */
}

/* 顶部导航栏 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1100;
    height: 56px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    background: #ffffffcc;
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid #e6e8eb;
}

.topbar-left,
.topbar-center,
.topbar-right {
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-left { justify-content: flex-start; padding-left: 20px; }
.topbar-center { justify-content: center; width: 100%; }

.logo-text,
.home-link {
    color: #2c3e50;
    text-decoration: none;
    font-weight: 600;
    font-size: 18px;
    white-space: nowrap;
    cursor: pointer;
}

.menu-btn {
    width: 56px;
    height: 56px;
    border: none;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
    color: #2c3e50;
    display: none;
    padding: 0;
    z-index: 100;
    position: relative;
}

/* 覆盖层（仅移动端侧栏时使用） */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 999;
    display: none;
}

.container {
    display: flex;
    height: calc(100vh - 56px); /* 减去顶部导航栏的高度 */
}

/* 侧边栏样式 */
.sidebar {
    width: 300px;
    background-color: #fff;
    border-right: 1px solid #e1e5e9;
    overflow-y: auto;
    position: fixed;
    height: calc(100vh - 56px);
    top: 56px;
    z-index: 1000;
    transition: transform 0.3s ease;
    left: 0; /* 默认显示侧边栏 */
}

.sidebar-header {
    padding: 10px 20px;
    border-bottom: 1px solid #e1e5e9;
    background-color: #f8f9fa;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
}


.problem-list {
    padding: 10px 0;
}

.problem-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f1f3f4;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.problem-item:hover {
    background-color: #f8f9fa;
}

.problem-item.active {
    background-color: #e3f2fd;
    border-left: 3px solid #2196f3;
}

.problem-number {
    font-size: 12px;
    color: #666;
    font-weight: 500;
    min-width: 0;
}

.problem-title {
    font-size: 14px;
    color: #333;
    font-weight: 400;
    flex: 1;
}

.problem-difficulty {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
}

.difficulty-easy {
    background-color: #e8f5e8;
    color: #2e7d32;
}

.difficulty-medium {
    background-color: #fff3e0;
    color: #f57c00;
}

.difficulty-hard {
    background-color: #ffebee;
    color: #d32f2f;
}

/* 主内容区样式 */
.main-content {
    flex: 1;
    margin-left: 300px;
    padding: 0;
    background-color: #fff;
    transition: margin-left 0.3s ease;
    height: 100%; /* 使用100%高度填充父容器 */
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr); /* 上方标题，下面内容区 */
    overflow-y: auto; /* 允许内容垂直滚动 */
    max-width: 100%;
}

.main-content.no-scroll {
    overflow: hidden; /* 防止内容滚动 */
}

.problem-header {
    padding: 15px 40px;
    border-bottom: 1px solid #e1e5e9;
    background-color: #fff;
}

.problem-header h1 {
    font-size: clamp(18px, 5vw, 28px);
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0; /* 使标题与上下边距一致（上15px，下15px） */
}

.problem-content {
    padding: 40px;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
}

/* 欢迎消息 */
.welcome-message {
    text-align: center;
    padding: 0;
    color: #333;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    grid-row: 2; /* 放在内容区这一行 */
    align-self: center;
    justify-self: center;
    height: 100%; /* 占满网格行以实现真正的垂直居中 */
    transform: translateY(-30px); /* 细微上移，抵消标题区边框/行高带来的视觉偏差 */
}

.welcome-message p {
    font-size: 24px;
    margin-bottom: 20px;
    font-weight: 500;
    line-height: 1.6;
}

.welcome-message p:first-child {
    font-size: 32px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 30px;
}

.welcome-message p:last-child {
    font-size: 20px;
    color: #666;
    margin-bottom: 0;
}

/* 题目内容样式 */
.problem-section {
    margin-bottom: 20px;
    margin-left: 0;
}

.problem-section h3 {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e1e5e9;
}

.problem-description {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.problem-description p {
    margin-bottom: 10px;
    line-height: 1.7;
}

.example {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.example pre {
    background-color: transparent;
    color: #333;
    padding: 0;
    border-radius: 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: anywhere;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    margin: 0;
}

.solution-approach {
    background-color: #e8f5e8;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #4caf50;
}

.solution-approach p {
    margin-bottom: 10px;
    line-height: 1.7;
}

/* 代码块样式 */
.code-section {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    border: none;
    max-width: 100%;
    overflow-x: auto;
}


/* 复制按钮样式 */
.copy-btn {
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: auto;
    min-width: 0;
    height: 32px;
    position: relative;
}

.copy-btn:hover {
    background-color: #34495e;
}

.copy-btn:active {
    transform: scale(0.95);
}

.copy-icon {
    font-size: 14px;
    font-weight: 500;
}

.copy-text {
    display: none;
}

.code-content {
    background-color: #f8f9fa;
    color: #2c3e50;
    padding: 0;
    border-radius: 0 0 8px 8px;
    margin: 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

/* 覆盖Prism.js的默认样式 */
.code-content pre,
pre[class*="language-"],
code[class*="language-"] {
    margin: 0 !important;
    padding: 20px !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    background-color: #fff !important;
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-wrap: break-word !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.token {
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

/* 复杂度信息 */
.complexity {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.complexity-item {
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    flex: 1;
}

.complexity-item .label {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    font-weight: 500;
}

.complexity-item .value {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

/* 响应式设计 */
/* 桌面端顶部栏布局：左LOGO 中首页 右空，隐藏菜单按钮，始终显示侧边栏 */
@media (min-width: 769px) {
    .menu-btn { display: none; }
    .sidebar {
        width: 300px;
        left: 0;
        transform: translateX(0) !important;
    }
    .main-content {
        margin-left: 300px;
    }
}

/* 移动端：顶部中间居中显示"首页"，隐藏左侧LOGO；侧栏改为抽屉且不挤压内容 */
@media (max-width: 768px) {
    /* 固定字号，布局无限制变窄依靠容器自适应与断行 */
    html { font-size: 16px; }

    /* 保持合理的紧凑内边距但不限制内容收缩 */
    .problem-header { padding: 16px; }
    .problem-content { padding: 16px; }
    .problem-description, .example { padding: 12px; }
    .solution-tab { padding: 12px; }
    .copy-btn { height: 32px; }
    .logo-text { display: none; }
    .topbar { 
        grid-template-columns: 56px 1fr 56px; 
    }
    .topbar-left { 
        display: flex; 
        justify-content: center; 
    }
    .topbar-right { display: none; }
    .topbar-center { 
        justify-content: center; 
        width: 100%; 
        text-align: center;
        position: absolute;
        left: 0;
        right: 0;
    }
    .menu-btn { display: block; }
    .main-content { 
        margin-left: 0; 
        width: 100%; 
        max-width: 100%; 
        overflow-x: hidden; 
    }
    .container { width: 100%; max-width: 100%; overflow-x: hidden; }
    .sidebar {
        left: -280px; /* 移动端默认隐藏侧边栏 */
        width: 280px;
        transform: translateX(0);
    }
    .sidebar.open { 
        left: 0; 
    }
    .overlay.show { display: block; }
}

@media (max-width: 768px) {
    /* 固定字号，布局无限制变窄依靠容器自适应与断行 */
    html { font-size: 16px; }

    /* 保持合理的紧凑内边距但不限制内容收缩 */
    .problem-header { padding: 16px; }
    .problem-content { padding: 16px; }
    .problem-description, .example { padding: 12px; }
    .solution-tab { padding: 12px; }
    .copy-btn { height: 32px; }
    .logo-text { display: none; }
    .topbar { grid-template-columns: 56px 1fr 56px; }
    .topbar-left { display: flex; justify-content: center; }
    .topbar-right { display: none; }
    .topbar-center { 
        justify-content: center; 
        width: 100%; 
        text-align: center;
    }
    .menu-btn { display: block; }
    .main-content { margin-left: 0; width: 100%; max-width: 100%; overflow-x: hidden; }
    .container { width: 100%; max-width: 100%; overflow-x: hidden; }
    .sidebar {
        left: -280px; /* 彻底移出视口，避免产生横向滚动 */
        top: 56px;
        height: calc(100vh - 56px);
        border-right: 1px solid #e1e5e9;
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        transform: translateX(0);
    }
    .sidebar.open { left: 0; }
    .overlay.show { display: block; }

    .problem-content {
        padding: 20px 16px; /* 稍微减小左右内边距，避免累积宽度撑出 */
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
    img, video, table, pre, code, .code-content, .example { max-width: 100%; }
    p, li { overflow-wrap: anywhere; word-break: break-word; }

    .problem-header {
        padding: 20px;
        width: 100%;
        max-width: 100%;
    }

    .problem-header h1 {
        font-size: 24px;
        word-break: break-word;
    }

    /* 移动端欢迎消息样式 */
    .welcome-message {
        padding: 40px 20px;
    }

    .welcome-message p:first-child {
        font-size: 28px;
        margin-bottom: 20px;
    }

    .welcome-message p:last-child {
        font-size: 18px;
    }

    /* 移动端题目列表优化 */
    .problem-item {
        padding: 10px 15px;
    }

    .problem-number {
        min-width: 0;
        font-size: 11px;
    }

    .problem-title {
        font-size: 13px;
    }

    .problem-difficulty {
        font-size: 9px;
        padding: 1px 4px;
    }

    /* 移动端解法选择器优化 */
    .solution-tabs {
        flex-direction: column;
    }

    .solution-tab {
        min-width: auto;
        width: 100%;
        padding: 10px 12px;
    }

    .solution-name {
        font-size: 13px;
    }

    .solution-desc {
        font-size: 11px;
    }
}

/* 主页模式：锁定页面滚动 */
body.home-mode {
    overflow: hidden;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* 移动端等比缩放兜底，保证任何屏宽都能看全内容 */
@media (max-width: 768px) {
    .sidebar {
        max-height: calc(100vh - 56px);
        overflow-y: auto;
    }

    .problem-content {
        padding: 15px;
    }

    .problem-header {
        padding: 15px;
    }

    .problem-header h1 {
        font-size: 20px;
    }

    .welcome-message {
        padding: 30px 15px;
    }

    .welcome-message p:first-child {
        font-size: 24px;
        margin-bottom: 15px;
    }

    .welcome-message p:last-child {
        font-size: 16px;
    }

    /* 代码块移动端优化 */
    .code-content pre {
        padding: 15px;
        font-size: 13px;
    }
    /* 去除整体缩放，改为内容自适应 + 断行，避免缩放导致布局异常 */
    .container, .main-content { overflow-x: hidden; width: 100%; max-width: 100%; }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 难度分组样式 */
.difficulty-group {
    margin-bottom: 20px;
}

.difficulty-header {
    padding: 10px 20px;
    background-color: #f8f9fa;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    border-bottom: 1px solid #e1e5e9;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* 动画效果 */
.problem-item {
    transition: all 0.2s ease;
}

.problem-content {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 搜索框样式 */
.search-container {
    padding: 15px 20px;
    border-bottom: 1px solid #e1e5e9;
    background-color: #f8f9fa;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.search-input:focus {
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

/* 代码高亮优化 - 浅色主题 */
.code-content pre {
    background: #f8f9fa !important;
    color: #2c3e50 !important;
    border-radius: 0 0 8px 8px;
    margin: 0;
    padding: 20px;
    overflow-x: auto;
    font-size: 14px;
    line-height: 1.6;
    font-family: 'JetBrains Mono', monospace;
    font-variant-ligatures: contextual discretionary-ligatures;
    font-feature-settings: "liga" 1, "calt" 1, "clig" 1, "dlig" 1;
    text-rendering: optimizeLegibility;
    border: none;
    box-shadow: none;
}

.code-content pre code {
    background: transparent !important;
    color: inherit !important;
    font-size: inherit !important;
    line-height: inherit !important;
    font-weight: 400;
    font-family: 'JetBrains Mono', monospace !important;
    font-variant-ligatures: contextual discretionary-ligatures;
    font-feature-settings: "liga" 1, "calt" 1, "clig" 1, "dlig" 1;
}

/* 强制 Prism 代码块也使用 JetBrains Mono 与连字 */
pre[class*="language-"],
code[class*="language-"] {
    font-family: 'JetBrains Mono', monospace !important;
    font-variant-ligatures: contextual discretionary-ligatures;
    font-feature-settings: "liga" 1, "calt" 1, "clig" 1, "dlig" 1;
    text-rendering: optimizeLegibility;
}

/* 确保代码高亮正常工作 */
.code-content pre code.language-go {
    color: #2c3e50 !important;
    background: transparent !important;
}

/* 代码语法高亮优化 - 浅色主题 */
.code-content pre code .token.comment,
.code-content pre code .token.prolog,
.code-content pre code .token.doctype,
.code-content pre code .token.cdata {
    color: #6a737d !important;
    font-style: italic;
}

.code-content pre code .token.punctuation {
    color: #586069 !important;
}

.code-content pre code .token.property,
.code-content pre code .token.tag,
.code-content pre code .token.boolean,
.code-content pre code .token.number,
.code-content pre code .token.constant,
.code-content pre code .token.symbol,
.code-content pre code .token.deleted {
    color: #005cc5 !important;
}

.code-content pre code .token.selector,
.code-content pre code .token.attr-name,
.code-content pre code .token.string,
.code-content pre code .token.char,
.code-content pre code .token.builtin,
.code-content pre code .token.inserted {
    color: #032f62 !important;
}

.code-content pre code .token.operator,
.code-content pre code .token.entity,
.code-content pre code .token.url,
.code-content pre code .language-css .token.string,
.code-content pre code .style .token.string {
    color: #d73a49 !important;
}

.code-content pre code .token.atrule,
.code-content pre code .token.attr-value,
.code-content pre code .token.keyword {
    color: #d73a49 !important;
}

.code-content pre code .token.function,
.code-content pre code .token.class-name {
    color: #6f42c1 !important;
}

.code-content pre code .token.regex,
.code-content pre code .token.important,
.code-content pre code .token.variable {
    color: #e36209 !important;
}

/* 滚动条优化 */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 加载指示器样式 */
.loading-indicator {
    font-size: 12px;
    color: #666;
    margin-left: auto;
    transition: all 0.3s ease;
}

.loading-indicator:before {
    content: "🔄 ";
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Go代码高亮样式 */
.code-content pre code.language-go {
    color: #d4d4d4;
    background: #1e1e1e;
}

/* 代码头部样式优化 */
.code-header {
    background-color: #e3f2fd;
    color: #1976d2;
    padding: 10px 15px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
}

.code-header .language {
    background: none;
    color: #333;
    padding: 0;
    border: none;
    font-size: 14px;
    font-weight: 500;
    outline: none;
    box-shadow: none;
}

/* 解法选择器样式 */
.solution-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.solution-tab {
    background-color: #f8f9fa;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 250px; /* 设置最小宽度，使图标变长 */
    width: auto; /* 允许根据内容自动调整宽度 */
    text-align: left;
}

.solution-tab:hover {
    background-color: #e3f2fd;
    border-color: #2196f3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.15);
}

.solution-tab.active {
    background-color: #2196f3;
    border-color: #1976d2;
    color: white;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.solution-tab.active:hover {
    background-color: #1976d2;
    transform: translateY(-2px);
}

.solution-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.solution-desc {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.solution-tab.active .solution-desc {
    color: rgba(255, 255, 255, 0.9);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .solution-tabs {
        flex-direction: column;
    }

    .solution-tab {
        min-width: auto;
        width: 100%;
        padding: 15px 20px; /* 增加内边距使按钮更大 */
        margin-bottom: 8px; /* 增加按钮间距 */
    }
    
    .solution-name {
        font-size: 16px; /* 增大字体 */
    }
    
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .menu-btn {
        display: block;
    }
    
    .overlay.show {
        display: block;
    }
}
