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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden;
}

/* 背景图案 */
.background-pattern {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle at 25% 25%, rgba(165, 180, 252, 0.1) 0%, transparent 50%),
                      radial-gradient(circle at 75% 75%, rgba(165, 180, 252, 0.1) 0%, transparent 50%);
    z-index: -1;
}

/* 主容器 */
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100vw;
    overflow-x: hidden;
}

/* 顶部操作栏 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.logo-section .logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4f46e5;
    margin: 0;
}

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

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn i {
    font-size: 0.95rem;
}

.control-btn.primary {
    background-color: #4f46e5;
    color: white;
}

.control-btn.primary:hover {
    background-color: #4338ca;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.control-btn.secondary {
    background-color: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.control-btn.secondary:hover {
    background-color: #e2e8f0;
    color: #475569;
    transform: translateY(-1px);
}

/* 主内容区 */
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* 左侧元件库 */
.component-library {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow-y: auto;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 1rem;
}

.component-category {
    margin-bottom: 1.5rem;
}

.category-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.component-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.component-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.component-item:active {
    cursor: grabbing;
}

.component-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
}

/* 元件图标样式 */
.battery-icon {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
}

.power-supply-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.resistor-icon {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.variable-resistor-icon {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.switch-icon {
    background: linear-gradient(135deg, #ec4899, #db2777);
}

.light-bulb-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.ammeter-icon {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
}

.voltmeter-icon {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.component-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #334155;
}

/* 中间工作区 */
.workspace {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.canvas-container {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

#circuit-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.canvas-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(200, 200, 200, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(200, 200, 200, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: 1;
}

.operation-hint {
    background: white;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    font-size: 0.9rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.operation-hint i {
    color: #4f46e5;
    font-size: 1rem;
}

/* 右侧属性面板 */
.properties-panel {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}


/* 元件信息 */
.component-info {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
}

.no-selection, .no-results {
    color: #94a3b8;
    font-style: italic;
    text-align: center;
}

.component-details {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #64748b;
}

.detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}

/* 电路总览 */
.circuit-overview {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.overview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e2e8f0;
}

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

.overview-item .label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #64748b;
}

.overview-item .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4f46e5;
}

/* 计算结果 */
.calculation-results {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.result-item {
    background: white;
    padding: 0.75rem;
    border-radius: 6px;
    border-left: 4px solid #4f46e5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.result-item h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.25rem;
}

.result-item p {
    font-size: 0.8rem;
    color: #64748b;
}

/* 学习提示 */
.learning-tips {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.05), rgba(79, 70, 229, 0.02));
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.learning-tips p {
    font-size: 0.85rem;
    color: #334155;
    margin: 0;
}

.learning-tips strong {
    color: #4f46e5;
}

/* 页脚 */
.footer {
    text-align: center;
    padding: 0.75rem;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    font-size: 0.85rem;
    color: #64748b;
}

.footer a {
    color: #4f46e5;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: #4338ca;
    text-decoration: underline;
}

/* 帮助模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    transition: color 0.2s ease;
}

.close-btn:hover {
    color: #334155;
}

.modal-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    padding: 2rem 2rem 1rem;
    margin: 0;
}

.help-content {
    padding: 0 2rem 2rem;
}

.help-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #334155;
    margin: 1.5rem 0 0.75rem;
}

.help-content ul {
    list-style-position: inside;
    padding-left: 0.5rem;
    margin-bottom: 1rem;
}

.help-content li {
    margin-bottom: 0.5rem;
    color: #64748b;
    font-size: 0.95rem;
}

.help-content p {
    color: #64748b;
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

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

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 响应式设计 */
@media (max-width: 1400px) {
    .main-content {
        grid-template-columns: 250px 1fr 280px;
    }
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 220px 1fr 250px;
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .header {
        padding: 0.75rem 1.5rem;
    }
    
    .logo-section .logo {
        font-size: 1.25rem;
    }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        overflow-y: auto;
    }
    
    .component-library {
        grid-row: 1;
        max-height: 200px;
        overflow-y: auto;
    }
    
    .properties-panel {
        grid-row: 3;
        max-height: 200px;
        overflow-y: auto;
    }
    
    .controls-section {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .control-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
}

/* 手机端适配 */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .logo-section .logo {
        font-size: 1.25rem;
        text-align: center;
    }
    
    .controls-section {
        justify-content: center;
        max-width: 100%;
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }
    
    .main-content {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .component-library {
        max-height: 150px;
        padding: 1rem;
    }
    
    .properties-panel {
        max-height: 150px;
        padding: 1rem;
    }
    
    .component-item {
        padding: 0.5rem;
        margin-bottom: 0.3rem;
    }
    
    .component-name {
        font-size: 0.8rem;
    }
    
    .section-title {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .category-title {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .operation-hint {
        font-size: 0.8rem;
        padding: 0.5rem;
    }
    
    /* 确保模态框在手机上正常显示 */
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-content h2 {
        padding: 1.5rem 1.5rem 0.5rem;
        font-size: 1.25rem;
    }
    
    .help-content, .preset-content {
        padding: 0.5rem 1.5rem 1.5rem;
    }
    
    .preset-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .preset-modal-btn {
        min-width: auto;
        padding: 0.75rem;
    }
}

/* 拖拽时的样式 */
.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

/* 连接点样式 */
.connection-point {
    width: 8px;
    height: 8px;
    background: #4f46e5;
    border: 2px solid white;
    border-radius: 50%;
    position: absolute;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.connection-point:hover {
    transform: scale(1.5);
    background: #4338ca;
}

.connection-point.active {
    background: #ef4444;
    transform: scale(1.8);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

/* 导线样式 */
.wire {
    stroke: #4f46e5;
    stroke-width: 2;
    fill: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.wire:hover {
    stroke: #4338ca;
    stroke-width: 3;
}

.wire.active {
    stroke: #ef4444;
    stroke-width: 4;
}

/* 电流动画 */
@keyframes currentFlow {
    0% {
        stroke-dashoffset: 100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.wire.flow {
    stroke-dasharray: 10;
    animation: currentFlow 1s linear infinite;
}

/* 灯泡状态 */
.light-bulb.on {
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.8));
}

.light-bulb.off {
    opacity: 0.5;
}

/* 开关状态 */
.switch.on {
    background: linear-gradient(135deg, #10b981, #059669);
}

.switch.off {
    background: linear-gradient(135deg, #6b7280, #4b5563);
}

/* 电路预设弹窗样式 */
.modal-content h2 {
    padding: 1rem 2rem 0;
    margin: 0;
    display: flex;
    align-items: center;
    height: 3rem;
}

.preset-content {
    padding: 1rem 2rem 2rem;
}

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

.preset-modal-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    min-width: 280px;
    white-space: nowrap;
    width: 100%;
}

.preset-modal-btn:hover {
    border-color: #4f46e5;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.15);
    transform: translateY(-1px);
}

.preset-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.preset-info h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 0.25rem 0;
}

.preset-info p {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0;
}

/* 成功/错误提示 */
.notification {
    position: fixed;
    top: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    z-index: 1000;
    animation: slideInRight 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.notification.success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid #10b981;
}

.notification.error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}

.notification.warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid #f59e0b;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #4f46e5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}