/* ===== 基础重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    touch-action: none;
    overscroll-behavior: none;
    /* 始终占满整个视口 —— 包括 PWA 全屏模式下"无地址栏"后的整个屏幕 */
    width: 100vw;
    height: 100vh;
    height: 100dvh;          /* 动态视口高度，适配移动浏览器地址栏 */
    width: 100dvw;
}

/* ===== 应用容器：留出 1/30 边距 ===== */
.app {
    position: fixed;
    inset: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
}

.board-wrapper {
    position: relative;
    /* 边距压缩到极小（4px），最大化展示画布，避免黑色边框占用 */
    width: calc(100% - 8px);
    height: calc(100% - 8px);
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    touch-action: none;
}

/* ===== 画板 Canvas ===== */
.board {
    display: block;
    width: 100%;
    height: 100%;
    background: #ffffff;
    touch-action: none;
    cursor: crosshair;
}

/* ===== 启动引导层（全屏 API 必须用户手势） ===== */
.boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.boot-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.boot-content {
    text-align: center;
    color: #ffffff;
    padding: 20px;
    user-select: none;
    -webkit-user-select: none;
}

.boot-content svg {
    color: #007aff;
    margin-bottom: 24px;
    animation: pulse 2s ease-in-out infinite;
}

.boot-content h1 {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #ffffff;
}

.boot-content h1.boot-brand {
    font-size: 26px;
    font-weight: 300;
    letter-spacing: 2px;
    color: #8a8a8a;
    margin-bottom: 0;
}

.boot-content p {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 14px;
}

/* ===== PWA 安装对话框（Chrome PWA 安装方案，位于引导层之上） ===== */
.install-dialog-mask {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.install-dialog {
    width: min(86vw, 340px);
    background: #ffffff;
    border-radius: 16px;
    padding: 26px 22px 20px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.install-dialog-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 14px;
    border-radius: 14px;
    background: rgba(0, 122, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.install-dialog h3 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.install-dialog p {
    font-size: 14px;
    color: #666666;
    line-height: 1.5;
    margin-bottom: 18px;
}

.install-dialog-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.install-btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 0;
    border: none;
    border-radius: 10px;
    background: #007aff;
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 122, 255, 0.35);
    transition: transform 0.15s ease;
}

.install-btn-primary:active,
.install-btn-primary.auto-press {
    transform: scale(0.94);
}

.install-btn-secondary {
    padding: 10px 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #888888;
    font-size: 15px;
    cursor: pointer;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.7; }
}

/* ===== 右上角控件：齿轮 + 关闭 ===== */
.corner-controls {
    position: absolute;
    top: 12px;
    /* 向右偏移基础上再加 2cm，实现按钮组整体再向左移动 2cm（总计左移 3.2cm） */
    right: calc(12px + 3.2cm);
    display: flex;
    gap: 8px;
    z-index: 20;
    transition: opacity 0.25s ease;
}

.corner-controls.hidden {
    opacity: 0;
    pointer-events: none;
}

.corner-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.2s ease;
}

.corner-btn:active {
    transform: scale(0.92);
}

.close-btn {
    background: rgba(255, 59, 48, 0.95);
    color: #ffffff;
}

.close-btn:hover {
    background: rgba(255, 59, 48, 1);
}

/* 关闭按钮始终显示在设置按钮右侧，全屏模式下也不隐藏 */

/* ===== 工具栏：默认隐藏，展开后从右上角弹出 ===== */
.toolbar {
    position: absolute;
    top: 60px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 15;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-height: calc(100% - 80px);
    overflow-y: auto;
}

.toolbar.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.tool-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    align-items: center;
    justify-content: center;
}

/* 颜色按钮 */
.color-btn {
    width: 28px;
    height: 28px;
    border: 2px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s ease, border-color 0.2s ease;
}

.color-btn[data-color="#ffffff"] {
    border-color: #ccc;
}

.color-btn:active,
.color-btn.active {
    transform: scale(1.15);
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

/* 画笔粗细按钮 */
.size-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.size-btn:active,
.size-btn.active {
    background: rgba(0, 122, 255, 0.15);
}

.size-btn .dot {
    background: #333;
    border-radius: 50%;
    display: block;
}

/* 线形按钮 */
.shape-btn {
    width: 44px;
    height: 36px;
    border: none;
    background: transparent;
    color: #555;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 0 4px;
}

.shape-btn svg {
    width: 100%;
    height: 100%;
}

.shape-btn:active,
.shape-btn.active {
    background: rgba(0, 122, 255, 0.15);
    color: #007aff;
}

/* 工具按钮：画笔/橡皮/清空/模式 */
.tool-btn {
    height: 40px;
    border: none;
    background: rgba(0, 0, 0, 0.04);
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
    flex: 1;
    min-width: 60px;
}

.tool-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
    background: #007aff;
    color: #ffffff;
}

.tool-btn.active svg {
    stroke: #ffffff;
}

/* ===== 响应式：小屏幕优化 ===== */
@media (max-width: 600px) {
    .board-wrapper {
        border-radius: 4px;
    }

    .corner-btn {
        width: 36px;
        height: 36px;
    }

    .toolbar {
        top: 56px;
        right: 8px;
        padding: 10px;
        max-width: calc(100vw - 16px - 1/30 * 100vw);
    }

    .corner-controls {
        top: 8px;
        right: calc(8px + 3.2cm);
    }

    .color-btn {
        width: 24px;
        height: 24px;
    }

    .size-btn {
        width: 32px;
        height: 32px;
    }

    .shape-btn {
        width: 38px;
        height: 32px;
    }

    .tool-btn {
        min-width: 50px;
        font-size: 12px;
    }
}

/* PWA 全屏模式下隐藏浏览器可能渲染的 UI */
@media (display-mode: fullscreen) {
    body { background: #1a1a1a; }
}
@media (display-mode: standalone) {
    body { background: #1a1a1a; }
}

/* 防止双击放大 */
* {
    touch-action: manipulation;
}
