/* ============================================
   WebSocket 教程网站样式
   ============================================ */

/* CSS 变量定义 */
:root {
    /* 主色调 - 蓝色渐变 */
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);

    /* 辅助色 */
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;

    /* 文字颜色 */
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-light: #ffffff;

    /* 背景色 */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-dark: #0f172a;
    --bg-code: #1e293b;

    /* 边框颜色 */
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;

    /* 阴影 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* 圆角 */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* 过渡 */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    font-size: 16px;
}

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

/* 头部样式 */
.header {
    background: var(--primary-gradient);
    color: var(--text-light);
    padding: 60px 20px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.25rem;
    opacity: 0.9;
    font-weight: 300;
}

/* 导航栏样式 */
.nav {
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 15px 0;
}

.nav-links {
    display: flex;
    justify-content: center;
    list-style: none;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    font-weight: 500;
}

.nav-links a:hover {
    color: var(--primary-color);
    background: var(--bg-tertiary);
}

.nav-links a.active {
    color: var(--text-light);
    background: var(--primary-color);
}

/* 主内容区域 */
main {
    padding: 40px 0;
}

/* 区块样式 */
.section {
    margin-bottom: 60px;
    scroll-margin-top: 100px;
}

.section h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 30px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 卡片样式 */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--primary-dark);
}

.card p {
    color: var(--text-secondary);
    margin-bottom: 15px;
}

/* 卡片图标 */
.card-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

/* 网格布局 */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

/* 比较样式 */
.comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.comparison-item {
    padding: 20px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
}

.comparison-item.highlight {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    border: 2px solid var(--primary-color);
}

.comparison-item h4 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.comparison-item ul {
    list-style: none;
    padding: 0;
}

.comparison-item li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
    color: var(--text-secondary);
}

.comparison-item li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
}

/* 特性列表 */
.feature-list {
    list-style: none;
    padding: 0;
}

.feature-list li {
    padding: 12px 0;
    padding-left: 35px;
    position: relative;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}

.feature-list li:last-child {
    border-bottom: none;
}

.feature-list li::before {
    content: attr(data-icon);
    position: absolute;
    left: 0;
    font-size: 1.2rem;
}

.feature-list strong {
    color: var(--primary-dark);
    font-weight: 600;
}

/* 层次结构图 */
.layer-diagram {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    margin: 20px auto;
}

.layer {
    padding: 15px;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: var(--text-light);
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.layer:nth-child(2) {
    background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-green) 100%);
}

.layer:nth-child(3) {
    background: linear-gradient(135deg, var(--accent-orange) 0%, var(--accent-red) 100%);
}

.layer:nth-child(4) {
    background: linear-gradient(135deg, var(--accent-purple) 0%, var(--primary-dark) 100%);
}

/* 图表容器 */
.diagram-container {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 30px;
    margin: 20px 0;
    box-shadow: var(--shadow-md);
    overflow-x: auto;
}

/* 帧结构 */
.frame-structure {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

.frame-byte {
    padding: 15px;
    background: var(--bg-code);
    color: var(--text-light);
    border-radius: var(--radius-md);
    font-family: 'Courier New', monospace;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.bit-group {
    padding: 8px 12px;
    background: var(--primary-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
}

.bit-group.extended {
    background: var(--accent-purple);
    flex-grow: 1;
}

.bit-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: auto;
}

/* 字段列表 */
.field-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.field-item {
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary-color);
}

.field-item h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--primary-dark);
}

.field-item p {
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.field-item ul {
    margin-left: 20px;
    color: var(--text-secondary);
}

.field-item li {
    padding: 5px 0;
}

.field-item code {
    background: var(--bg-code);
    color: var(--accent-cyan);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* 表格样式 */
.table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table thead {
    background: var(--primary-gradient);
    color: var(--text-light);
}

.table th,
.table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-weight: 600;
}

.table tbody tr:hover {
    background: var(--bg-tertiary);
}

.table code {
    background: var(--bg-code);
    color: var(--accent-cyan);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* 代码块样式 */
pre {
    background: var(--bg-code);
    color: var(--text-light);
    padding: 20px;
    border-radius: var(--radius-lg);
    overflow-x: auto;
    margin: 15px 0;
    box-shadow: var(--shadow-md);
}

pre code {
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* 列表样式 */
ul {
    margin: 15px 0;
    padding-left: 20px;
}

li {
    margin: 8px 0;
    color: var(--text-secondary);
}

li strong {
    color: var(--primary-dark);
}

/* 页脚样式 */
.footer {
    background: var(--bg-dark);
    color: var(--text-muted);
    padding: 40px 20px;
    text-align: center;
    margin-top: 60px;
}

.footer p {
    margin: 5px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .header h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .nav-links {
        gap: 5px;
    }

    .nav-links a {
        padding: 6px 12px;
        font-size: 0.9rem;
    }

    .comparison {
        grid-template-columns: 1fr;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .section h2 {
        font-size: 1.5rem;
    }

    .card {
        padding: 20px;
    }

    .frame-byte {
        flex-direction: column;
        align-items: flex-start;
    }

    .bit-desc {
        margin-left: 0;
        margin-top: 10px;
    }
}

/* 打印样式 */
@media print {
    .header,
    .nav,
    .footer {
        display: none;
    }

    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

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

.card {
    animation: fadeIn 0.5s ease-out;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: var(--radius-full);
}

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

/* 代码块折叠样式 */
.code-block-wrapper {
    margin: 15px 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--bg-code) 0%, #1e293b 100%);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-base);
}

.code-block-header:hover {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.code-block-title {
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-block-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    color: var(--text-light);
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

.code-block-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.code-block-toggle:active {
    transform: scale(0.95);
}

.code-block-wrapper pre {
    margin: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    transition: all var(--transition-base);
    max-height: 600px;
    overflow-y: auto;
}

.code-block-wrapper.collapsed pre {
    max-height: 0;
    overflow: hidden;
    padding: 0;
}

.code-block-wrapper.collapsed .code-block-toggle {
    transform: rotate(-90deg);
}