* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    /* 不在 body 上设置 touch-action: none，否则会阻止触屏设备将 touch 事件转换为 click 事件，导致工具栏按钮无法响应触屏点击 */
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background: #ffffff;
}

/* 工具栏 */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 6px 10px;
    background: #ffffff;
    border-bottom: 1px solid #e4e7ec;
    flex-shrink: 0;
    min-height: 44px;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    /* 修复 Win7 Chrome PWA standalone 模式下工具栏无法点击的问题：
       显式声明工具栏区域不可拖拽，防止窗口标题栏拖拽行为覆盖按钮点击事件 */
    -webkit-app-region: no-drag;
    app-region: no-drag;
    /* 允许触屏设备将触摸转换为点击事件，使工具栏按钮可响应触屏操作 */
    touch-action: manipulation;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-wrap: wrap;
    -webkit-app-region: no-drag;
    app-region: no-drag;
}

.toolbar-divider {
    width: 1px;
    height: 22px;
    background: #e4e7ec;
    margin: 0 3px;
    flex-shrink: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #1f2a3a;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
    touch-action: manipulation;
    /* 兼容旧版浏览器：确保 SVG 图标居中 */
    line-height: 1;
    -webkit-app-region: no-drag;
    app-region: no-drag;
}
.btn svg {
    display: block;
    pointer-events: none;
}
.btn:hover { background: #f0f2f5; }
.btn:active { transform: scale(0.92); }
.btn.active {
    background: #e6f0ff;
    color: #1677ff;
}
.btn.danger:hover {
    background: #fff1f0;
    color: #ff4d4f;
}

/* 导出按钮 */
.btn-export:hover {
    background: #e6f7ff;
    color: #1677ff;
}

/* 全屏按钮 */
.btn-fullscreen:hover {
    color: #1677ff;
}

/* 图形弹出菜单 */
.shape-picker {
    position: relative;
}
.shape-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 6px;
    z-index: 100;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    min-width: 160px;
}
.shape-popup.show {
    display: grid;
}
.shape-option {
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1f2a3a;
    transition: background 0.12s;
}
.shape-option:hover { background: #f0f2f5; }
.shape-option.active {
    background: #e6f0ff;
    color: #1677ff;
}
/* 小三角箭头 */
.shape-popup::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: #fff;
}

/* 背景色选择 */
.bg-picker {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 2px;
}
.bg-btn {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid transparent;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s, transform 0.1s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}
.bg-btn:hover { transform: scale(1.1); }
.bg-btn.active {
    border-color: #1677ff;
    box-shadow: 0 0 0 2px rgba(22,119,255,0.25);
}
.bg-custom-wrap input[type="color"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}
.bg-custom-wrap {
    position: relative;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid #d9d9d9;
    flex-shrink: 0;
    background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 0 2px;
}
.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.active {
    border-color: #1677ff;
    box-shadow: 0 0 0 2px rgba(22,119,255,0.25);
}
.color-swatch.custom {
    border-color: #d9d9d9;
    background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
    position: relative;
}
.color-swatch.custom input[type="color"] {
    position: absolute;
    inset: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}

.size-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 2px;
}
.size-row {
    display: flex;
    align-items: center;
    gap: 3px;
    min-height: 18px;
}
.size-icon {
    width: 16px;
    text-align: center;
    font-size: 12px;
    flex-shrink: 0;
}
.size-row input[type="range"] {
    width: 52px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #d9d9d9;
    border-radius: 2px;
    outline: none;
    touch-action: none;
}
.size-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #1677ff;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.size-row input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #1677ff;
    cursor: pointer;
    border: none;
}
.size-label {
    font-size: 11px;
    color: #1f2a3a;
    min-width: 20px;
    text-align: center;
    font-weight: 500;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 1px;
}
.zoom-control .btn { width: 24px; height: 24px; font-size: 13px; }
.zoom-label {
    font-size: 11px;
    color: #1f2a3a;
    min-width: 36px;
    text-align: center;
    font-weight: 500;
}

/* 画布容器 —— 填满剩余空间 */
.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #fafafa;
    touch-action: none;
    cursor: crosshair;
    transition: background 0.2s;
}
.canvas-wrapper.dragging { cursor: grab; }
.canvas-wrapper.dragging:active { cursor: grabbing; }

#whiteboard {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: transparent;
}

/* 提示 */
.hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(6px);
}
.hint.show { opacity: 1; }

/* 橡皮擦光标 */
.canvas-wrapper.eraser-active {
    cursor: none;
}
.canvas-wrapper.eraser-active canvas {
    cursor: none;
}
.eraser-cursor {
    display: none;
    position: fixed;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.15);
    pointer-events: none;
    z-index: 10;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1), inset 0 0 0 1px rgba(0,0,0,0.05);
}
.eraser-cursor.show {
    display: block;
}

/* 右下角水印 */
.watermark {
    position: absolute;
    bottom: 12px;
    right: 16px;
    color: rgba(0, 0, 0, 0.15);
    font-size: 13px;
    font-family: "Georgia", "Times New Roman", serif;
    font-style: italic;
    pointer-events: none;
    z-index: 5;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

/* 页面控件（工具栏内） */
.page-controls {
    display: flex;
    align-items: center;
    gap: 1px;
    max-width: 200px;
    flex-shrink: 0;
}
.page-controls .page-btn {
    width: 22px;
    height: 22px;
    font-size: 10px;
    flex-shrink: 0;
}
.page-controls .page-add { color: #1677ff; }
.page-controls .page-del { color: #e74c3c; }
.page-controls .page-del:disabled { opacity: 0.3; cursor: not-allowed; }

.page-list {
    display: flex;
    align-items: center;
    gap: 1px;
    overflow-x: auto;
    flex: 1;
    min-width: 30px;
    max-width: 100px;
    scrollbar-width: thin;
    padding: 0 1px;
}
.page-list::-webkit-scrollbar { height: 2px; }
.page-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.page-tab {
    min-width: 22px;
    height: 20px;
    border: none;
    background: transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    flex-shrink: 0;
    padding: 0 4px;
    user-select: none;
    transition: background 0.15s;
}
.page-tab:hover { background: #ddd; }
.page-tab.active {
    background: #1677ff;
    color: #fff;
    font-weight: 600;
}

@media (max-width: 700px) {
    .toolbar { padding: 6px 10px; gap: 4px 8px; min-height: 48px; }
    .btn { width: 30px; height: 30px; font-size: 16px; }
    .color-swatch { width: 22px; height: 22px; }
    .size-row input[type="range"] { width: 44px; }
    .size-icon { width: 16px; font-size: 12px; }
    .size-label { font-size: 11px; min-width: 18px; }
    .zoom-label { min-width: 38px; font-size: 12px; }
    .toolbar-divider { height: 22px; }
    .page-controls { max-width: 160px; }
    .page-list { max-width: 80px; }
    .page-tab { min-width: 22px; height: 20px; font-size: 10px; padding: 0 4px; }
    .page-controls .page-btn { width: 22px; height: 22px; font-size: 10px; }
}
@media (max-width: 480px) {
    .toolbar { padding: 4px 6px; gap: 3px 6px; min-height: 42px; }
    .btn { width: 26px; height: 26px; font-size: 14px; }
    .color-swatch { width: 18px; height: 18px; }
    .size-row input[type="range"] { width: 34px; }
    .size-icon { width: 14px; font-size: 11px; }
    .size-label { font-size: 11px; min-width: 20px; }
    .zoom-label { min-width: 32px; font-size: 11px; }
    .toolbar-divider { margin: 0 2px; height: 18px; }
    .page-controls { max-width: 120px; }
    .page-list { max-width: 50px; }
    .page-tab { min-width: 18px; height: 18px; font-size: 9px; padding: 0 3px; }
    .page-controls .page-btn { width: 20px; height: 20px; font-size: 9px; }
}
