/**
 * 首页底部 macOS 风格 Dock 导航栏（core/mac-dock.php 输出）
 *
 * - 仅首页显示，底部居中，毛玻璃圆角面板
 * - 图标为上传图片，鼠标靠近鱼眼放大（尺寸由 JS 逐帧控制）
 * - hover 显示名称 tooltip；深色模式 + 移动端自适应
 */

.knn-dock-wrapper {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1020;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    max-width: calc(100vw - 24px);
}

.knn-dock {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    box-sizing: border-box;
    height: 60px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.22);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    backdrop-filter: blur(30px) saturate(180%);
    border: 0.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 20px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18), inset 0 0.5px 0 rgba(255, 255, 255, 0.4);
    max-width: 100%;
}

.knn-dock-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    width: 54px; /* BASE_SIZE(44) + GAP(10)，由 JS 逐帧控制 */
    text-decoration: none;
    cursor: pointer;
}

.knn-dock-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center bottom;
    will-change: width, height;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.knn-dock-icon img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 12px;
    pointer-events: none;
}

/* 悬停名称标签 */
.knn-dock-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: rgba(246, 246, 248, 0.85);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    color: #1d1d1f;
    font-size: 13px;
    line-height: 1.4;
    padding: 4px 12px;
    border-radius: 8px;
    border: 0.5px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.knn-dock-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(246, 246, 248, 0.85);
}

.knn-dock-item:hover .knn-dock-tooltip {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ---------- 深色模式 ---------- */
body.dark-mode .knn-dock {
    background: rgba(40, 40, 46, 0.45);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), inset 0 0.5px 0 rgba(255, 255, 255, 0.12);
}

body.dark-mode .knn-dock-tooltip {
    background: rgba(50, 50, 56, 0.9);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e8e8e8;
}

body.dark-mode .knn-dock-tooltip::after {
    border-top-color: rgba(50, 50, 56, 0.9);
}

/* ---------- 移动端：不显示 Dock 导航（仅电脑端） ---------- */
@media (max-width: 768px) {
    .knn-dock-wrapper {
        display: none !important;
    }
}

/* ============================================================
 * 点击弹跳动画
 * ========================================================== */
@keyframes knn-dock-bounce {
    0%   { transform: translateY(0); }
    35%  { transform: translateY(-30px); }
    60%  { transform: translateY(0); }
    78%  { transform: translateY(-10px); }
    100% { transform: translateY(0); }
}

.knn-dock-icon.knn-bouncing {
    animation: knn-dock-bounce 0.7s ease;
}

/* ============================================================
 * macOS 风格窗口（点击 Dock 图标以内嵌窗口打开链接）
 * ========================================================== */
.knn-mac-window {
    position: fixed;
    background: #f5f5f7;
    border-radius: 10px;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 3000;
    animation: knn-mac-open 0.22s ease;
    transition: opacity 0.25s ease, transform 0.25s ease;
    /* 提升为独立合成层：最小化/还原的 scale 动画交给 GPU，
       不再每帧重绘页面（尤其是 Dock 的 backdrop-filter 毛玻璃） */
    will-change: transform, opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

@keyframes knn-mac-open {
    from { opacity: 0; transform: scale(0.88); }
    to   { opacity: 1; transform: scale(1); }
}

.knn-mac-window.knn-mac-min {
    opacity: 0;
    transform: scale(0.05) translateY(120vh);
    pointer-events: none;
}

.knn-mac-window.knn-mac-max {
    left: 6px !important;
    top: 60px !important;
    width: calc(100% - 12px) !important;
    height: calc(100% - 72px) !important;
    border-radius: 6px;
}

.knn-mac-bar {
    flex: none;
    height: 38px;
    background: rgba(246, 246, 248, 0.95);
    -webkit-backdrop-filter: blur(30px);
    backdrop-filter: blur(30px);
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: default;
    user-select: none;
}

.knn-mac-btns {
    display: flex;
    flex-direction: row-reverse;
    gap: 8px;
    order: 2;
}

.knn-mac-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    line-height: 1;
    font-weight: 700;
    color: transparent;
    cursor: pointer;
}

.knn-mac-btn.close { background: #ff5f57; }
.knn-mac-btn.min   { background: #febc2e; }
.knn-mac-btn.zoom  { background: #28c840; }

/* 悬停时才显示 × / − / + 字符（与 macOS 一致） */
.knn-mac-btns:hover .knn-mac-btn.close { color: #7d0f0a; }
.knn-mac-btns:hover .knn-mac-btn.min   { color: #985713; }
.knn-mac-btns:hover .knn-mac-btn.zoom  { color: #0d652d; }

.knn-mac-title {
    flex: 1;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #4a4a4e;
    margin-left: 52px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.knn-mac-body {
    flex: 1;
    background: #fff;
    position: relative;
    overflow: hidden;
}

.knn-mac-body iframe {
    /* 宽高各多 20px，把滚动条挤出裁剪区外，视觉隐藏 */
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    border: none;
    display: block;
    /* 强制 iframe 独立成层并缓存为纹理，窗口缩放时不再逐帧重栅格化，
       解决内嵌重页面时最小化/还原卡顿 */
    transform: translateZ(0);
    will-change: transform;
}

.knn-mac-tip {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 20px;
    color: #86868b;
    font-size: 13px;
    background: #fff;
    z-index: -1;
}

/* macOS 窗口 深色模式 */
body.dark-mode .knn-mac-window {
    background: #1e1e1e;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.7), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
}

body.dark-mode .knn-mac-bar {
    background: rgba(40, 40, 46, 0.98);
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .knn-mac-title { color: #ccc; }

/* macOS 窗口 移动端 */
@media (max-width: 768px) {
    .knn-mac-window.knn-mac-max {
        top: 50px !important;
        height: calc(100% - 60px) !important;
    }
}
