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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
    background: #f5f5f5;
}

/* 工具栏 */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-right: 1px solid #e0e0e0;
}

.tool-group:last-child {
    border-right: none;
}

.tool-btn,
.action-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #333;
}

.tool-label {
    font-size: 12px;
    color: #666;
    margin-right: 4px;
}

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

.dropdown-btn {
    display: flex !important;
    align-items: center;
    gap: 4px;
    width: auto !important;
    padding: 0 12px !important;
    font-size: 13px;
    font-weight: 500;
}

.dropdown-arrow {
    opacity: 0.4;
    transition: transform 0.2s;
}

.dropdown-btn:hover .dropdown-arrow {
    opacity: 0.8;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 300;
    min-width: 200px;
    margin-top: 4px;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-item:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
}

.tool-btn:hover,
.action-btn:hover {
    background: #f0f0f0;
}

.tool-btn.active {
    background: #007bff;
    color: white;
}

.tool-btn.active:hover {
    background: #0056b3;
}

.action-btn:active {
    transform: scale(0.95);
}

/* 颜色选择器 */
.color-picker-label {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s;
}

.color-picker-label:hover {
    background: #f0f0f0;
}

.color-picker-label input[type="color"] {
    width: 28px;
    height: 28px;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.color-picker-label input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-label input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-picker-label input[type="checkbox"] {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    cursor: pointer;
}

/* 线条粗细 */
.stroke-width-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
    font-size: 14px;
    color: #666;
}

.stroke-width-label input[type="range"] {
    width: 80px;
    cursor: pointer;
}

.stroke-width-label span {
    min-width: 20px;
    text-align: center;
    font-weight: 500;
}

/* 画布容器 */
.canvas-container {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: #f5f5f5;
    cursor: crosshair;
}

.canvas-container.tool-select {
    cursor: default;
}

.canvas-container.tool-pen {
    cursor: crosshair;
}

.canvas-container.tool-text {
    cursor: text;
}

.canvas-container.panning {
    cursor: grabbing;
}

.canvas-container.tool-space {
    cursor: grab;
}

.canvas-container.tool-space.panning {
    cursor: grabbing;
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 文字输入框 */
.text-input {
    position: fixed;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 16px;
    padding: 4px 8px;
    outline: none;
    resize: none;
    min-width: 100px;
    min-height: 30px;
    z-index: 50;
}

.text-input:focus {
    border: 2px solid #007bff;
    background: white;
}

/* 选中框 */
.selection-box {
    position: absolute;
    border: 2px dashed #007bff;
    background: rgba(0, 123, 255, 0.1);
    pointer-events: none;
}

/* 右侧属性面板 */
.properties-panel {
    position: fixed;
    top: 56px;
    right: -320px;
    width: 300px;
    bottom: 0;
    background: white;
    border-left: 1px solid #e0e0e0;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 200;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.properties-panel.open {
    right: 0;
}

.properties-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.properties-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.properties-header button {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    line-height: 1;
}

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

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

.property-group label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 6px;
    font-weight: 500;
}

.property-group input[type="number"],
.property-group input[type="text"],
.property-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.property-group input[type="color"] {
    width: 100%;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.property-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

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

/* 尺寸行 + 比例锁 */
.property-size-row {
    display: flex; align-items: center; gap: 6px;
}
.property-size-row input { flex: 1; }
.lock-btn {
    padding: 4px 6px; border: 1px solid #ddd; border-radius: 6px;
    background: #fafafa; cursor: pointer; font-size: 14px;
    transition: all 0.15s; line-height: 1; display: flex; align-items: center;
}
.lock-btn:hover { border-color: #007bff; }
.lock-btn.locked { background: #e8f0fe; border-color: #007bff; }

/* 颜色预设 */
.color-presets {
    display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap;
}
.color-preset {
    width: 22px; height: 22px; border-radius: 4px; cursor: pointer;
    border: 2px solid transparent; transition: all 0.15s;
}
.color-preset:hover { transform: scale(1.2); border-color: #333; }

/* 暗色模式 */
body.dark { background: #1a1a2e; color: #e0e0e0; }
body.dark .toolbar { background: #16213e; border-bottom-color: #2a2a4a; }
body.dark .properties-panel { background: #16213e; border-left-color: #2a2a4a; }
body.dark .canvas-container { background: #1a1a2e; }
body.dark .tool-btn, body.dark .action-btn { color: #ccc; }
body.dark .tool-btn:hover, body.dark .action-btn:hover { background: #2a2a4a; }
body.dark .tool-btn.active { background: #007bff; color: #fff; }
body.dark #canvas { background: #0f0f23; box-shadow: none; }
body.dark .property-group label { color: #aaa; }
body.dark .property-group input,
body.dark .property-group select,
body.dark .property-group textarea,
body.dark .lock-btn { background: #1a1a2e; border-color: #333; color: #ddd; }
body.dark .properties-header h3 { color: #ddd; }
body.dark .home-link { color: #aaa; }
body.dark .home-link:hover { color: #007bff; background: #2a2a4a; }
body.dark .dropdown-menu { background: #16213e; border-color: #2a2a4a; }
body.dark .dropdown-item { color: #ccc; }
body.dark .dropdown-item:hover { background: #2a2a4a; }
body.dark kbd { background: #2a2a4a; border-color: #444; color: #ccc; }
body.dark .shortcut-card { background: #16213e; }
body.dark .shortcut-table td { border-bottom-color: #2a2a4a; }

/* 弹窗 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-dialog-small {
    max-width: 380px;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 24px 12px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 { font-size: 18px; color: #333; }

.modal-close {
    background: none; border: none; font-size: 28px;
    color: #999; cursor: pointer; line-height: 1;
}

.modal-body { padding: 20px 24px; }

/* 快捷键卡片 */
.shortcut-card {
    background: #fafafa;
    border-radius: 8px;
    padding: 14px 16px;
}
.shortcut-card-title {
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: 8px;
}
.shortcut-card .shortcut-table td {
    padding: 6px 8px;
    font-size: 13px;
}

/* 设置面板 */
.settings-section { margin-bottom: 20px; }
.settings-bg-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 14px; border: 2px solid #e0e0e0;
    border-radius: 8px; background: white;
    font-size: 13px; cursor: pointer; font-family: inherit;
    transition: all 0.15s;
}
.settings-bg-btn i { width: 16px; height: 16px; }
.settings-bg-btn:hover { border-color: #007bff; background: #f0f7ff; }
.settings-bg-btn.active { border-color: #007bff; background: #e8f0fe; color: #007bff; font-weight: 600; }

/* 返回首页链接 */
.home-link {
    display: flex; align-items: center; gap: 6px;
    text-decoration: none; color: #555; font-size: 13px;
    padding: 8px 12px; border-radius: 6px;
    transition: all 0.15s; white-space: nowrap;
}
.home-link:hover { color: #007bff; background: #f0f7ff; }

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    /* 工具栏水平滚动 */
    .toolbar {
        height: 48px; padding: 0 8px; gap: 4px;
        overflow-x: auto; overflow-y: hidden;
        white-space: nowrap; -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    .toolbar::-webkit-scrollbar { height: 2px; }
    .toolbar::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
    
    .tool-group { padding: 0 4px; border-right-width: 0; }
    .tool-btn, .action-btn { width: 34px; height: 34px; min-width: 34px; }
    .tool-btn svg, .action-btn svg, .tool-btn i, .action-btn i { width: 16px; height: 16px; }
    .tool-label { font-size: 10px; margin-right: 2px; }
    .stroke-width-label { gap: 4px; font-size: 11px; }
    .stroke-width-label input[type="range"] { width: 50px; }
    .dropdown-btn { padding: 0 8px !important; font-size: 11px; }
    .dropdown-btn span { display: none; }
    .dropdown-btn::after { content: '⇩'; font-size: 12px; }
    
    /* 画布容器 */
    .canvas-container { top: 48px; }
    
    /* 属性面板全宽 */
    .properties-panel { top: 48px; right: -100%; width: 100%; max-width: 320px; }
    .properties-panel.open { right: 0; }
    .canvas-container.with-panel { right: 0; }
    
    /* 弹窗适配 */
    .modal-dialog { max-width: 95% !important; width: 95%; margin: 0 auto; }
    .shortcut-card .shortcut-table td { padding: 4px 6px; font-size: 12px; }
    .settings-bg-btn { padding: 8px 10px; font-size: 12px; }
    .settings-bg-btn i { width: 14px; height: 14px; }
    
    /* 文字输入框 */
    .text-input { z-index: 300; }
    
    /* 首页返回链接 */
    .home-link { font-size: 11px; padding: 6px 8px; }
    .home-link i { width: 14px; height: 14px; }
}

@media (max-width: 480px) {
    .toolbar { padding: 0 4px; gap: 2px; }
    .tool-btn, .action-btn { width: 30px; height: 30px; min-width: 30px; }
    .tool-btn svg, .action-btn svg { width: 14px; height: 14px; }
    .stroke-width-label input[type="range"] { width: 40px; }
    .dropdown-btn { font-size: 10px; padding: 0 6px !important; }
    .home-link { padding: 4px 6px; font-size: 10px; }
}

.modal-icon { font-size: 48px; margin-bottom: 8px; }

.modal-actions {
    display: flex; gap: 12px; justify-content: center; margin-top: 20px;
}

.modal-btn {
    padding: 10px 32px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    font-family: inherit; transition: all 0.15s;
}

.modal-btn-primary { background: #007bff; color: white; }
.modal-btn-primary:hover { background: #0056b3; }
.modal-btn-danger { background: #dc3545; color: white; }
.modal-btn-danger:hover { background: #b02a37; }
.modal-btn-cancel { background: #f0f0f0; color: #666; }
.modal-btn-cancel:hover { background: #ddd; }

/* 快捷键表 */
.shortcut-table {
    width: 100%; border-collapse: collapse;
}

.shortcut-table td {
    padding: 10px 12px; border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.shortcut-table td:first-child {
    white-space: nowrap; width: 40%;
}

.shortcut-table kbd {
    display: inline-block;
    padding: 2px 8px; background: #f5f5f5;
    border: 1px solid #ddd; border-radius: 4px;
    font-size: 13px; font-family: monospace;
    margin-right: 4px;
}

.shortcut-table span {
    font-size: 12px; color: #999; margin-left: 4px;
}

/* 响应式 */
@media (max-width: 768px) {
    .toolbar {
        padding: 0 8px;
        gap: 4px;
    }

    .tool-group {
        padding: 0 4px;
    }

    .stroke-width-label input[type="range"] {
        width: 60px;
    }
}
