/* =====================================================================
 * friends.css - 友情链接卡片 Joe 风格
 *
 * 设计要点（参照截图）：
 *   1. 整张卡片一个大色渐变（按站点哈希自动分配 0~8 共 9 种主色，保证每张友链不同）
 *   2. 左上：站点名（白色加粗，超长单行省略）
 *   3. 紧贴站点名右侧：响应时间药丸（半透明白底绿字，小圆角）
 *   4. 中部：站点简介（白色 + 半透明、最多 2 行省略）
 *   5. 右下：圆形头像（白色描边）
 *   6. hover：轻微抬起 + 加深阴影，强化交互反馈
 *
 * 暗色模式：玻璃卡背景更暗时，本卡片样式仍以饱和渐变为主，背景对比度足够，
 * 不需要逐色调暗处理——保证了 Joe「明亮、强对比」的核心观感。
 * ===================================================================== */

/* ---------- 容器：3 列响应式网格 ---------- */
.friendship-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 1rem;
}

/* ---------- 卡片主体 ---------- */
.friendship-card {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 132px;
    padding: 16px 18px 18px;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: #fff;
    background: linear-gradient(135deg, #ee9ca7 0%, #ffdde1 100%);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    transition: transform .28s ease, box-shadow .28s ease, filter .28s ease;
    isolation: isolate;          /* 防止渐变之外的子元素色值泄露 */
}

.friendship-card::before {
    /* 顶部高光：Joe 风卡片的轻量景深感；
       不用 ::after，避免与暗色 mask 抢层叠顺序 */
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 60% at 0% 0%, rgba(255, 255, 255, 0.18), transparent 60%);
    pointer-events: none;
    z-index: -1;
}

.friendship-card:hover,
.friendship-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
    filter: saturate(1.05);
    outline: none;
}

.friendship-card:active {
    transform: translateY(-1px) scale(.99);
}

/* ---------- 9 种色彩主题（由 PHP 写入 data-tone 选择） ---------- */
.friendship-card[data-tone="0"] { background: linear-gradient(135deg, #ff5e62 0%, #ff9966 100%); }   /* 橘红 */
.friendship-card[data-tone="1"] { background: linear-gradient(135deg, #654ea3 0%, #eaafc8 100%); }   /* 紫粉 */
.friendship-card[data-tone="2"] { background: linear-gradient(135deg, #2193b0 0%, #6dd5ed 100%); }   /* 青蓝 */
.friendship-card[data-tone="3"] { background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%); }   /* 橙黄 */
.friendship-card[data-tone="4"] { background: linear-gradient(135deg, #ee9ca7 0%, #ffdde1 100%); }   /* 桃粉 */
.friendship-card[data-tone="5"] { background: linear-gradient(135deg, #373b44 0%, #4286f4 100%); }   /* 深蓝 */
.friendship-card[data-tone="6"] { background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%); }   /* 红橙 */
.friendship-card[data-tone="7"] { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); }   /* 碧绿 */
.friendship-card[data-tone="8"] { background: linear-gradient(135deg, #8e2de2 0%, #4a00e0 100%); }   /* 暗紫 */

/* ---------- 顶部：站点名 + 响应时间药丸 ---------- */
.friendship-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;          /* 防止 flex 子项拒绝收缩 */
}

.friendship-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .12);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friendship-ping {
    /* 默认状态下：测速未完成时显示「--」；完成后由 JS 写入形如「791ms」 */
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .22);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
    font-weight: 500;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background-color .28s ease, color .28s ease;
}

/* 测速完成且数值小于 1000ms：绿色（图中绿色药丸） */
.friendship-ping[data-state="ok"] {
    background: #22c55e;
    color: #fff;
}
/* 测速完成但数值 ≥ 1000ms：橙红警示 */
.friendship-ping[data-state="slow"] {
    background: rgba(255, 87, 34, .92);
    color: #fff;
}
/* 测速失败（CORS/网络/超时）：暗灰低调显示，避免破坏卡片视觉 */
.friendship-ping[data-state="fail"] {
    background: rgba(0, 0, 0, .22);
    color: rgba(255, 255, 255, .85);
}

/* ---------- 描述（中部，最多 2 行省略） ---------- */
.friendship-desc {
    margin: 8px 0 0;
    font-size: 13.5px;
    line-height: 1.55;
    color: rgba(255, 255, 255, .92);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

/* ---------- 头像（右下，悬浮于卡片渐变之上） ---------- */
.friendship-avatar {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
    transition: transform .28s ease;
}

.friendship-card:hover .friendship-avatar {
    transform: scale(1.06) rotate(-3deg);
}

.friendship-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.friendship-avatar-fallback {
    /* 头像图加载失败 / 未配置图片时显示的占位字母 */
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

/* ---------- 描述留白微调：让右下头像与文字不挤 ---------- */
.friendship-desc {
    padding-right: 50px;     /* 给右下头像预留空间 */
}

.friendship-desc:empty,
.friendship-desc.is-empty {
    display: none;
}

/* 升级：当用户没填简介时，把头像再下移一点点作为视觉点缀。
   用 is-empty-card 显式类标记（由 PHP 渲染时根据 desc 是否为空输出），
   避免依赖 :has 选择器嵌套带来的跨浏览器差异。 */
.friendship-card.is-empty-card .friendship-avatar {
    bottom: 18px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
    .friendship-grid {
        gap: 10px;
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
    .friendship-card {
        min-height: 116px;
        padding: 14px 16px 16px;
    }
    .friendship-avatar {
        width: 38px;
        height: 38px;
        right: 12px;
        bottom: 12px;
    }
}

/* ---------- 暗色模式：保持原始观感，只调整药丸可读性 ---------- */
html.dark .friendship-ping {
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

/* =====================================================================
 * 公共场景变体 —— 页脚友联区（紧凑矮卡版：不吃响应时间药丸 / 头像与站点名同排 / 简介展开时铺满整卡
 * 名称行淡出让位 / PC 6 列 移动 2 列自适应）
 *
 * 通过 #friendship-links 选择器把页脚场景与友联专页区分：
 *   - 友联专页（friends.php）渲染 .friendship-grid 但不带 id：完整大卡 + 右下角头像 + 常显描述
 *   - 页脚（public/footer.php）渲染 .friendship-grid + id="friendship-links"：头像移入名称行（见 footer.php 结构），走下面的紧凑样式
 * ===================================================================== */

/* ---------- 0) 兜底：移除非预期的药丸残留（footer.php 已不渲染，这里防御） ---------- */
#friendship-links .friendship-ping { display: none !important; }

/* ---------- 1) 简介：毛玻璃面板（展开时铺满整卡，站点名与头像淡出让位） ---------- */
#friendship-links .friendship-desc {
    position: absolute;
    inset: 0;                       /* 铺满整卡：展开时整卡变身毛玻璃面板（矮卡无法容纳“贴底浮层”，面板必须覆盖全卡） */
    margin: 0;
    padding: 6px 14px;              /* 两侧留白；站点名与头像随 head 淡出让位，不再需要右侧躲头像 */
    display: -webkit-box;
    -webkit-line-clamp: 2;          /* 旧语法（兼容老浏览器） */
    line-clamp: 2;                  /* 新标准语法（Chrome 120+/Safari 等都支持） */
    -webkit-box-orient: vertical;
    -webkit-box-pack: center;       /* 两行文字在面板内垂直居中 */
    overflow: hidden;
    text-overflow: ellipsis;
    /* 毛玻璃：半透明白底 + 背景模糊，透过它可见卡片渐变被柔化 */
    background: rgba(255, 255, 255, .5);
    -webkit-backdrop-filter: blur(12px) saturate(1.25);
    backdrop-filter: blur(12px) saturate(1.25);
    color: #1f2937;
    border-radius: 12px;            /* 铺满整卡：圆角跟随卡片 */
    font-size: 12px;
    line-height: 1.45;
    /* 进出场动画（整体淡入） */
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity .22s ease, transform .22s ease, visibility .22s;
    z-index: 5;
}

/* 暗色模式：毛玻璃改用深色半透明，文字转亮，保持同样的通透模糊质感 */
html.dark #friendship-links .friendship-desc {
    background: rgba(17, 24, 39, .5);
    color: #f3f4f6;
}
/* 名称行（站点名+头像）：默认可见，面板展开时淡出让位（避免两行简介文字与其互相遮挡） */
#friendship-links .friendship-head {
    position: relative;
    transition: opacity .22s ease;
}
/* 桌面：仅 hover 时弹出（触屏不触发 :hover，避免「悬浮残留」） */
@media (hover: hover) and (pointer: fine) {
    #friendship-links .friendship-card:hover .friendship-desc:not(.is-empty) {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    #friendship-links .friendship-card:hover:not(.is-empty-card) .friendship-head {
        opacity: 0;
    }
}
/* 触屏：仅由 JS 切换 .is-expanded 控制 */
#friendship-links .friendship-card.is-expanded .friendship-desc:not(.is-empty) {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
#friendship-links .friendship-card.is-expanded:not(.is-empty-card) .friendship-head {
    opacity: 0;
}

/* ---------- 2) 布局与高度：头像并入名称行（同排垂直居中），卡片只剩一行 → 高度大幅压缩 ---------- */
#friendship-links .friendship-avatar {
    position: static;               /* 全局样式默认右下角 absolute，页脚场景改为行内排布 */
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

#friendship-links .friendship-card {
    min-height: 64px;               /* 头像行(36px) + 上下 padding(12+14px) ≈ 62px */
    padding: 12px 14px 14px;
}
/* 空简介卡片：头像同样在名称行内（position:static 时全局 bottom 偏移规则自动失效，无需覆盖） */

/* ---------- 3) 响应式：手机 2 / sm 3 / md 4 / PC 6 ---------- */
#friendship-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 0.5rem;
}
@media (min-width: 640px) {
    #friendship-links {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
    }
}
@media (min-width: 768px) {
    #friendship-links {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
@media (min-width: 1024px) {
    #friendship-links {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 14px;
    }
}

/* ---------- 4) 手机端：再紧凑一档（卡片压到一行 56px，头像 30px） ---------- */
@media (max-width: 640px) {
    #friendship-links .friendship-card {
        min-height: 56px;           /* 头像行(30px) + 上下 padding(20px) ≈ 50px */
        padding: 10px 12px;
    }
    #friendship-links .friendship-avatar {
        width: 30px;
        height: 30px;
    }
    #friendship-links .friendship-name {
        font-size: 0.875rem;
    }
    /* 简介面板与 PC 同构（铺满整卡 + 两行垂直居中），无需单独覆盖 */
}

/* =====================================================================
 * 申请友链入口（文章内容与卡片网格之间的居中按钮，点击打开申请弹窗）
 *
 * 主题色实底药丸：var(--theme) 跟随主题色，白字 + 轻投影，
 * hover 微抬 + 提亮，与前台主按钮观感一致；宽度由文字自适应，移动端不撑满。
 * ===================================================================== */
.friendship-apply-bar {
    display: flex;
    justify-content: center;
    margin: 0 0 2px;
}

.friendship-apply-entry {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 28px;
    border: none;
    border-radius: 999px;
    background: var(--theme, #3b82f6);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--theme, #3b82f6) 35%, transparent);
    transition: transform .22s ease, box-shadow .22s ease, filter .22s ease;
}

.friendship-apply-entry i {
    font-size: 12px;
}

.friendship-apply-entry:hover,
.friendship-apply-entry:focus-visible {
    transform: translateY(-2px);
    filter: brightness(1.08);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--theme, #3b82f6) 45%, transparent);
    outline: none;
}

.friendship-apply-entry:active {
    transform: translateY(0);
    filter: brightness(.97);
}

/* 无友链（空态提示）时入口按钮与提示文字拉开间距 */
.friendship-apply-bar + .text-center,
.friendship-apply-bar ~ .friendship-grid {
    margin-top: 14px;
}

/* 弹窗「提交申请」按钮：居中 + 宽度由文字自适应（PC/移动一致，不再撑满弹窗） */
.friendship-apply-submit {
    display: flex;
    width: fit-content;
    margin: 0 auto;
    padding: 8px 44px;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition: filter .22s ease, transform .22s ease, box-shadow .22s ease;
    box-shadow: 0 4px 14px rgba(59, 130, 246, .30);
}

.friendship-apply-submit:hover,
.friendship-apply-submit:focus-visible {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(59, 130, 246, .40);
    outline: none;
}

.friendship-apply-submit:disabled {
    opacity: .6;
    cursor: not-allowed;
    transform: none;
}

html.dark .friendship-apply-submit {
    box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}

html.dark .friendship-apply-entry {
    box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}

