/* ============================================================
 * Craft Tools · 基础层
 * ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { list-style: none; padding: 0; }

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

/* 图标统一尺寸 */
.icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    pointer-events: none;
}
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.8125rem;
    letter-spacing: -0.01em;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: fixed;
    top: 0; left: 50%;
    transform: translate(-50%, -160%);
    z-index: 200;
    padding: 0.55rem 1.1rem;
    background: var(--ink);
    color: var(--accent-ink);
    border-radius: 0 0 var(--r-md) var(--r-md);
    font-size: var(--fs-sm);
    transition: transform var(--fast) var(--ease);
}
.skip-link:focus { transform: translate(-50%, 0); }

/* ===== 顶栏 ===== */
.appbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 40;
    height: var(--appbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 clamp(16px, 4vw, 32px);
    border-bottom: 1px solid var(--line);
    background: var(--bg); /* 老浏览器兜底 */
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(1.5);
    backdrop-filter: blur(18px) saturate(1.5);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: -0.03em;
    color: var(--text);
    white-space: nowrap;
}
.brand__mark { width: 26px; height: 26px; flex: 0 0 auto; }
.brand__word { display: inline-flex; gap: 0.28rem; }
.brand__word b { font-weight: 700; }

.appbar__actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: var(--r-md);
    color: var(--text);
    transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.iconbtn:hover { background: var(--surface-3); }
.iconbtn:active { transform: scale(0.94); }

/* ===== 导航：桌面浮在顶栏中央，移动端落成底部 Dock ===== */
.tabs {
    position: fixed;
    top: calc((var(--appbar-h) - var(--tabs-h)) / 2);
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 2px;
    height: var(--tabs-h);
    padding: 4px;
    border-radius: var(--r-pill);
    max-width: calc(100vw - 2 * 220px);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

/* 液态玻璃高光块只在移动端底栏出现 */
.tabs__pill { display: none; }

.tabs__btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 100%;
    padding: 0 0.95rem;
    border-radius: var(--r-pill);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.tabs__btn:hover { color: var(--text); }
.tabs__btn[aria-current="page"] {
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 600;
}
.tabs__icon { display: none; }
.tabs__label { display: inline; }

@media (min-width: 860px) {
    .tabs__btn { font-size: 0.875rem; }
}

/* JS 就绪后导航轻微淡入，避免激活态先闪一下 */
html.is-ready .tabs { animation: tabsIn 0.3s var(--ease); }
@keyframes tabsIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== 主区域 ===== */
.appmain {
    position: relative;
    height: 100%;
    height: 100dvh;
}

.view {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(var(--appbar-h) + 20px) clamp(16px, 4vw, 32px) 40px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.view[hidden] { display: none; }
.view:focus { outline: none; }

.view__inner {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
}

.view-enter { animation: viewIn var(--med) var(--ease); }
@keyframes viewIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.view__head { margin-bottom: 18px; }
.view__title {
    font-size: clamp(1.5rem, 4vw, 1.9rem);
    font-weight: 700;
    letter-spacing: -0.035em;
}
.view__sub {
    margin-top: 3px;
    font-size: var(--fs-sm);
    color: var(--muted);
}

.view::-webkit-scrollbar { width: 8px; }
.view::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 99px;
}
.view::-webkit-scrollbar-track { background: transparent; }

/* 自定义背景 */
body.has-custom-bg {
    background-image: var(--ct-custom-bg);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
}
body.has-custom-bg .appbar,
body.has-custom-bg .view { background-color: transparent; }
body.has-custom-bg .appbar {
    background-color: color-mix(in srgb, var(--bg) 55%, transparent);
    border-bottom-color: transparent;
}

/* ===== 移动端：Dock ===== */
@media (max-width: 859px) {
    :root { --dock-h: 64px; }

    /* ===== 液态玻璃底栏（iOS 风格）=====
     * 5 格等宽，图标在上、文字在下；一块玻璃胶囊在格子之间连续滑动。
     * 不做「选中变宽」——那会导致重排，拖动就会一跳一跳。 */
    .tabs {
        top: auto;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        left: 10px;
        right: 10px;
        transform: none;
        max-width: none;
        height: var(--dock-h);
        gap: 0;
        padding: 6px;
        border-radius: calc(var(--r-lg) + 4px);
        overflow: visible;
        justify-content: stretch;
        touch-action: none;
        transition: height 0.34s var(--ease), border-radius 0.34s var(--ease);
    }

    .tabs__pill {
        display: block;
        position: absolute;
        top: 6px;
        bottom: 6px;
        left: 0;
        width: var(--pill-w, 56px);
        z-index: 0;
        border-radius: var(--r-md);
        background: linear-gradient(145deg, var(--glass-a), var(--glass-b) 60%, var(--glass-c));
        border: 1px solid var(--glass-edge);
        box-shadow:
            inset 0 1px 0 var(--glass-glow),
            inset 0 -1px 0 rgba(255, 255, 255, 0.14),
            0 6px 18px rgba(30, 22, 8, 0.16);
        -webkit-backdrop-filter: blur(10px) saturate(1.7) brightness(1.08);
        backdrop-filter: blur(10px) saturate(1.7) brightness(1.08);
        pointer-events: none;
        will-change: transform, scale;
        /* 位移和宽度必须用同一条曲线。
           两条曲线不同步时，中心 = 左边缘 + 宽度/2 会左右来回过冲，看起来就是抖。
           同曲线后中心只单调地过冲一次，像弹簧落位。 */
        transition: transform 0.5s cubic-bezier(0.26, 1.45, 0.44, 1),
                    width 0.5s cubic-bezier(0.26, 1.45, 0.44, 1);
    }
    .glass-lens .tabs__pill {
        -webkit-backdrop-filter: url(#ct-lens) blur(1px) saturate(1.7) brightness(1.06);
        backdrop-filter: url(#ct-lens) blur(1px) saturate(1.7) brightness(1.06);
    }

    .tabs__btn {
        position: relative;
        z-index: 1;
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        gap: 2px;
        padding: 0;
        font-size: 0.625rem;
        font-weight: 500;
        border-radius: var(--r-md);
        background: none;
        color: var(--muted);
        transition: color 0.22s var(--ease);
    }
    .tabs__icon {
        display: block;
        width: 22px;
        height: 22px;
        transition: transform 0.22s var(--ease);
    }
    /* 文字在图标下面，始终可见 */
    .tabs__label {
        display: block;
        max-width: none;
        opacity: 0.72;
        overflow: hidden;
        white-space: nowrap;
        line-height: 1.1;
        transition: opacity 0.22s var(--ease);
    }
    .tabs__btn[aria-current="page"] { color: var(--text); font-weight: 600; }
    .tabs__btn[aria-current="page"] .tabs__label { opacity: 1; }
    .tabs__btn[aria-current="page"] .tabs__icon {
        color: var(--gold);
        animation: iconPop 0.42s var(--ease);
    }

    /* 注意：不要给胶囊加 scale 动画。
       胶囊的位置写在 transform: translateX() 里，而独立的 scale 属性会在
       transform 之后相乘，把位移一起放大 —— 实测会让中心偏 11px，看起来就是抖。
       弹性只靠下面这条过渡曲线的过冲来实现。 */
    @keyframes iconPop {
        0%   { scale: 1; }
        38%  { scale: 1.28; }
        70%  { scale: 0.94; }
        100% { scale: 1; }
    }

    .tabs__btn:active .tabs__icon { transform: scale(0.86); }

    /* 拖动时手指底下那一格只变亮，不放大 —— 放大交给玻璃胶囊 */
    .tabs__btn[data-drag-target="true"] { color: var(--text); }
    .tabs__btn[data-drag-target="true"] .tabs__icon { color: var(--text); }
    .tabs__btn[data-drag-target="true"] .tabs__label { opacity: 1; }

    /* 拖动中：胶囊直接跟手，关掉过渡 */
    .tabs.is-dragging .tabs__pill { transition: none; }

    /* 向下滚动收起：变矮、只剩图标 */
    .tabs[data-collapsed="true"] {
        height: 50px;
        border-radius: var(--r-md);
    }
    .tabs[data-collapsed="true"] .tabs__label {
        opacity: 0;
        max-height: 0;
    }

    .view {
        padding-top: calc(var(--appbar-h) + 12px);
        padding-bottom: calc(var(--dock-h) + 28px + env(safe-area-inset-bottom, 0px));
    }
    .view__head { margin-bottom: 12px; }
    .view__sub { display: none; }
    .view__title { font-size: 1.375rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
