:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --accent: #ec4899;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 1.25rem;
}

.logo-icon {
    font-size: 1.5rem;
}

.nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-light);
    font-size: 0.95rem;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--primary);
}

.btn-create {
    background: var(--primary);
    color: white !important;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.btn-create:hover {
    background: var(--primary-dark) !important;
}

.app-main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px;
}

.app-footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.875rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
}

.loading {
    text-align: center;
    padding: 60px;
    color: var(--text-muted);
}

.error {
    background: #fef2f2;
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid #fecaca;
    margin: 16px 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    gap: 4px;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #e5e7eb;
    color: var(--text);
}

.btn-secondary:hover {
    background: #d1d5db;
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

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

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

.home-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
}

.home-header p {
    color: var(--text-light);
    margin-top: 4px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.artwork-card {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.artwork-card:hover {
    transform: translateY(-2px);
}

.artwork-thumb {
    aspect-ratio: 10/7;
    background: #f3f4f6;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.artwork-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.artwork-thumb svg {
    width: 100%;
    height: 100%;
}

.artwork-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.artwork-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-light);
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.editor-layout {
    display: flex;
    gap: 20px;
}

.editor-sidebar {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.tool-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tool-btn {
    padding: 8px;
    border: 1px solid var(--border);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.tool-btn:hover {
    background: #f3f4f6;
}

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

.tool-btn.active:hover {
    background: var(--primary-dark);
}

.color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: var(--primary);
    transform: scale(1.15);
}

.color-swatch input[type="color"] {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
}

.range-input {
    width: 100%;
    margin-top: 8px;
}

.editor-canvas {
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    touch-action: none;
}

.editor-canvas svg {
    display: block;
    width: 100%;
    height: auto;
}

.editor-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 8px 12px;
    background: #f9fafb;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.editor-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

.detail-layout {
    display: flex;
    gap: 20px;
}

.detail-main {
    flex: 1;
}

.detail-sidebar {
    width: 320px;
    flex-shrink: 0;
}

.detail-header {
    margin-bottom: 20px;
}

.detail-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.detail-meta {
    display: flex;
    gap: 16px;
    color: var(--text-light);
    font-size: 0.875rem;
    flex-wrap: wrap;
}

.detail-description {
    color: var(--text-light);
    margin-top: 8px;
}

.detail-svg {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.detail-svg svg {
    width: 100%;
    height: auto;
    display: block;
}

.detail-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    font-size: 0.875rem;
}

.info-grid .label {
    color: var(--text-light);
}

.info-grid .value {
    color: var(--text);
    font-weight: 500;
}

.tree-container {
    width: 100%;
    min-height: 400px;
}

.tree-container svg {
    width: 100%;
    height: auto;
}

.tree-node {
    cursor: pointer;
}

.tree-node circle {
    transition: r 0.2s;
}

.tree-node text {
    font-size: 11px;
    fill: var(--text-light);
    pointer-events: none;
}

.tree-node:hover circle {
    filter: brightness(1.1);
}

.replay-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.replay-modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
}

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

.replay-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.replay-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.replay-body {
    padding: 20px;
}

.replay-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.replay-progress input[type="range"] {
    flex: 1;
}

.replay-canvas {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 16px;
}

.replay-canvas svg {
    width: 100%;
    height: auto;
    display: block;
}

.replay-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.replay-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.replay-step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    transition: background 0.2s;
}

.replay-step.active {
    background: #eff6ff;
}

.replay-step .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
}

.replay-step.active .dot {
    background: var(--primary);
}

.replay-step.done .dot {
    background: var(--success);
}

@media (max-width: 900px) {
    .editor-layout {
        flex-direction: column;
    }

    .editor-sidebar {
        width: 100%;
    }

    .detail-layout {
        flex-direction: column;
    }

    .detail-sidebar {
        width: 100%;
    }

    .home-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

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

    .detail-actions {
        flex-direction: column;
    }

    .detail-actions .btn {
        width: 100%;
    }

    .replay-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 600px) {
    .app-main {
        padding: 16px 12px;
    }

    .header-inner {
        padding: 10px 12px;
    }

    .nav {
        gap: 8px;
    }

    .nav-link:not(.btn-create) {
        display: none;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .editor-actions {
        flex-direction: column;
    }

    .editor-actions .btn {
        width: 100%;
    }

    .card {
        padding: 14px;
    }
}
