/* 基础样式和变量 */
:root {
    --primary-color: #3b82f6;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --purple-color: #a855f7;
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%);
    --card-gradient: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    padding: 20px;
    color: #1e293b;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

/* 头部样式 */
.header {
    text-align: center;
    margin-bottom: 30px;
    animation: fadeInDown 0.6s ease-out;
}

.header h1 {
    font-size: 2.8rem;
    color: #1e293b;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--purple-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: #64748b;
    font-size: 1.2rem;
    font-weight: 500;
}

/* 信息面板 */
.info-panel {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    border-left: 4px solid var(--primary-color);
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    position: relative;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.6s ease-out;
    transition: var(--transition);
}

.info-panel:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.info-panel h3 {
    color: #1e3a8a;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.info-panel ul {
    list-style: none;
    color: #1e40af;
}

.info-panel li {
    margin: 10px 0;
    font-size: 0.95rem;
    padding-left: 10px;
    position: relative;
}

.info-panel li::before {
    content: "•";
    position: absolute;
    left: -10px;
    color: var(--primary-color);
    font-weight: bold;
}

.close-info {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #2563eb;
    font-size: 1.8rem;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
    padding: 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-info:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #1d4ed8;
    transform: scale(1.1);
}

/* 主内容布局 */
.main-content {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    animation: fadeIn 0.8s ease-out;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* 面板样式 */
.panel {
    background: var(--card-gradient);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 25px;
    transition: var(--transition);
}

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

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.panel-header h2 {
    font-size: 1.8rem;
    color: #1e293b;
    font-weight: 700;
}

/* 按钮样式 */
.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:hover::before {
    width: 300px;
    height: 300px;
}

button span {
    position: relative;
    z-index: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #6366f1);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color), #059669);
    color: white;
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary-color), #475569);
    color: white;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #475569, #334155);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-purple {
    background: linear-gradient(135deg, var(--purple-color), #9333ea);
    color: white;
}

.btn-purple:hover {
    background: linear-gradient(135deg, #9333ea, #7e22ce);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-small {
    padding: 8px 15px;
    font-size: 0.85rem;
}

/* 工具栏样式 */
.toolbar {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
    padding: 15px;
    background: rgba(248, 250, 252, 0.8);
    border-radius: var(--border-radius);
    border: 1px solid #e2e8f0;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.tool-group {
    display: flex;
    gap: 8px;
    background: white;
    padding: 8px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9;
}

.tool-btn {
    padding: 10px 15px;
    background: white;
    color: #64748b;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.tool-btn:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.tool-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.tool-btn.active:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    pointer-events: none;
    background: #cbd5e1 !important;
    color: #94a3b8 !important;
    border-color: #e2e8f0 !important;
}

/* 设计网格 */
.grid-container {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    padding: 20px;
    background: rgba(241, 245, 249, 0.8);
    border-radius: var(--border-radius);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.design-grid {
    display: inline-grid;
    grid-template-columns: repeat(16, 32px);
    gap: 2px;
    background: #cbd5e1;
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
    .design-grid {
        grid-template-columns: repeat(16, 25px);
        gap: 1px;
    }
    
    .cell {
        width: 25px !important;
        height: 25px !important;
    }
}

.cell {
    width: 32px;
    height: 32px;
    cursor: pointer;
    transition: var(--transition);
    border-radius: 2px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
}

.cell:hover {
    transform: scale(1.15);
    z-index: 10;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.cell-filled {
    background: #1e293b;
    animation: fillCell 0.3s ease-out;
}

.cell-empty {
    background: #e5e7eb;
    animation: emptyCell 0.3s ease-out;
}

/* 织造区域 */
.weave-container {
    animation: fadeIn 0.6s ease-out;
}

.weave-controls {
    background: rgba(248, 250, 252, 0.8);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 25px;
    box-shadow: var(--shadow-sm);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.weave-progress {
    color: #64748b;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    padding: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.weave-speed-control {
    display: flex;
    align-items: center;
    gap: 15px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.weave-speed-control label {
    font-weight: 600;
    color: #374151;
    min-width: 50px;
}

.weave-speed-control input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
}

.weave-speed-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.weave-speed-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-md);
}

.weave-speed-control span {
    font-weight: 600;
    color: #374151;
    min-width: 70px;
    text-align: right;
}

.weave-playback {
    display: flex;
    gap: 10px;
    justify-content: center;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.weave-cards {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding: 20px;
    background: rgba(248, 250, 252, 0.8);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 25px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f5f9;
}

.weave-cards::-webkit-scrollbar {
    height: 8px;
}

.weave-cards::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

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

.weave-cards::-webkit-scrollbar-thumb:hover {
    background: #2563eb;
}

.weave-card {
    flex-shrink: 0;
    padding: 15px;
    border-radius: 8px;
    background: white;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
    animation: fadeIn 0.4s ease-out;
}

.weave-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #e2e8f0;
}

.weave-card.active {
    background: #dbeafe;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
}

.weave-card-title {
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
    color: #64748b;
}

/* 卡片列表 */
.cards-list {
    max-height: 700px;
    overflow-y: auto;
    padding-right: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f5f9;
}

.cards-list::-webkit-scrollbar {
    width: 8px;
}

.cards-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

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

.cards-list::-webkit-scrollbar-thumb:hover {
    background: #2563eb;
}

.card-item {
    background: #f8fafc;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9;
    position: relative;
    cursor: move;
}

.card-item:hover {
    background: #f1f5f9;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.card-header span {
    font-weight: bold;
    color: #334155;
    font-size: 0.95rem;
}

.delete-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px 10px;
    border-radius: 4px;
    transition: var(--transition);
    font-weight: 600;
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    transform: translateY(-1px);
}

/* 卡片预览 */
.card-preview {
    display: inline-grid;
    grid-template-columns: repeat(16, 12px);
    gap: 1px;
    background: #cbd5e1;
    padding: 8px;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
    width: calc(16 * 12px + 15 * 1px + 16px); /* 16 cells * 12px + 15 gaps * 1px + 16px padding */
    height: calc(16 * 12px + 15 * 1px + 16px); /* 16 cells * 12px + 15 gaps * 1px + 16px padding */
    overflow: hidden;
    box-sizing: border-box;
}

.preview-cell {
    width: 12px;
    height: 12px;
    border-radius: 1px;
    transition: var(--transition);
}

/* 织物预览 */
.weave-result {
    margin-top: 30px;
    background: #f8fafc;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9;
}

.weave-result h3 {
    color: #334155;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.3rem;
}

.weave-status {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    font-size: 0.95rem;
    color: #374151;
    line-height: 1.6;
}

.weave-status p {
    margin: 8px 0;
    padding: 5px 0;
    border-bottom: 1px solid #f1f5f9;
}

.weave-status p:last-child {
    border-bottom: none;
    font-weight: 600;
    color: #1e40af;
}

.fabric-preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: auto;
}

.fabric-preview {
    display: inline-block;
    background: white;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.fabric-row {
    display: flex;
}

.fabric-col {
    display: flex;
    flex-direction: column;
}

.fabric-pixel {
    width: 10px;
    height: 10px;
    transition: var(--transition);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: #94a3b8;
    background: #f8fafc;
    border-radius: var(--border-radius);
    border: 2px dashed #cbd5e1;
    margin: 20px 0;
    animation: fadeIn 0.6s ease-out;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    display: block;
    animation: bounce 2s infinite;
}

.empty-state p {
    margin: 5px 0;
    font-size: 1rem;
}

.empty-state-hint {
    font-size: 0.9rem !important;
    opacity: 0.8;
}

/* 知识面板 */
.knowledge-section {
    animation: fadeIn 0.8s ease-out;
}

.knowledge-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

@media (max-width: 968px) {
    .knowledge-grid {
        grid-template-columns: 1fr;
    }
}

.knowledge-panel {
    background: var(--card-gradient);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 25px;
    transition: var(--transition);
    border: 1px solid #f1f5f9;
}

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

.knowledge-panel h3 {
    color: #1e293b;
    margin-bottom: 15px;
    font-size: 1.3rem;
    font-weight: 700;
}

.knowledge-panel p {
    color: #64748b;
    line-height: 1.6;
    margin: 12px 0;
    font-size: 0.95rem;
}

.knowledge-panel strong {
    color: #334155;
}

/* 下拉菜单 */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    border: 1px solid #e2e8f0;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu button {
    width: 100%;
    text-align: left;
    padding: 12px 15px;
    border: none;
    background: none;
    border-radius: 0;
    font-size: 0.9rem;
    color: #64748b;
    transition: var(--transition);
    box-shadow: none;
}

.dropdown-menu button:hover {
    background: #f1f5f9;
    color: #334155;
    transform: none;
}

.dropdown-menu button:first-child {
    border-radius: 8px 8px 0 0;
}

.dropdown-menu button:last-child {
    border-radius: 0 0 8px 8px;
}

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

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

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

@keyframes fillCell {
    from {
        transform: scale(0.8);
        opacity: 0.5;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes emptyCell {
    from {
        transform: scale(0.8);
        opacity: 0.5;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .header p {
        font-size: 1rem;
    }
    
    .panel {
        padding: 15px;
    }
    
    .panel-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .button-group {
        justify-content: center;
    }
    
    .toolbar {
        flex-direction: column;
        gap: 15px;
    }
    
    .tool-group {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .info-panel {
        padding: 15px;
    }
    
    .weave-controls {
        gap: 10px;
        padding: 15px;
    }
    
    .weave-speed-control {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .weave-speed-control span {
        text-align: center;
    }
    
    .knowledge-panel {
        padding: 20px;
    }
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 工具提示 */
[title] {
    position: relative;
}

[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #334155;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    margin-bottom: 5px;
    animation: fadeIn 0.2s ease-out;
}

[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #334155;
    z-index: 1000;
    margin-bottom: -1px;
    animation: fadeIn 0.2s ease-out;
}