:root {
    --primary-color: #2D3436;
    --secondary-color: #636E72;
    --accent-color: #FF6B6B;
    --success-color: #00B894;
    --warning-color: #FDCB6E;
    --background-primary: #FAFAFA;
    --background-secondary: #FFFFFF;
    --border-color: #DFE6E9;
    --text-primary: #2D3436;
    --text-secondary: #636E72;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: 0.3s ease;
}

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

body {
    font-family: 'Noto Sans SC', 'PingFang SC', -apple-system, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--background-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    height: 60px;
    background: var(--background-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    color: var(--accent-color);
    display: flex;
    align-items: center;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-nav {
    display: flex;
    gap: 8px;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.nav-tab:hover {
    background: var(--background-primary);
    color: var(--text-primary);
}

.nav-tab.active {
    background: var(--accent-color);
    color: white;
}

.nav-tab svg {
    flex-shrink: 0;
}

.header-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--background-primary);
    color: var(--text-primary);
}

.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.upload-section,
.process-section,
.export-section {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow: auto;
}

.upload-section {
    max-width: 600px;
    margin: 0 auto;
}

.upload-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--background-secondary);
    padding: 48px;
    cursor: pointer;
    transition: var(--transition);
    min-height: 300px;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(255, 107, 107, 0.05);
}

.upload-icon {
    color: var(--border-color);
    margin-bottom: 16px;
    transition: var(--transition);
}

.upload-area:hover .upload-icon {
    color: var(--accent-color);
    transform: translateY(-4px);
}

.upload-area h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.upload-formats {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--background-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
}

.preview-container {
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-md);
}

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

.preview-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.btn-text {
    border: none;
    background: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-text:hover {
    background: rgba(255, 107, 107, 0.1);
}

.preview-image-wrapper {
    position: relative;
    width: 100%;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#f0f0f0 0% 0% 50%) 50% / 20px 20px 25%, white;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.preview-image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.upload-info {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.process-section {
    display: none;
}

.process-section.active {
    display: flex;
}

.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-primary);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: var(--background-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

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

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

.zoom-level {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

.canvas-wrapper {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#f5f5f5 0% 25%, white 0% 50%) 50% / 20px 20px;
    padding: 24px;
}

#drawingCanvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-lg);
    background: white;
}

.process-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 16px;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: #ff5252;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-large {
    padding: 14px 28px;
    font-size: 16px;
}

.process-options {
    flex: 1;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.option-group label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.option-group input[type="range"] {
    width: 100px;
    height: 4px;
    appearance: none;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
}

.option-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.option-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.option-group span {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 30px;
}

.option-group select {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    background: var(--background-secondary);
    cursor: pointer;
    outline: none;
}

.option-group select:focus {
    border-color: var(--accent-color);
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--success-color));
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 80px;
}

.export-section {
    display: none;
    flex-direction: row;
    gap: 24px;
}

.export-section.active {
    display: flex;
}

.export-preview {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.export-preview canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-lg);
}

.export-options {
    width: 320px;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.export-options h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
}

.radio-label input[type="radio"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.radio-label input[type="radio"]:checked {
    border-color: var(--accent-color);
}

.radio-label input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
}

.sidebar {
    width: 320px;
    background: var(--background-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    overflow: hidden;
}

.sidebar.collapsed {
    width: 48px;
}

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

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .sidebar-content {
    display: none;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.info-card {
    background: var(--background-primary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
}

.info-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.stroke-detail {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.detail-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.color-badge {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
    border: 1px solid var(--border-color);
}

.stats-summary {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 12px;
    background: var(--background-secondary);
    border-radius: var(--radius-md);
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-color);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.color-distribution {
    margin-top: 12px;
}

.color-bar {
    display: flex;
    height: 24px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.color-detail-list {
    margin-top: 16px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.color-detail-list h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.color-list-scroll {
    max-height: 200px;
    overflow-y: auto;
}

.color-detail-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.color-detail-item:hover {
    background: var(--background-secondary);
}

.color-detail-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.color-detail-info {
    flex: 1;
    min-width: 0;
}

.color-detail-id {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.color-detail-name {
    font-size: 11px;
    color: var(--text-secondary);
}

.color-detail-percent {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-color);
    min-width: 45px;
    text-align: right;
}

.color-detail-count {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 35px;
    text-align: right;
}

.color-bar-segment {
    height: 100%;
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.color-bar-segment:hover {
    transform: scaleY(1.2);
}

.color-bar-segment::after {
    content: attr(data-color);
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    opacity: 0;
    transition: var(--transition);
}

.color-bar-segment:hover::after {
    opacity: 1;
}

.color-search {
    margin-bottom: 12px;
}

.color-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

.color-search input:focus {
    border-color: var(--accent-color);
}

.color-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.category-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    background: var(--background-secondary);
    color: var(--text-secondary);
    font-size: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

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

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

.color-list {
    max-height: 300px;
    overflow-y: auto;
}

.color-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.color-item:hover {
    background: var(--background-secondary);
}

.color-item.active {
    background: rgba(255, 107, 107, 0.1);
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.color-info {
    flex: 1;
    min-width: 0;
}

.color-id {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.color-name {
    font-size: 12px;
    color: var(--text-secondary);
}

.footer {
    height: 40px;
    background: var(--background-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    font-size: 12px;
    color: var(--text-secondary);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

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

.modal-content {
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    transform: translateY(20px);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

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

.modal-content h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 24px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--accent-color);
}

.help-section p {
    color: var(--text-secondary);
    line-height: 1.8;
}

@media (max-width: 1199px) {
    .sidebar {
        width: 280px;
    }
    
    .export-section {
        flex-direction: column;
    }
    
    .export-options {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 16px;
    }
    
    .header-title {
        display: none;
    }
    
    .nav-tab span {
        display: none;
    }
    
    .nav-tab {
        padding: 8px 12px;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        position: fixed;
        right: 0;
        top: 60px;
        bottom: 40px;
        z-index: 50;
        transform: translateX(100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .process-options {
        flex-direction: column;
        gap: 12px;
    }
    
    .option-group {
        width: 100%;
    }
    
    .option-group input[type="range"] {
        flex: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

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