/**
 * 版权所有 © 2026 air-descenders
 * 
 * 本代码库为个人备份用途，仅供作者本人使用。
 * 未经明确书面许可，禁止任何形式的复制、分发、修改或商业使用。
 * 
 * GitHub Pages展示仅用于技术分享，不构成代码使用授权。
 */

/* 主样式文件 */

/* 工具栏通用样式 */
.toolbar {
    position: fixed;
    left: 0;
    right: 0;
    height: 50px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* 确保工具栏不会干扰画布触摸事件 */
    pointer-events: none;
}

/* 只让按钮区域可点击，其他区域穿透到画布 */
.toolbar .btn,
.toolbar > div {
    pointer-events: auto;
    /* 确保按钮能正常响应触摸 */
    touch-action: manipulation;
}

.top-toolbar {
    top: 0;
}

.bottom-toolbar {
    bottom: 0;
    border-top: 1px solid #e0e0e0;
    border-bottom: none;
    flex-direction: row;
    flex-wrap: wrap; /* 允许换行 */
    padding: 6px 4px;
    height: auto;
    max-height: 20vh;
    min-height: 60px;
    max-width: 100vw;
    padding-bottom: env(safe-area-inset-bottom, 6px);
    align-items: center;
    gap: 4px;
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-center {
    flex: 1;
    justify-content: center;
}

.toolbar-center .title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    letter-spacing: 0;
    writing-mode: horizontal-tb !important;
}

.app-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.toolbar-right {
    gap: 2px;
}

.btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s ease;
    font-size: 18px;
}

.btn:hover {
    background-color: #f0f0f0;
}

.btn:active {
    transform: scale(0.95);
    background-color: #e0e0e0;
}

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

/* 画布容器 */
.canvas-container {
    position: fixed;
    top: 50px; /* 50px确保顶部不被header遮挡 */
    left: 0;
    right: 0;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    background-color: #ffffff;
    display: block;
    overflow: hidden;
    z-index: 1;
    pointer-events: auto; /* 确保画布容器可以接收触摸事件 */
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent !important;
    z-index: 2;
    /* 确保触摸事件正确传递 */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 底部工具栏内容 */
.tool-group {
    display: flex;
    gap: 4px;
    justify-content: flex-start; /* 工具按钮居左 */
    flex: 1 1 100%; /* 独占一行 */
    order: 1; /* 第一行 */
    padding: 2px 0;
    align-items: center;
}

.tool-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 2px 4px; /* 减小padding */
    border-radius: 6px;
    background-color: transparent;
    color: #666;
    font-size: 0;
    transition: all 0.2s ease;
    min-width: 28px; /* 减小最小宽度 */
}

.tool-btn span {
    display: none; /* 隐藏文字span */
}

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

.tool-btn.active i {
    color: white;
}

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

.tool-btn i {
    font-size: 18px; /* 减小图标尺寸 */
    color: #666;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    line-height: 1;
}

.tool-btn:hover i {
    color: #333;
}

/* 透明度控制（第一行右侧） */
.opacity-control {
    flex: 0 0 auto;
    margin-left: auto; /* 右侧对齐 */
    padding-left: 8px;
}

#opacity-slider {
    width: 60px; /* 固定宽度 */
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

#opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #34C759;
    cursor: pointer;
}

/* 确保图标在移动设备上正确显示 */
@media screen and (max-width: 768px) {
    .tool-btn i {
        font-size: 22px;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* 颜色选择器 */
.color-picker {
    margin-bottom: 0;
    padding-left: 4px;
    flex: 1; /* 占一半空间 */
    order: 2; /* 第二行 */
}

.color-option {
    width: 100% !important; /* 占满整行宽度 */
    height: 10px !important; /* 增大高度 */
    border-radius: 1px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1; /* 均分空间 */
}

.color-palette {
    display: flex;
    gap: 2px !important;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    flex: 1; /* 占满 color-picker */
}

.color-option.active {
    border-color: #007AFF;
    transform: scale(1.1);
}

.color-option:active {
    transform: scale(0.9);
}

/* 右侧尺寸滑块 */
.size-slider {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 4px;
    padding-left: 8px;
    border-left: 1px solid #e0e0e0;
    flex: 1; /* 占一半空间 */
    order: 3; /* 第三行 */
}

#brush-size {
    flex: 1;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

#brush-size::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007AFF;
    cursor: pointer;
}

.size-display {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.size-preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #000;
}

/* 属性面板 */
.property-panel {
    position: fixed;
    bottom: 80px;
    left: 16px;
    right: 16px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
}

.panel-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #333;
}

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

.setting-group label {
    min-width: 60px;
    font-size: 14px;
    color: #666;
}

.setting-group input[type="color"] {
    width: 50px;
    height: 32px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.setting-group input[type="color"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.setting-group input[type="range"] {
    flex: 1;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007AFF;
    cursor: pointer;
}

.marker-setting {
    display: flex !important;
}

/* 形状工具面板 */
.shape-panel {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    width: 90%;
    max-width: 320px;
}

.shape-options {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    justify-content: center;
}

.shape-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    border-radius: 8px;
    background-color: transparent;
    color: #666;
    font-size: 12px;
    transition: all 0.2s ease;
    min-width: 70px;
    border: 2px solid transparent;
}

.shape-btn.active {
    background-color: #007AFF;
    color: white;
    border-color: #0051d5;
}

.shape-btn i {
    font-size: 24px;
}

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

/* 背景菜单 */
.background-menu {
    position: fixed;
    top: 60px;
    right: 16px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    min-width: 120px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-item:hover {
    background-color: #f0f0f0;
}

.menu-item:active {
    transform: scale(0.95);
}

.menu-divider {
    height: 1px;
    background-color: #e0e0e0;
    margin: 4px 0;
}

.bg-preview {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.bg-white {
    background-color: #ffffff;
}

.bg-yellow {
    background-color: #fef3c7;
}

.bg-grid {
    background-image:
        linear-gradient(#e0e0e0 1px, transparent 1px),
        linear-gradient(90deg, #e0e0e0 1px, transparent 1px);
    background-size: 20px 20px;
}

.bg-dots {
    background-image: radial-gradient(circle, #e0e0e0 1px, transparent 1px);
    background-size: 20px 20px;
}

.menu-item span {
    font-size: 14px;
    color: #333;
}

/* 更多操作菜单 */
.more-menu {
    position: fixed;
    top: 60px;
    right: 16px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    min-width: 140px;
}

.more-menu .menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.more-menu .menu-item:hover {
    background-color: #f0f0f0;
}

.more-menu .menu-item:active {
    transform: scale(0.95);
    background-color: #e0e0e0;
}

.more-menu .menu-item i {
    font-size: 18px;
    color: #666;
}

.more-menu .menu-item span {
    font-size: 14px;
    color: #333;
}

/* 确认对话框 */
.confirm-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
}

.dialog-content {
    position: relative;
    background-color: white;
    border-radius: 12px;
    padding: 20px 24px;
    width: 80%;
    max-width: 280px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.dialog-content p {
    font-size: 16px;
    color: #333;
    text-align: center;
    margin: 0 0 20px 0;
}

.dialog-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.dialog-buttons .btn {
    padding: 10px 24px;
    font-size: 14px;
    border-radius: 8px;
}

.dialog-buttons .btn.primary {
    background-color: #007AFF;
    color: white;
}

.dialog-buttons .btn.primary:active {
    background-color: #0051d5;
}

/* 喷漆/填充子菜单 */
.paint-submenu {
    display: flex;
    gap: 6px; /* 与工具栏间距一致 */
    padding: 8px 12px 8px 12px; /* 左侧留出空隙 */
    border-top: 1px solid #f0f0f0;
    margin-top: 4px;
}

.submenu-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 12px;
    border-radius: 8px;
    background-color: transparent;
    color: #666;
    font-size: 11px;
    transition: all 0.2s ease;
    min-width: 55px;
}

.submenu-btn.active {
    background-color: #007AFF;
    color: white;
}

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

.submenu-btn i {
    font-size: 20px;
}

/* 图层子菜单 */
.layer-submenu {
    position: fixed;
    top: 60px;
    right: 16px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    display: flex;
    gap: 4px;
}

/* 颜色按钮减小尺寸 */
.color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-option.active {
    border-color: #007AFF;
    transform: scale(1.1);
}

.color-option:active {
    transform: scale(0.9);
}

/* 图层聚合按钮样式 - 更加醒目 */
#layer-tools-btn {
    background-color: #f0f0f0;
}

#layer-tools-btn:hover {
    background-color: #e0e0e0;
}
@media (hover: none) and (pointer: coarse) {
    /* 增加触摸目标大小 */
    .btn {
        min-width: 36px;
        min-height: 36px;
    }

    .tool-btn {
        min-height: 40px;
        padding: 4px 6px; /* 减小内边距 */
        min-width: 50px; /* 减小最小宽度 */
    }

    .color-option {
        width: 32px;
        height: 32px;
    }

    /* 增加触摸反馈 */
    .btn:active {
        transform: scale(0.95);
        background-color: rgba(0, 0, 0, 0.1);
    }

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

    /* 优化工具栏间距 */
    .tool-group {
        gap: 6px; /* 与基础样式一致 */
        padding-left: 12px; /* 左侧留出空隙 */
    }

    .color-palette {
        gap: 6px; /* 与基础样式一致 */
        padding-left: 12px; /* 左侧留出空隙 */
    }
}

/* 响应式设计 */
@media (max-width: 480px) {
    .toolbar {
        height: 48px;
        padding: 0 12px;
    }

    .bottom-toolbar {
        padding: 10px 12px;
        min-height: 80px;
    }

    .tool-btn {
        min-width: 50px;
        padding: 4px 6px;
        font-size: 11px;
    }

    .tool-group {
        gap: 6px;
        padding-left: 12px;
    }

    .color-palette {
        gap: 6px;
        padding-left: 12px;
    }

    .property-panel {
        left: 12px;
        right: 12px;
        bottom: 80px;
    }

    .background-menu {
        right: 12px;
        min-width: 110px;
    }

    .canvas-container {
        top: 48px;
        bottom: 80px;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .toolbar {
        height: 46px;
        padding: 0 8px;
    }

    .bottom-toolbar {
        padding: 8px;
        min-height: 75px;
    }

    .tool-group {
        gap: 6px;
        padding-left: 12px;
    }

    .color-palette {
        gap: 6px;
        padding-left: 12px;
        justify-content: flex-start;
    }

    .color-option {
        width: 28px;
        height: 28px;
    }
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
    display: none;
}

/* Toast提示消息 */
.toast-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 80%;
    word-wrap: break-word;
}

.toast-message.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* 历史记录面板 */
.history-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-panel .panel-content {
    background-color: white;
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.history-panel h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    text-align: center;
    color: #333;
}

.history-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.history-input-group input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.history-input-group input:focus {
    border-color: #4a90d9;
}

.history-input-group .btn {
    padding: 10px 16px;
    font-size: 14px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 16px;
    max-height: 300px;
}

.history-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

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

.history-item:hover {
    background-color: #f5f5f5;
}

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

.history-item-name {
    font-size: 14px;
    color: #333;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-time {
    font-size: 12px;
    color: #999;
}

.history-item-actions {
    display: flex;
    gap: 8px;
}

.history-item .btn {
    min-width: 36px;
    min-height: 36px;
    padding: 8px;
}

.history-item .btn.delete {
    color: #ff4444;
}

.history-item .btn.load {
    color: #4a90d9;
}

.history-empty {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}

#close-history-btn {
    width: 100%;
    margin-top: auto;
    padding: 12px;
    font-size: 14px;
}

/* 分享背景选项样式 */
.menu-section-title {
    font-size: 12px;
    color: #999;
    padding: 8px 12px 4px;
    margin: 0;
}

.share-bg-options {
    display: flex;
    gap: 8px;
    padding: 4px 8px;
}

.share-bg-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.share-bg-item:hover {
    background-color: #f0f0f0;
}

.share-bg-item:active {
    transform: scale(0.95);
    background-color: #e0e0e0;
}

.share-bg-item.active {
    background-color: #007AFF;
}

.share-bg-item.active span {
    color: white;
}

.share-bg-item .bg-preview {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.share-bg-item.active .bg-preview {
    border-color: white;
}

.share-bg-item span {
    font-size: 12px;
    color: #333;
}

/* 透明背景预览 */
.bg-transparent {
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
}