/* CSS 变量定义 */
:root {
    /* 亮色主题 */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

/* 暗色主题 */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --border-hover: #475569;
    --accent-primary: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-light: #1e3a8a;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

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

/* 禁用页面拖拽和移动 */
html, body {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    overflow-x: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* 允许文本编辑区域的选择 */
#codeEditor,
.CodeMirror,
input,
textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* 禁用所有图片和SVG的拖拽 */
img, svg, canvas {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: auto;
}

/* 禁用按钮和链接的拖拽 */
button, a {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-y: auto;
}

/* 容器布局 */
.container {
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 头部样式 */
.header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-icon {
    width: 2rem;
    height: 2rem;
    color: var(--accent-primary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--border-hover);
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

.btn svg {
    width: 1rem;
    height: 1rem;
}

.btn-primary {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

/* 主题切换按钮 */
.theme-toggle {
    position: relative;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.5rem;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
}

.theme-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.sun-icon {
    opacity: 1;
}

.moon-icon {
    opacity: 0;
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
}

/* 语言选择器样式 */
.language-selector {
    position: relative;
    display: inline-block;
}

.language-btn {
    min-width: 7rem;
    justify-content: center;
    position: relative;
}

.language-btn .language-text {
    font-size: 0.8rem;
    font-weight: 500;
}

.language-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    overflow: hidden;
}

.language-option {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.language-option:last-child {
    border-bottom: none;
}

.language-option:hover {
    background-color: var(--bg-tertiary);
}

.language-option.active {
    background-color: var(--accent-light);
    color: var(--accent-primary);
    font-weight: 600;
}

[data-theme="dark"] .language-option.active {
    background-color: var(--accent-light);
    color: var(--accent-hover);
}

/* 语言选择器响应式调整 */
@media (max-width: 768px) {
    .language-btn {
        min-width: 5rem;
        padding: 0.375rem 0.5rem;
    }
    
    .language-btn .language-text {
        font-size: 0.75rem;
    }
    
    .language-dropdown {
        min-width: 8rem;
    }
}

/* 主内容区域 */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
    overflow: auto;
    height: calc(100vh - 80px); /* 减去header高度 */
}

/* 面板样式 */
.panel {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.panel:hover {
    box-shadow: var(--shadow-lg);
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-title svg {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--accent-primary);
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
}

.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 代码编辑器样式 */
#codeEditor {
    width: 100%;
    height: 100%;
    min-height: 400px;
    border: none;
    outline: none;
    resize: none;
    padding: 1.5rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

#codeEditor::placeholder {
    color: var(--text-muted);
}

/* CodeMirror 主题适配 */
.CodeMirror {
    height: 100% !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
    font-size: 0.875rem !important;
    line-height: 1.6 !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

.CodeMirror-gutters {
    background-color: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-color) !important;
}

.CodeMirror-linenumber {
    color: var(--text-muted) !important;
}

.CodeMirror-cursor {
    border-left: 1px solid var(--accent-primary) !important;
}

.CodeMirror-selected {
    background-color: var(--accent-light) !important;
}

/* 图表容器样式 */
.chart-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background-color: var(--bg-primary);
}

.chart-output {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    transition: all 0.3s ease;
}

.chart-output svg {
    max-width: 100%;
    height: auto;
    transition: transform 0.3s ease;
}

/* 空状态样式 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    width: 4rem;
    height: 4rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1rem;
    max-width: 300px;
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 1rem;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 2rem;
    height: 2rem;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-close svg {
    width: 1.25rem;
    height: 1.25rem;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    /* 优化滚动体验 */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 示例网格 */
.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    max-height: none;
    /* 滚动优化 */
    scroll-behavior: smooth;
}

.example-item {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* 防止内容溢出 */
    overflow: hidden;
}

.example-item:hover {
    border-color: var(--accent-primary);
    background-color: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.example-item h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.example-item p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* 缩放控制 */
.chart-output.zoomed {
    overflow: auto;
}

.chart-output.zoomed svg {
    transform: scale(var(--zoom-level, 1));
    transform-origin: top left;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-content {
        padding: 1rem;
    }
    
    .logo {
        font-size: 1.25rem;
    }
    
    .panel-header {
        padding: 1rem;
    }
    
    .panel-content {
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .header-controls {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .logo {
        justify-content: center;
    }
    
    .panel-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .panel-actions {
        justify-content: center;
    }
    
    .examples-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .example-item {
        padding: 0.75rem;
        min-height: 60px;
    }
    
    .modal {
        padding: 0.5rem;
    }
    
    .modal-content {
        max-height: 85vh;
    }
    
    .modal-body {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.5rem;
    }
    
    .header-content {
        padding: 0.75rem;
    }
    
    .panel-header {
        padding: 0.75rem;
    }
    
    #codeEditor {
        padding: 1rem;
        font-size: 0.8rem;
    }
    
    .chart-output {
        padding: 1rem;
        min-height: 250px;
    }
    
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .example-item {
        padding: 0.5rem;
        min-height: 50px;
    }
    
    .example-item h4 {
        font-size: 1rem;
        margin-bottom: 0.25rem;
    }
    
    .example-item p {
        font-size: 0.8rem;
    }
    
    .modal-content {
        max-height: 90vh;
    }
    
    .modal-body {
        padding: 0.75rem;
    }
}

/* 加载动画 */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading {
    animation: spin 1s linear infinite;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

/* 选择文本样式 */
::selection {
    background-color: var(--accent-light);
    color: var(--text-primary);
}

/* 焦点样式 */
button:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* 过渡动画 */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* 全屏样式 */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-primary);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.fullscreen-overlay.active {
    opacity: 1;
    visibility: visible;
}

.fullscreen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.fullscreen-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.fullscreen-title svg {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--accent-primary);
}

.fullscreen-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.fullscreen-content {
    flex: 1;
    display: block;
    padding: 2rem;
    overflow: auto;
    background-color: var(--bg-primary);
    /* 确保滚动区域足够大以容纳放大的内容 */
    width: 100%;
    height: 100%;
    /* 优化滚动体验 */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.fullscreen-chart {
    /* 移除最大宽高限制，允许内容超出视口 */
    display: inline-block;
    /* 确保容器能够容纳放大后的内容 */
    min-width: 100%;
    min-height: 100%;
    /* 让容器根据内容自适应，但确保有足够的空间 */
    width: auto;
    height: auto;
    /* 添加一些内边距确保内容不会贴边 */
    padding: 1rem;
    box-sizing: border-box;
}

.fullscreen-chart svg {
    /* 移除最大宽高限制，允许SVG在放大时超出原始尺寸 */
    width: auto;
    height: auto;
    display: block;
    /* 确保SVG不会被压缩 */
    flex-shrink: 0;
    /* 确保SVG在容器中正确定位 */
    position: relative;
    /* 防止SVG出现意外的边距 */
    margin: 0;
    /* 确保变换原点正确 */
    transform-origin: top left;
}

.fullscreen-chart .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    text-align: center;
}

/* 全屏按钮状态 */
.fullscreen-active .fullscreen-enter {
    display: none;
}

.fullscreen-active .fullscreen-exit {
    display: inline !important;
}

/* 全屏时隐藏页面滚动 */
body.fullscreen-mode {
    overflow: hidden;
}

/* 全屏响应式 */
@media (max-width: 768px) {
    .fullscreen-header {
        padding: 0.75rem 1rem;
    }
    
    .fullscreen-title {
        font-size: 1.125rem;
    }
    
    .fullscreen-content {
        padding: 1rem;
    }
    
    .fullscreen-controls {
        gap: 0.5rem;
    }
} 