/* ==========================================================================
   站点外壳样式（Header + Sidebar + Content）
   仅作用于 <body class="md-shell"> 的页面，覆盖 app.css 中移动端窄栏布局
   ========================================================================== */

:root {
    --md-header-h: 56px;
    --md-side-w: 232px;
    --md-primary: #ff3f60;
    --md-primary-2: #ff6a3d;
    --md-bg: #252941;
    --md-bg-deep: #1c2036;
    --md-side-bg: #1f2338;
    --md-line: rgba(255, 255, 255, .07);
    --md-text: #e8e8f3;
    --md-text-dim: #9697ad;
    --md-z-header: 1200;
    --md-z-side: 1100;
    --md-z-scrim: 1090;
}

body.md-shell {
    background: var(--md-bg);
}

/* 内容区让位：顶部 Header 高度 + 桌面端左侧 Sidebar 宽度 */
body.md-shell .app-container {
    padding-top: var(--md-header-h);
}

body.md-shell .page-index {
    min-height: calc(100vh - var(--md-header-h));
    background-color: var(--md-bg);
}

/* ---------------------------- 顶部 Header ---------------------------- */
.md-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--md-header-h);
    z-index: var(--md-z-header);
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 12px;
    box-sizing: border-box;
    background: linear-gradient(180deg, rgba(28, 32, 54, .98), rgba(28, 32, 54, .92));
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--md-line);
    box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
}

.md-header__left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 0 1 auto;
}

.md-header__right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

/* 菜单按钮（仅窄屏：文字按钮，替代原三条杠图标） */
.md-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 11px;
    border: 1px solid var(--md-line);
    border-radius: 9px;
    background: rgba(255, 255, 255, .04);
    color: var(--md-text);
    font-size: 13px;
    line-height: 1;
    letter-spacing: .02em;
    cursor: pointer;
    flex: 0 0 auto;
    transition: color .18s ease, background .18s ease, border-color .18s ease;
}

.md-menu-btn__text {
    display: block;
    white-space: nowrap;
}

.md-menu-btn:hover,
.md-menu-btn:focus-visible {
    color: #fff;
    border-color: rgba(255, 63, 96, .58);
    background: rgba(255, 63, 96, .12);
}

.md-menu-btn[aria-expanded="true"] {
    color: #fff;
    border-color: var(--md-primary);
    background: rgba(255, 63, 96, .2);
}

.md-menu-btn:active {
    background: rgba(255, 255, 255, .1);
}

/* LOGO：白色底板保证浅底 LOGO 在暗色 Header 上清晰可见 */
.md-logo {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    text-decoration: none;
}

.md-logo__plate {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    height: 34px;
    padding: 3px 9px;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
    overflow: hidden;
}

.md-logo__img {
    display: block;
    height: 26px;
    width: auto;
    max-width: 148px;
    object-fit: contain;
}

/* Header 右侧按钮 */
.md-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 13px;
    border-radius: 999px;
    font-size: 13px;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition: background .2s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.md-btn--line {
    color: var(--md-text);
    border: 1px dashed rgba(255, 255, 255, .34);
    background: transparent;
}

.md-btn--line:hover,
.md-btn--line:focus-visible {
    color: #fff;
    border-color: var(--md-primary);
    background: rgba(255, 63, 96, .13);
}

.md-btn--primary {
    color: #fff;
    border: none;
    font-weight: 600;
    background: linear-gradient(135deg, var(--md-primary), var(--md-primary-2));
    box-shadow: 0 6px 16px rgba(255, 63, 96, .34);
}

.md-btn--primary:hover,
.md-btn--primary:focus-visible {
    background: linear-gradient(135deg, #ff5174, #ff7d52);
    box-shadow: 0 8px 22px rgba(255, 63, 96, .46);
    transform: translateY(-1px);
}

/* ---------------------- Header 右侧：登录态两套形态 ---------------------- */
.md-auth {
    display: flex;
    align-items: center;
    gap: 8px;
}

.md-auth[hidden],
.md-user[hidden] {
    display: none !important;
}

.md-user {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
}

.md-user__link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 32px;
    max-width: 168px;
    padding: 0 10px 0 4px;
    border-radius: 999px;
    color: var(--md-text);
    text-decoration: none;
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--md-line);
    transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.md-user__link:hover,
.md-user__link:focus-visible {
    color: #fff;
    border-color: rgba(255, 63, 96, .55);
    background: rgba(255, 63, 96, .12);
}

.md-user__avatar {
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    background: #2c3150;
    flex: 0 0 auto;
}

.md-user__name {
    min-width: 0;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    line-height: 1;
}

.md-user__caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--md-text-dim);
    cursor: pointer;
    transition: color .18s ease, background .18s ease;
}

.md-user__caret:hover,
.md-user__caret[aria-expanded="true"] {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.md-user__caret-ico {
    width: 7px;
    height: 7px;
    margin-top: -4px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform .2s ease;
}

.md-user__caret[aria-expanded="true"] .md-user__caret-ico {
    margin-top: 2px;
    transform: rotate(-135deg);
}

.md-user__menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 5;
    min-width: 148px;
    padding: 6px;
    border-radius: 12px;
    background: #23273d;
    border: 1px solid rgba(255, 255, 255, .09);
    box-shadow: 0 16px 34px rgba(0, 0, 0, .48);
}

.md-user__menu[hidden] {
    display: none !important;
}

.md-user__menu-item {
    display: block;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.2;
    color: var(--md-text);
    text-decoration: none;
    white-space: nowrap;
    transition: background .16s ease, color .16s ease;
}

.md-user__menu-item:hover,
.md-user__menu-item:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, .07);
}

.md-user__menu-item--out {
    color: #ff8fa2;
    border-top: 1px solid var(--md-line);
    margin-top: 4px;
    padding-top: 11px;
    border-radius: 0 0 8px 8px;
}

.md-user__menu-item--out:hover,
.md-user__menu-item--out:focus-visible {
    color: #fff;
    background: rgba(255, 63, 96, .2);
}

/* ---------------------------- 左侧 Sidebar ---------------------------- */
.md-sidebar {
    position: fixed;
    top: var(--md-header-h);
    left: 0;
    bottom: 0;
    width: var(--md-side-w);
    z-index: var(--md-z-side);
    box-sizing: border-box;
    background: linear-gradient(180deg, #1f2338 0%, #232741 100%);
    border-right: 1px solid var(--md-line);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.md-sidebar__inner {
    padding: 10px 10px 90px;
}

.md-sidebar__group + .md-sidebar__group {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--md-line);
}

.md-sidebar__title {
    margin: 6px 10px 8px;
    font-size: 11px;
    letter-spacing: .12em;
    color: var(--md-text-dim);
}

.md-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.md-nav__item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 12px 10px 14px;
    border-radius: 10px;
    color: var(--md-text);
    font-size: 14px;
    line-height: 1.3;
    text-decoration: none;
    transition: background .18s ease, color .18s ease;
}

.md-nav__item::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 50%;
    width: 3px;
    height: 0;
    border-radius: 3px;
    background: linear-gradient(180deg, var(--md-primary), var(--md-primary-2));
    transform: translateY(-50%);
    transition: height .2s ease;
}

.md-nav__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    flex: 0 0 auto;
    transition: background .18s ease, box-shadow .18s ease;
}

.md-nav__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-nav__item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.md-nav__item:hover .md-nav__dot {
    background: var(--md-primary);
}

.md-nav__item.is-active {
    background: rgba(255, 63, 96, .14);
    color: #fff;
    font-weight: 600;
}

.md-nav__item.is-active::before {
    height: 18px;
}

.md-nav__item.is-active .md-nav__dot {
    background: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(255, 63, 96, .22);
}

/* 遮罩层（窄屏抽屉用） */
.md-shell__scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--md-z-scrim);
    background: rgba(9, 11, 22, .58);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* ---------------------------- 窄屏：抽屉式 Sidebar ---------------------------- */
@media (max-width: 1023.98px) {
    .md-sidebar {
        width: min(82vw, 290px);
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4, 0, .2, 1);
        box-shadow: 0 0 40px rgba(0, 0, 0, .5);
    }

    html.md-drawer-open .md-sidebar {
        transform: translateX(0);
    }

    html.md-drawer-open .md-shell__scrim {
        display: block;
    }

    html.md-drawer-open,
    html.md-drawer-open body {
        overflow: hidden;
    }

    .md-btn {
        height: 30px;
        padding: 0 11px;
        font-size: 12px;
    }

    .md-logo__plate {
        height: 32px;
        padding: 3px 8px;
    }

    .md-logo__img {
        height: 24px;
        max-width: 116px;
    }
}

/* ---------------------------- 桌面端：固定侧栏 ---------------------------- */
@media (min-width: 1024px) {
    :root {
        --md-header-h: 64px;
    }

    .md-menu-btn {
        display: none;
    }

    .md-header {
        padding: 0 22px;
    }

    .md-header__right {
        gap: 10px;
    }

    .md-btn {
        height: 34px;
        padding: 0 16px;
        font-size: 13.5px;
    }

    .md-user__link {
        height: 34px;
        max-width: 190px;
    }

    .md-user__avatar {
        width: 28px;
        height: 28px;
    }

    .md-user__caret {
        height: 34px;
    }

    .md-logo__plate {
        height: 38px;
        padding: 4px 11px;
    }

    .md-logo__img {
        height: 30px;
        max-width: 190px;
    }

    /* 内容区铺满 Sidebar 右侧，取消 app.css 的 750px 居中限制 */
    body.md-shell .app-container {
        max-width: none;
        margin: 0;
        padding-left: var(--md-side-w);
        background-color: var(--md-bg);
    }

    body.md-shell .page-index,
    body.md-shell .page-play,
    body.md-shell .page-topic,
    body.md-shell .page-search,
    body.md-shell .page-personal {
        max-width: 1180px;
        margin: 0 auto;
    }

    /* 浮层跟随内容区，避免压到侧栏 */
    body.md-shell .notice-dialog,
    body.md-shell .ad-splash,
    body.md-shell .ad-dialog {
        left: var(--md-side-w);
        right: 0;
        width: auto;
        max-width: 1180px;
        margin: 0 auto;
    }

    body.md-shell .van-popup--bottom {
        left: var(--md-side-w) !important;
        right: 0 !important;
        max-width: none;
    }

    body.md-shell .van-tabbar,
    body.md-shell .index-tabbar {
        display: none !important;
    }

    .md-sidebar__inner {
        padding-bottom: 28px;
    }
}

/* ---------------------------- 大屏微调 ---------------------------- */
@media (min-width: 1440px) {
    :root {
        --md-side-w: 248px;
    }

    body.md-shell .page-index,
    body.md-shell .page-play,
    body.md-shell .page-topic,
    body.md-shell .page-search,
    body.md-shell .page-personal {
        max-width: 1280px;
    }
}

/* 手机窄屏：Header 三按钮与 LOGO 同步压缩，保证一行放得下不溢出 */
@media (max-width: 480px) {
    .md-header {
        padding: 0 10px;
        gap: 8px;
    }

    .md-header__left {
        gap: 8px;
    }

    .md-header__right {
        gap: 6px;
    }

    .md-menu-btn {
        height: 28px;
        padding: 0 9px;
        font-size: 11.5px;
    }

    /* 窄屏头像胶囊收窄：只留头像与下拉箭头 */
    .md-user__link {
        height: 28px;
        padding: 0 6px 0 3px;
    }

    .md-user__avatar {
        width: 22px;
        height: 22px;
    }

    .md-user__name {
        display: none;
    }

    .md-user__caret {
        height: 28px;
        width: 18px;
    }

    .md-logo__plate {
        height: 30px;
        padding: 3px 6px;
        border-radius: 8px;
    }

    .md-logo__img {
        height: 22px;
        max-width: 88px;
    }

    .md-btn {
        height: 28px;
        padding: 0 9px;
        font-size: 11.5px;
    }

    .md-btn--line {
        padding: 0 8px;
    }
}

/* 极窄屏：进一步压缩，仍保持三个按钮同时可见 */
@media (max-width: 359.98px) {
    .md-header {
        padding: 0 8px;
        gap: 6px;
    }

    .md-header__right {
        gap: 5px;
    }

    .md-btn {
        height: 26px;
        padding: 0 7px;
        font-size: 11px;
    }

    .md-menu-btn {
        height: 26px;
        padding: 0 7px;
        font-size: 11px;
    }

    .md-user__link {
        height: 26px;
    }

    .md-user__avatar {
        width: 20px;
        height: 20px;
    }

    .md-logo__img {
        height: 20px;
        max-width: 72px;
    }
}

/* 桌面端不需要遮罩 */
@media (min-width: 1024px) {
    .md-shell__scrim {
        display: none !important;
    }
}