/* css/bookmark.css */

.bookmark-swiper {
    width: 100%; overflow: hidden; flex-grow: 1;
    touch-action: pan-y;
}

.bookmark-swiper-wrapper {
    display: flex; height: 100%;
    transition: transform 0.3s ease-out; will-change: transform;
}

.bookmark-page {
    flex-shrink: 0; width: 100%; height: 100%;
    display: flex; align-items: flex-start; justify-content: center;
    box-sizing: border-box; padding-top: 0; overflow-y: auto;
}

.bookmark-page-content {
    display: grid; grid-template-columns: repeat(auto-fill, var(--card-size));
    gap: var(--gap); justify-content: flex-start;
    width: var(--page-width); max-width: 90%;
    align-content: flex-start; padding-bottom: 50px;
    transform-origin: center center;
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease, filter 0.24s ease;
}

.page-title {
    grid-column: 1 / -1; font-size: 24px; font-weight: 600; color: inherit;
    margin: 0 0 5px 0; text-shadow: 0 1px 2px rgba(255,255,255,0.6);
    padding: 5px; border-radius: 8px;
}

.bookmark-item {
    display: flex; flex-direction: column; align-items: center;
    width: var(--card-size); cursor: pointer; position: relative;
    transition: transform 0.2s; -webkit-tap-highlight-color: transparent;
    will-change: transform; user-select: none; -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.bookmark-item:hover { transform: scale(1.05); }

.bookmark-item .icon-box {
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease, filter 0.22s ease;
}

.bookmark-item.long-press-armed {
    transform: scale(0.94);
}

.bookmark-item.long-press-armed .icon-box {
    filter: brightness(0.94) saturate(0.92);
    transform: scale(0.96);
}

.bookmark-item.long-press-active {
    z-index: 50;
    transform: scale(1.08) translateY(-3px);
    transition-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1.2);
}

.bookmark-item.long-press-active .icon-box {
    box-shadow:
        0 20px 38px rgba(25, 20, 30, 0.24),
        0 8px 18px rgba(25, 20, 30, 0.16);
    filter: brightness(1.03) saturate(1.04);
    transform: scale(1.06);
}

body.long-press-bookmark-active .bookmark-item:not(.long-press-active) {
    opacity: 0.52;
    filter: blur(0.7px) saturate(0.82);
    transform: scale(0.97);
}

body.long-press-theme-armed .bookmark-page-content {
    opacity: 0.9;
    transform: scale(0.992);
}

body.long-press-theme-active .bookmark-page-content {
    opacity: 0.48;
    filter: blur(1.4px) saturate(0.82);
    transform: scale(0.972);
}

body.long-press-theme-armed .bookmark-dock,
body.long-press-theme-active .bookmark-dock {
    filter: blur(0.5px) saturate(0.84);
}

body.long-press-theme-active .bookmark-dock {
    opacity: 0.5;
    filter: blur(1.2px) saturate(0.76);
}

.bookmark-dock.long-press-armed {
    transform: translateX(-50%) scale(0.96);
}

.bookmark-dock.long-press-active {
    transform: translateX(-50%) translateY(-4px) scale(1.04);
    box-shadow:
        0 22px 44px rgba(49, 37, 55, 0.26),
        inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

body.long-press-dock-armed .bookmark-page-content {
    opacity: 0.9;
    transform: scale(0.992);
}

body.long-press-dock-active .bookmark-page-content {
    opacity: 0.48;
    filter: blur(1.4px) saturate(0.82);
    transform: scale(0.972);
}

.bookmark-tooltip {
    position: fixed; left: 0; top: 0; z-index: 2000;
    max-width: min(300px, calc(100vw - 24px));
    padding: 10px 12px; border-radius: 10px;
    background: rgba(24, 24, 28, 0.94); color: #fff;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
    font-size: 12px; line-height: 1.5; text-align: left;
    white-space: normal; overflow-wrap: anywhere;
    pointer-events: none; opacity: 0; visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}

.bookmark-tooltip.visible {
    opacity: 1; visibility: visible; transform: translateY(0);
}

.icon-box {
    width: var(--card-size); height: var(--card-size);
    background: white; border-radius: var(--radius);
    overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    display: flex; align-items: center; justify-content: center;
    position: relative;
    aspect-ratio: 1 / 1;
}

/* --- 核心修改开始：解决 Logo 比例变形 --- */

/* 1. 默认铺满模式 (Full) */
.icon-box img { 
    width: 100%; 
    height: 100%; 
    object-fit: cover; /* 铺满裁剪 */
    padding: 0;
    pointer-events: none; 
}

/* 2. 适中模式 (Fit) - 修改为 padding 控制，保持正方形 */
.bookmark-item.style-fit .icon-box img { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; /* 保持比例 */
    padding: 15%; /* 内边距控制显示大小 */
    box-sizing: border-box; /* 确保 padding 算在尺寸内 */
}

/* 3. 留白模式 (White) - 修改为 padding 控制，保持正方形 */
.bookmark-item.style-white .icon-box img { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; /* 保持比例 */
    padding: 25%; /* 更大的内边距 */
    box-sizing: border-box; 
}

/* --- 核心修改结束 --- */

.text-icon {
    width: 100%; height: 100%; background: #e0e0e0; color: #555;
    display: flex; align-items: center; justify-content: center;
    font-size: 36px; font-weight: bold; text-transform: uppercase;
}

.bookmark-title {
    margin-top: 8px; font-size: 13px; color: inherit; text-align: center;
    width: 120%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500; text-shadow: 0 1px 2px rgba(255,255,255,0.6);
}

@keyframes ios-jiggle {
    0% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } 100% { transform: rotate(-1.5deg); }
}
.is-editing .bookmark-item:not(.sortable-drag):not(.sortable-ghost) {
    animation: ios-jiggle 0.25s infinite ease-in-out; cursor: grab; transform-origin: center center;
}
.is-editing .bookmark-item:nth-child(2n) { animation-duration: 0.26s; animation-delay: -0.05s; }
.is-editing .bookmark-item:nth-child(3n) { animation-duration: 0.24s; animation-delay: -0.12s; }
.is-editing .bookmark-item:nth-child(5n) { animation-duration: 0.27s; animation-delay: -0.08s; }
.is-editing .bookmark-item:nth-child(7n) { animation-direction: alternate-reverse; }

.sortable-ghost { opacity: 0.2; background: #cce5ff; border-radius: var(--radius); }
.sortable-ghost .bookmark-title, .sortable-ghost .icon-box { opacity: 0.5; }
.sortable-drag {
    opacity: 1 !important; transform: scale(1.15); box-shadow: 0 20px 40px rgba(0,0,0,0.25);
    z-index: 9999 !important; cursor: grabbing; transition: none !important;
}

@keyframes popIn { 0% { transform: scale(0); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.delete-btn {
    position: absolute; top: -8px; left: -8px; width: 22px; height: 22px;
    background: rgba(150, 150, 150, 0.9); color: white; border-radius: 50%;
    text-align: center; line-height: 20px; font-size: 14px;
    display: none; z-index: 10; cursor: pointer;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.is-editing .delete-btn { display: block; }

.pagination-dots {
    position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 12px; z-index: 100; padding: 20px 40px; border-radius: 30px;
    opacity: 0; transition: opacity 0.3s ease-in-out; pointer-events: auto;
}
.pagination-dots.visible, .pagination-dots:hover { opacity: 1; }
.pagination-dots .dot {
    width: 8px; height: 8px; border-radius: 50%; background: rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s cubic-bezier(0.25, 1.5, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1.5, 0.5, 1); cursor: pointer; position: relative;
}
.pagination-dots .dot.active { background: rgba(0, 0, 0, 0.8); transform: scale(1.2); }
.pagination-dots .dot:hover { background: #007AFF; transform: scale(1.8); }
.pagination-dots .dot::after {
    content: attr(data-title); position: absolute; bottom: 20px; left: 50%;
    opacity: 0; visibility: hidden; transform: translateX(-50%) scale(0.8); transform-origin: bottom center;
    background: rgba(0,0,0,0.85); color: white; padding: 5px 10px; font-size: 10px;
    border-radius: 12px; white-space: nowrap; pointer-events: none; font-weight: 500;
    transition: opacity 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), visibility 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.pagination-dots .dot:hover::after { opacity: 1; visibility: visible; transform: translateX(-50%) scale(1); }

.bookmark-dock {
    position: fixed; left: 50%; bottom: 14px;
    z-index: 500;
    display: flex; align-items: center; justify-content: center; gap: 14px;
    width: fit-content;
    max-width: min(calc(var(--page-width) + 36px), calc(100vw - 16px), 94vw);
    padding: 8px 14px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 22px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.54), rgba(255, 255, 255, 0.24)),
        rgba(235, 235, 240, 0.46);
    box-shadow:
        0 16px 34px rgba(49, 37, 55, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(22px) saturate(1.3);
    -webkit-backdrop-filter: blur(22px) saturate(1.3);
    transform: translateX(-50%);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

.bookmark-dock:hover {
    transform: translateX(-50%);
    box-shadow:
        0 20px 42px rgba(49, 37, 55, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.dock-group,
.dock-items {
    display: flex; align-items: center; min-width: 0;
}

.dock-group { gap: 8px; }
.dock-items { gap: 8px; }

.dock-divider {
    width: 1px; height: 32px; flex: 0 0 1px;
    background: linear-gradient(180deg, transparent, rgba(58, 52, 66, 0.22), transparent);
}

.dock-item {
    --dock-item-size: 46px;
    --dock-scale: 1;
    --dock-lift: 0px;
    --dock-shadow-y: 5px;
    --dock-shadow-blur: 12px;
    --dock-shadow-alpha: 0.16;
    position: relative; flex: 0 0 auto;
    width: calc(var(--dock-item-size) * var(--dock-scale)); height: var(--dock-item-size); padding: 0; border: 0;
    background: transparent; color: inherit; cursor: pointer;
    transform-origin: bottom center;
    transition: width 0.16s cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-tap-highlight-color: transparent;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

.dock-item.long-press-armed {
    opacity: 0.82;
    transform: scale(0.92);
}

.dock-item.long-press-active {
    z-index: 6;
    transform: translateY(-7px) scale(1.12);
}

.dock-item.long-press-active .dock-icon {
    box-shadow: 0 16px 26px rgba(30, 24, 35, 0.25);
}

body.long-press-bookmark-active .dock-item:not(.long-press-active) {
    opacity: 0.55;
    transform: scale(0.96);
}

.dock-item:hover,
.dock-item:focus-visible {
    z-index: 3;
    outline: none;
}

.dock-item:focus-visible {
    --dock-scale: 1.38;
    --dock-lift: -8px;
    --dock-shadow-y: 12px;
    --dock-shadow-blur: 26px;
    --dock-shadow-alpha: 0.28;
}

.dock-item .dock-icon {
    width: var(--dock-item-size); height: var(--dock-item-size); border-radius: 12px;
    margin: 0 auto;
    box-shadow: 0 var(--dock-shadow-y) var(--dock-shadow-blur) rgba(40, 34, 46, var(--dock-shadow-alpha));
    transform: translate3d(0, var(--dock-lift), 0) scale3d(var(--dock-scale), var(--dock-scale), 1);
    transform-origin: bottom center;
    transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.16s ease;
    will-change: transform;
}

.dock-icon .text-icon { font-size: 21px; }
.dock-item.style-fit .dock-icon img { object-fit: contain; padding: 15%; box-sizing: border-box; }
.dock-item.style-white .dock-icon img { object-fit: contain; padding: 25%; box-sizing: border-box; }

.dock-item-label {
    position: absolute; left: 50%; bottom: calc(100% + 28px);
    max-width: 180px; padding: 6px 9px; border-radius: 9px;
    background: rgba(24, 24, 28, 0.92); color: #fff;
    box-shadow: 0 7px 18px rgba(0, 0, 0, 0.18);
    font-size: 11px; font-weight: 600; line-height: 1.2; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    opacity: 0; visibility: hidden; pointer-events: none;
    transform: translate(-50%, 5px) scale(0.96);
    transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
}

.dock-item:hover .dock-item-label {
    opacity: 1; visibility: visible;
    transform: translate(-50%, 0) scale(1);
    transition-delay: 700ms;
}

.dock-item:focus-visible .dock-item-label {
    opacity: 1; visibility: visible;
    transform: translate(-50%, 0) scale(1);
    transition-delay: 0s;
}

.dock-empty {
    display: inline-flex; align-items: center; min-height: 38px;
    padding: 0 10px;
    color: rgba(48, 44, 54, 0.46);
    font-size: 11px; font-weight: 600; white-space: nowrap;
}

.is-editing .bookmark-dock { display: none !important; }

body.dark-mode .bookmark-dock {
    border-color: rgba(255, 255, 255, 0.18);
    background:
        linear-gradient(180deg, rgba(52, 52, 58, 0.72), rgba(28, 28, 32, 0.56)),
        rgba(18, 18, 20, 0.58);
    box-shadow:
        0 16px 34px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

body.dark-mode .dock-empty { color: rgba(255, 255, 255, 0.58); }
body.dark-mode .dock-divider { background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.24), transparent); }

.dock-edit-modal-content {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.dock-edit-sections {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px; min-height: 300px;
}
.dock-edit-section {
    display: flex; flex-direction: column; min-width: 0; min-height: 0;
    padding: 12px; border-radius: 16px; background: #f5f7f9;
}
.dock-edit-header {
    display: flex; align-items: center; justify-content: space-between;
    min-height: 24px; margin-bottom: 9px;
    color: #555; font-size: 12px; font-weight: 700;
}
.dock-edit-count { color: #8a8a8e; font-variant-numeric: tabular-nums; }
.dock-edit-list {
    display: flex; flex-direction: column; gap: 8px;
    min-height: 0; max-height: min(48vh, 420px); margin: 0; padding: 2px;
    overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; list-style: none;
}
.dock-edit-item {
    display: flex; align-items: center; gap: 10px;
    min-height: 50px; padding: 7px 8px; border-radius: 12px; background: #fff;
    box-sizing: border-box; box-shadow: 0 2px 7px rgba(0, 0, 0, 0.05);
}
.dock-edit-handle {
    flex: 0 0 auto; color: #8a8a8e; cursor: grab; font-size: 15px; line-height: 1;
}
.dock-edit-icon {
    width: 36px; height: 36px; flex: 0 0 36px; border-radius: 9px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.dock-edit-icon .text-icon { font-size: 16px; }
.dock-edit-title {
    min-width: 0; flex: 1; overflow: hidden; color: #333;
    font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap;
}
.dock-edit-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; flex: 0 0 28px; padding: 0; border: 0; border-radius: 50%;
    background: #e9e9eb; color: #444; cursor: pointer; font-size: 20px; line-height: 1;
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}
.dock-edit-toggle:hover { transform: scale(1.08); }
.dock-edit-toggle.add { background: rgba(0, 122, 255, 0.12); color: #007aff; }
.dock-edit-toggle.remove { background: rgba(255, 59, 48, 0.1); color: #ff3b30; }
.dock-edit-empty {
    display: flex; align-items: center; justify-content: center;
    min-height: 90px; padding: 12px; color: #8a8a8e; font-size: 12px; text-align: center;
}
.dock-edit-ghost { opacity: 0.42; background: #dcecff; }
.dock-edit-modal-content .modal-actions { flex: 0 0 auto; }

body.dark-mode .dock-edit-section { background: #29292d; }
body.dark-mode .dock-edit-item { background: #37373c; box-shadow: none; }
body.dark-mode .dock-edit-header,
body.dark-mode .dock-edit-title { color: #f2f2f4; }
body.dark-mode .dock-edit-count,
body.dark-mode .dock-edit-empty { color: #a8a8ad; }
body.dark-mode .dock-edit-toggle { background: #48484d; color: #f2f2f4; }
body.dark-mode .dock-edit-toggle.add { background: rgba(10, 132, 255, 0.22); color: #64b5ff; }
body.dark-mode .dock-edit-toggle.remove { background: rgba(255, 69, 58, 0.18); color: #ff6961; }

@media (prefers-reduced-motion: reduce) {
    .is-editing .bookmark-item { animation: none; }
    .bookmark-item,
    .bookmark-item .icon-box,
    .bookmark-page-content,
    .dock-item,
    .dock-item .dock-icon { transition: none; }
    body.long-press-bookmark-active .bookmark-item:not(.long-press-active),
    body.long-press-theme-active .bookmark-page-content,
    body.long-press-theme-active .bookmark-dock { filter: none; }
    .toast, .toast.visible { transition: none; animation: none; }
    .user-pill, .user-pill.shrunk { transition: none; }
    .bookmark-dock, .dock-item, .dock-edit-toggle { transition: none; }
}
