/* ==================== 全站桌面窗口框架 ==================== */
/* 桌面端把整站收进一个居中的圆角窗口，内容在窗口内滚动；手机端保持全屏。 */
@media (min-width: 960px) {
  html, body { height: 100%; }

  body {
    --frame-margin: max(24px, calc((100vw - 1320px) / 2));
    --frame-pad-y: 20px;
    margin: 0;
    padding: 20px 24px;
    overflow: hidden;
    background:
      radial-gradient(900px 620px at 8% -8%, rgba(var(--mdui-color-primary), .10), transparent 62%),
      radial-gradient(820px 560px at 102% 108%, rgba(var(--mdui-color-tertiary), .075), transparent 58%),
      rgb(var(--mdui-color-surface-container));
  }

  .app-frame {
    width: 100%;
    max-width: 1320px !important;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    min-height: 0 !important;
    margin: 0 auto;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .62);
    border-radius: 24px;
    overflow: hidden;
    background: rgb(var(--mdui-color-surface));
    box-shadow:
      0 1px 2px rgba(0, 0, 0, .04),
      0 18px 54px rgba(0, 0, 0, .11),
      0 0 0 1px rgba(255, 255, 255, .035) inset;
  }

  /* 左侧栏贴住窗口，不再按视口高度固定 */
  .app-desktop-rail {
    position: relative;
    top: auto;
    height: 100%;
    min-height: 0;
    align-self: stretch;
    overflow: auto;
    background: rgba(var(--mdui-color-surface-container-low), .94);
    border-radius: 24px 0 0 24px;
  }

  /* 顶栏留在窗口第一行 */
  .app-topbar {
    position: relative;
    top: auto;
    overflow: hidden;
    border-radius: 0 24px 0 0;
  }

  /* 内容区独立滚动，窗口本身不动 */
  body[class] .app-main,
  body[class] .app-main.has-tabs {
    min-height: 0 !important;
    height: auto;
    margin: 0 !important;
    padding: 12px 36px 44px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--mdui-color-outline), .28) transparent;
  }
  .app-main::-webkit-scrollbar { width: 8px; height: 8px; }
  .app-main::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(var(--mdui-color-outline), .24);
  }
  .app-main::-webkit-scrollbar-track { background: transparent; }

  /* 右侧社区栏不要超出窗口可视高度 */
  .forum-rail {
    top: 12px;
    max-height: calc(100% - 24px);
  }

  /* 首页固定的“写帖子”按钮跟着窗口右上角走 */
  body:is(.page-home, .page-category, .page-search, .page-tags) .rail-compose {
    top: 32px !important;
    right: calc((100vw - min(1320px, 100vw - 48px)) / 2 + 36px) !important;
  }

  /* 帖子底部回复栏固定在窗口内，不压到左侧栏和窗口边框 */
  body.page-post .app-reply-bar {
    left: calc(var(--frame-margin) + 268px) !important;
    right: calc(var(--frame-margin) + 36px) !important;
    bottom: var(--frame-pad-y) !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
  }
  @media (min-width: 1280px) {
    body.page-post .app-main.has-forum-rail .app-reply-bar {
      right: calc(var(--frame-margin) + 340px) !important;
    }
  }

  /* 回顶按钮跟着窗口右下角走，不飘到窗口外 */
  .forum-top-btn {
    right: max(32px, calc((100vw - 1320px) / 2 + 18px));
    bottom: 34px;
  }

  /* 消息页保持窗口内满高 */
  body.page-messages .page-content {
    height: 100% !important;
    min-height: 0 !important;
  }

  /* 登录 / 注册 / 找回：窗口里居中一张卡片 */
  body:is(.page-login, .page-register, .page-forgot) .app-frame {
    display: block !important;
    max-width: 1320px !important;
    background: rgb(var(--mdui-color-surface-container-low)) !important;
  }
  body:is(.page-login, .page-register, .page-forgot) .app-topbar {
    width: 100% !important;
  }
  body:is(.page-login, .page-register, .page-forgot) .app-main {
    width: 100% !important;
    max-width: 560px !important;
    height: calc(100% - 64px) !important;
    margin: 0 auto !important;
    padding: 48px 20px 32px !important;
    overflow-y: auto;
  }
}

/* 窗口圆角在小屏上收一点，避免太像悬浮卡片 */
@media (min-width: 960px) and (max-width: 1199px) {
  body { padding: 12px; --frame-margin: 12px; --frame-pad-y: 12px; }
  .app-frame { height: calc(100vh - 24px); height: calc(100dvh - 24px); border-radius: 18px; }
  .app-desktop-rail { border-radius: 18px 0 0 18px; }
  .app-topbar { border-radius: 0 18px 0 0; }
  body:is(.page-home, .page-category, .page-search, .page-tags) .rail-compose {
    top: 24px !important;
    right: calc((100vw - min(1320px, 100vw - 24px)) / 2 + 36px) !important;
  }
}
