/* ========================================
   Grand Archive 移动端适配样式
   ======================================== */

/* ===== 基础移动端样式 ===== */
.mobile-bottom-nav {
    display: none;
}

.mobile-locale-switch {
    display: none;
}

@media (min-width: 769px) {
    /* 桌面保护：移动端底部导航和移动菜单入口永远不参与桌面布局。 */
    .mobile-bottom-nav,
    .mobile-page-indicator,
    .mobile-nav-actions,
    .mobile-nav-back,
    .mobile-auth-entry,
    .mobile-locale-switch {
        display: none !important;
    }
}

@media (max-width: 768px) {
    :root {
        --mobile-header-height: 56px;
        --mobile-topbar-offset: calc(var(--mobile-header-height) + env(safe-area-inset-top));
        --mobile-tabbar-height: 60px;
        --mobile-tabbar-space: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
        --mobile-page-gutter: 0.9rem;
    }

    html {
        font-size: 16px;
    }
    
    body {
        font-size: 1rem;
        line-height: 1.5;
        padding-bottom: var(--mobile-tabbar-space);
    }

    body.mobile-tool-page {
        /* 高优先级工具页移动端直接进入搜索/筛选，不保留 GA/Home/登录/菜单顶栏占位。 */
        --mobile-header-height: 0px;
        --mobile-topbar-offset: env(safe-area-inset-top);
    }

    body.mobile-tool-page .navbar {
        display: none;
    }

    body.mobile-tool-page .main-content {
        /* 工具页顶栏已移除，主内容不能继续继承桌面 navbar 预留高度。 */
        padding-top: 0 !important;
    }
    
    /* 触摸优化 */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* 按钮触摸尺寸 */
    button, .btn, a {
        min-height: 44px;
        min-width: 44px;
    }
    
    button:active, .btn:active, .nav-link:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .navbar {
        padding-top: env(safe-area-inset-top);
        height: var(--mobile-topbar-offset);
        background: rgba(7, 11, 20, 0.78);
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
        backdrop-filter: blur(18px);
    }

    .nav-container {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        height: var(--mobile-header-height);
        max-width: none;
        padding: 0 var(--mobile-page-gutter);
        gap: 0.65rem;
    }

    .mobile-nav-leading,
    .mobile-nav-actions {
        display: flex;
        align-items: center;
        gap: 0.45rem;
    }

    .mobile-nav-leading {
        justify-self: start;
        min-width: 0;
    }

    .mobile-nav-actions {
        justify-self: end;
    }

    .nav-logo {
        display: inline-flex;
        align-items: center;
        min-width: 0;
        font-size: 1rem;
        letter-spacing: 0.08em;
    }

    .nav-logo-desktop {
        display: none;
    }

    .nav-logo-mobile {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 38px;
        height: 38px;
        padding: 0 0.6rem;
        border-radius: 999px;
        background: rgba(255, 215, 0, 0.08);
        border: 1px solid rgba(255, 215, 0, 0.16);
        color: #ffd86a;
        font-size: 0.96rem;
        font-weight: 800;
        letter-spacing: 0.08em;
    }

    .mobile-nav-back,
    .mobile-auth-entry,
    .mobile-menu-toggle-secondary {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        min-width: 38px;
        height: 38px;
        min-height: 38px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.06);
        color: #f4f6fb;
        text-decoration: none;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    }

    .mobile-nav-back span {
        font-size: 1.65rem;
        line-height: 1;
        transform: translateX(-1px);
    }

    .mobile-auth-entry {
        overflow: hidden;
    }

    .mobile-auth-avatar {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .mobile-auth-initial,
    .mobile-auth-glyph {
        color: #ffd86a;
        font-size: 0.92rem;
        font-weight: 800;
    }

    .mobile-page-indicator {
        display: block;
        min-width: 0;
        text-align: center;
        color: #f8fafc;
        font-size: 0.94rem;
        font-weight: 760;
        letter-spacing: 0.01em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .navbar.mobile-back-mode .nav-logo {
        display: none;
    }

    .mobile-nav-back[hidden] {
        display: none !important;
    }

    .user-section {
        display: none !important;
    }

    .nav-links {
        display: none;
    }

    .nav-links.active {
        position: fixed;
        top: calc(var(--mobile-topbar-offset) + 0.5rem);
        right: var(--mobile-page-gutter);
        z-index: 1002;
        display: grid;
        width: min(280px, calc(100vw - (var(--mobile-page-gutter) * 2)));
        gap: 0.24rem;
        padding: 0.5rem;
        background: rgba(12, 18, 31, 0.96);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 22px;
        box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
        backdrop-filter: blur(16px);
    }

    .nav-link {
        min-height: 42px;
        padding: 0.75rem 0.9rem;
        border-radius: 14px;
        color: #e2e8f0;
        font-size: 0.9rem;
        text-align: left;
    }

    .nav-link.active,
    .nav-link:hover {
        color: #ffd86a;
        background: rgba(255, 215, 0, 0.08);
    }

    .nav-link.active::after {
        display: none;
    }

    .mobile-menu-toggle-secondary span {
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .mobile-menu-toggle-secondary.is-open span:nth-child(1) {
        transform: translateY(4px) rotate(45deg);
    }

    .mobile-menu-toggle-secondary.is-open span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-toggle-secondary.is-open span:nth-child(3) {
        transform: translateY(-4px) rotate(-45deg);
    }

    .mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 950;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0;
        min-height: var(--mobile-tabbar-height);
        padding: 0.22rem 0 max(0.22rem, env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid rgba(15, 23, 42, 0.12);
        border-right: none;
        border-bottom: none;
        border-left: none;
        border-radius: 0;
        box-shadow: 0 -1px 10px rgba(15, 23, 42, 0.08);
        backdrop-filter: saturate(150%) blur(18px);
    }

    .mobile-locale-switch {
        position: fixed;
        right: 0.78rem;
        bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom) + 0.36rem);
        z-index: 960;
        display: none;
        align-items: center;
        gap: 0.08rem;
        padding: 0.12rem;
        border-radius: 999px;
        border: 1px solid rgba(255, 215, 0, 0.25);
        background: rgba(7, 11, 20, 0.88);
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.34);
        backdrop-filter: blur(10px);
    }

    body.mobile-home-page .mobile-locale-switch {
        display: inline-flex;
    }

    .mobile-locale-option {
        min-width: 30px;
        min-height: 24px;
        height: 24px;
        padding: 0 0.35rem;
        border: 1px solid transparent;
        border-radius: 999px;
        background: transparent;
        color: rgba(226, 232, 240, 0.84);
        font-size: 0.72rem;
        font-weight: 700;
        line-height: 1;
        letter-spacing: 0.01em;
    }

    .mobile-locale-option.is-active {
        border-color: rgba(255, 215, 0, 0.48);
        background: rgba(255, 215, 0, 0.16);
        color: #ffd86a;
    }

    .mobile-bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.24rem;
        min-width: 0;
        min-height: 50px;
        padding: 0.32rem 0.2rem 0.24rem;
        border-radius: 0;
        color: #64748b;
        font-size: 0.64rem;
        font-weight: 760;
        line-height: 1.05;
        letter-spacing: 0.01em;
        text-decoration: none;
    }

    .mobile-bottom-nav-item.is-active {
        color: #1d4ed8;
        background: transparent;
        box-shadow: inset 0 2px 0 rgba(29, 78, 216, 0.92);
    }

    .mobile-bottom-nav-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
    }

    .mobile-bottom-nav-icon svg {
        width: 100%;
        height: 100%;
        stroke: currentColor;
        stroke-width: 1.85;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .mobile-bottom-nav-label {
        display: block;
        min-width: 0;
        text-align: center;
        white-space: normal;
    }

    body.mobile-menu-open {
        overflow: hidden;
    }
}

/* ===== 卡片网格响应式 ===== */
@media (max-width: 768px) {
    .card-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        padding: 0.5rem;
    }
    
    .card-item {
        width: 100%;
    }
    
    .card-item img {
        width: 100%;
        height: auto;
        max-height: 400px;
        object-fit: contain;
    }
}

/* ===== 构筑器布局移动端适配 ===== */
@media (max-width: 768px) {
    .deck-builder-container {
        flex-direction: column !important;
    }
    
    .deck-builder-sidebar {
        width: 100% !important;
        height: 50vh;
        order: 2;
    }
    
    .deck-builder-main {
        width: 100% !important;
        order: 1;
    }
}

/* ===== 本轮移动端从 0 大修：只作用于高优先级工具页，不触碰桌面断点 ===== */
@media (max-width: 768px) {
    body.mobile-tool-page {
        background: #f4f6fa !important;
        color: #111827;
    }

    body.mobile-tool-page .main-content {
        width: 100%;
        max-width: none;
        min-height: calc(100vh - var(--mobile-tabbar-space, 60px));
        padding: 0 0 var(--mobile-tabbar-space, 60px) !important;
        overflow-x: clip;
    }

    body.mobile-tool-page .mobile-bottom-nav {
        min-height: var(--mobile-tabbar-height, 60px);
        padding: 0.18rem 0 max(0.18rem, env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid rgba(15, 23, 42, 0.12);
        box-shadow: 0 -1px 10px rgba(15, 23, 42, 0.08);
        backdrop-filter: saturate(150%) blur(18px);
    }

    body.mobile-tool-page .mobile-bottom-nav-item {
        min-height: 50px;
        color: #64748b;
        font-size: 0.62rem;
    }

    body.mobile-tool-page .mobile-bottom-nav-item.is-active {
        color: #1d4ed8;
        box-shadow: inset 0 2px 0 rgba(29, 78, 216, 0.92);
    }
}

/* ===== 筛选器移动端适配 ===== */
@media (max-width: 768px) {
    .filter-container {
        display: none;
    }
    
    .filter-container.mobile-open {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 80vh;
        background: rgba(0, 0, 0, 0.95);
        backdrop-filter: blur(10px);
        z-index: 1000;
        padding: 1.5rem;
        border-radius: 1rem 1rem 0 0;
        overflow-y: auto;
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .mobile-filter-btn {
        display: flex !important;
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #ffd700, #ffaa00);
        color: #1a1a2e;
        border: none;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
        z-index: 999;
    }
    
    .filter-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .filter-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {
    .mobile-filter-btn {
        display: none !important;
    }
}

/* ===== 表格转卡片列表 ===== */
@media (max-width: 768px) {
    .data-table {
        display: none;
    }
    
    .mobile-card-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .mobile-card-item {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 215, 0, 0.2);
        border-radius: 8px;
        padding: 1rem;
    }
    
    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .mobile-card-row:last-child {
        border-bottom: none;
    }
    
    .mobile-card-label {
        color: #888;
        font-size: 0.875rem;
    }
    
    .mobile-card-value {
        color: #e0e0e0;
        font-weight: 500;
    }
}

@media (min-width: 769px) {
    .mobile-card-list {
        display: none;
    }
}

/* ===== 图片懒加载优化 ===== */
/* 懒加载图片样式 - 默认显示，加载完成后保持 */
img[loading="lazy"] {
    opacity: 1;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* ===== 触摸优化 ===== */
@media (hover: none) {
    .nav-link:hover,
    .btn:hover,
    .card-item:hover {
        transform: none;
    }
    
    .nav-link:active,
    .btn:active,
    .card-item:active {
        opacity: 0.8;
    }
}

/* ===== 通用移动端优化 ===== */
@media (max-width: 768px) {
    /* 减少内边距 */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* 调整标题大小 */
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    /* 调整段落 */
    p {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    /* 表单元素 */
    input, select, textarea {
        font-size: 16px; /* 防止 iOS 缩放 */
        padding: 0.75rem;
    }
    
    /* 滚动优化 */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== 本轮限定：移动端底部导航深色贴底视觉，不改变页面结构 ===== */
@media (max-width: 768px) {
    .mobile-bottom-nav,
    body.mobile-tool-page .mobile-bottom-nav {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        display: grid !important;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        width: 100vw;
        min-height: var(--mobile-tabbar-height, 60px);
        margin: 0 !important;
        padding: 0.2rem 0 max(0.2rem, env(safe-area-inset-bottom));
        border: 0;
        border-top: 1px solid rgba(255, 215, 106, 0.18);
        border-radius: 0 !important;
        background:
            linear-gradient(180deg, rgba(14, 21, 36, 0.98), rgba(6, 10, 19, 0.99));
        box-shadow: 0 -8px 26px rgba(0, 0, 0, 0.36);
        backdrop-filter: saturate(140%) blur(18px);
        transform: none !important;
    }

    .mobile-bottom-nav-item,
    body.mobile-tool-page .mobile-bottom-nav-item {
        min-width: 0;
        min-height: 50px;
        padding: 0.32rem 0.08rem 0.22rem;
        border-radius: 0 !important;
        color: #93a4c2;
        background: transparent !important;
        box-shadow: none;
        font-size: 0.66rem;
        font-weight: 760;
        line-height: 1.05;
        letter-spacing: 0;
        white-space: nowrap;
    }

    .mobile-bottom-nav-item.is-active,
    body.mobile-tool-page .mobile-bottom-nav-item.is-active {
        color: #ffd76a;
        box-shadow: inset 0 2px 0 rgba(255, 215, 106, 0.95);
    }

    .mobile-bottom-nav-icon {
        width: 22px;
        height: 22px;
    }

    .mobile-bottom-nav-label {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ===== 本轮限定：从 mobile 壳层移除 GA / 页面名 / 圆按钮 / 三横，不触碰桌面 ===== */
@media (max-width: 768px) {
    :root {
        --mobile-header-height: 0px;
        --mobile-topbar-offset: env(safe-area-inset-top);
    }

    .navbar,
    .mobile-nav-leading,
    .mobile-page-indicator,
    .mobile-nav-actions {
        display: none !important;
    }

    .nav-links.active {
        display: none !important;
    }

    .main-content,
    body.mobile-tool-page .main-content {
        padding-top: 0 !important;
    }

    body.mobile-tool-page {
        background: #0b1220 !important;
        color: #e8eefc;
    }

    body.mobile-tool-page .main-content {
        background: transparent;
    }

    .mobile-bottom-nav,
    body.mobile-tool-page .mobile-bottom-nav {
        background:
            linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(9, 14, 26, 0.995)) !important;
        border-top: 1px solid rgba(255, 215, 106, 0.16) !important;
        box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.34) !important;
    }

    .mobile-bottom-nav-item,
    body.mobile-tool-page .mobile-bottom-nav-item {
        color: #93a4c2 !important;
    }

    .mobile-bottom-nav-item.is-active,
    body.mobile-tool-page .mobile-bottom-nav-item.is-active {
        color: #ffd76a !important;
        box-shadow: inset 0 2px 0 rgba(255, 215, 106, 0.95) !important;
    }
}
